@Override public void close() { try { if (reader != null) { reader.close(); } } catch (IOException e) { throw new RuntimeException(e); } }
private void close() { closed = true; try { reader.close(); } catch (final IOException e) { throw new RuntimeException(e); } }
@Override public void onRemoval( final RemovalNotification<MicrobatchSource<?, ?>, Source.Reader<?>> notification) { try { notification.getValue().close(); } catch (final IOException e) { throw new RuntimeException(e); } } }
@Test public void testCloseUnstartedFilePatternReader() throws IOException { PipelineOptions options = PipelineOptionsFactory.create(); List<KV<IntWritable, Text>> data1 = createRandomRecords(3, 10, 0); File file1 = createFileWithData("file1", data1); List<KV<IntWritable, Text>> data2 = createRandomRecords(3, 10, 10); createFileWithData("file2", data2); List<KV<IntWritable, Text>> data3 = createRandomRecords(3, 10, 20); createFileWithData("file3", data3); List<KV<IntWritable, Text>> data4 = createRandomRecords(3, 10, 30); createFileWithData("otherfile", data4); HDFSFileSource<KV<IntWritable, Text>, IntWritable, Text> source = HDFSFileSource.from( new File(file1.getParent(), "file*").toString(), SequenceFileInputFormat.class, IntWritable.class, Text.class); Source.Reader<KV<IntWritable, Text>> reader = source.createReader(options); // Closing an unstarted FilePatternReader should not throw an exception. try { reader.close(); } catch (Exception e) { fail("Closing an unstarted FilePatternReader should not throw an exception"); } }
@Test public void testCloseUnstartedFilePatternReader() throws IOException { PipelineOptions options = PipelineOptionsFactory.create(); List<String> data1 = createStringDataset(3, 50); File file1 = createFileWithData("file1", data1); List<String> data2 = createStringDataset(3, 50); createFileWithData("file2", data2); List<String> data3 = createStringDataset(3, 50); createFileWithData("file3", data3); List<String> data4 = createStringDataset(3, 50); createFileWithData("otherfile", data4); TestFileBasedSource source = new TestFileBasedSource(new File(file1.getParent(), "file*").getPath(), 64, null); Reader<String> reader = source.createReader(options); // Closing an unstarted FilePatternReader should not throw an exception. try { reader.close(); } catch (Exception e) { throw new AssertionError( "Closing an unstarted FilePatternReader should not throw an exception", e); } }