Class TestingServer

  • All Implemented Interfaces:
    Closeable, AutoCloseable

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

      • 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 Detail

      • getPort

        public int getPort()
        Return the port being used
        Returns:
        port
      • getTempDirectory

        public File getTempDirectory()
        Returns the temp directory being used
        Returns:
        directory
      • 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
      • getConnectString

        public String getConnectString()
        Returns the connection string to use
        Returns:
        connection string