use of org.talend.sdk.component.runtime.manager.chain.GroupKeyProvider 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();
}
}
}
}
}
Aggregations