List of usage examples for org.springframework.integration.zookeeper.metadata ZookeeperMetadataStore remove
@Override
public String remove(String key)
From source file:org.springframework.integration.zookeeper.metadata.ZookeeperMetadataStoreTests.java
@Test public void testListenerInvokedOnRemoteChanges() throws Exception { String testKey = "ZookeeperMetadataStoreTests"; CuratorFramework otherClient = createNewClient(); ZookeeperMetadataStore otherMetadataStore = new ZookeeperMetadataStore(otherClient); // register listeners final List<List<String>> notifiedChanges = new ArrayList<List<String>>(); final Map<String, CyclicBarrier> barriers = new HashMap<String, CyclicBarrier>(); barriers.put("add", new CyclicBarrier(2)); barriers.put("remove", new CyclicBarrier(2)); barriers.put("update", new CyclicBarrier(2)); metadataStore.addListener(new MetadataStoreListenerAdapter() { @Override/*ww w. j a v a2 s. c om*/ public void onAdd(String key, String value) { notifiedChanges.add(Arrays.asList("add", key, value)); waitAtBarrier("add", barriers); } @Override public void onRemove(String key, String oldValue) { notifiedChanges.add(Arrays.asList("remove", key, oldValue)); waitAtBarrier("remove", barriers); } @Override public void onUpdate(String key, String newValue) { notifiedChanges.add(Arrays.asList("update", key, newValue)); waitAtBarrier("update", barriers); } }); // the tests themselves barriers.get("add").reset(); otherMetadataStore.put(testKey, "Integration"); waitAtBarrier("add", barriers); assertThat(notifiedChanges, hasSize(1)); assertThat(notifiedChanges.get(0), IsIterableContainingInOrder.contains("add", testKey, "Integration")); otherMetadataStore.putIfAbsent(testKey, "Integration++"); // there is no update and therefore we expect no changes assertThat(notifiedChanges, hasSize(1)); barriers.get("update").reset(); otherMetadataStore.put(testKey, "Integration-2"); waitAtBarrier("update", barriers); assertThat(notifiedChanges, hasSize(2)); assertThat(notifiedChanges.get(1), IsIterableContainingInOrder.contains("update", testKey, "Integration-2")); barriers.get("update").reset(); otherMetadataStore.replace(testKey, "Integration-2", "Integration-3"); waitAtBarrier("update", barriers); assertThat(notifiedChanges, hasSize(3)); assertThat(notifiedChanges.get(2), IsIterableContainingInOrder.contains("update", testKey, "Integration-3")); otherMetadataStore.replace(testKey, "Integration-2", "Integration-none"); assertThat(notifiedChanges, hasSize(3)); barriers.get("remove").reset(); otherMetadataStore.remove(testKey); waitAtBarrier("remove", barriers); assertThat(notifiedChanges, hasSize(4)); assertThat(notifiedChanges.get(3), IsIterableContainingInOrder.contains("remove", testKey, "Integration-3")); // sleep and try to see if there were any other updates - if there any pending updates, we should catch them by now Thread.sleep(1000); assertThat(notifiedChanges, hasSize(4)); }