chevaris commented on code in PR #1264: URL: https://github.com/apache/curator/pull/1264#discussion_r2046275893
########## curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentTtlNode.java: ########## @@ -237,4 +241,88 @@ void touch() { } } } + + @Test + public void testInternalExecutorClose() throws Exception { + final String mainPath = "/parent/main"; + final String touchPath = ZKPaths.makePath(mainPath, PersistentTtlNode.DEFAULT_CHILD_NODE_NAME); + final CountDownLatch touchCreatedLatch = new CountDownLatch(1); + try (CuratorFramework client = + CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1))) { + client.start(); + assertTrue(client.blockUntilConnected(1, TimeUnit.SECONDS)); + try (PersistentWatcher watcher = new PersistentWatcher(client, mainPath, true)) { + final Watcher listener = event -> { + final String path = event.getPath(); + if (touchPath.equals(path)) { + touchCreatedLatch.countDown(); + } + }; + watcher.getListenable().addListener(listener); + watcher.start(); + final AtomicLong executorThreadId = new AtomicLong(); + try (PersistentTtlNode node = new PersistentTtlNode(client, mainPath, ttlMs, new byte[0])) { + node.start(); + assertTrue(touchCreatedLatch.await(5 * ttlMs, TimeUnit.MILLISECONDS)); + node.getCloseableScheduledExecutorService() + .submit(() -> + executorThreadId.set(Thread.currentThread().getId())); + assertFalse(getThreadsWithIdAndName(executorThreadId, PersistentTtlNode.TOUCH_THREAD_NAME) + .isEmpty()); + } + Thread.sleep(10L); + assertTrue(getThreadsWithIdAndName(executorThreadId, PersistentTtlNode.TOUCH_THREAD_NAME) + .isEmpty()); + } + } + } + + private List<Thread> getThreadsWithIdAndName(final AtomicLong executorThreadId, final String name) { + return Thread.getAllStackTraces().keySet().stream() + .filter(t -> t.getId() == executorThreadId.get() && t.getName().contains(name)) + .collect(Collectors.toList()); + } + + @Test + public void testExternalExecutorClose() throws Exception { + final String mainPath = "/parent/main"; + final String touchPath = ZKPaths.makePath(mainPath, PersistentTtlNode.DEFAULT_CHILD_NODE_NAME); + final CountDownLatch touchCreatedLatch = new CountDownLatch(1); + try (CuratorFramework client = + CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1))) { + client.start(); + assertTrue(client.blockUntilConnected(1, TimeUnit.SECONDS)); + try (PersistentWatcher watcher = new PersistentWatcher(client, mainPath, true)) { + final Watcher listener = event -> { + final String path = event.getPath(); + if (touchPath.equals(path)) { + touchCreatedLatch.countDown(); + } + }; + watcher.getListenable().addListener(listener); + watcher.start(); + final AtomicLong executorThreadId = new AtomicLong(); + final String threadName = "testThreadName"; + try (PersistentTtlNode node = new PersistentTtlNode( + client, + Executors.newSingleThreadScheduledExecutor(task -> new Thread(task, threadName)), Review Comment: You are right. That was missing -- 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: commits-unsubscr...@curator.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org