You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@curator.apache.org by GitBox <gi...@apache.org> on 2022/10/19 11:40:43 UTC

[GitHub] [curator] kezhuw commented on a diff in pull request #435: CURATOR-654: Remove watcher after waiting on barrier.

kezhuw commented on code in PR #435:
URL: https://github.com/apache/curator/pull/435#discussion_r999325439


##########
curator-recipes/src/test/java/org/apache/curator/framework/recipes/barriers/TestDistributedBarrier.java:
##########
@@ -218,4 +230,48 @@ public Object call() throws Exception
             client.close();
         }
     }
+
+    @Test
+    public void     testIsSet() throws Exception
+    {
+        try (CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1))) {
+            client.start();
+
+            final DistributedBarrier barrier = new DistributedBarrier(client, "/barrier");
+            barrier.setBarrier();
+
+            assertTrue(barrier.isSet());
+        }
+    }
+
+    @Test
+    public void     testIsNotSet() throws Exception
+    {
+        try (CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1))) {
+            client.start();
+
+            final DistributedBarrier barrier = new DistributedBarrier(client, "/barrier");
+            barrier.setBarrier();
+            barrier.removeBarrier();
+
+            assertFalse(barrier.isSet());
+        }
+    }
+
+    @Test
+    public void     testWatchersRemoved() throws Exception
+    {
+        CuratorFramework              client = mock(CuratorFramework.class);
+        WatcherRemoveCuratorFramework watcherRemoveClient = mock(WatcherRemoveCuratorFramework.class);
+        ExistsBuilder                 existsBuilder = mock(ExistsBuilder.class);
+
+        when(client.newWatcherRemoveCuratorFramework()).thenReturn(watcherRemoveClient);
+        when(watcherRemoveClient.checkExists()).thenReturn(existsBuilder);
+        when(existsBuilder.usingWatcher(any(Watcher.class))).thenReturn(existsBuilder);
+
+        final DistributedBarrier      barrier = new DistributedBarrier(client, "/barrier");
+        barrier.waitOnBarrier(1, TimeUnit.SECONDS);
+        verify(watcherRemoveClient, atLeastOnce()).removeWatchers();
+    }

Review Comment:
   I guess it might be particular important to test this as `ZooKeeper.removeWatches` is cheating since [ZOOKEEPER-1910](https://issues.apache.org/jira/browse/ZOOKEEPER-1910). See also kezhuw/zookeeper-client-rust#2.



-- 
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: dev-unsubscribe@curator.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org