Search in sources :

Example 1 with Input

use of org.talend.sdk.component.runtime.input.Input in project component-runtime by Talend.

the class ComponentExtensionTest method manualMapper.

@Test
void manualMapper() {
    final Mapper mapper = handler.createMapper(Source.class, new Source.Config() {

        {
            values = asList("a", "b");
        }
    });
    assertFalse(mapper.isStream());
    final Input input = mapper.create();
    assertEquals("a", input.next());
    assertEquals("b", input.next());
    assertNull(input.next());
}
Also used : Mapper(org.talend.sdk.component.runtime.input.Mapper) Input(org.talend.sdk.component.runtime.input.Input) Source(org.talend.sdk.component.junit.component.Source) Test(org.junit.jupiter.api.Test)

Example 2 with Input

use of org.talend.sdk.component.runtime.input.Input in project component-runtime by Talend.

the class SimpleComponentRuleTest method manualMapper.

@Test
public void manualMapper() {
    final Mapper mapper = COMPONENT_FACTORY.createMapper(Source.class, new Source.Config() {

        {
            values = asList("a", "b");
        }
    });
    assertFalse(mapper.isStream());
    final Input input = mapper.create();
    assertEquals("a", input.next());
    assertEquals("b", input.next());
    assertNull(input.next());
}
Also used : Mapper(org.talend.sdk.component.runtime.input.Mapper) Input(org.talend.sdk.component.runtime.input.Input) Source(org.talend.sdk.component.junit.component.Source) Test(org.junit.Test)

Example 3 with Input

use of org.talend.sdk.component.runtime.input.Input in project component-runtime by Talend.

the class BeamIOWrappingTest method mapper.

@Test
public void mapper() {
    final Object source = newComponent("beamio_input", ComponentManager.ComponentType.MAPPER);
    assertThat(source, instanceOf(BeamSource.class));
    final Mapper mapper = new BeamMapperImpl((PTransform<PBegin, ?>) source, getPlugin(), "test", "beamio_input");
    mapper.start();
    assertEquals(2, mapper.assess());
    final Input input = mapper.create();
    assertNotNull(input);
    input.start();
    assertEquals(new Sample("a"), input.next());
    assertEquals(new Sample("b"), input.next());
    assertNull(input.next());
    input.stop();
    mapper.stop();
}
Also used : PartitionMapper(org.talend.sdk.component.api.input.PartitionMapper) Mapper(org.talend.sdk.component.runtime.input.Mapper) Input(org.talend.sdk.component.runtime.input.Input) BeamMapperImpl(org.talend.sdk.component.runtime.beam.impl.BeamMapperImpl) Sample(org.talend.sdk.component.runtime.beam.data.Sample) PBegin(org.apache.beam.sdk.values.PBegin) Test(org.junit.Test)

Example 4 with Input

use of org.talend.sdk.component.runtime.input.Input in project component-runtime by Talend.

the class BeamIOWrappingTest method inputChain.

@Test
public void inputChain() {
    MySink.DATA.clear();
    final Object source = newComponent("beamio_input_chain", ComponentManager.ComponentType.MAPPER);
    final Mapper mapper = new BeamMapperImpl((PTransform<PBegin, ?>) source, getPlugin(), "test", "beamio_input_chain");
    mapper.start();
    assertEquals(4, mapper.assess());
    final Input input = mapper.create();
    assertNotNull(input);
    input.start();
    assertNotNull(input.next());
    assertNotNull(input.next());
    assertNull(input.next());
    try {
        input.stop();
    } catch (final IllegalArgumentException iae) {
        // for now we ignore this error which is issuing an output in an after bundle
        assertEquals("chunk outputs are not yet supported", iae.getMessage());
    }
    mapper.stop();
    assertEquals(asList("setup", "start-bundle", "1a", "2b", "teardown"), MySink.DATA);
}
Also used : PartitionMapper(org.talend.sdk.component.api.input.PartitionMapper) Mapper(org.talend.sdk.component.runtime.input.Mapper) Input(org.talend.sdk.component.runtime.input.Input) BeamMapperImpl(org.talend.sdk.component.runtime.beam.impl.BeamMapperImpl) PBegin(org.apache.beam.sdk.values.PBegin) Test(org.junit.Test)

Example 5 with Input

use of org.talend.sdk.component.runtime.input.Input in project component-runtime by Talend.

the class DIBatchSimulationTest method doRun.

private void doRun(final ComponentManager manager, final Collection<Object> sourceData, final Collection<Object> processorData, final Map<String, Object> globalMap, final AutoChunkProcessor processorProcessor, final InputsHandler inputsHandlerProcessor, final OutputsHandler outputHandlerProcessor, final InputFactory inputsProcessor, final OutputFactory outputsProcessor, final Mapper tempMapperMapper) {
    row1Struct row1 = new row1Struct();
    tempMapperMapper.start();
    final ChainedMapper mapperMapper;
    try {
        final List<Mapper> splitMappersMapper = tempMapperMapper.split(tempMapperMapper.assess());
        mapperMapper = new ChainedMapper(tempMapperMapper, splitMappersMapper.iterator());
        mapperMapper.start();
        globalMap.put("mapperMapper", mapperMapper);
    } finally {
        try {
            tempMapperMapper.stop();
        } catch (final RuntimeException re) {
            re.printStackTrace();
        }
    }
    final Input inputMapper = mapperMapper.create();
    inputMapper.start();
    globalMap.put("inputMapper", inputMapper);
    final Jsonb jsonbMapper = Jsonb.class.cast(manager.findPlugin(mapperMapper.plugin()).get().get(ComponentManager.AllServices.class).getServices().get(Jsonb.class));
    Object dataMapper;
    while ((dataMapper = inputMapper.next()) != null) {
        final String jsonValueMapper = javax.json.JsonValue.class.isInstance(dataMapper) ? javax.json.JsonValue.class.cast(dataMapper).toString() : jsonbMapper.toJson(dataMapper);
        row1 = jsonbMapper.fromJson(jsonValueMapper, row1.getClass());
        sourceData.add(row1);
        inputsHandlerProcessor.reset();
        inputsHandlerProcessor.setInputValue("FLOW", row1);
        outputHandlerProcessor.reset();
        processorProcessor.onElement(name -> {
            assertEquals(Branches.DEFAULT_BRANCH, name);
            final Object read = inputsProcessor.read(name);
            processorData.add(read);
            return read;
        }, outputsProcessor);
    }
}
Also used : ToString(lombok.ToString) PartitionMapper(org.talend.sdk.component.api.input.PartitionMapper) ChainedMapper(org.talend.sdk.component.runtime.manager.chain.ChainedMapper) Mapper(org.talend.sdk.component.runtime.input.Mapper) Input(org.talend.sdk.component.runtime.input.Input) Jsonb(javax.json.bind.Jsonb) ChainedMapper(org.talend.sdk.component.runtime.manager.chain.ChainedMapper) JsonObject(javax.json.JsonObject)

Aggregations

Input (org.talend.sdk.component.runtime.input.Input)11 Mapper (org.talend.sdk.component.runtime.input.Mapper)9 JsonObject (javax.json.JsonObject)4 Map (java.util.Map)3 Jsonb (javax.json.bind.Jsonb)3 Test (org.junit.Test)3 PartitionMapper (org.talend.sdk.component.api.input.PartitionMapper)3 ChainedMapper (org.talend.sdk.component.runtime.manager.chain.ChainedMapper)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 Optional (java.util.Optional)2 ExecutorService (java.util.concurrent.ExecutorService)2 SECONDS (java.util.concurrent.TimeUnit.SECONDS)2 Collectors.toMap (java.util.stream.Collectors.toMap)2 Slf4j (lombok.extern.slf4j.Slf4j)2 PBegin (org.apache.beam.sdk.values.PBegin)2 Source (org.talend.sdk.component.junit.component.Source)2 Sample (org.talend.sdk.component.runtime.beam.data.Sample)2 BeamMapperImpl (org.talend.sdk.component.runtime.beam.impl.BeamMapperImpl)2 JobStateAware (org.talend.sdk.component.runtime.di.JobStateAware)2