leonardBang commented on code in PR #28069:
URL: https://github.com/apache/flink/pull/28069#discussion_r3240004173


##########
flink-connectors/flink-connector-base/src/test/java/org/apache/flink/connector/base/source/hybrid/HybridSourceReaderTest.java:
##########
@@ -281,6 +282,55 @@ void testReaderRecovery() throws Exception {
         reader.close();
     }
 
+    @Test
+    void testReaderRecoveryInitializationOrder() throws Exception {
+        TestingReaderContext readerContext = new TestingReaderContext();
+        MockBaseSource source = new MockBaseSource(1, 1, Boundedness.BOUNDED);
+
+        // First pass: create a snapshot with an in-progress split
+        HybridSourceReader<Integer> reader = new 
HybridSourceReader<>(readerContext);
+        reader.start();
+        assertAndClearSourceReaderFinishedEvent(readerContext, -1);
+        reader.handleSourceEvents(new SwitchSourceEvent(0, source, false));
+
+        MockSourceSplit mockSplit = new MockSourceSplit(0, 0, 2147483647);
+        SwitchedSources switchedSources = new SwitchedSources();
+        switchedSources.put(0, source);
+        HybridSourceSplit hybridSplit = HybridSourceSplit.wrapSplit(mockSplit, 
0, switchedSources);
+        reader.addSplits(Collections.singletonList(hybridSplit));
+        List<HybridSourceSplit> snapshot = reader.snapshotState(0);
+        reader.close();
+
+        // Recovery: capture the underlying reader as a spy to verify call 
order
+        readerContext.clearSentEvents();
+        SourceReader<Integer, MockSourceSplit>[] spyHolder = new 
SourceReader[1];
+        Source spySource =
+                new MockSource(null, 0) {
+                    @Override
+                    public SourceReader<Integer, MockSourceSplit> createReader(
+                            SourceReaderContext ctx) {
+                        SourceReader<Integer, MockSourceSplit> spy =
+                                Mockito.spy(source.createReader(ctx));
+                        spyHolder[0] = spy;
+                        return spy;
+                    }
+                };
+
+        HybridSourceReader<Integer> recoveredReader = new 
HybridSourceReader<>(readerContext);
+        recoveredReader.addSplits(snapshot);
+        recoveredReader.start();
+        assertAndClearSourceReaderFinishedEvent(readerContext, -1);
+
+        recoveredReader.handleSourceEvents(new SwitchSourceEvent(0, spySource, 
false));
+
+        // Verify addSplits was called before start on the underlying reader

Review Comment:
   // Verify the contract: addSplits() must be called before start() during 
recovery



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

Reply via email to