Package org.apache.curator.test
Class TestingServer
java.lang.Object
org.apache.curator.test.TestingServer
- All Implemented Interfaces:
Closeable
,AutoCloseable
manages an internally running ZooKeeper server. FOR TESTING PURPOSES ONLY
-
Constructor Summary
ConstructorDescriptionCreate the server using a random portTestingServer
(boolean start) Create the server using a random portTestingServer
(int port) Create and start the server using the given portTestingServer
(int port, boolean start) Create the server using the given portTestingServer
(int port, File tempDirectory) Create and start the server using the given portTestingServer
(int port, File tempDirectory, boolean start) Create the server using the given portTestingServer
(InstanceSpec spec, boolean start) Create the server using the given port -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close the server and any open clients and delete the temp directoryReturns the connection string to useint
getPort()
Return the port being used or will be used.Returns the temp directory being usedvoid
restart()
Restart the server.void
start()
Start the servervoid
stop()
Stop the server without deleting the temp directory
-
Constructor Details
-
TestingServer
Create the server using a random port- Throws:
Exception
- errors
-
TestingServer
Create the server using a random port- Parameters:
start
- True if the server should be started, false otherwise- Throws:
Exception
- errors
-
TestingServer
Create and start the server using the given port- Parameters:
port
- the port- Throws:
Exception
- errors
-
TestingServer
Create the server using the given port- Parameters:
port
- the portstart
- True if the server should be started, false otherwise- Throws:
Exception
- errors
-
TestingServer
Create and start the server using the given port- Parameters:
port
- the porttempDirectory
- directory to use- Throws:
Exception
- errors
-
TestingServer
Create the server using the given port- Parameters:
port
- the porttempDirectory
- directory to usestart
- True if the server should be started, false otherwise- Throws:
Exception
- errors
-
TestingServer
Create the server using the given port- Parameters:
spec
- instance detailsstart
- 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
Returns the temp directory being used- Returns:
- directory
-
start
Start the server- Throws:
Exception
-
stop
Stop the server without deleting the temp directory- Throws:
IOException
-
restart
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
Close the server and any open clients and delete the temp directory- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
getConnectString
Returns the connection string to use- Returns:
- connection string
- Throws:
IllegalStateException
- if server is configured to bind to port 0 but not started
-