use of org.talend.sdk.component.runtime.output.Processor in project component-runtime by Talend.
the class ComponentExtensionTest method processorCollector.
@Test
void processorCollector() {
final Processor processor = handler.createProcessor(Transform.class, null);
final SimpleComponentRule.Outputs outputs = handler.collect(processor, new JoinInputFactory().withInput("__default__", asList(new Transform.Record("a"), new Transform.Record("bb"))).withInput("second", asList(new Transform.Record("1"), new Transform.Record("2"))));
assertEquals(2, outputs.size());
assertEquals(asList(2, 3), outputs.get(Integer.class, "size"));
assertEquals(asList("a1", "bb2"), outputs.get(String.class, "value"));
}
use of org.talend.sdk.component.runtime.output.Processor in project component-runtime by Talend.
the class BeamProcessorChainImpl method onNext.
@Override
public void onNext(final InputFactory input, final OutputFactory output) {
Collection<InputFactory> finalInput = singletonList(input);
if (!preProcessors.isEmpty()) {
for (final Processor p : preProcessors) {
final StoringOuputFactory tmpOutput = new StoringOuputFactory();
finalInput.forEach(in -> p.onNext(in, tmpOutput));
if (tmpOutput.getValues() == null) {
// chain is stopped
return;
}
finalInput = tmpOutput.getValues().stream().map(val -> (InputFactory) name -> {
if (!Branches.DEFAULT_BRANCH.equals(name)) {
throw new IllegalArgumentException("Only default branch is supported at the moment");
}
return val;
}).collect(toList());
}
}
finalInput.forEach(in -> lastProcessor.onNext(in, output));
}
use of org.talend.sdk.component.runtime.output.Processor in project component-runtime by Talend.
the class BeamProcessorChainImpl method start.
@Override
public void start() {
startedCount = 0;
for (final Processor p : processors) {
p.start();
startedCount++;
}
}
use of org.talend.sdk.component.runtime.output.Processor in project component-runtime by Talend.
the class ComponentManagerTest method doCheckRegistry.
private void doCheckRegistry(final File plugin1, final File plugin2, final ComponentManager manager) throws Exception {
Stream.of(plugin1, plugin2).map(File::getAbsolutePath).forEach(manager::addPlugin);
final List<ContainerComponentRegistry> registries = manager.find(c -> Stream.of(c.get(ContainerComponentRegistry.class))).collect(toList());
// we saw both plugin
assertEquals(2, registries.size());
registries.forEach(registry -> {
final Container container = manager.find(c -> registry == c.get(ContainerComponentRegistry.class) ? Stream.of(c) : Stream.empty()).findFirst().get();
assertEquals(1, registry.getServices().size());
assertNotNull(registry.getServices().iterator().next().getInstance());
final Collection<ServiceMeta.ActionMeta> actions = registry.getServices().iterator().next().getActions();
assertEquals(1, actions.size());
assertEquals(pluginGenerator.toPackage(container.getId()) + ".AModel", actions.iterator().next().getInvoker().apply(null).getClass().getName());
assertEquals(1, registry.getComponents().size());
registry.getComponents().forEach((name, component) -> {
assertEquals("comp", name);
assertEquals(name, component.getName());
assertEquals(singletonList("Misc"), component.getCategories());
assertEquals(1, component.getProcessors().size());
component.getProcessors().forEach((procName, processorMeta) -> {
assertEquals("proc", procName);
assertEquals("default", processorMeta.getIcon());
final String packageName = pluginGenerator.toPackage(container.getId());
final Processor processor = processorMeta.getInstantiator().apply(emptyMap());
assertNotNull(processor);
final Object model;
try {
final String className = packageName + ".AModel";
model = container.getLoader().loadClass(className).getConstructor().newInstance();
} catch (final Exception e) {
fail(e.getMessage());
throw new IllegalArgumentException(e);
}
runProcessorLifecycle(model, processor);
});
});
});
// now try to execute the processor outside the correct TCCL and ensure it still
// works
final Container container = manager.find(Stream::of).findFirst().get();
final String packageName = pluginGenerator.toPackage(container.getId());
final ContainerComponentRegistry registry = container.get(ContainerComponentRegistry.class);
final ComponentFamilyMeta componentFamilyMeta = registry.getComponents().values().iterator().next();
final ComponentFamilyMeta.ProcessorMeta processorMeta = componentFamilyMeta.getProcessors().values().iterator().next();
final Processor processor = processorMeta.getInstantiator().apply(emptyMap());
final Object aModel = container.getLoader().loadClass(packageName + ".AModel").getConstructor().newInstance();
runProcessorLifecycle(aModel, processor);
// finally ensure it is serializable
DynamicContainerFinder.LOADERS.clear();
manager.find(Stream::of).forEach(c -> DynamicContainerFinder.LOADERS.put(c.getId(), c.getLoader()));
runProcessorLifecycle(aModel, copy(processor, container.getLoader()));
}
use of org.talend.sdk.component.runtime.output.Processor 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());
}
Aggregations