Search in sources :

Example 1 with ZookeeperConfigurationWriter

use of com.kixeye.chassis.bootstrap.configuration.zookeeper.ZookeeperConfigurationWriter in project chassis by Kixeye.

the class ZookeeperConfigurationWriterTest method noBasePathExists.

@Test
public void noBasePathExists() throws Exception {
    Assert.assertNull(curatorFramework.checkExists().forPath(base));
    try (CuratorFramework zkCurator = createCuratorFramework()) {
        ZookeeperConfigurationWriter writer = new ZookeeperConfigurationWriter(applicationName, environmentName, version, zkCurator, false);
        writer.write(new MapConfiguration(props), new DefaultPropertyFilter());
        Assert.assertEquals(val1, new String(curatorFramework.getData().forPath(base + "/" + key1)));
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) MapConfiguration(org.apache.commons.configuration.MapConfiguration) DefaultPropertyFilter(com.kixeye.chassis.bootstrap.configuration.DefaultPropertyFilter) ZookeeperConfigurationWriter(com.kixeye.chassis.bootstrap.configuration.zookeeper.ZookeeperConfigurationWriter) Test(org.junit.Test)

Example 2 with ZookeeperConfigurationWriter

use of com.kixeye.chassis.bootstrap.configuration.zookeeper.ZookeeperConfigurationWriter in project chassis by Kixeye.

the class ZookeeperConfigurationWriterTest method partialBasePathExists.

@Test
public void partialBasePathExists() throws Exception {
    Assert.assertNull(curatorFramework.checkExists().forPath(base));
    curatorFramework.create().forPath("/" + environmentName);
    Assert.assertNotNull(curatorFramework.checkExists().forPath("/" + environmentName));
    try (CuratorFramework zkCurator = createCuratorFramework()) {
        ZookeeperConfigurationWriter writer = new ZookeeperConfigurationWriter(applicationName, environmentName, version, zkCurator, false);
        writer.write(new MapConfiguration(props), new DefaultPropertyFilter());
        Assert.assertEquals(val1, new String(curatorFramework.getData().forPath(base + "/" + key1)));
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) MapConfiguration(org.apache.commons.configuration.MapConfiguration) DefaultPropertyFilter(com.kixeye.chassis.bootstrap.configuration.DefaultPropertyFilter) ZookeeperConfigurationWriter(com.kixeye.chassis.bootstrap.configuration.zookeeper.ZookeeperConfigurationWriter) Test(org.junit.Test)

Example 3 with ZookeeperConfigurationWriter

use of com.kixeye.chassis.bootstrap.configuration.zookeeper.ZookeeperConfigurationWriter in project chassis by Kixeye.

the class ZookeeperConfigurationWriterTest method basePathExists_overwrite.

@Test
public void basePathExists_overwrite() throws Exception {
    Assert.assertNull(curatorFramework.checkExists().forPath(base));
    try (CuratorFramework zkCurator = createCuratorFramework()) {
        ZookeeperConfigurationWriter writer = new ZookeeperConfigurationWriter(applicationName, environmentName, version, zkCurator, true);
        writer.write(new MapConfiguration(props), new DefaultPropertyFilter());
        Assert.assertEquals(val1, new String(curatorFramework.getData().forPath(base + "/" + key1)));
        Assert.assertEquals(val2, new String(curatorFramework.getData().forPath(base + "/" + key2)));
        String key3 = RandomUtils.nextInt() + "";
        String val3 = RandomUtils.nextInt() + "";
        String newVal1 = RandomUtils.nextInt() + "";
        props.clear();
        //updates key1
        props.put(key1, newVal1);
        //adds key3
        props.put(key3, val3);
        //key2 should be deleted
        writer.write(new MapConfiguration(props), new DefaultPropertyFilter());
        Assert.assertEquals(newVal1, new String(curatorFramework.getData().forPath(base + "/" + key1)));
        Assert.assertEquals(val3, new String(curatorFramework.getData().forPath(base + "/" + key3)));
        Assert.assertNull(curatorFramework.checkExists().forPath(base + "/" + key2));
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) MapConfiguration(org.apache.commons.configuration.MapConfiguration) DefaultPropertyFilter(com.kixeye.chassis.bootstrap.configuration.DefaultPropertyFilter) ZookeeperConfigurationWriter(com.kixeye.chassis.bootstrap.configuration.zookeeper.ZookeeperConfigurationWriter) Test(org.junit.Test)

Example 4 with ZookeeperConfigurationWriter

use of com.kixeye.chassis.bootstrap.configuration.zookeeper.ZookeeperConfigurationWriter in project chassis by Kixeye.

the class ZookeeperConfigurationWriterTest method basePathExists_noOverwrite.

@Test
public void basePathExists_noOverwrite() throws Exception {
    Assert.assertNull(curatorFramework.checkExists().forPath(base));
    try (CuratorFramework zkCurator = createCuratorFramework()) {
        ZookeeperConfigurationWriter writer = new ZookeeperConfigurationWriter(applicationName, environmentName, version, zkCurator, false);
        writer.write(new MapConfiguration(props), new DefaultPropertyFilter());
        Assert.assertEquals(val1, new String(curatorFramework.getData().forPath(base + "/" + key1)));
        Assert.assertEquals(val2, new String(curatorFramework.getData().forPath(base + "/" + key2)));
        try {
            writer.write(new MapConfiguration(props), new DefaultPropertyFilter());
            Assert.fail();
        } catch (BootstrapException e) {
        //expected
        }
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) MapConfiguration(org.apache.commons.configuration.MapConfiguration) DefaultPropertyFilter(com.kixeye.chassis.bootstrap.configuration.DefaultPropertyFilter) ZookeeperConfigurationWriter(com.kixeye.chassis.bootstrap.configuration.zookeeper.ZookeeperConfigurationWriter) Test(org.junit.Test)

Aggregations

DefaultPropertyFilter (com.kixeye.chassis.bootstrap.configuration.DefaultPropertyFilter)4 ZookeeperConfigurationWriter (com.kixeye.chassis.bootstrap.configuration.zookeeper.ZookeeperConfigurationWriter)4 MapConfiguration (org.apache.commons.configuration.MapConfiguration)4 CuratorFramework (org.apache.curator.framework.CuratorFramework)4 Test (org.junit.Test)4