Skip to content

Instantly share code, notes, and snippets.

@abramsm
Created February 26, 2014 19:52
Show Gist options
  • Save abramsm/9237098 to your computer and use it in GitHub Desktop.
Save abramsm/9237098 to your computer and use it in GitHub Desktop.
Configuration for fast start embedded Zookeeper, useful for unit tests
InstanceSpec spec = new InstanceSpec(null, -1, -1, -1, true, -1, 2000, 10);
System.setProperty("zookeeper.serverCnxnFactory", "org.apache.zookeeper.server.NettyServerCnxnFactory");
myKeeper = new TestingServer(spec);
String keeperPort = String.valueOf(spec.getPort());
System.setProperty("zk.servers", "localhost:" + keeperPort);
zkClient = CuratorFrameworkFactory.builder()
.sessionTimeoutMs(60000)
.connectionTimeoutMs(10000)
.connectString("localhost:" + keeperPort)
.retryPolicy(new RetryOneTime(1000))
.defaultData(null)
.build();
zkClient.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment