use of org.talend.sdk.component.runtime.manager.ComponentManager in project component-runtime by Talend.
the class BeamJobTest method complex.
@Test
void complex(final TestInfo info, final TemporaryFolder temporaryFolder) throws IOException {
final String testName = info.getTestMethod().get().getName();
final String plugin = testName + ".jar";
final File jar = pluginGenerator.createChainPlugin(temporaryFolder.getRoot(), plugin);
final File out = new File(temporaryFolder.getRoot(), testName + "-out.txt");
try (final ComponentManager manager = new ComponentManager(new File("target/fake-m2"), "TALEND-INF/dependencies.txt", null) {
private final ComponentManager contextualInstance;
{
contextualInstance = CONTEXTUAL_INSTANCE.get();
CONTEXTUAL_INSTANCE.set(this);
addPlugin(jar.getAbsolutePath());
}
@Override
public void close() {
CONTEXTUAL_INSTANCE.set(contextualInstance);
super.close();
removePlugin(jar.getAbsolutePath());
}
}) {
Job.components().component("formatter", "chain://formatter?__version=1").component("concat", "chain://concat?__version=1").component("concat_2", "chain://concat?__version=1").component("firstNames-dataset", "chain://list?__version=1" + "&values[0]=noha" + "&values[1]=Emma" + "&values[2]=liam" + "&values[3]=Olivia").component("lastNames-dataset", "chain://list?__version=1" + "&values[0]=manson" + "&values[1]=Sophia" + "&values[2]=jacob").component("address", "chain://list?__version=1" + "&values[0]=Paris" + "&values[1]=Strasbourg" + "&values[2]=Bordeaux" + "&values[3]=Nantes").component("outFile", "chain://file?__version=1&file=" + encode(out.getAbsolutePath(), "utf-8")).connections().from("firstNames-dataset").to("formatter", "firstName").from("lastNames-dataset").to("formatter", "lastName").from("formatter", "formatted-lastName").to("concat", "str1").from("formatter", "formatted-firstName").to("concat", "str2").from("concat").to("concat_2", "str1").from("address").to("concat_2", "str2").from("concat_2").to("outFile").build().property(GroupKeyProvider.class.getName(), (GroupKeyProvider) (context) -> context.getData().getJsonObject("$$internal").getString("key")).run();
final int maxRetries = 120;
for (int i = 0; i < maxRetries; i++) {
// https://github.com/apache/beam/pull/4372
try {
assertTrue(out.isFile());
assertEquals(Stream.of("MANSON noha Paris", "SOPHIA emma Strasbourg", "JACOB liam Bordeaux", "null olivia Nantes").collect(toSet()), new HashSet<>(Files.readAllLines(out.toPath())));
} catch (final AssertionError ae) {
if (i == maxRetries - 1) {
throw ae;
}
try {
sleep(500);
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
}
}
use of org.talend.sdk.component.runtime.manager.ComponentManager in project component-runtime by Talend.
the class JobTest method jobKeyProvider.
@Test
void jobKeyProvider(final TestInfo info, final TemporaryFolder temporaryFolder) throws IOException {
final String testName = info.getTestMethod().get().getName();
final String plugin = testName + ".jar";
final File jar = pluginGenerator.createChainPlugin(temporaryFolder.getRoot(), plugin);
final File out = new File(temporaryFolder.getRoot(), testName + "-out.txt");
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("users", "db://input?__version=1&tableName=users").component("address", "db://input?__version=1&tableName=address").component("salary", "db://input?__version=1&tableName=salary").component("concat", "processor://concat?__version=1").component("concat_2", "processor://concat?__version=1").component("outFile", "file://out?__version=1&file=" + encode(out.getAbsolutePath(), "utf-8")).connections().from("users").to("concat", "str1").from("address").to("concat", "str2").from("concat").to("concat_2", "str1").from("salary").to("concat_2", "str2").from("concat_2").to("outFile").build().property(GroupKeyProvider.class.getName(), (GroupKeyProvider) context -> {
if (context.getComponentId().equals("users")) {
return context.getData().getString("id");
}
return context.getData().getString("userId");
}).run();
assertTrue(out.isFile());
assertEquals(asList("emma strasbourg 1900", "sophia nantes 2000.5", "liam lyon 3055", "ava paris 2600.30"), Files.readAllLines(out.toPath()));
}
}
use of org.talend.sdk.component.runtime.manager.ComponentManager 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());
}
}
use of org.talend.sdk.component.runtime.manager.ComponentManager in project component-runtime by Talend.
the class InterceptorTest method run.
@Test
void run(final TemporaryFolder temporaryFolder) throws Exception {
final File pluginFolder = new File(temporaryFolder.getRoot(), "test-plugins_" + UUID.randomUUID().toString());
pluginFolder.mkdirs();
final File plugin = pluginGenerator.createChainPlugin(pluginFolder, "plugin.jar");
try (final ComponentManager manager = new ComponentManager(new File("target/test-dependencies"), "META-INF/test/dependencies", "org.talend.test:type=plugin,value=%s")) {
manager.addPlugin(plugin.getAbsolutePath());
final List<Object> collect = manager.find(c -> c.get(ComponentManager.AllServices.class).getServices().values().stream()).filter(c -> c.getClass().getName().endsWith("SuperService$$TalendServiceProxy")).collect(toList());
assertEquals(1, collect.size());
final Object instance = collect.iterator().next();
final Method method = instance.getClass().getMethod("canBeLong", int.class);
assertEquals("exec_1/1", method.invoke(instance, 1));
assertEquals("exec_1/1", method.invoke(instance, 1));
sleep(450);
assertEquals("exec_1/2", method.invoke(instance, 1));
assertEquals("exec_3/3", method.invoke(instance, 3));
assertEquals("exec_4/4", method.invoke(instance, 4));
final LightContainer container = manager.find(c -> Stream.of(c.get(LightContainer.class))).findFirst().get();
DynamicContainerFinder.LOADERS.put("plugin", container.classloader());
DynamicContainerFinder.SERVICES.put(instance.getClass().getSuperclass(), instance);
final Object roundTrip = roundTrip(instance);
assertEquals(roundTrip, instance);
} finally {
// clean temp files
DynamicContainerFinder.LOADERS.clear();
DynamicContainerFinder.SERVICES.clear();
}
}
use of org.talend.sdk.component.runtime.manager.ComponentManager in project component-runtime by Talend.
the class StandaloneContainerFinder method find.
// IMPORTANT: don't abuse of lambdas here, it is on the runtime codepath
@Override
public LightContainer find(final String plugin) {
final ComponentManager manager = ComponentManager.instance();
Optional<Container> optionalContainer = manager.findPlugin(plugin);
if (!optionalContainer.isPresent()) {
log.info("Didn't find plugin " + plugin + ", had: " + manager.availablePlugins());
// nested in current jar.
try {
optionalContainer = manager.findPlugin(manager.addPlugin(plugin));
} catch (final IllegalArgumentException iae) {
// concurrent request?
optionalContainer = manager.findPlugin(plugin);
}
}
if (optionalContainer.isPresent()) {
final LightContainer lightContainer = optionalContainer.get().get(LightContainer.class);
if (lightContainer != null) {
return lightContainer;
}
}
// TCCL
return super.find(plugin);
}
Aggregations