Class TestingServer

java.lang.Object
org.apache.curator.test.TestingServer
All Implemented Interfaces:
Closeable, AutoCloseable

public class TestingServer extends Object implements Closeable
manages an internally running ZooKeeper server. FOR TESTING PURPOSES ONLY
  • Constructor Details

    • TestingServer

      public TestingServer() throws Exception
      Create the server using a random port
      Throws:
      Exception - errors
    • TestingServer

      public TestingServer(boolean start) throws Exception
      Create the server using a random port
      Parameters:
      start - True if the server should be started, false otherwise
      Throws:
      Exception - errors
    • TestingServer

      public TestingServer(int port) throws Exception
      Create and start the server using the given port
      Parameters:
      port - the port
      Throws:
      Exception - errors
    • TestingServer

      public TestingServer(int port, boolean start) throws Exception
      Create the server using the given port
      Parameters:
      port - the port
      start - True if the server should be started, false otherwise
      Throws:
      Exception - errors
    • TestingServer

      public TestingServer(int port, File tempDirectory) throws Exception
      Create and start the server using the given port
      Parameters:
      port - the port
      tempDirectory - directory to use
      Throws:
      Exception - errors
    • TestingServer

      public TestingServer(int port, File tempDirectory, boolean start) throws Exception
      Create the server using the given port
      Parameters:
      port - the port
      tempDirectory - directory to use
      start - True if the server should be started, false otherwise
      Throws:
      Exception - errors
    • TestingServer

      public TestingServer(InstanceSpec spec, boolean start) throws Exception
      Create the server using the given port
      Parameters:
      spec - instance details
      start - True if the server should be started, false otherwise
      Throws:
      Exception - errors
  • Method Details

    • getPort

      public int getPort()
      Return the port being used or will be used.
      Returns:
      port
      Throws:
      IllegalStateException - if server is configured to bind to port 0 but not started
    • getTempDirectory

      public File getTempDirectory()
      Returns the temp directory being used
      Returns:
      directory
    • start

      public void start() throws Exception
      Start the server
      Throws:
      Exception
    • stop

      public void stop() throws IOException
      Stop the server without deleting the temp directory
      Throws:
      IOException
    • restart

      public void restart() throws Exception
      Restart the server. If the server is currently running it will be stopped and restarted. If it's not currently running then it will be started. If it has been closed (had close() called on it) then an exception will be thrown.
      Throws:
      Exception
    • close

      public void close() throws IOException
      Close the server and any open clients and delete the temp directory
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • getConnectString

      public String getConnectString()
      Returns the connection string to use
      Returns:
      connection string
      Throws:
      IllegalStateException - if server is configured to bind to port 0 but not started