Skip to content

Commit 9f44c52

Browse files
authored
[hotfix][tests] Fix unstable testInitialStartupModeWithOpTs case (#3809)
Signed-off-by: yuxiqian <[email protected]>
1 parent 8424467 commit 9f44c52

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-mysql/src/test/java/org/apache/flink/cdc/connectors/mysql/source/MySqlPipelineITCase.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -397,17 +397,27 @@ public void testInitialStartupModeWithOpTs() throws Exception {
397397
BinaryStringData.fromString("c-21")
398398
})));
399399
}
400+
401+
int snapshotRecordsCount = expectedSnapshot.size();
402+
int binlogRecordsCount = expectedBinlog.size();
403+
404+
// Ditto, CreateTableEvent might be emitted in multiple partitions.
400405
List<Event> actual =
401-
fetchResults(events, 1 + expectedSnapshot.size() + expectedBinlog.size());
402-
assertThat(actual.get(0)).isEqualTo(createTableEvent);
403-
assertThat(actual.subList(1, 10))
404-
.containsExactlyInAnyOrder(expectedSnapshot.toArray(new Event[0]));
405-
for (int i = 0; i < expectedBinlog.size(); i++) {
406+
fetchResultsExcept(
407+
events, snapshotRecordsCount + binlogRecordsCount, createTableEvent);
408+
409+
List<Event> actualSnapshotEvents = actual.subList(0, snapshotRecordsCount);
410+
List<Event> actualBinlogEvents = actual.subList(snapshotRecordsCount, actual.size());
411+
412+
assertThat(actualSnapshotEvents).containsExactlyInAnyOrderElementsOf(expectedSnapshot);
413+
assertThat(actualBinlogEvents).hasSize(binlogRecordsCount);
414+
415+
for (int i = 0; i < binlogRecordsCount; i++) {
406416
if (expectedBinlog.get(i) instanceof SchemaChangeEvent) {
407-
assertThat(expectedBinlog.get(i)).isEqualTo(actual.get(10 + i));
417+
assertThat(actualBinlogEvents.get(i)).isEqualTo(expectedBinlog.get(i));
408418
} else {
409419
DataChangeEvent expectedEvent = (DataChangeEvent) expectedBinlog.get(i);
410-
DataChangeEvent actualEvent = (DataChangeEvent) actual.get(10 + i);
420+
DataChangeEvent actualEvent = (DataChangeEvent) actualBinlogEvents.get(i);
411421
assertThat(actualEvent.op()).isEqualTo(expectedEvent.op());
412422
assertThat(actualEvent.before()).isEqualTo(expectedEvent.before());
413423
assertThat(actualEvent.after()).isEqualTo(expectedEvent.after());

0 commit comments

Comments
 (0)