Search in sources :

Example 36 with FileSourceSplit

use of org.apache.flink.connector.file.src.FileSourceSplit in project flink by apache.

the class StaticFileSplitEnumeratorTest method testCheckpointNoSplitRequested.

@Test
public void testCheckpointNoSplitRequested() throws Exception {
    final TestingSplitEnumeratorContext<FileSourceSplit> context = new TestingSplitEnumeratorContext<>(4);
    final FileSourceSplit split = createRandomSplit();
    final StaticFileSplitEnumerator enumerator = createEnumerator(context, split);
    final PendingSplitsCheckpoint<FileSourceSplit> checkpoint = enumerator.snapshotState(1L);
    assertThat(checkpoint.getSplits(), contains(split));
}
Also used : FileSourceSplit(org.apache.flink.connector.file.src.FileSourceSplit) TestingSplitEnumeratorContext(org.apache.flink.connector.testutils.source.reader.TestingSplitEnumeratorContext) Test(org.junit.Test)

Example 37 with FileSourceSplit

use of org.apache.flink.connector.file.src.FileSourceSplit in project flink by apache.

the class NonSplittingRecursiveEnumeratorTest method testIncludeFilesFromNestedDirectories.

// ------------------------------------------------------------------------
@Test
public void testIncludeFilesFromNestedDirectories() throws Exception {
    final Path[] testPaths = new Path[] { new Path("testfs:///dir/file1"), new Path("testfs:///dir/nested/file.out"), new Path("testfs:///dir/nested/anotherfile.txt") };
    testFs = TestingFileSystem.createWithFiles("testfs", testPaths);
    testFs.register();
    final NonSplittingRecursiveEnumerator enumerator = createEnumerator();
    final Collection<FileSourceSplit> splits = enumerator.enumerateSplits(new Path[] { new Path("testfs:///dir") }, 1);
    assertThat(toPaths(splits), containsInAnyOrder(testPaths));
}
Also used : Path(org.apache.flink.core.fs.Path) FileSourceSplit(org.apache.flink.connector.file.src.FileSourceSplit) Test(org.junit.Test)

Example 38 with FileSourceSplit

use of org.apache.flink.connector.file.src.FileSourceSplit in project flink by apache.

the class NonSplittingRecursiveEnumeratorTest method testFileWithMultipleBlocks.

@Test
public void testFileWithMultipleBlocks() throws Exception {
    final Path testPath = new Path("testfs:///dir/file");
    testFs = TestingFileSystem.createForFileStatus("testfs", TestingFileSystem.TestFileStatus.forFileWithBlocks(testPath, 1000L, new TestingFileSystem.TestBlockLocation(0L, 100L, "host1", "host2"), new TestingFileSystem.TestBlockLocation(100L, 520L, "host2", "host3"), new TestingFileSystem.TestBlockLocation(620L, 380L, "host3", "host4")));
    testFs.register();
    final NonSplittingRecursiveEnumerator enumerator = createEnumerator();
    final Collection<FileSourceSplit> splits = enumerator.enumerateSplits(new Path[] { new Path("testfs:///dir") }, 0);
    assertSplitsEqual(new FileSourceSplit("ignoredId", testPath, 0L, 1000L, 0, 1000L, "host1", "host2", "host3", "host4"), splits.iterator().next());
}
Also used : Path(org.apache.flink.core.fs.Path) FileSourceSplit(org.apache.flink.connector.file.src.FileSourceSplit) TestingFileSystem(org.apache.flink.connector.file.src.testutils.TestingFileSystem) Test(org.junit.Test)

Example 39 with FileSourceSplit

use of org.apache.flink.connector.file.src.FileSourceSplit in project flink by apache.

the class NonSplittingRecursiveEnumeratorTest method testFileWithIncorrectBlocks.

@Test
public void testFileWithIncorrectBlocks() throws Exception {
    final Path testPath = new Path("testfs:///testdir/testfile");
    testFs = TestingFileSystem.createForFileStatus("testfs", TestingFileSystem.TestFileStatus.forFileWithBlocks(testPath, 10000L, new TestingFileSystem.TestBlockLocation(0L, 1000L), new TestingFileSystem.TestBlockLocation(2000L, 1000L)));
    testFs.register();
    final NonSplittingRecursiveEnumerator enumerator = createEnumerator();
    final Collection<FileSourceSplit> splits = enumerator.enumerateSplits(new Path[] { new Path("testfs:///testdir") }, 0);
    assertEquals(1, splits.size());
    assertSplitsEqual(new FileSourceSplit("ignoredId", testPath, 0L, 10000L, 0, 12345L), splits.iterator().next());
}
Also used : Path(org.apache.flink.core.fs.Path) FileSourceSplit(org.apache.flink.connector.file.src.FileSourceSplit) TestingFileSystem(org.apache.flink.connector.file.src.testutils.TestingFileSystem) Test(org.junit.Test)

Example 40 with FileSourceSplit

use of org.apache.flink.connector.file.src.FileSourceSplit in project flink by apache.

the class NonSplittingRecursiveEnumeratorTest method testHiddenDirectories.

@Test
public void testHiddenDirectories() throws Exception {
    final Path[] testPaths = new Path[] { new Path("testfs:///dir/visiblefile"), new Path("testfs:///dir/.hiddendir/file"), new Path("testfs:///_notvisible/afile") };
    testFs = TestingFileSystem.createWithFiles("testfs", testPaths);
    testFs.register();
    final NonSplittingRecursiveEnumerator enumerator = createEnumerator();
    final Collection<FileSourceSplit> splits = enumerator.enumerateSplits(new Path[] { new Path("testfs:///") }, 1);
    assertEquals(Collections.singletonList(new Path("testfs:///dir/visiblefile")), toPaths(splits));
}
Also used : Path(org.apache.flink.core.fs.Path) FileSourceSplit(org.apache.flink.connector.file.src.FileSourceSplit) Test(org.junit.Test)

Aggregations

FileSourceSplit (org.apache.flink.connector.file.src.FileSourceSplit)50 Test (org.junit.Test)32 Path (org.apache.flink.core.fs.Path)20 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 BulkFormat (org.apache.flink.connector.file.src.reader.BulkFormat)11 Configuration (org.apache.flink.configuration.Configuration)10 ArrayList (java.util.ArrayList)9 TestingSplitEnumeratorContext (org.apache.flink.connector.testutils.source.reader.TestingSplitEnumeratorContext)7 IOException (java.io.IOException)6 RowData (org.apache.flink.table.data.RowData)6 LogicalType (org.apache.flink.table.types.logical.LogicalType)6 LinkedHashMap (java.util.LinkedHashMap)5 TestingFileSystem (org.apache.flink.connector.file.src.testutils.TestingFileSystem)5 FileStatus (org.apache.flink.core.fs.FileStatus)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 BigIntType (org.apache.flink.table.types.logical.BigIntType)4 DoubleType (org.apache.flink.table.types.logical.DoubleType)4 IntType (org.apache.flink.table.types.logical.IntType)4 SmallIntType (org.apache.flink.table.types.logical.SmallIntType)4 TinyIntType (org.apache.flink.table.types.logical.TinyIntType)4