Search in sources :

Example 1 with TestingFileSystem

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

the class AdapterTestBase method testClosesStreamIfReaderCreationFails.

// ------------------------------------------------------------------------
@Test
public void testClosesStreamIfReaderCreationFails() throws Exception {
    // setup
    final Path testPath = new Path("testFs:///testpath-1");
    final CloseTestingInputStream in = new CloseTestingInputStream();
    final TestingFileSystem testFs = TestingFileSystem.createForFileStatus("testFs", TestingFileSystem.TestFileStatus.forFileWithStream(testPath, 1024, in));
    testFs.register();
    // test
    final BulkFormat<Integer, FileSourceSplit> adapter = wrapWithAdapter(createFormatFailingInInstantiation());
    try {
        adapter.createReader(new Configuration(), new FileSourceSplit("id", testPath, 0, 1024, 0, 1024));
    } catch (IOException ignored) {
    }
    // assertions
    assertTrue(in.closed);
    // cleanup
    testFs.unregister();
}
Also used : Path(org.apache.flink.core.fs.Path) FileSourceSplit(org.apache.flink.connector.file.src.FileSourceSplit) Configuration(org.apache.flink.configuration.Configuration) TestingFileSystem(org.apache.flink.connector.file.src.testutils.TestingFileSystem) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with TestingFileSystem

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

the class AdapterTestBase method testClosesStreamIfReaderRestoreFails.

@Test
public void testClosesStreamIfReaderRestoreFails() throws Exception {
    // setup
    final Path testPath = new Path("testFs:///testpath-1");
    final CloseTestingInputStream in = new CloseTestingInputStream();
    final TestingFileSystem testFs = TestingFileSystem.createForFileStatus("testFs", TestingFileSystem.TestFileStatus.forFileWithStream(testPath, 1024, in));
    testFs.register();
    // test
    final BulkFormat<Integer, FileSourceSplit> adapter = wrapWithAdapter(createFormatFailingInInstantiation());
    final FileSourceSplit split = new FileSourceSplit("id", testPath, 0, 1024, 0, 1024, new String[0], new CheckpointedPosition(0L, 5L));
    try {
        adapter.restoreReader(new Configuration(), split);
    } catch (IOException ignored) {
    }
    // assertions
    assertTrue(in.closed);
    // cleanup
    testFs.unregister();
}
Also used : Path(org.apache.flink.core.fs.Path) FileSourceSplit(org.apache.flink.connector.file.src.FileSourceSplit) Configuration(org.apache.flink.configuration.Configuration) TestingFileSystem(org.apache.flink.connector.file.src.testutils.TestingFileSystem) CheckpointedPosition(org.apache.flink.connector.file.src.util.CheckpointedPosition) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)2 Configuration (org.apache.flink.configuration.Configuration)2 FileSourceSplit (org.apache.flink.connector.file.src.FileSourceSplit)2 TestingFileSystem (org.apache.flink.connector.file.src.testutils.TestingFileSystem)2 Path (org.apache.flink.core.fs.Path)2 Test (org.junit.Test)2 CheckpointedPosition (org.apache.flink.connector.file.src.util.CheckpointedPosition)1