Example usage for org.apache.zookeeper.server NIOServerCnxnFactory join

List of usage examples for org.apache.zookeeper.server NIOServerCnxnFactory join

Introduction

In this page you can find the example usage for org.apache.zookeeper.server NIOServerCnxnFactory join.

Prototype

@Override
    public void join() throws InterruptedException 

Source Link

Usage

From source file:io.fabric8.groups.GroupTest.java

License:Apache License

@Test
public void testJoinAfterConnect() throws Exception {
    int port = AvailablePortFinder.getNextAvailable(3000);

    CuratorFramework curator = CuratorFrameworkFactory.builder().connectString("localhost:" + port)
            .retryPolicy(new RetryNTimes(10, 100)).build();
    curator.start();//from   w w  w  .j av a 2  s.c  o  m

    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();
}

From source file:io.fabric8.groups.GroupTest.java

License:Apache License

@Test
public void testJoinBeforeConnect() throws Exception {
    int port = AvailablePortFinder.getNextAvailable(3010);

    CuratorFramework curator = CuratorFrameworkFactory.builder().connectString("localhost:" + port)
            .retryPolicy(new RetryNTimes(10, 100)).build();
    curator.start();/*w  w  w.j a va2 s.  c o  m*/

    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();
}

From source file:io.fabric8.groups.GroupTest.java

License:Apache License

@Test
public void testRejoinAfterDisconnect() throws Exception {
    int port = AvailablePortFinder.getNextAvailable(3020);

    CuratorFramework curator = CuratorFrameworkFactory.builder().connectString("localhost:" + port)
            .retryPolicy(new RetryNTimes(10, 100)).build();
    curator.start();//from  w  w  w  . j a v  a  2s. com

    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();
}

From source file:io.fabric8.groups.GroupTest.java

License:Apache License

@Test
public void testGroupClose() throws Exception {
    int port = AvailablePortFinder.getNextAvailable(3030);

    NIOServerCnxnFactory cnxnFactory = startZooKeeper(port);

    CuratorFramework curator = CuratorFrameworkFactory.builder().connectString("localhost:" + port)
            .retryPolicy(new RetryNTimes(10, 100)).build();
    curator.start();/*from w  w  w .j  a  v  a 2 s.c o m*/
    curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
    String groupNode = "/singletons/test" + System.currentTimeMillis();
    curator.create().creatingParentsIfNeeded().forPath(groupNode);

    for (int i = 0; i < 10; i++) {
        Group<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());
    }

    curator.close();
    cnxnFactory.shutdown();
    cnxnFactory.join();
}

From source file:org.fusesource.fabric.groups.GroupTest.java

License:Apache License

@Test
public void testJoinAfterConnect() throws Exception {
    int port = findFreePort();

    CuratorFramework curator = CuratorFrameworkFactory.builder().connectString("localhost:" + port)
            .retryPolicy(new RetryNTimes(10, 100)).build();
    curator.start();//from  w  ww .ja v  a 2s.c  o m

    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());

    NIOServerCnxnFactory cnxnFactory = startZooKeeper(port);

    curator.getZookeeperClient().blockUntilConnectedOrTimedOut();

    assertTrue(group.isConnected());
    assertFalse(group.isMaster());

    group.update(new NodeState("foo"));
    Thread.sleep(1000);
    assertTrue(group.isMaster());

    group.close();
    curator.close();
    cnxnFactory.shutdown();
    cnxnFactory.join();
}

From source file:org.fusesource.fabric.groups.GroupTest.java

License:Apache License

@Test
public void testJoinBeforeConnect() throws Exception {
    int port = findFreePort();

    CuratorFramework curator = CuratorFrameworkFactory.builder().connectString("localhost:" + port)
            .retryPolicy(new RetryNTimes(10, 100)).build();
    curator.start();/*from   w w w .  j  av a  2  s .com*/

    Group<NodeState> group = new ZooKeeperGroup<NodeState>(curator,
            "/singletons/test" + System.currentTimeMillis(), NodeState.class);
    group.add(listener);
    group.start();

    assertFalse(group.isConnected());
    assertFalse(group.isMaster());
    group.update(new NodeState("foo"));

    NIOServerCnxnFactory cnxnFactory = startZooKeeper(port);

    curator.getZookeeperClient().blockUntilConnectedOrTimedOut();

    assertTrue(group.isConnected());
    Thread.sleep(1000);
    assertTrue(group.isMaster());

    group.close();
    curator.close();
    cnxnFactory.shutdown();
    cnxnFactory.join();
}

From source file:org.fusesource.fabric.groups.GroupTest.java

License:Apache License

@Test
public void testRejoinAfterDisconnect() throws Exception {
    int port = findFreePort();

    CuratorFramework curator = CuratorFrameworkFactory.builder().connectString("localhost:" + port)
            .retryPolicy(new RetryNTimes(10, 100)).build();
    curator.start();/*from w  w w. java 2s  . c om*/

    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();

    curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
    Thread.sleep(1000);

    assertTrue(group.isConnected());
    assertTrue(group.isMaster());

    cnxnFactory.shutdown();
    cnxnFactory.join();

    Thread.sleep(1000);

    assertFalse(group.isConnected());
    assertFalse(group.isMaster());

    cnxnFactory = startZooKeeper(port);

    curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
    Thread.sleep(1000);

    assertTrue(group.isConnected());
    assertTrue(group.isMaster());

    group.close();
    curator.close();
    cnxnFactory.shutdown();
    cnxnFactory.join();
}