Search in sources :

Example 6 with Mapper

use of org.talend.sdk.component.runtime.input.Mapper 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 7 with Mapper

use of org.talend.sdk.component.runtime.input.Mapper 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 8 with Mapper

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

the class MycompMapperTest method produce.

@Test
@Ignore("You need to complete this test")
public void produce() throws IOException {
    // Source configuration
    // Setup your component configuration for the test here
    final MycompMapperConfiguration configuration = new MycompMapperConfiguration();
    // We create the component mapper instance using the configuration filled above
    final Mapper mapper = COMPONENT_FACTORY.createMapper(MycompMapper.class, configuration);
    // Collect the source as a list
    assertEquals(asList(), COMPONENT_FACTORY.collectAsList(JsonObject.class, mapper));
}
Also used : Mapper(org.talend.sdk.component.runtime.input.Mapper) JsonObject(javax.json.JsonObject) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with Mapper

use of org.talend.sdk.component.runtime.input.Mapper 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)

Example 10 with Mapper

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

the class BeamComponentExtensionTest method toMapper.

@Test
public void toMapper() throws IOException, ClassNotFoundException {
    final ComponentContextImpl context = new ComponentContextImpl(BeamSource.class);
    context.setCurrentExtension(extension);
    extension.onComponent(context);
    context.setCurrentExtension(null);
    assertTrue(context.isNoValidation());
    assertEquals(extension, context.getOwningExtension());
    final Mapper mapper = extension.convert(new ComponentExtension.ComponentInstance() {

        @Override
        public Object instance() {
            return new BeamSource(asList("a", "b"));
        }

        @Override
        public String plugin() {
            // path as id
            return jarLocation(BeamComponentExtensionTest.class).getAbsolutePath();
        }

        @Override
        public String family() {
            return "test";
        }

        @Override
        public String name() {
            return "extension";
        }
    }, Mapper.class);
    assertMapper(mapper);
    // ensure the mapper is serializable even if not intended to be used this way
    final byte[] bytes = Serializer.toBytes(mapper);
    try (final ObjectInputStream ois = new EnhancedObjectInputStream(new ByteArrayInputStream(bytes), Thread.currentThread().getContextClassLoader())) {
        final Serializable deserialized = Serializable.class.cast(ois.readObject());
        assertMapper(Mapper.class.cast(deserialized));
    }
}
Also used : Serializable(java.io.Serializable) EnhancedObjectInputStream(org.talend.sdk.component.runtime.serialization.EnhancedObjectInputStream) PartitionMapper(org.talend.sdk.component.api.input.PartitionMapper) Mapper(org.talend.sdk.component.runtime.input.Mapper) ComponentContextImpl(org.talend.sdk.component.runtime.manager.extension.ComponentContextImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) ComponentExtension(org.talend.sdk.component.spi.component.ComponentExtension) ObjectInputStream(java.io.ObjectInputStream) EnhancedObjectInputStream(org.talend.sdk.component.runtime.serialization.EnhancedObjectInputStream) Test(org.junit.jupiter.api.Test)

Aggregations

Mapper (org.talend.sdk.component.runtime.input.Mapper)18 Input (org.talend.sdk.component.runtime.input.Input)9 JsonObject (javax.json.JsonObject)8 Test (org.junit.Test)6 PartitionMapper (org.talend.sdk.component.api.input.PartitionMapper)6 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Jsonb (javax.json.bind.Jsonb)4 ChainedMapper (org.talend.sdk.component.runtime.manager.chain.ChainedMapper)4 Processor (org.talend.sdk.component.runtime.output.Processor)4 Collection (java.util.Collection)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Collectors.toMap (java.util.stream.Collectors.toMap)3 Test (org.junit.jupiter.api.Test)3 Source (org.talend.sdk.component.junit.component.Source)3 Annotation (java.lang.annotation.Annotation)2 Method (java.lang.reflect.Method)2 List (java.util.List)2 Optional (java.util.Optional)2 ExecutorService (java.util.concurrent.ExecutorService)2