com.twitter.common.zookeeper.testing
Class BaseZooKeeperTest

java.lang.Object
  extended by com.google.common.testing.junit4.TearDownTestCase
      extended by com.twitter.common.zookeeper.testing.BaseZooKeeperTest
All Implemented Interfaces:
com.google.common.testing.TearDownAccepter

public abstract class BaseZooKeeperTest
extends com.google.common.testing.junit4.TearDownTestCase

A baseclass for in-process zookeeper tests. Uses ZooKeeperTestHelper to start the server and create clients: new tests should directly use that helper class instead of extending this class.


Constructor Summary
BaseZooKeeperTest()
          Creates a test case where the test server uses its ZooKeeperTestServer.DEFAULT_SESSION_TIMEOUT for clients created without an explicit session timeout.
BaseZooKeeperTest(Amount<Integer,Time> defaultSessionTimeout)
          Creates a test case where the test server uses the given defaultSessionTimeout for clients created without an explicit session timeout.
 
Method Summary
protected  ZooKeeperClient createZkClient()
          Returns a new unauthenticated zookeeper client connected to the in-process zookeeper server with the default session timeout.
protected  ZooKeeperClient createZkClient(Amount<Integer,Time> sessionTimeout)
          Returns a new unauthenticated zookeeper client connected to the in-process zookeeper server with a custom sessionTimeout.
protected  ZooKeeperClient createZkClient(Amount<Integer,Time> sessionTimeout, ZooKeeperClient.Credentials credentials)
          Returns a new authenticated zookeeper client connected to the in-process zookeeper server with a custom sessionTimeout.
protected  ZooKeeperClient createZkClient(String username, String password)
          Returns a new authenticated zookeeper client connected to the in-process zookeeper server with the default session timeout.
protected  ZooKeeperClient createZkClient(ZooKeeperClient.Credentials credentials)
          Returns a new authenticated zookeeper client connected to the in-process zookeeper server with the default session timeout.
protected  void expireSession(ZooKeeperClient zkClient)
          Expires the active session for the given client.
protected  int getPort()
          Returns the current port to connect to the in-process zookeeper instance.
protected  void restartNetwork()
          Starts zookeeper back up on the last used port.
 void setUp()
           
protected  void shutdownNetwork()
          Shuts down the in-process zookeeper network server.
 
Methods inherited from class com.google.common.testing.junit4.TearDownTestCase
addTearDown, tearDown
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseZooKeeperTest

public BaseZooKeeperTest()
Creates a test case where the test server uses its ZooKeeperTestServer.DEFAULT_SESSION_TIMEOUT for clients created without an explicit session timeout.


BaseZooKeeperTest

public BaseZooKeeperTest(Amount<Integer,Time> defaultSessionTimeout)
Creates a test case where the test server uses the given defaultSessionTimeout for clients created without an explicit session timeout.

Method Detail

setUp

public final void setUp()
                 throws Exception
Throws:
Exception

restartNetwork

protected final void restartNetwork()
                             throws IOException,
                                    InterruptedException
Starts zookeeper back up on the last used port.

Throws:
IOException
InterruptedException

shutdownNetwork

protected final void shutdownNetwork()
Shuts down the in-process zookeeper network server.


expireSession

protected final void expireSession(ZooKeeperClient zkClient)
                            throws ZooKeeperClient.ZooKeeperConnectionException,
                                   InterruptedException
Expires the active session for the given client. The client should be one returned from createZkClient().

Parameters:
zkClient - the client to expire
Throws:
ZooKeeperClient.ZooKeeperConnectionException - if a problem is encountered connecting to the local zk server while trying to expire the session
InterruptedException - if interrupted while requesting expiration

getPort

protected final int getPort()
Returns the current port to connect to the in-process zookeeper instance.


createZkClient

protected final ZooKeeperClient createZkClient()
Returns a new unauthenticated zookeeper client connected to the in-process zookeeper server with the default session timeout.


createZkClient

protected final ZooKeeperClient createZkClient(ZooKeeperClient.Credentials credentials)
Returns a new authenticated zookeeper client connected to the in-process zookeeper server with the default session timeout.


createZkClient

protected final ZooKeeperClient createZkClient(String username,
                                               String password)
Returns a new authenticated zookeeper client connected to the in-process zookeeper server with the default session timeout. The client is authenticated in the digest authentication scheme with the given username and password.


createZkClient

protected final ZooKeeperClient createZkClient(Amount<Integer,Time> sessionTimeout)
Returns a new unauthenticated zookeeper client connected to the in-process zookeeper server with a custom sessionTimeout.


createZkClient

protected final ZooKeeperClient createZkClient(Amount<Integer,Time> sessionTimeout,
                                               ZooKeeperClient.Credentials credentials)
Returns a new authenticated zookeeper client connected to the in-process zookeeper server with a custom sessionTimeout.