Package org.apache.curator.test
Class TestingCluster
- java.lang.Object
-
- org.apache.curator.test.TestingCluster
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class TestingCluster extends Object implements Closeable
manages an internally running ensemble of ZooKeeper servers. FOR TESTING PURPOSES ONLY
-
-
Constructor Summary
Constructors Constructor Description TestingCluster(int instanceQty)
Creates an ensemble comprised ofn
servers.TestingCluster(Collection<InstanceSpec> specs)
Creates an ensemble using the given server specsTestingCluster(Map<InstanceSpec,Collection<InstanceSpec>> specs)
Creates an ensemble using the given server specsTestingCluster(InstanceSpec... specs)
Creates an ensemble using the given server specs
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Shutdown the ensemble, free resources, etc.InstanceSpec
findConnectionInstance(org.apache.zookeeper.ZooKeeper client)
Given a ZooKeeper instance, returns which server it is connected toString
getConnectString()
Returns the connection string to pass to the ZooKeeper constructorCollection<InstanceSpec>
getInstances()
Returns the set of servers in the ensembleList<TestingZooKeeperServer>
getServers()
boolean
killServer(InstanceSpec instance)
Kills the given server.static Map<InstanceSpec,Collection<InstanceSpec>>
makeSpecs(int instanceQty)
static Map<InstanceSpec,Collection<InstanceSpec>>
makeSpecs(int instanceQty, boolean resetServerIds)
boolean
restartServer(InstanceSpec instance)
Restart the given server of the clustervoid
start()
Start the ensemble.void
stop()
Shutdown the ensemble WITHOUT freeing resources, etc.
-
-
-
Constructor Detail
-
TestingCluster
public TestingCluster(int instanceQty)
Creates an ensemble comprised ofn
servers. Each server will use a temp directory and random ports- Parameters:
instanceQty
- number of servers to create in the ensemble
-
TestingCluster
public TestingCluster(InstanceSpec... specs)
Creates an ensemble using the given server specs- Parameters:
specs
- the server specs
-
TestingCluster
public TestingCluster(Collection<InstanceSpec> specs)
Creates an ensemble using the given server specs- Parameters:
specs
- the server specs
-
TestingCluster
public TestingCluster(Map<InstanceSpec,Collection<InstanceSpec>> specs)
Creates an ensemble using the given server specs- Parameters:
specs
- map of an instance spec to its set of quorum instances. Allows simulation of an ensemble with instances having different config peers
-
-
Method Detail
-
getInstances
public Collection<InstanceSpec> getInstances()
Returns the set of servers in the ensemble- Returns:
- set of servers
-
getServers
public List<TestingZooKeeperServer> getServers()
-
getConnectString
public String getConnectString()
Returns the connection string to pass to the ZooKeeper constructor- Returns:
- connection string
-
start
public void start() throws Exception
Start the ensemble. The cluster must be started before use.- Throws:
Exception
- errors
-
stop
public void stop() throws IOException
Shutdown the ensemble WITHOUT freeing resources, etc.- Throws:
IOException
-
close
public void close() throws IOException
Shutdown the ensemble, free resources, etc. If temp directories were used, they are deleted. You should call this in afinally
block.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- errors
-
killServer
public boolean killServer(InstanceSpec instance) throws Exception
Kills the given server. This simulates the server unexpectedly crashing- Parameters:
instance
- server to kill- Returns:
- true if the instance was found
- Throws:
Exception
- errors
-
restartServer
public boolean restartServer(InstanceSpec instance) throws Exception
Restart the given server of the cluster- Parameters:
instance
- server instance- Returns:
- true of the server was found
- Throws:
Exception
- errors
-
findConnectionInstance
public InstanceSpec findConnectionInstance(org.apache.zookeeper.ZooKeeper client) throws Exception
Given a ZooKeeper instance, returns which server it is connected to- Parameters:
client
- ZK instance- Returns:
- the server
- Throws:
Exception
- errors
-
makeSpecs
public static Map<InstanceSpec,Collection<InstanceSpec>> makeSpecs(int instanceQty)
-
makeSpecs
public static Map<InstanceSpec,Collection<InstanceSpec>> makeSpecs(int instanceQty, boolean resetServerIds)
-
-