Search in sources :

Example 16 with FileSinkCommittable

use of org.apache.flink.connector.file.sink.FileSinkCommittable in project flink by apache.

the class FileWriterBucketTest method testOnCheckpointNoPendingRecoverable.

@Test
public void testOnCheckpointNoPendingRecoverable() throws IOException {
    File outDir = TEMP_FOLDER.newFolder();
    Path path = new Path(outDir.toURI());
    TestRecoverableWriter recoverableWriter = getRecoverableWriter(path);
    FileWriterBucket<String> bucket = createBucket(recoverableWriter, path, DEFAULT_ROLLING_POLICY, OutputFileConfig.builder().build());
    bucket.write("test-element", 0);
    List<FileSinkCommittable> fileSinkCommittables = bucket.prepareCommit(false);
    FileWriterBucketState bucketState = bucket.snapshotState();
    compareNumberOfPendingAndInProgress(fileSinkCommittables, 0, 0);
    assertEquals(BUCKET_ID, bucketState.getBucketId());
    assertEquals(path, bucketState.getBucketPath());
    assertNotNull("The bucket should have in-progress recoverable", bucketState.getInProgressFileRecoverable());
}
Also used : Path(org.apache.flink.core.fs.Path) FileSinkCommittable(org.apache.flink.connector.file.sink.FileSinkCommittable) File(java.io.File) Test(org.junit.Test)

Example 17 with FileSinkCommittable

use of org.apache.flink.connector.file.sink.FileSinkCommittable in project flink by apache.

the class FileWriterBucketTest method testOnCheckpointMultiplePendingFiles.

@Test
public void testOnCheckpointMultiplePendingFiles() throws IOException {
    File outDir = TEMP_FOLDER.newFolder();
    Path path = new Path(outDir.toURI());
    TestRecoverableWriter recoverableWriter = getRecoverableWriter(path);
    FileWriterBucket<String> bucket = createBucket(recoverableWriter, path, EACH_ELEMENT_ROLLING_POLICY, OutputFileConfig.builder().build());
    bucket.write("test-element", 0);
    bucket.write("test-element", 0);
    bucket.write("test-element", 0);
    List<FileSinkCommittable> fileSinkCommittables = bucket.prepareCommit(false);
    FileWriterBucketState bucketState = bucket.snapshotState();
    // The last element would not roll
    compareNumberOfPendingAndInProgress(fileSinkCommittables, 2, 0);
    assertEquals(BUCKET_ID, bucketState.getBucketId());
    assertEquals(path, bucketState.getBucketPath());
    assertNotNull("The bucket should not have in-progress recoverable", bucketState.getInProgressFileRecoverable());
}
Also used : Path(org.apache.flink.core.fs.Path) FileSinkCommittable(org.apache.flink.connector.file.sink.FileSinkCommittable) File(java.io.File) Test(org.junit.Test)

Example 18 with FileSinkCommittable

use of org.apache.flink.connector.file.sink.FileSinkCommittable in project flink by apache.

the class FileWriterBucketTest method testTableRollingOnProcessingTime.

@Test
public void testTableRollingOnProcessingTime() throws IOException {
    File outDir = TEMP_FOLDER.newFolder();
    Path path = new Path(outDir.toURI());
    FileSystemTableSink.TableRollingPolicy tableRollingPolicy = new FileSystemTableSink.TableRollingPolicy(false, Long.MAX_VALUE, Duration.ofMillis(20).toMillis(), Duration.ofMillis(10).toMillis());
    TestRecoverableWriter recoverableWriter = getRecoverableWriter(path);
    FileWriterBucket<RowData> bucket = createRowDataBucket(recoverableWriter, path, tableRollingPolicy, OutputFileConfig.builder().build());
    bucket.write(GenericRowData.of(StringData.fromString("test-element")), 11);
    bucket.write(GenericRowData.of(StringData.fromString("test-element")), 12);
    bucket.onProcessingTime(21);
    assertNotNull("The bucket should not roll since interval and inactivity not reached", bucket.getInProgressPart());
    bucket.onProcessingTime(22);
    assertNull("The bucket should roll since inactivity is reached", bucket.getInProgressPart());
    bucket.write(GenericRowData.of(StringData.fromString("test-element")), 11);
    bucket.write(GenericRowData.of(StringData.fromString("test-element")), 21);
    bucket.onProcessingTime(30);
    assertNotNull("The bucket should not roll since interval and inactivity not reached", bucket.getInProgressPart());
    bucket.onProcessingTime(31);
    assertNull("The bucket should roll since interval is reached", bucket.getInProgressPart());
    List<FileSinkCommittable> fileSinkCommittables = bucket.prepareCommit(false);
    compareNumberOfPendingAndInProgress(fileSinkCommittables, 2, 0);
}
Also used : Path(org.apache.flink.core.fs.Path) GenericRowData(org.apache.flink.table.data.GenericRowData) RowData(org.apache.flink.table.data.RowData) FileSystemTableSink(org.apache.flink.connector.file.table.FileSystemTableSink) FileSinkCommittable(org.apache.flink.connector.file.sink.FileSinkCommittable) File(java.io.File) Test(org.junit.Test)

Example 19 with FileSinkCommittable

use of org.apache.flink.connector.file.sink.FileSinkCommittable in project flink by apache.

the class FileWriterBucketTest method compareNumberOfPendingAndInProgress.

private void compareNumberOfPendingAndInProgress(List<FileSinkCommittable> fileSinkCommittables, int expectedPendingFiles, int expectedInProgressFiles) {
    int numPendingFiles = 0;
    int numInProgressFiles = 0;
    for (FileSinkCommittable committable : fileSinkCommittables) {
        if (committable.getPendingFile() != null) {
            numPendingFiles++;
        }
        if (committable.getInProgressFileToCleanup() != null) {
            numInProgressFiles++;
        }
    }
    assertEquals(expectedPendingFiles, numPendingFiles);
    assertEquals(expectedInProgressFiles, numInProgressFiles);
}
Also used : FileSinkCommittable(org.apache.flink.connector.file.sink.FileSinkCommittable)

Example 20 with FileSinkCommittable

use of org.apache.flink.connector.file.sink.FileSinkCommittable in project flink by apache.

the class FileCommitterTest method testCleanupInProgressFiles.

@Test
public void testCleanupInProgressFiles() throws Exception {
    StubBucketWriter stubBucketWriter = new StubBucketWriter();
    FileCommitter fileCommitter = new FileCommitter(stubBucketWriter);
    MockCommitRequest<FileSinkCommittable> fileSinkCommittable = new MockCommitRequest<>(new FileSinkCommittable("0", new FileSinkTestUtils.TestInProgressFileRecoverable()));
    fileCommitter.commit(Collections.singletonList(fileSinkCommittable));
    assertEquals(0, stubBucketWriter.getRecoveredPendingFiles().size());
    assertEquals(1, stubBucketWriter.getNumCleanUp());
    assertEquals(0, fileSinkCommittable.getNumberOfRetries());
}
Also used : MockCommitRequest(org.apache.flink.api.connector.sink2.mocks.MockCommitRequest) FileSinkCommittable(org.apache.flink.connector.file.sink.FileSinkCommittable) Test(org.junit.Test)

Aggregations

FileSinkCommittable (org.apache.flink.connector.file.sink.FileSinkCommittable)32 Test (org.junit.Test)22 CommittableMessage (org.apache.flink.streaming.api.connector.sink2.CommittableMessage)12 Path (org.apache.flink.core.fs.Path)11 CompactorRequest (org.apache.flink.connector.file.sink.compactor.operator.CompactorRequest)10 OneInputStreamOperatorTestHarness (org.apache.flink.streaming.util.OneInputStreamOperatorTestHarness)10 File (java.io.File)8 CompactCoordinator (org.apache.flink.connector.file.sink.compactor.operator.CompactCoordinator)8 ArrayList (java.util.ArrayList)7 CommittableWithLineage (org.apache.flink.streaming.api.connector.sink2.CommittableWithLineage)6 CommittableSummary (org.apache.flink.streaming.api.connector.sink2.CommittableSummary)5 List (java.util.List)4 MockCommitRequest (org.apache.flink.api.connector.sink2.mocks.MockCommitRequest)4 OperatorSubtaskState (org.apache.flink.runtime.checkpoint.OperatorSubtaskState)4 PendingFileRecoverable (org.apache.flink.streaming.api.functions.sink.filesystem.InProgressFileWriter.PendingFileRecoverable)4 Map (java.util.Map)3 IOException (java.io.IOException)2 Collection (java.util.Collection)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Collectors (java.util.stream.Collectors)2