Package org.apache.curator.test
Class TestingCluster
java.lang.Object
org.apache.curator.test.TestingCluster
- All Implemented Interfaces:
Closeable
,AutoCloseable
manages an internally running ensemble of ZooKeeper servers. FOR TESTING PURPOSES ONLY
-
Constructor Summary
ConstructorDescriptionTestingCluster
(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
Modifier and TypeMethodDescriptionvoid
close()
Shutdown the ensemble, free resources, etc.findConnectionInstance
(org.apache.zookeeper.ZooKeeper client) Given a ZooKeeper instance, returns which server it is connected toReturns the connection string to pass to the ZooKeeper constructorReturns the set of servers in the ensembleboolean
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 Details
-
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
Creates an ensemble using the given server specs- Parameters:
specs
- the server specs
-
TestingCluster
Creates an ensemble using the given server specs- Parameters:
specs
- the server specs
-
TestingCluster
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 Details
-
getInstances
Returns the set of servers in the ensemble- Returns:
- set of servers
-
getServers
-
getConnectString
Returns the connection string to pass to the ZooKeeper constructor- Returns:
- connection string
-
start
Start the ensemble. The cluster must be started before use.- Throws:
Exception
- errors
-
stop
Shutdown the ensemble WITHOUT freeing resources, etc.- Throws:
IOException
-
close
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
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
Restart the given server of the cluster- Parameters:
instance
- server instance- Returns:
- true of the server was found
- Throws:
Exception
- errors
-
findConnectionInstance
Given a ZooKeeper instance, returns which server it is connected to- Parameters:
client
- ZK instance- Returns:
- the server
- Throws:
Exception
- errors
-
makeSpecs
-
makeSpecs
public static Map<InstanceSpec,Collection<InstanceSpec>> makeSpecs(int instanceQty, boolean resetServerIds)
-