use of org.apache.zookeeper.server.NIOServerCnxnFactory in project camel by apache.
the class ZKServerFactoryBean method afterPropertiesSet.
public void afterPropertiesSet() throws Exception {
if (purge) {
deleteFilesInDir(getDataLogDir());
deleteFilesInDir(getDataDir());
}
FileTxnSnapLog ftxn = new FileTxnSnapLog(getDataLogDir(), getDataDir());
zooKeeperServer.setTxnLogFactory(ftxn);
zooKeeperServer.setTickTime(getTickTime());
zooKeeperServer.setMinSessionTimeout(getMinSessionTimeout());
zooKeeperServer.setMaxSessionTimeout(getMaxSessionTimeout());
connectionFactory = new NIOServerCnxnFactory();
connectionFactory.configure(getClientPortAddress(), getMaxClientConnections());
connectionFactory.startup(zooKeeperServer);
}
use of org.apache.zookeeper.server.NIOServerCnxnFactory in project camel by apache.
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 camel by apache.
the class GroupTest method testJoinAfterConnect.
@Test
public void testJoinAfterConnect() throws Exception {
int port = findFreePort();
CuratorFramework curator = CuratorFrameworkFactory.builder().connectString("localhost:" + port).retryPolicy(new RetryNTimes(10, 100)).build();
curator.start();
final Group<NodeState> group = new ZooKeeperGroup<NodeState>(curator, "/singletons/test" + System.currentTimeMillis(), NodeState.class);
group.add(listener);
group.start();
assertFalse(group.isConnected());
assertFalse(group.isMaster());
GroupCondition groupCondition = new GroupCondition();
group.add(groupCondition);
NIOServerCnxnFactory cnxnFactory = startZooKeeper(port);
curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
assertTrue(groupCondition.waitForConnected(5, TimeUnit.SECONDS));
assertFalse(group.isMaster());
group.update(new NodeState("foo"));
assertTrue(groupCondition.waitForMaster(5, TimeUnit.SECONDS));
group.close();
curator.close();
cnxnFactory.shutdown();
cnxnFactory.join();
}
use of org.apache.zookeeper.server.NIOServerCnxnFactory in project camel by apache.
the class GroupTest method testGroupClose.
//Tests that if close() is executed right after start(), there are no left over entries.
//(see https://github.com/jboss-fuse/fuse/issues/133)
@Test
public void testGroupClose() throws Exception {
int port = findFreePort();
NIOServerCnxnFactory cnxnFactory = startZooKeeper(port);
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString("localhost:" + port).connectionTimeoutMs(6000).sessionTimeoutMs(6000).retryPolicy(new RetryNTimes(10, 100));
CuratorFramework curator = builder.build();
curator.start();
curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
String groupNode = "/singletons/test" + System.currentTimeMillis();
curator.create().creatingParentsIfNeeded().forPath(groupNode);
for (int i = 0; i < 100; i++) {
ZooKeeperGroup<NodeState> group = new ZooKeeperGroup<NodeState>(curator, groupNode, NodeState.class);
group.add(listener);
group.update(new NodeState("foo"));
group.start();
group.close();
List<String> entries = curator.getChildren().forPath(groupNode);
assertTrue(entries.isEmpty() || group.isUnstable());
if (group.isUnstable()) {
// let's wait for session timeout
curator.close();
curator = builder.build();
curator.start();
curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
}
}
curator.close();
cnxnFactory.shutdown();
cnxnFactory.join();
}
use of org.apache.zookeeper.server.NIOServerCnxnFactory in project camel by apache.
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