Calling org.apache.zookeeper.server.quorum.QuorumPeerMain.main() isn't working.
To start the ZooKeeper server on a Linux system, use the Zookeeper/zookeeper/bin/zkServer.sh restart command from your Watson Explorer installation directory. On Microsoft Windows systems, use the Zookeeper\zookeeper\bin\zkServer. cmd command.
ZooKeeper is an open source Apache project that provides a centralized service for providing configuration information, naming, synchronization and group services over large clusters in distributed systems. The goal is to make these systems easier to manage with improved, more reliable propagation of changes.
It's basically the minimum number of server nodes that must be up and running and available for client requests. Any update done to the ZooKeeper tree by the clients must be persistently stored in this quorum of nodes for a transaction to be completed successfully.
Netfix opensourced Curator a framework to make use of Zookeeper even more convenient. It has build in test server class. Just add this test dependency to your project descriptor be it maven, gradle or else:
org.apache.curator:curator-framework:4.0.1 org.apache.curator:curator-test:4.0.1
And here are the test essentials.
TestingServer zkTestServer; CuratorFramework cli; @Before public void startZookeeper() throws Exception { zkTestServer = new TestingServer(2181); cli = CuratorFrameworkFactory.newClient(zkTestServer.getConnectString(), new RetryOneTime(2000)); cli.start(); } @After public void stopZookeeper() throws IOException { cli.close(); zkTestServer.stop(); }
With cli
creating any test data is very easy (requires the curator-framework
dependency).
cli.create() .creatingParentsIfNeeded() .forPath("/a1", "testvalue".getBytes("UTF-8"));
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 { quorumConfiguration.parseProperties(startupProperties); } catch(Exception e) { throw new RuntimeException(e); } zooKeeperServer = new ZooKeeperServerMain(); final ServerConfig configuration = new ServerConfig(); configuration.readFrom(quorumConfiguration); new Thread() { public void run() { try { zooKeeperServer.runFromConfig(configuration); } catch (IOException e) { log.error("ZooKeeper Failed", e); } } }.start();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With