@Test public void verifyNodesAreRetainedWhenZkGoesDown() throws Exception { final String foo1 = "/foos/foo1"; final String foo2 = "/foos/foo2"; final Set<String> paths = ImmutableSet.of(foo1, foo2); for (final String path : paths) { ensure(path, new DataPojo(path)); } Polling.await(5, MINUTES, new Callable<Object>() { @Override public Object call() throws Exception { return cache.getNodes().keySet().equals(paths) ? true : null; } }); verify(listener, atLeastOnce()).nodesChanged(cache); final SettableFuture<Void> connectionLost = SettableFuture.create(); doAnswer(new Answer<Object>() { @Override public Object answer(final InvocationOnMock invocationOnMock) throws Throwable { if (invocationOnMock.getArguments()[0] == ConnectionState.LOST) { connectionLost.set(null); } return null; } }).when(listener).connectionStateChanged(any(ConnectionState.class)); zk.stop(); connectionLost.get(5, MINUTES); for (int i = 0; i < 30; i++) { Thread.sleep(1000); assertEquals(paths, cache.getNodes().keySet()); } }
public Map<String, T> getNodes() { return snapshot.get(); }
PersistentPathChildrenCache extends AbstractIdleService { public Map<String, T> getNodes() { return snapshot.get(); } }
PersistentPathChildrenCache extends AbstractIdleService { public Map<String, T> getNodes() { return snapshot.get(); } PersistentPathChildrenCache(final CuratorFramework curator, final String path,
                                     final String clusterId, final Path snapshotFile,
                                     final JavaType valueType); }
PersistentPathChildrenCache extends AbstractIdleService { public Map<String, T> getNodes() { return snapshot.get(); } PersistentPathChildrenCache(final CuratorFramework curator, final String path,
                                     final String clusterId, final Path snapshotFile,
                                     final JavaType valueType); void addListener(final Listener listener); void removeListener(final Listener listener); Map<String, T> getNodes(); }
PersistentPathChildrenCache extends AbstractIdleService { public Map<String, T> getNodes() { return snapshot.get(); } PersistentPathChildrenCache(final CuratorFramework curator, final String path,
                                     final String clusterId, final Path snapshotFile,
                                     final JavaType valueType); void addListener(final Listener listener); void removeListener(final Listener listener); Map<String, T> getNodes();  }