[
https://issues.apache.org/jira/browse/CURATOR-654?focusedWorklogId=818434&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-818434
]
ASF GitHub Bot logged work on CURATOR-654:
------------------------------------------
Author: ASF GitHub Bot
Created on: 19/Oct/22 11:40
Start Date: 19/Oct/22 11:40
Worklog Time Spent: 10m
Work Description: 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.
Issue Time Tracking
-------------------
Worklog Id: (was: 818434)
Time Spent: 0.5h (was: 20m)
> DistributedBarrier watcher leak
> -------------------------------
>
> Key: CURATOR-654
> URL: https://issues.apache.org/jira/browse/CURATOR-654
> Project: Apache Curator
> Issue Type: Bug
> Components: Recipes
> Affects Versions: 5.3.0
> Reporter: Stuart Scott
> Priority: Major
> Attachments:
> CURATOR-654__Remove_watchers_after_waiting_for_barrier_.patch
>
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> The DistributedBarrier adds a zookeeper exists watcher in the waitOnBarrier()
> method. It appears as though the watcher is never removed. In a system where
> DistributedBarriers are used heavily this eventually results in the system
> running out of memory.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)