use of org.apache.beam.sdk.transforms.PTransform in project component-runtime by Talend.
the class BeamIOWrappingTest method fileOutput.
@Test
public void fileOutput() throws IOException {
final Object source = newComponent("beamio_text", ComponentManager.ComponentType.PROCESSOR);
final Processor processor = new BeamProcessorChainImpl((PTransform<PCollection<?>, PDone>) source, null, getPlugin(), "test", "beamio_text");
processor.start();
processor.beforeGroup();
Stream.of("first", "second").forEach(data -> processor.onNext(name -> {
assertEquals(Branches.DEFAULT_BRANCH, name);
return data;
}, name -> value -> fail(name + " >> " + value)));
final AtomicReference<Object> output = new AtomicReference<>();
processor.afterGroup(name -> {
assertEquals(Branches.DEFAULT_BRANCH, name);
return output::set;
});
processor.stop();
final FileBasedSink.FileResult result = FileBasedSink.FileResult.class.cast(output.get());
assertNotNull(result);
final File file = new File(result.getTempFilename().toString());
assertTrue(file.exists());
assertEquals(file.getParentFile().getParentFile(), TEMPORARY_FOLDER.getRoot());
assertEquals("first\nsecond", Files.lines(file.toPath()).collect(joining("\n")));
}
Aggregations