abhishekagarwal87 commented on code in PR #15726:
URL: https://github.com/apache/druid/pull/15726#discussion_r1512330473
##########
server/src/test/java/org/apache/druid/discovery/BaseNodeRoleWatcherTest.java:
##########
@@ -125,15 +190,40 @@ private DiscoveryDruidNode
buildDiscoveryDruidNode(NodeRole role, String host)
);
}
- private void assertListener(TestListener listener, boolean
nodeViewInitialized, List<DiscoveryDruidNode> nodesAdded,
List<DiscoveryDruidNode> nodesRemoved)
+ private void assertListenerTimedOut(TestListener listener)
Review Comment:
why is it done inside exec?
##########
server/src/test/java/org/apache/druid/discovery/BaseNodeRoleWatcherTest.java:
##########
@@ -116,6 +117,70 @@ public void testGeneralUseSimulation()
assertListener(listener3, true, nodesAdded, nodesRemoved);
}
+ @Test(timeout = 60_000L)
+ public void testRegisterListenerBeforeTimeout() throws InterruptedException
+ {
+ BaseNodeRoleWatcher nodeRoleWatcher = new BaseNodeRoleWatcher(exec,
NodeRole.BROKER, 3);
+
+ TestListener listener1 = new TestListener();
+ nodeRoleWatcher.registerListener(listener1);
+
+ DiscoveryDruidNode broker1 = buildDiscoveryDruidNode(NodeRole.BROKER,
"broker1");
+ DiscoveryDruidNode broker2 = buildDiscoveryDruidNode(NodeRole.BROKER,
"broker2");
+ DiscoveryDruidNode broker3 = buildDiscoveryDruidNode(NodeRole.BROKER,
"broker3");
+
+ DiscoveryDruidNode notBroker = new DiscoveryDruidNode(
+ new DruidNode("s3", "h3", false, 8080, null, true, false),
+ NodeRole.COORDINATOR,
+ ImmutableMap.of()
+ );
+
+ nodeRoleWatcher.childAdded(broker1);
+ nodeRoleWatcher.childAdded(notBroker);
+ nodeRoleWatcher.childAdded(broker3);
+ nodeRoleWatcher.childRemoved(broker2);
+
+ assertListener(listener1, false, Collections.emptyList(),
Collections.emptyList());
+
+ Thread.sleep(3100);
Review Comment:
or you could just do `listener.getAllNodes()` and get rid of
`assertListenerTimedout`
##########
server/src/test/java/org/apache/druid/discovery/BaseNodeRoleWatcherTest.java:
##########
@@ -116,6 +117,70 @@ public void testGeneralUseSimulation()
assertListener(listener3, true, nodesAdded, nodesRemoved);
}
+ @Test(timeout = 60_000L)
+ public void testRegisterListenerBeforeTimeout() throws InterruptedException
+ {
+ BaseNodeRoleWatcher nodeRoleWatcher = new BaseNodeRoleWatcher(exec,
NodeRole.BROKER, 3);
+
+ TestListener listener1 = new TestListener();
+ nodeRoleWatcher.registerListener(listener1);
+
+ DiscoveryDruidNode broker1 = buildDiscoveryDruidNode(NodeRole.BROKER,
"broker1");
+ DiscoveryDruidNode broker2 = buildDiscoveryDruidNode(NodeRole.BROKER,
"broker2");
+ DiscoveryDruidNode broker3 = buildDiscoveryDruidNode(NodeRole.BROKER,
"broker3");
+
+ DiscoveryDruidNode notBroker = new DiscoveryDruidNode(
+ new DruidNode("s3", "h3", false, 8080, null, true, false),
+ NodeRole.COORDINATOR,
+ ImmutableMap.of()
+ );
+
+ nodeRoleWatcher.childAdded(broker1);
+ nodeRoleWatcher.childAdded(notBroker);
+ nodeRoleWatcher.childAdded(broker3);
+ nodeRoleWatcher.childRemoved(broker2);
+
+ assertListener(listener1, false, Collections.emptyList(),
Collections.emptyList());
+
+ Thread.sleep(3100);
Review Comment:
rather than doing this, you could instead wait on listenerTimedOut. This can
be done by having a sort of latch.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]