kezhuw commented on code in PR #501:
URL: https://github.com/apache/curator/pull/501#discussion_r1601428566
##########
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:
Swapping the order of assertion and `latch.await` is sufficient for this to
pass. Then it is same as `testInitialLoad`.
--
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]