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();
}
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);
}
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));
}
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);
}
}
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));
}
}
Aggregations