org.apache.curator.test
Class TestingCluster

java.lang.Object
  extended by org.apache.curator.test.TestingCluster
All Implemented Interfaces:
Closeable

public class TestingCluster
extends Object
implements Closeable

manages an internally running ensemble of ZooKeeper servers. FOR TESTING PURPOSES ONLY


Constructor Summary
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
 
Method Summary
 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.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TestingCluster

public TestingCluster(int instanceQty)
Creates an ensemble comprised of n 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 a finally block.

Specified by:
close in interface Closeable
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


Copyright © 2011–2014 The Apache Software Foundation. All rights reserved.