Search in sources :

Example 36 with Group

use of io.fabric8.kubernetes.model.annotation.Group 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 37 with Group

use of io.fabric8.kubernetes.model.annotation.Group 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 38 with Group

use of io.fabric8.kubernetes.model.annotation.Group 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 39 with Group

use of io.fabric8.kubernetes.model.annotation.Group 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 40 with Group

use of io.fabric8.kubernetes.model.annotation.Group in project fabric8 by jboss-fuse.

the class ZooKeeperGroupTest method setUp.

@Before
public void setUp() throws Exception {
    int port = findFreePort();
    curator = CuratorFrameworkFactory.builder().connectString("localhost:" + port).retryPolicy(new RetryOneTime(1)).build();
    // curator.start();
    group = new ZooKeeperGroup<>(curator, PATH, NodeState.class);
// group.start();
// Starting curator and group is not necessary for the current tests.
}
Also used : RetryOneTime(org.apache.curator.retry.RetryOneTime) NodeState(io.fabric8.groups.NodeState) Before(org.junit.Before)

Aggregations

Test (org.junit.jupiter.api.Test)32 Test (org.junit.Test)29 IOException (java.io.IOException)19 ArrayList (java.util.ArrayList)17 Map (java.util.Map)16 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)15 List (java.util.List)14 File (java.io.File)13 HashMap (java.util.HashMap)13 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)12 Collectors (java.util.stream.Collectors)11 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)10 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)9 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)9 CuratorFramework (org.apache.curator.framework.CuratorFramework)9 ZooKeeperGroup (io.fabric8.groups.internal.ZooKeeperGroup)8 Pod (io.fabric8.kubernetes.api.model.Pod)8 KubernetesClientBuilder (io.fabric8.kubernetes.client.KubernetesClientBuilder)8 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)8