Search in sources :

Example 1 with BeamProcessorChainImpl

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();
}
Also used : PartitionMapper(org.talend.sdk.component.api.input.PartitionMapper) PBegin(org.apache.beam.sdk.values.PBegin) PipelineResult(org.apache.beam.sdk.PipelineResult) RequiredArgsConstructor(lombok.RequiredArgsConstructor) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) Sample(org.talend.sdk.component.runtime.beam.data.Sample) Create(org.apache.beam.sdk.transforms.Create) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) GlobalWindow(org.apache.beam.sdk.transforms.windowing.GlobalWindow) Assert.fail(org.junit.Assert.fail) ClassRule(org.junit.ClassRule) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Processor(org.talend.sdk.component.runtime.output.Processor) Collectors.joining(java.util.stream.Collectors.joining) StandardCharsets(java.nio.charset.StandardCharsets) Serializable(java.io.Serializable) List(java.util.List) Branches(org.talend.sdk.component.runtime.output.Branches) Stream(java.util.stream.Stream) ParDo(org.apache.beam.sdk.transforms.ParDo) Optional(java.util.Optional) BeamMapperImpl(org.talend.sdk.component.runtime.beam.impl.BeamMapperImpl) BeamProcessorChainImpl(org.talend.sdk.component.runtime.beam.impl.BeamProcessorChainImpl) Getter(lombok.Getter) CapturingPipeline(org.talend.sdk.component.runtime.beam.impl.CapturingPipeline) Coder(org.apache.beam.sdk.coders.Coder) HashMap(java.util.HashMap) Option(org.talend.sdk.component.api.configuration.Option) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) PTransform(org.apache.beam.sdk.transforms.PTransform) FileBasedSink(org.apache.beam.sdk.io.FileBasedSink) TestPipeline(org.apache.beam.sdk.testing.TestPipeline) DelegatingTransform(org.talend.sdk.component.runtime.beam.transform.DelegatingTransform) Input(org.talend.sdk.component.runtime.input.Input) OutputStream(java.io.OutputStream) DoFn(org.apache.beam.sdk.transforms.DoFn) PDone(org.apache.beam.sdk.values.PDone) Files(java.nio.file.Files) PAssert(org.apache.beam.sdk.testing.PAssert) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) PCollection(org.apache.beam.sdk.values.PCollection) InputStreamReader(java.io.InputStreamReader) File(java.io.File) Collectors.toList(java.util.stream.Collectors.toList) Mapper(org.talend.sdk.component.runtime.input.Mapper) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) Instant(org.joda.time.Instant) JarLocation.jarLocation(org.apache.ziplock.JarLocation.jarLocation) BufferedReader(java.io.BufferedReader) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) Assert.assertEquals(org.junit.Assert.assertEquals) TextIO(org.apache.beam.sdk.io.TextIO) TemporaryFolder(org.junit.rules.TemporaryFolder) InputStream(java.io.InputStream) PCollection(org.apache.beam.sdk.values.PCollection) Processor(org.talend.sdk.component.runtime.output.Processor) BeamProcessorChainImpl(org.talend.sdk.component.runtime.beam.impl.BeamProcessorChainImpl) Test(org.junit.Test)

Example 2 with BeamProcessorChainImpl

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();
}
Also used : PartitionMapper(org.talend.sdk.component.api.input.PartitionMapper) PBegin(org.apache.beam.sdk.values.PBegin) PipelineResult(org.apache.beam.sdk.PipelineResult) RequiredArgsConstructor(lombok.RequiredArgsConstructor) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) Sample(org.talend.sdk.component.runtime.beam.data.Sample) Create(org.apache.beam.sdk.transforms.Create) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) GlobalWindow(org.apache.beam.sdk.transforms.windowing.GlobalWindow) Assert.fail(org.junit.Assert.fail) ClassRule(org.junit.ClassRule) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Processor(org.talend.sdk.component.runtime.output.Processor) Collectors.joining(java.util.stream.Collectors.joining) StandardCharsets(java.nio.charset.StandardCharsets) Serializable(java.io.Serializable) List(java.util.List) Branches(org.talend.sdk.component.runtime.output.Branches) Stream(java.util.stream.Stream) ParDo(org.apache.beam.sdk.transforms.ParDo) Optional(java.util.Optional) BeamMapperImpl(org.talend.sdk.component.runtime.beam.impl.BeamMapperImpl) BeamProcessorChainImpl(org.talend.sdk.component.runtime.beam.impl.BeamProcessorChainImpl) Getter(lombok.Getter) CapturingPipeline(org.talend.sdk.component.runtime.beam.impl.CapturingPipeline) Coder(org.apache.beam.sdk.coders.Coder) HashMap(java.util.HashMap) Option(org.talend.sdk.component.api.configuration.Option) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) PTransform(org.apache.beam.sdk.transforms.PTransform) FileBasedSink(org.apache.beam.sdk.io.FileBasedSink) TestPipeline(org.apache.beam.sdk.testing.TestPipeline) DelegatingTransform(org.talend.sdk.component.runtime.beam.transform.DelegatingTransform) Input(org.talend.sdk.component.runtime.input.Input) OutputStream(java.io.OutputStream) DoFn(org.apache.beam.sdk.transforms.DoFn) PDone(org.apache.beam.sdk.values.PDone) Files(java.nio.file.Files) PAssert(org.apache.beam.sdk.testing.PAssert) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) PCollection(org.apache.beam.sdk.values.PCollection) InputStreamReader(java.io.InputStreamReader) File(java.io.File) Collectors.toList(java.util.stream.Collectors.toList) Mapper(org.talend.sdk.component.runtime.input.Mapper) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) Instant(org.joda.time.Instant) JarLocation.jarLocation(org.apache.ziplock.JarLocation.jarLocation) BufferedReader(java.io.BufferedReader) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) Assert.assertEquals(org.junit.Assert.assertEquals) TextIO(org.apache.beam.sdk.io.TextIO) TemporaryFolder(org.junit.rules.TemporaryFolder) InputStream(java.io.InputStream) PCollection(org.apache.beam.sdk.values.PCollection) Processor(org.talend.sdk.component.runtime.output.Processor) BeamProcessorChainImpl(org.talend.sdk.component.runtime.beam.impl.BeamProcessorChainImpl) PDone(org.apache.beam.sdk.values.PDone) Sample(org.talend.sdk.component.runtime.beam.data.Sample) Test(org.junit.Test)

Example 3 with BeamProcessorChainImpl

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")));
}
Also used : PartitionMapper(org.talend.sdk.component.api.input.PartitionMapper) PBegin(org.apache.beam.sdk.values.PBegin) PipelineResult(org.apache.beam.sdk.PipelineResult) RequiredArgsConstructor(lombok.RequiredArgsConstructor) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) Sample(org.talend.sdk.component.runtime.beam.data.Sample) Create(org.apache.beam.sdk.transforms.Create) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) GlobalWindow(org.apache.beam.sdk.transforms.windowing.GlobalWindow) Assert.fail(org.junit.Assert.fail) ClassRule(org.junit.ClassRule) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Processor(org.talend.sdk.component.runtime.output.Processor) Collectors.joining(java.util.stream.Collectors.joining) StandardCharsets(java.nio.charset.StandardCharsets) Serializable(java.io.Serializable) List(java.util.List) Branches(org.talend.sdk.component.runtime.output.Branches) Stream(java.util.stream.Stream) ParDo(org.apache.beam.sdk.transforms.ParDo) Optional(java.util.Optional) BeamMapperImpl(org.talend.sdk.component.runtime.beam.impl.BeamMapperImpl) BeamProcessorChainImpl(org.talend.sdk.component.runtime.beam.impl.BeamProcessorChainImpl) Getter(lombok.Getter) CapturingPipeline(org.talend.sdk.component.runtime.beam.impl.CapturingPipeline) Coder(org.apache.beam.sdk.coders.Coder) HashMap(java.util.HashMap) Option(org.talend.sdk.component.api.configuration.Option) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) PTransform(org.apache.beam.sdk.transforms.PTransform) FileBasedSink(org.apache.beam.sdk.io.FileBasedSink) TestPipeline(org.apache.beam.sdk.testing.TestPipeline) DelegatingTransform(org.talend.sdk.component.runtime.beam.transform.DelegatingTransform) Input(org.talend.sdk.component.runtime.input.Input) OutputStream(java.io.OutputStream) DoFn(org.apache.beam.sdk.transforms.DoFn) PDone(org.apache.beam.sdk.values.PDone) Files(java.nio.file.Files) PAssert(org.apache.beam.sdk.testing.PAssert) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) PCollection(org.apache.beam.sdk.values.PCollection) InputStreamReader(java.io.InputStreamReader) File(java.io.File) Collectors.toList(java.util.stream.Collectors.toList) Mapper(org.talend.sdk.component.runtime.input.Mapper) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) Instant(org.joda.time.Instant) JarLocation.jarLocation(org.apache.ziplock.JarLocation.jarLocation) BufferedReader(java.io.BufferedReader) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) Assert.assertEquals(org.junit.Assert.assertEquals) TextIO(org.apache.beam.sdk.io.TextIO) TemporaryFolder(org.junit.rules.TemporaryFolder) InputStream(java.io.InputStream) FileBasedSink(org.apache.beam.sdk.io.FileBasedSink) PCollection(org.apache.beam.sdk.values.PCollection) Processor(org.talend.sdk.component.runtime.output.Processor) BeamProcessorChainImpl(org.talend.sdk.component.runtime.beam.impl.BeamProcessorChainImpl) PDone(org.apache.beam.sdk.values.PDone) AtomicReference(java.util.concurrent.atomic.AtomicReference) File(java.io.File) Test(org.junit.Test)

Aggregations

BufferedReader (java.io.BufferedReader)3 File (java.io.File)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 InputStreamReader (java.io.InputStreamReader)3 OutputStream (java.io.OutputStream)3 Serializable (java.io.Serializable)3 StandardCharsets (java.nio.charset.StandardCharsets)3 Files (java.nio.file.Files)3 ArrayList (java.util.ArrayList)3 Arrays.asList (java.util.Arrays.asList)3 Collection (java.util.Collection)3 Collections.emptyList (java.util.Collections.emptyList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 Optional (java.util.Optional)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Collectors.joining (java.util.stream.Collectors.joining)3 Collectors.toList (java.util.stream.Collectors.toList)3