marathon marathon - 2 years ago 147
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.

Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download