marathon marathon - 4 months ago 45
Java Question

Is it possible to start a zookeeper server instance in process, say for unit tests?

calling org.apache.zookeeper.server.quorum.QuorumPeerMain.main() isn't working.


To start ZooKeeper you have to execute ZooKeeperServerMain class.

You can use following code to start ZooKeeper in embedded mode.

Properties startupProperties = ...

QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();
try {
} catch(Exception e) {
    throw new RuntimeException(e);

zooKeeperServer = new ZooKeeperServerMain();
final ServerConfig configuration = new ServerConfig();

new Thread() {
    public void run() {
        try {
        } catch (IOException e) {
            log.error("ZooKeeper Failed", e);