use of org.talend.sdk.component.runtime.beam.impl.BeamProcessorChainImpl in project component-runtime by Talend.
the class BeamIOWrappingTest method processor.
@Test
public void processor() {
MySink.DATA.clear();
final Object source = newComponent("beamio_output", ComponentManager.ComponentType.PROCESSOR);
final Processor processor = new BeamProcessorChainImpl((PTransform<PCollection<?>, ?>) source, null, getPlugin(), "test", "beamio_output");
processor.start();
processor.beforeGroup();
Stream.of("tsrif", "dnoces").forEach(data -> processor.onNext(name -> {
assertEquals(Branches.DEFAULT_BRANCH, name);
return data;
}, null));
processor.afterGroup(name -> {
assertEquals(Branches.DEFAULT_BRANCH, name);
return value -> MySink.DATA.add(value.toString());
});
processor.stop();
assertEquals(asList("setup", "start-bundle", "first", "second", "finish-out", "finish-bundle", "teardown"), MySink.DATA);
MySink.DATA.clear();
}
use of org.talend.sdk.component.runtime.beam.impl.BeamProcessorChainImpl in project component-runtime by Talend.
the class BeamIOWrappingTest method outputChain.
@Test
public void outputChain() {
MySink.DATA.clear();
final Object source = newComponent("beamio_output_chain", ComponentManager.ComponentType.PROCESSOR);
final Processor processor = new BeamProcessorChainImpl((PTransform<PCollection<?>, PDone>) source, null, getPlugin(), "test", "beamio_output");
processor.start();
processor.beforeGroup();
Stream.of("tsrif", "dnoces").forEach(data -> processor.onNext(name -> {
assertEquals(Branches.DEFAULT_BRANCH, name);
return new Sample(data);
}, name -> value -> MySink.DATA.add(value.toString())));
processor.afterGroup(name -> {
assertEquals(Branches.DEFAULT_BRANCH, name);
return value -> MySink.DATA.add(value.toString());
});
processor.stop();
assertEquals(asList("setup", "start-bundle", "first", "second", "finish-out", "finish-bundle", "teardown"), MySink.DATA);
MySink.DATA.clear();
}
use of org.talend.sdk.component.runtime.beam.impl.BeamProcessorChainImpl 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