Search in sources :

Example 1 with ProcessorImpl

use of org.talend.sdk.component.runtime.output.ProcessorImpl in project component-runtime by Talend.

the class JobTest method validateJobLifeCycle.

@Test
void validateJobLifeCycle(final TestInfo info, final TemporaryFolder temporaryFolder) {
    final String testName = info.getTestMethod().get().getName();
    final String plugin = testName + ".jar";
    final File jar = pluginGenerator.createChainPlugin(temporaryFolder.getRoot(), plugin);
    try (final ComponentManager manager = new ComponentManager(new File("target/fake-m2"), "TALEND-INF/dependencies.txt", null) {

        {
            CONTEXTUAL_INSTANCE.set(this);
            addPlugin(jar.getAbsolutePath());
        }

        @Override
        public void close() {
            super.close();
            CONTEXTUAL_INSTANCE.set(null);
        }
    }) {
        Job.components().component("countdown", "lifecycle://countdown?__version=1&start=2").component("square", "lifecycle://square?__version=1").connections().from("countdown").to("square").build().run();
        final LocalPartitionMapper mapper = LocalPartitionMapper.class.cast(manager.findMapper("lifecycle", "countdown", 1, emptyMap()).get());
        assertEquals(asList("start", "produce(1)", "produce(0)", "produce(null)", "stop"), ((Supplier<List<String>>) mapper.getDelegate()).get());
        final ProcessorImpl processor = (ProcessorImpl) manager.findProcessor("lifecycle", "square", 1, emptyMap()).get();
        assertEquals(asList("start", "beforeGroup", "onNext(1)", "afterGroup", "beforeGroup", "onNext(0)", "afterGroup", "stop"), ((Supplier<List<String>>) processor.getDelegate()).get());
    }
}
Also used : LocalPartitionMapper(org.talend.sdk.component.runtime.input.LocalPartitionMapper) ProcessorImpl(org.talend.sdk.component.runtime.output.ProcessorImpl) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) List(java.util.List) Arrays.asList(java.util.Arrays.asList) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 2 with ProcessorImpl

use of org.talend.sdk.component.runtime.output.ProcessorImpl in project component-runtime by Talend.

the class AdvancedProcessorImplTest method subclassing.

@Test
void subclassing() {
    final Processor processor = new ProcessorImpl("Root", "Test", "Plugin", new SampleOutput());
    final AtomicReference<Object> ref = new AtomicReference<>();
    // just to enforce the init
    processor.beforeGroup();
    processor.onNext(name -> new Whatever(1), name -> value -> assertTrue(ref.compareAndSet(null, value)));
    final Object out = ref.get();
    assertNotNull(out);
    assertTrue(() -> String.class.isInstance(out));
    assertEquals("1", out.toString());
}
Also used : Processor(org.talend.sdk.component.runtime.output.Processor) ProcessorImpl(org.talend.sdk.component.runtime.output.ProcessorImpl) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Example 3 with ProcessorImpl

use of org.talend.sdk.component.runtime.output.ProcessorImpl in project component-runtime by Talend.

the class AdvancedProcessorImplTest method serialization.

@Test
void serialization() throws IOException, ClassNotFoundException {
    final Processor processor = new ProcessorImpl("Root", "Test", "Plugin", new SampleOutput());
    final Processor copy = Serializer.roundTrip(processor);
    assertNotSame(copy, processor);
    assertEquals("Root", copy.rootName());
    assertEquals("Test", copy.name());
    assertEquals("Plugin", copy.plugin());
}
Also used : Processor(org.talend.sdk.component.runtime.output.Processor) ProcessorImpl(org.talend.sdk.component.runtime.output.ProcessorImpl) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 ProcessorImpl (org.talend.sdk.component.runtime.output.ProcessorImpl)3 Processor (org.talend.sdk.component.runtime.output.Processor)2 File (java.io.File)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 LocalPartitionMapper (org.talend.sdk.component.runtime.input.LocalPartitionMapper)1 ComponentManager (org.talend.sdk.component.runtime.manager.ComponentManager)1