public class TestingCluster
extends java.lang.Object
implements java.io.Closeable
Constructor and Description |
---|
TestingCluster(java.util.Collection<InstanceSpec> specs)
Creates an ensemble using the given server specs
|
TestingCluster(InstanceSpec... specs)
Creates an ensemble using the given server specs
|
TestingCluster(int instanceQty)
Creates an ensemble comprised of
n servers. |
Modifier and Type | Method and 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 to
|
java.lang.String |
getConnectString()
Returns the connection string to pass to the ZooKeeper constructor
|
java.util.Collection<InstanceSpec> |
getInstances()
Returns the set of servers in the ensemble
|
boolean |
killServer(InstanceSpec instance)
Kills the given server.
|
boolean |
restartServer(InstanceSpec instance)
Restart the given server of the cluster
|
void |
start()
Start the ensemble.
|
void |
stop()
Shutdown the ensemble WITHOUT freeing resources, etc.
|
public TestingCluster(int instanceQty)
n
servers. Each server will use
a temp directory and random portsinstanceQty
- number of servers to create in the ensemblepublic TestingCluster(InstanceSpec... specs)
specs
- the server specspublic TestingCluster(java.util.Collection<InstanceSpec> specs)
specs
- the server specspublic java.util.Collection<InstanceSpec> getInstances()
public java.lang.String getConnectString()
public void start() throws java.lang.Exception
java.lang.Exception
- errorspublic void stop() throws java.io.IOException
java.io.IOException
public void close() throws java.io.IOException
finally
block.close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
- errorspublic boolean killServer(InstanceSpec instance) throws java.lang.Exception
instance
- server to killjava.lang.Exception
- errorspublic boolean restartServer(InstanceSpec instance) throws java.lang.Exception
instance
- server instancejava.lang.Exception
- errorspublic InstanceSpec findConnectionInstance(org.apache.zookeeper.ZooKeeper client) throws java.lang.Exception
client
- ZK instancejava.lang.Exception
- errors