-
Notifications
You must be signed in to change notification settings - Fork 1.2k
CURATOR-654: Remove watcher after waiting on barrier. #435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,16 +18,15 @@ | |
| */ | ||
| package org.apache.curator.framework.recipes.barriers; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.junit.jupiter.api.Assertions.fail; | ||
| import com.google.common.collect.Lists; | ||
| import org.apache.curator.test.BaseClassForTests; | ||
| import org.apache.curator.utils.CloseableUtils; | ||
| import org.apache.curator.framework.CuratorFramework; | ||
| import org.apache.curator.framework.CuratorFrameworkFactory; | ||
| import org.apache.curator.retry.RetryOneTime; | ||
| import org.apache.zookeeper.KeeperException; | ||
| import org.junit.jupiter.api.Test; | ||
| import static org.mockito.Matchers.any; | ||
| import static org.mockito.Mockito.atLeastOnce; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
|
|
||
| import java.util.List; | ||
| import java.util.concurrent.Callable; | ||
|
|
@@ -36,6 +35,19 @@ | |
| import java.util.concurrent.Future; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import org.apache.curator.framework.CuratorFramework; | ||
| import org.apache.curator.framework.CuratorFrameworkFactory; | ||
| import org.apache.curator.framework.WatcherRemoveCuratorFramework; | ||
| import org.apache.curator.framework.api.ExistsBuilder; | ||
| import org.apache.curator.retry.RetryOneTime; | ||
| import org.apache.curator.test.BaseClassForTests; | ||
| import org.apache.curator.utils.CloseableUtils; | ||
| import org.apache.zookeeper.KeeperException; | ||
| import org.apache.zookeeper.Watcher; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import com.google.common.collect.Lists; | ||
|
|
||
| public class TestDistributedBarrier extends BaseClassForTests | ||
| { | ||
| @Test | ||
|
|
@@ -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(); | ||
| } | ||
|
Comment on lines
+262
to
+275
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps add watches and verify the following events triggered:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it might be particular important to test this as
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kezhuw I agree that it can be a bug as I mentioned in https://lists.apache.org/thread/0kcnklcxs0s5656c1sbh3crgdodbb0qg. You can reply on the mailing list and file an issue. |
||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annotated with
@VisibleForTesting.