Search in sources :

Example 1 with NodeState

use of io.fabric8.groups.NodeState in project fabric8 by jboss-fuse.

the class ZooKeeperGroupTest method testMaster_withStaleNodes1.

@Test
public void testMaster_withStaleNodes1() throws Exception {
    // stale
    putChildData(group, PATH + "/001", "container1");
    putChildData(group, PATH + "/002", "container1");
    // stale
    putChildData(group, PATH + "/003", "container2");
    // stale
    putChildData(group, PATH + "/004", "container3");
    putChildData(group, PATH + "/005", "container2");
    putChildData(group, PATH + "/006", "container3");
    NodeState master = group.master();
    assertThat(master, notNullValue());
    assertThat(master.getContainer(), equalTo("container1"));
}
Also used : NodeState(io.fabric8.groups.NodeState) Test(org.junit.Test)

Example 2 with NodeState

use of io.fabric8.groups.NodeState in project fabric8 by jboss-fuse.

the class ZooKeeperGroupTest method testMaster.

@Test
public void testMaster() throws Exception {
    putChildData(group, PATH + "/001", "container1");
    putChildData(group, PATH + "/002", "container2");
    putChildData(group, PATH + "/003", "container3");
    NodeState master = group.master();
    assertThat(master, notNullValue());
    assertThat(master.getContainer(), equalTo("container1"));
}
Also used : NodeState(io.fabric8.groups.NodeState) Test(org.junit.Test)

Example 3 with NodeState

use of io.fabric8.groups.NodeState in project fabric8 by jboss-fuse.

the class ZooKeeperGroupTest method testMaster_withStaleNodes2.

@Test
public void testMaster_withStaleNodes2() throws Exception {
    // stale
    putChildData(group, PATH + "/001", "container1");
    putChildData(group, PATH + "/002", "container2");
    putChildData(group, PATH + "/003", "container1");
    // stale
    putChildData(group, PATH + "/004", "container3");
    putChildData(group, PATH + "/005", "container3");
    NodeState master = group.master();
    assertThat(master, notNullValue());
    assertThat(master.getContainer(), equalTo("container2"));
}
Also used : NodeState(io.fabric8.groups.NodeState) Test(org.junit.Test)

Example 4 with NodeState

use of io.fabric8.groups.NodeState in project fabric8 by jboss-fuse.

the class ZooKeeperGroupTest method putChildData.

private static void putChildData(ZooKeeperGroup<NodeState> group, String path, String container) throws Exception {
    NodeState node = new NodeState("test", container);
    ByteArrayOutputStream data = new ByteArrayOutputStream();
    new ObjectMapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).writeValue(data, node);
    ChildData<NodeState> child = new ChildData<>(path, new Stat(), data.toByteArray(), node);
    group.currentData.put(path, child);
}
Also used : NodeState(io.fabric8.groups.NodeState) Stat(org.apache.zookeeper.data.Stat) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with NodeState

use of io.fabric8.groups.NodeState in project fabric8 by jboss-fuse.

the class ZooKeeperMultiGroup method isMaster.

@Override
public boolean isMaster(String name) {
    List<ChildData<T>> children = getActiveChildren();
    Collections.sort(children, sequenceComparator);
    for (ChildData child : children) {
        NodeState node = (NodeState) child.getNode();
        if (node.id.equals(name)) {
            if (child.getPath().equals(getId())) {
                return true;
            } else {
                return false;
            }
        }
    }
    return false;
}
Also used : NodeState(io.fabric8.groups.NodeState)

Aggregations

Test (org.junit.Test)11 ZooKeeperGroup (io.fabric8.groups.internal.ZooKeeperGroup)8 CuratorFramework (org.apache.curator.framework.CuratorFramework)8 RetryNTimes (org.apache.curator.retry.RetryNTimes)8 NodeState (io.fabric8.groups.NodeState)7 NIOServerCnxnFactory (org.apache.zookeeper.server.NIOServerCnxnFactory)6 ArrayList (java.util.ArrayList)3 Group (io.fabric8.groups.Group)2 GroupListener (io.fabric8.groups.GroupListener)2 IOException (java.io.IOException)2 URI (java.net.URI)2 BlockingQueue (java.util.concurrent.BlockingQueue)2 ExecutorService (java.util.concurrent.ExecutorService)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 SocketProxy (org.apache.activemq.util.SocketProxy)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ChildData (io.fabric8.groups.internal.ChildData)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 CountDownLatch (java.util.concurrent.CountDownLatch)1