AmatyaAvadhanula commented on code in PR #15726:
URL: https://github.com/apache/druid/pull/15726#discussion_r1512570219


##########
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:
   I've added a test with a latch instead of a manual timeout.
   I'm also using a global executor for all three tests. Is a shutdown still 
needed?



-- 
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]

Reply via email to