kezhuw commented on code in PR #501:
URL: https://github.com/apache/curator/pull/501#discussion_r1601401364
##########
curator-x-discovery/src/test/java/org/apache/curator/x/discovery/TestServiceCache.java:
##########
@@ -114,6 +117,81 @@ public void stateChanged(CuratorFramework client,
ConnectionState newState) {}
}
}
+ @Test
+ public void testInitialLoadUsingExecutor() throws Exception {
+ List<Closeable> closeables = Lists.newArrayList();
+ ExecutorService runSafeExec = new ThreadPoolExecutor(2, 2, 0,
TimeUnit.SECONDS, new ArrayBlockingQueue<>(5));
+ try {
+ CuratorFramework client = CuratorFrameworkFactory.builder()
+ .connectString(server.getConnectString())
+ .retryPolicy(new RetryOneTime(1))
+ .runSafeService(runSafeExec)
+ .build();
+ closeables.add(client);
+ client.start();
+
+ ServiceDiscovery<String> discovery =
ServiceDiscoveryBuilder.builder(String.class)
+ .basePath("/discovery")
+ .client(client)
+ .build();
+ closeables.add(discovery);
+ discovery.start();
+
+ ServiceInstance<String> instance1 =
ServiceInstance.<String>builder()
+ .payload("test")
+ .name("test")
+ .port(10064)
+ .build();
+ discovery.registerService(instance1);
+
+ ServiceCache<String> cache =
+ discovery.serviceCacheBuilder().name("test").build();
+ closeables.add(cache);
+
+ final CountDownLatch latch = new CountDownLatch(2);
+ ServiceCacheListener listener = new ServiceCacheListener() {
+ @Override
+ public void cacheChanged() {
+ latch.countDown();
+ }
+
+ @Override
+ public void stateChanged(CuratorFramework client,
ConnectionState newState) {}
+ };
+ cache.addListener(listener);
+ cache.start();
+ //assertEquals(1, cache.getInstances().size());
+
+ ServiceInstance<String> instance2 =
ServiceInstance.<String>builder()
+ .payload("test")
+ .name("test")
+ .port(10065)
+ .build();
+ ServiceInstance<String> instance3 =
ServiceInstance.<String>builder()
+ .payload("test")
+ .name("test")
+ .port(10066)
+ .build();
+ discovery.registerService(instance2);
+ discovery.registerService(instance3);
+ assertEquals(3, cache.getInstances().size());
Review Comment:
Adding `Thread.sleep(500)` before assertions pass them.
I think it is about freshness, and the javadoc says:
> NOTE: there is no guarantee of freshness.
Similar, `testInitialLoad` asserts after `latch.await`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]