use of org.apache.zookeeper.server.NIOServerCnxnFactory in project bookkeeper by apache.
the class ZooKeeperServerShimImpl method initialize.
@Override
public void initialize(File snapDir, File logDir, int zkPort, int maxCC) throws IOException {
zks = new ZooKeeperServer(snapDir, logDir, ZooKeeperServer.DEFAULT_TICK_TIME);
serverFactory = new NIOServerCnxnFactory();
serverFactory.configure(new InetSocketAddress(zkPort), maxCC);
}
use of org.apache.zookeeper.server.NIOServerCnxnFactory in project fabric8 by jboss-fuse.
the class ZookeeperServerTestSupport method startZooKeeper.
protected NIOServerCnxnFactory startZooKeeper(int port) throws Exception {
ServerConfig cfg = new ServerConfig();
cfg.parse(new String[] { Integer.toString(port), "target/zk/data-" + String.format("%15d", new Date().getTime()) });
ZooKeeperServer zkServer = new ZooKeeperServer();
FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(cfg.getDataLogDir()), new File(cfg.getDataDir()));
zkServer.setTxnLogFactory(ftxn);
zkServer.setTickTime(cfg.getTickTime());
zkServer.setMinSessionTimeout(cfg.getMinSessionTimeout());
zkServer.setMaxSessionTimeout(cfg.getMaxSessionTimeout());
NIOServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory();
cnxnFactory.configure(cfg.getClientPortAddress(), cfg.getMaxClientCnxns());
cnxnFactory.startup(zkServer);
return cnxnFactory;
}
use of org.apache.zookeeper.server.NIOServerCnxnFactory in project fabric8 by jboss-fuse.
the class GitDataStoreImplTestSupport method startZooKeeper.
private NIOServerCnxnFactory startZooKeeper(int port, String directory) throws Exception {
ServerConfig cfg = new ServerConfig();
cfg.parse(new String[] { Integer.toString(port), directory });
ZooKeeperServer zkServer = new ZooKeeperServer();
FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(cfg.getDataLogDir()), new File(cfg.getDataDir()));
zkServer.setTxnLogFactory(ftxn);
zkServer.setTickTime(cfg.getTickTime());
zkServer.setMinSessionTimeout(cfg.getMinSessionTimeout());
zkServer.setMaxSessionTimeout(cfg.getMaxSessionTimeout());
NIOServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory();
cnxnFactory.configure(cfg.getClientPortAddress(), cfg.getMaxClientCnxns());
cnxnFactory.startup(zkServer);
return cnxnFactory;
}
use of org.apache.zookeeper.server.NIOServerCnxnFactory in project fabric8 by jboss-fuse.
the class GroupTest method testJoinBeforeConnect.
@Test
public void testJoinBeforeConnect() throws Exception {
int port = findFreePort();
CuratorFramework curator = CuratorFrameworkFactory.builder().connectString("localhost:" + port).retryPolicy(new RetryNTimes(10, 100)).build();
curator.start();
Group<NodeState> group = new ZooKeeperGroup<NodeState>(curator, "/singletons/test" + System.currentTimeMillis(), NodeState.class);
group.add(listener);
group.start();
GroupCondition groupCondition = new GroupCondition();
group.add(groupCondition);
assertFalse(group.isConnected());
assertFalse(group.isMaster());
group.update(new NodeState("foo"));
NIOServerCnxnFactory cnxnFactory = startZooKeeper(port);
curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
assertTrue(groupCondition.waitForConnected(5, TimeUnit.SECONDS));
assertTrue(groupCondition.waitForMaster(5, TimeUnit.SECONDS));
group.close();
curator.close();
cnxnFactory.shutdown();
cnxnFactory.join();
}
use of org.apache.zookeeper.server.NIOServerCnxnFactory in project fabric8 by jboss-fuse.
the class GroupTest method testRejoinAfterDisconnect.
@Test
public void testRejoinAfterDisconnect() throws Exception {
int port = findFreePort();
CuratorFramework curator = CuratorFrameworkFactory.builder().connectString("localhost:" + port).retryPolicy(new RetryNTimes(10, 100)).build();
curator.start();
NIOServerCnxnFactory cnxnFactory = startZooKeeper(port);
Group<NodeState> group = new ZooKeeperGroup<NodeState>(curator, "/singletons/test" + System.currentTimeMillis(), NodeState.class);
group.add(listener);
group.update(new NodeState("foo"));
group.start();
GroupCondition groupCondition = new GroupCondition();
group.add(groupCondition);
curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
assertTrue(groupCondition.waitForConnected(5, TimeUnit.SECONDS));
assertTrue(groupCondition.waitForMaster(5, TimeUnit.SECONDS));
cnxnFactory.shutdown();
cnxnFactory.join();
groupCondition.waitForDisconnected(5, TimeUnit.SECONDS);
group.remove(groupCondition);
assertFalse(group.isConnected());
assertFalse(group.isMaster());
groupCondition = new GroupCondition();
group.add(groupCondition);
cnxnFactory = startZooKeeper(port);
curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
assertTrue(groupCondition.waitForConnected(5, TimeUnit.SECONDS));
assertTrue(groupCondition.waitForMaster(5, TimeUnit.SECONDS));
group.close();
curator.close();
cnxnFactory.shutdown();
cnxnFactory.join();
}
Aggregations