Example usage for org.springframework.integration.zookeeper.metadata ZookeeperMetadataStore get

List of usage examples for org.springframework.integration.zookeeper.metadata ZookeeperMetadataStore get

Introduction

In this page you can find the example usage for org.springframework.integration.zookeeper.metadata ZookeeperMetadataStore get.

Prototype

@Override
    public String get(String key) 

Source Link

Usage

From source file:org.springframework.integration.zookeeper.metadata.ZookeeperMetadataStoreTests.java

@Test
public void testPutIfAbsent() throws Exception {
    final String testKey = "ZookeeperMetadataStoreTests-Persist";
    final String testKey2 = "ZookeeperMetadataStoreTests-Persist-2";
    metadataStore.put(testKey, "Integration");
    assertNotNull(client.checkExists().forPath(metadataStore.getPath(testKey)));
    assertEquals("Integration",
            IntegrationUtils.bytesToString(client.getData().forPath(metadataStore.getPath(testKey)), "UTF-8"));
    CuratorFramework otherClient = createNewClient();
    final ZookeeperMetadataStore otherMetadataStore = new ZookeeperMetadataStore(otherClient);
    otherMetadataStore.start();/*from   w  ww  .ja v  a2s.  c o m*/
    otherMetadataStore.putIfAbsent(testKey, "OtherValue");
    assertEquals("Integration",
            IntegrationUtils.bytesToString(client.getData().forPath(metadataStore.getPath(testKey)), "UTF-8"));
    assertEquals("Integration", metadataStore.get(testKey));
    assertThat("Integration", eventually(equalsResult(new Evaluator<String>() {
        @Override
        public String evaluate() {
            return otherMetadataStore.get(testKey);
        }
    })));
    otherMetadataStore.putIfAbsent(testKey2, "Integration-2");
    assertEquals("Integration-2",
            IntegrationUtils.bytesToString(client.getData().forPath(metadataStore.getPath(testKey2)), "UTF-8"));
    assertEquals("Integration-2", otherMetadataStore.get(testKey2));
    assertThat("Integration-2", eventually(equalsResult(new Evaluator<String>() {
        @Override
        public String evaluate() {
            return metadataStore.get(testKey2);
        }
    })));
    closeClient(otherClient);
}

From source file:org.springframework.integration.zookeeper.metadata.ZookeeperMetadataStoreTests.java

@Test
public void testReplace() throws Exception {
    final String testKey = "ZookeeperMetadataStoreTests-Replace";
    metadataStore.put(testKey, "Integration");
    assertNotNull(client.checkExists().forPath(metadataStore.getPath(testKey)));
    assertEquals("Integration",
            IntegrationUtils.bytesToString(client.getData().forPath(metadataStore.getPath(testKey)), "UTF-8"));
    CuratorFramework otherClient = createNewClient();
    final ZookeeperMetadataStore otherMetadataStore = new ZookeeperMetadataStore(otherClient);
    otherMetadataStore.start();//  www.  j a  v  a  2s  . c o m
    otherMetadataStore.replace(testKey, "OtherValue", "Integration-2");
    assertEquals("Integration",
            IntegrationUtils.bytesToString(client.getData().forPath(metadataStore.getPath(testKey)), "UTF-8"));
    assertEquals("Integration", metadataStore.get(testKey));
    assertThat("Integration", eventually(equalsResult(new Evaluator<String>() {
        @Override
        public String evaluate() {
            return otherMetadataStore.get(testKey);
        }
    })));
    otherMetadataStore.replace(testKey, "Integration", "Integration-2");
    assertEquals("Integration-2",
            IntegrationUtils.bytesToString(client.getData().forPath(metadataStore.getPath(testKey)), "UTF-8"));
    assertThat("Integration-2", eventually(equalsResult(new Evaluator<String>() {
        @Override
        public String evaluate() {
            return metadataStore.get(testKey);
        }
    })));
    assertEquals("Integration-2", otherMetadataStore.get(testKey));
    closeClient(otherClient);
}