use of org.apache.curator.test.ExecuteCalledWatchingExecutorService in project xian by happyyangyuan.
the class TestPathChildrenCache method testDeleteNodeAfterCloseDoesntCallExecutor.
@Test
public void testDeleteNodeAfterCloseDoesntCallExecutor() throws Exception {
Timing timing = new Timing();
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
client.start();
try {
client.create().forPath("/test");
final ExecuteCalledWatchingExecutorService exec = new ExecuteCalledWatchingExecutorService(Executors.newSingleThreadExecutor());
PathChildrenCache cache = new PathChildrenCache(client, "/test", true, false, exec);
cache.start();
client.create().forPath("/test/one", "hey there".getBytes());
cache.rebuild();
Assert.assertEquals(new String(cache.getCurrentData("/test/one").getData()), "hey there");
Assert.assertTrue(exec.isExecuteCalled());
exec.setExecuteCalled(false);
cache.close();
Assert.assertFalse(exec.isExecuteCalled());
client.delete().forPath("/test/one");
timing.sleepABit();
Assert.assertFalse(exec.isExecuteCalled());
} finally {
client.close();
}
}
use of org.apache.curator.test.ExecuteCalledWatchingExecutorService in project xian by happyyangyuan.
the class TestServiceCache method testExecutorServiceIsInvoked.
@Test
public void testExecutorServiceIsInvoked() throws Exception {
List<Closeable> closeables = Lists.newArrayList();
try {
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
closeables.add(client);
client.start();
ServiceDiscovery<String> discovery = ServiceDiscoveryBuilder.builder(String.class).basePath("/discovery").client(client).build();
closeables.add(discovery);
discovery.start();
ExecuteCalledWatchingExecutorService exec = new ExecuteCalledWatchingExecutorService(Executors.newSingleThreadExecutor());
Assert.assertFalse(exec.isExecuteCalled());
ServiceCache<String> cache = discovery.serviceCacheBuilder().name("test").executorService(exec).build();
closeables.add(cache);
cache.start();
final Semaphore semaphore = new Semaphore(0);
ServiceCacheListener listener = new ServiceCacheListener() {
@Override
public void cacheChanged() {
semaphore.release();
}
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
}
};
cache.addListener(listener);
ServiceInstance<String> instance1 = ServiceInstance.<String>builder().payload("thing").name("test").port(10064).build();
discovery.registerService(instance1);
Assert.assertTrue(semaphore.tryAcquire(10, TimeUnit.SECONDS));
Assert.assertTrue(exec.isExecuteCalled());
} finally {
Collections.reverse(closeables);
for (Closeable c : closeables) {
CloseableUtils.closeQuietly(c);
}
}
}
Aggregations