Package io.debezium.kafka
Class ZookeeperServer
- java.lang.Object
-
- io.debezium.kafka.ZookeeperServer
-
@ThreadSafe public class ZookeeperServer extends Object
A lightweight embeddable Zookeeper server useful for unit testing.- Author:
- Randall Hauch
- See Also:
KafkaCluster
-
-
Field Summary
Fields Modifier and Type Field Description private FiledataDirstatic intDEFAULT_TICK_TIMEprivate org.apache.zookeeper.server.ServerCnxnFactoryfactoryprivate FilelogDirprivate static org.slf4j.LoggerLOGGERprivate intportprivate org.apache.zookeeper.server.ZooKeeperServerserverprivate FilesnapshotDirprivate inttickTimeThe basic time unit in milliseconds used by ZooKeeper.
-
Constructor Summary
Constructors Constructor Description ZookeeperServer()Create a new server instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetConnection()Get the connection string.(package private) FilegetLogDirectory()Get the parent directory where the server's logs are kept.intgetPort()Get the current port.(package private) FilegetSnapshotDirectory()Get the parent directory where the server's snapshots are kept.FilegetStateDirectory()Get the parent directory where the server's logs and snapshots will be kept.intgetTickTime()Get the basic time unit in milliseconds used by ZooKeeper.(package private) voidonEachDirectory(Consumer<File> consumer)Perform the supplied function on each directory used by this server.ZookeeperServersetPort(int port)Set the port for the server.ZookeeperServersetStateDirectory(File dataDir)Set the parent directory where the server's logs and snapshots will be kept.ZookeeperServersetTickTime(int tickTime)Set the basic time unit in milliseconds used by ZooKeeper.voidshutdown()Shutdown the embedded Zookeeper server and delete all data.voidshutdown(boolean deleteData)Shutdown the embedded Kafka server.ZookeeperServerstartup()Start the embedded Zookeeper server.StringtoString()
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
DEFAULT_TICK_TIME
public static int DEFAULT_TICK_TIME
-
tickTime
private volatile int tickTime
The basic time unit in milliseconds used by ZooKeeper. It is used to do heartbeats and the minimum session timeout will be twice the tickTime.
-
port
private volatile int port
-
factory
private volatile org.apache.zookeeper.server.ServerCnxnFactory factory
-
dataDir
private volatile File dataDir
-
snapshotDir
private volatile File snapshotDir
-
logDir
private volatile File logDir
-
server
private volatile org.apache.zookeeper.server.ZooKeeperServer server
-
-
Method Detail
-
startup
public ZookeeperServer startup() throws IOException
Start the embedded Zookeeper server.- Returns:
- this instance to allow chaining methods; never null
- Throws:
IOException- if there is an error during startupIllegalStateException- if the server is already running
-
shutdown
public void shutdown()
Shutdown the embedded Zookeeper server and delete all data.
-
shutdown
public void shutdown(boolean deleteData)
Shutdown the embedded Kafka server.- Parameters:
deleteData- true if the data should be removed, or false otherwise
-
getConnection
public String getConnection()
Get the connection string. If the server is notrunningand the port is to be dynamically discovered upon startup, then this method returns "localhost:-1".- Returns:
- the connection string; never null
-
setPort
public ZookeeperServer setPort(int port)
Set the port for the server.- Parameters:
port- the desired port, or-1if a random available port should be found and used- Returns:
- this instance to allow chaining methods; never null
-
setTickTime
public ZookeeperServer setTickTime(int tickTime)
Set the basic time unit in milliseconds used by ZooKeeper. It is used to do heartbeats and the minimum session timeout will be twice the tickTime.- Parameters:
tickTime- the desired value, or non-positive if the default ofDEFAULT_TICK_TIMEbe used- Returns:
- this instance to allow chaining methods; never null
-
getPort
public int getPort()
Get the current port.- Returns:
- the port number, or
-1if the port should be discovered uponstartup()
-
getTickTime
public int getTickTime()
Get the basic time unit in milliseconds used by ZooKeeper.- Returns:
- tick time; always positive
-
onEachDirectory
void onEachDirectory(Consumer<File> consumer)
Perform the supplied function on each directory used by this server.- Parameters:
consumer- the consumer function; may not be null
-
getSnapshotDirectory
File getSnapshotDirectory()
Get the parent directory where the server's snapshots are kept.- Returns:
- the parent directory for the server's snapshots; never null once the server is running
-
getLogDirectory
File getLogDirectory()
Get the parent directory where the server's logs are kept.- Returns:
- the parent directory for the server's logs; never null once the server is running
-
getStateDirectory
public File getStateDirectory()
Get the parent directory where the server's logs and snapshots will be kept.- Returns:
- the parent directory for the server's logs and snapshots; may be null if a temporary directory will be used
-
setStateDirectory
public ZookeeperServer setStateDirectory(File dataDir)
Set the parent directory where the server's logs and snapshots will be kept.- Parameters:
dataDir- the parent directory for the server's logs and snapshots; may be null if a temporary directory will be used- Returns:
- this instance to allow method chaining; never null
- Throws:
IllegalArgumentException- if the supplied file is not a directory or not writable
-
-