public class TestingCluster extends Object implements Closeable
Constructor and Description |
---|
TestingCluster(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. |
TestingCluster(Map<InstanceSpec,Collection<InstanceSpec>> specs)
Creates an ensemble using the given server specs
|
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
|
String |
getConnectString()
Returns the connection string to pass to the ZooKeeper constructor
|
Collection<InstanceSpec> |
getInstances()
Returns the set of servers in the ensemble
|
List<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 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(Collection<InstanceSpec> specs)
specs
- the server specspublic TestingCluster(Map<InstanceSpec,Collection<InstanceSpec>> specs)
specs
- map of an instance spec to its set of quorum instances. Allows simulation of an ensemble with instances
having different config peerspublic Collection<InstanceSpec> getInstances()
public List<TestingZooKeeperServer> getServers()
public String getConnectString()
public void start() throws Exception
Exception
- errorspublic void stop() throws IOException
IOException
public void close() throws IOException
finally
block.close
in interface Closeable
close
in interface AutoCloseable
IOException
- errorspublic boolean killServer(InstanceSpec instance) throws Exception
instance
- server to killException
- errorspublic boolean restartServer(InstanceSpec instance) throws Exception
instance
- server instanceException
- errorspublic InstanceSpec findConnectionInstance(org.apache.zookeeper.ZooKeeper client) throws Exception
client
- ZK instanceException
- errorspublic static Map<InstanceSpec,Collection<InstanceSpec>> makeSpecs(int instanceQty)
public static Map<InstanceSpec,Collection<InstanceSpec>> makeSpecs(int instanceQty, boolean resetServerIds)
Copyright © 2011–2023 The Apache Software Foundation. All rights reserved.