gaoyunhaii commented on a change in pull request #25:
URL: https://github.com/apache/flink-ml/pull/25#discussion_r746358395



##########
File path: 
flink-ml-iteration/src/test/java/org/apache/flink/iteration/operator/ReplayOperatorTest.java
##########
@@ -50,12 +69,206 @@ public void testReplaying() throws Exception {
         final int numRecords = 10;
         OperatorID operatorId = new OperatorID();
 
+        createHarnessAndRun(
+                operatorId,
+                null,
+                harness -> {
+                    // First round
+                    for (int i = 0; i < numRecords; ++i) {
+                        harness.processElement(
+                                new 
StreamRecord<>(IterationRecord.newRecord(i, 0)), 0, 0);
+                    }
+                    harness.endInput(0, true);
+                    harness.processElement(
+                            new 
StreamRecord<>(IterationRecord.newEpochWatermark(0, "sender1")),
+                            1,
+                            0);
+                    assertOutputAllRecordsAndEpochWatermark(
+                            harness.getOutput(), numRecords, operatorId, 0);
+                    harness.getOutput().clear();
+
+                    // The round 1
+                    harness.processElement(
+                            new 
StreamRecord<>(IterationRecord.newEpochWatermark(1, "sender1")),
+                            1,
+                            0);
+                    // The output would be done asynchronously inside the 
ReplayerOperator.
+                    while (harness.getOutput().size() < numRecords + 1) {
+                        Thread.sleep(500);
+                    }
+                    assertOutputAllRecordsAndEpochWatermark(
+                            harness.getOutput(), numRecords, operatorId, 1);
+                    harness.getOutput().clear();
+
+                    // The round 2
+                    harness.processElement(
+                            new 
StreamRecord<>(IterationRecord.newEpochWatermark(2, "sender1")),
+                            1,
+                            0);
+                    // The output would be done asynchronously inside the 
ReplayerOperator.
+                    while (harness.getOutput().size() < numRecords + 1) {
+                        Thread.sleep(500);
+                    }
+                    assertOutputAllRecordsAndEpochWatermark(
+                            harness.getOutput(), numRecords, operatorId, 2);
+                    return null;
+                });
+    }
+
+    @Test
+    public void testSnapshotAndRestoreOnFirstEpoch() throws Exception {
+        final int numRecords = 10;
+        OperatorID operatorId = new OperatorID();
+
+        List<Object> firstRoundOutput = new ArrayList<>();
+        List<Object> secondRoundOutput = new ArrayList<>();
+
+        TaskStateSnapshot snapshot =
+                createHarnessAndRun(
+                        operatorId,
+                        null,
+                        harness -> {
+                            
harness.getTaskStateManager().getWaitForReportLatch().reset();
+
+                            for (int i = 0; i < numRecords / 2; ++i) {
+                                harness.processElement(
+                                        new 
StreamRecord<>(IterationRecord.newRecord(i, 0)), 0, 0);
+                            }
+
+                            harness.getStreamTask()
+                                    .triggerCheckpointAsync(
+                                            new CheckpointMetaData(2, 1000),
+                                            CheckpointOptions.alignedNoTimeout(
+                                                    CheckpointType.CHECKPOINT,
+                                                    
CheckpointStorageLocationReference
+                                                            .getDefault()));
+                            harness.processAll();
+
+                            firstRoundOutput.addAll(harness.getOutput());
+
+                            
harness.getTaskStateManager().getWaitForReportLatch().await();
+                            return harness.getTaskStateManager()
+                                    .getLastJobManagerTaskStateSnapshot();
+                        });
+
+        createHarnessAndRun(
+                operatorId,
+                snapshot,
+                harness -> {
+                    for (int i = numRecords / 2; i < numRecords; ++i) {
+                        harness.processElement(
+                                new 
StreamRecord<>(IterationRecord.newRecord(i, 0)), 0, 0);
+                    }
+                    harness.endInput(0, true);
+                    harness.processElement(
+                            new 
StreamRecord<>(IterationRecord.newEpochWatermark(0, "send-0")),
+                            1,
+                            0);
+                    harness.processAll();
+                    firstRoundOutput.addAll(harness.getOutput());
+
+                    // The second round
+                    harness.getOutput().clear();
+                    harness.processElement(
+                            new 
StreamRecord<>(IterationRecord.newEpochWatermark(1, "send-0")),
+                            1,
+                            0);
+                    secondRoundOutput.addAll(harness.getOutput());
+
+                    return null;
+                });
+
+        assertOutputAllRecordsAndEpochWatermark(firstRoundOutput, numRecords, 
operatorId, 0);
+        assertOutputAllRecordsAndEpochWatermark(secondRoundOutput, numRecords, 
operatorId, 1);
+    }
+
+    @Test
+    public void testSnapshotAndRestoreOnSecondEpoch() throws Exception {
+        final int numRecords = 20;

Review comment:
       It could also be 10, I changed it to 10 to be consistent.




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