Search in sources :

Example 1 with DefaultPropertyFilter

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

the class ZookeeperConfigurationProvider method writeApplicationConfiguration.

@Override
public void writeApplicationConfiguration(String environment, String applicationName, String applicationVersion, AbstractConfiguration configuration, boolean allowOverwrite) {
    ZookeeperConfigurationWriter writer = new ZookeeperConfigurationWriter(applicationName, environment, applicationVersion, curatorFramework, allowOverwrite);
    writer.write(configuration, new DefaultPropertyFilter());
}
Also used : DefaultPropertyFilter(com.kixeye.chassis.bootstrap.configuration.DefaultPropertyFilter)

Example 2 with DefaultPropertyFilter

use of com.kixeye.chassis.bootstrap.configuration.DefaultPropertyFilter 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 3 with DefaultPropertyFilter

use of com.kixeye.chassis.bootstrap.configuration.DefaultPropertyFilter 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 4 with DefaultPropertyFilter

use of com.kixeye.chassis.bootstrap.configuration.DefaultPropertyFilter 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 5 with DefaultPropertyFilter

use of com.kixeye.chassis.bootstrap.configuration.DefaultPropertyFilter 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)5 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