openinx commented on a change in pull request #1477:
URL: https://github.com/apache/iceberg/pull/1477#discussion_r505234841
##########
File path:
flink/src/test/java/org/apache/iceberg/flink/sink/TestIcebergFilesCommitter.java
##########
@@ -473,12 +535,65 @@ public void testBoundedStream() throws Exception {
harness.processElement(dataFile, 1);
((BoundedOneInput) harness.getOneInputOperator()).endInput();
+ assertFlinkManifests(0);
SimpleDataUtil.assertTableRows(tablePath, tableRows);
assertSnapshotSize(1);
assertMaxCommittedCheckpointId(jobId, Long.MAX_VALUE);
}
}
+ @Test
+ public void testFlinkManifests() throws Exception {
+ long timestamp = 0;
+ final long checkpoint = 10;
+
+ JobID jobId = new JobID();
+ try (OneInputStreamOperatorTestHarness<DataFile, Void> harness =
createStreamSink(jobId)) {
+ harness.setup();
+ harness.open();
+
+ assertMaxCommittedCheckpointId(jobId, -1L);
+
+ RowData row1 = SimpleDataUtil.createRowData(1, "hello");
+ DataFile dataFile1 = writeDataFile("data-1", ImmutableList.of(row1));
+
+ harness.processElement(dataFile1, ++timestamp);
+ assertMaxCommittedCheckpointId(jobId, -1L);
+
+ // 1. snapshotState for checkpoint#1
+ harness.snapshot(checkpoint, ++timestamp);
+ List<Path> manifestPaths = assertFlinkManifests(1);
+ Path manifestPath = manifestPaths.get(0);
+ Assert.assertEquals("File name should have the expected pattern.",
+ String.format("%s-%05d-%d-%d-%05d.avro", jobId, 0, 0, checkpoint,
1), manifestPath.getFileName().toString());
+
+ // 2. Read the data files from manifests and assert.
+ List<DataFile> dataFiles =
FlinkManifest.read(createTestingManifestFile(manifestPath), table.io());
+ Assert.assertEquals(1, dataFiles.size());
+ TestFlinkManifest.checkDataFile(dataFile1, dataFiles.get(0));
+
+ // 3. notifyCheckpointComplete for checkpoint#1
+ harness.notifyOfCompletedCheckpoint(checkpoint);
+ SimpleDataUtil.assertTableRows(tablePath, ImmutableList.of(row1));
+ assertMaxCommittedCheckpointId(jobId, checkpoint);
+ assertFlinkManifests(0);
+ }
+ }
+
+ private ManifestFile createTestingManifestFile(Path manifestPath) {
+ return new GenericManifestFile(manifestPath.toAbsolutePath().toString(),
manifestPath.toFile().length(), 0,
+ ManifestContent.DATA, 0, 0, 0L, 0, 0, 0, 0, 0, 0, null);
+ }
+
+ private List<Path> assertFlinkManifests(int expectedCount) throws
IOException {
+ List<Path> manifests = Files.list(flinkManifestFolder.toPath())
+ .filter(p -> !p.toString().endsWith(".crc"))
+ .collect(Collectors.toList());
+ Assert.assertEquals(String.format("Expected %s flink manifests, but the
list is: %s", expectedCount, manifests),
Review comment:
This message was designed to print the whole manifests lists so that we
could locate the reason why the `expectedCount` and `manifests.size()` is
mismatched. I think we could keep this message.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]