hudi-agent commented on code in PR #20339:
URL: https://github.com/apache/hudi/pull/20339#discussion_r4278488402
##########
hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/sink/TestStreamWriteOperatorCoordinator.java:
##########
@@ -306,6 +311,74 @@ public void testCheckpointAndRestore(boolean
isStreamingIndexWriteEnabled, boole
.filterCompletedInstants().containsInstant(instant));
}
+ @Test
+ void testGlobalRestoreWaitsForPendingCommit() throws Exception {
+ coordinator.close();
+ Configuration conf =
TestConfigurations.getDefaultConf(tempFile.getAbsolutePath());
+ conf.set(FlinkOptions.METADATA_ENABLED, false);
+ conf.set(FlinkOptions.TABLE_SERVICES_ENABLED, false);
+ coordinator = startCoordinator(conf, 2);
+ String instant = requestInstantTime(-1);
+ CompletableFuture<byte[]> checkpoint = new CompletableFuture<>();
+ coordinator.checkpointCoordinator(1, checkpoint);
+ coordinator.handleEventFromOperator(0, createOperatorEvent(0, instant,
"par1", true, 0.1));
+ coordinator.handleEventFromOperator(1, createOperatorEvent(1, instant,
"par2", true, 0.2));
+ byte[] checkpointData = checkpoint.get();
+
+ CountDownLatch commitEntered = new CountDownLatch(1);
+ CountDownLatch releaseCommit = new CountDownLatch(1);
+ AtomicInteger commitCalls = new AtomicInteger();
+ HoodieFlinkWriteClient client = Mockito.spy(coordinator.getWriteClient());
+ Mockito.doAnswer(invocation -> {
+ if (commitCalls.incrementAndGet() == 1) {
+ commitEntered.countDown();
+ assertTrue(releaseCommit.await(10, TimeUnit.SECONDS));
+ }
+ return invocation.callRealMethod();
+ }).when(client).commit(Mockito.eq(instant), Mockito.anyList(),
Mockito.any(), Mockito.anyString(), Mockito.anyMap());
+ Field clientField =
StreamWriteOperatorCoordinator.class.getDeclaredField("writeClient");
+ clientField.setAccessible(true);
+ clientField.set(coordinator, client);
+
+ MockOperatorCoordinatorContext ctx = (MockOperatorCoordinatorContext)
coordinator.getContext();
Review Comment:
🤖 nit: could you split the reflection swap of `writeClient` into a small
helper, or reuse an existing test hook if there is one? It would make the test
body shorter and easier to follow.
<sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag
quality.</i></sub>
--
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]