Copilot commented on code in PR #20293:
URL: https://github.com/apache/druid/pull/20293#discussion_r3955006563
##########
multi-stage-query/src/test/java/org/apache/druid/msq/exec/ControllerHolderTest.java:
##########
@@ -376,6 +379,72 @@ public void run(final QueryListener listener)
Assertions.assertTrue(deregistered.get(), "Should have been deregistered");
}
+ @Test
+ public void testFinalReportVisibleBeforeCompletionListenerReturns() throws
Exception
+ {
+ final MSQTaskReportPayload finalPayload = makeSuccessReport();
+ final CountDownLatch listenerCalled = new CountDownLatch(1);
+ final CountDownLatch releaseListener = new CountDownLatch(1);
+ final DartControllerRegistry registry = new DartControllerRegistry(new
DartControllerConfig());
+ final Controller controller = new TestController("test-query")
+ {
+ @Override
+ public void run(final QueryListener listener)
+ {
+ listener.onQueryComplete(finalPayload);
+ }
+ };
+ final ControllerHolder holder = new ControllerHolder(
+ controller,
+ "sql-1",
+ "SELECT 1",
+ new AuthenticationResult("user", null, "authn", Map.of()),
+ DateTimes.nowUtc()
+ )
+ {
+ @Override
+ public String getControllerHost()
+ {
+ return "localhost:8082";
+ }
+ };
+ final ListenableFuture<?> future = holder.runAsync(
+ new NoopQueryListener()
+ {
+ @Override
+ public void onQueryComplete(final MSQTaskReportPayload report)
+ {
+ listenerCalled.countDown();
+ try {
+ Assertions.assertTrue(releaseListener.await(10,
TimeUnit.SECONDS));
+ }
+ catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RuntimeException(e);
+ }
+ }
+ },
+ registry,
+ controllerThreadPool
+ );
+
+ try {
+ Assertions.assertTrue(listenerCalled.await(10, TimeUnit.SECONDS));
+ // The controller is still registered: readers must get the final
payload, not stale live counters.
+ Assertions.assertSame(holder, registry.getController("test-query"));
+ Assertions.assertSame(
+ finalPayload,
+
registry.getQueryDetailsBySqlQueryId("sql-1").getReportMap().get("multiStageQuery").getPayload()
+ );
Review Comment:
Avoid hard-coding the MSQ task report key in this assertion; using the
shared constant prevents drift if the key changes and reduces typo risk.
--
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]