[
https://issues.apache.org/jira/browse/ZOOKEEPER-2062?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14513407#comment-14513407
]
Rakesh R commented on ZOOKEEPER-2062:
-------------------------------------
[~cnauroth] I really appreciate your thoughts. Its very nice approach by
directly using the {{DataTree}} watch information in tests. This would make the
tests more deterministic as opposed to the waiting approach. Your idea of
{{WatchManagerListener}} makes it simple. On a second thought I'm trying to
avoid creating an extra listener just for testing purpose, if we couldn't
manage to find a best way, I agree to go ahead with the
{{WatchManagerListener}}. Can we first think of using existing data structures
and the APIs available in {{DataTree}} to satisfy the test assertions.
I've tried slightly different approach. Please see the below improvement and
does this sound good to you? If yes, we will modify all the similar waiting
cases into this kinda approach.
1. In {{testRemoveAllDataWatchesOnAPath}}. Modify the below part
{code}
Assert.assertNotNull("Didn't set data watches",
zk2.exists("/node1", w2));
removeAllWatches(zk2, "/node1", WatcherType.Data, false, Code.OK);
Assert.assertTrue("Didn't remove data watcher",
rmWatchCount.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS));
zk1.setData("/node1", "test".getBytes(), -1);
LOG.info("Waiting for data watchers notification after watch removal");
Assert.assertFalse("Received data watch notification!",
dWatchCount.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS));
Assert.assertEquals("Received watch notification after removal!", 2,
dWatchCount.getCount());
{code}
to
{code}
Set<Long> sessions = getServer(serverFactory).getZKDatabase()
.getDataTree().getWatchesByPath().getSessions("/node1");
Assert.assertNotNull("Didn't find the session", sessions);
final long sessionId = sessions.iterator().next();
Assert.assertEquals("Session mismatches", zk2.getSessionId(),
sessionId);
removeAllWatches(zk2, "/node1", WatcherType.Data, false, Code.OK);
Assert.assertTrue("Didn't remove data watcher",
rmWatchCount.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS));
Assert.assertFalse("Child watchers exists after removal!",
getServer(serverFactory).getZKDatabase().getDataTree()
.getWatchesByPath().hasSessions("/node1"));
{code}
2. In {{testChRootRemoveWatcher}}. Modify the below part
{code}
Assert.assertFalse("Shouldn't remove data watcher", w2.matches());
{code}
to
{code}
Assert.assertEquals("Didn't find child watcher", 1, zk2
.getChildWatches().size());
removeWatches(zk2, "/node1", w2, WatcherType.Any, false, Code.OK);
Assert.assertTrue("Didn't remove child watcher", w2.matches());
{code}
> RemoveWatchesTest takes forever to run
> --------------------------------------
>
> Key: ZOOKEEPER-2062
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2062
> Project: ZooKeeper
> Issue Type: Bug
> Components: tests
> Affects Versions: 3.5.0
> Reporter: Flavio Junqueira
> Assignee: Chris Nauroth
> Attachments: ZOOKEEPER-2062.001.patch, ZOOKEEPER-2062.002.patch
>
>
> [junit] Running org.apache.zookeeper.RemoveWatchesTest
> [junit] Tests run: 46, Failures: 0, Errors: 0, Skipped: 0, Time elapsed:
> 306.188 sec
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)