Search in sources :

Example 1 with EmbeddedAppLauncher

use of org.apache.apex.api.EmbeddedAppLauncher in project apex-malhar by apache.

the class ApplicationTest method testApplication.

@Test
public void testApplication() throws Exception {
    Configuration conf = new Configuration(false);
    conf.addResource(this.getClass().getResourceAsStream("/META-INF/properties.xml"));
    EmbeddedAppLauncher<?> launcher = Launcher.getLauncher(Launcher.LaunchMode.EMBEDDED);
    Attribute.AttributeMap launchAttributes = new Attribute.AttributeMap.DefaultAttributeMap();
    launchAttributes.put(EmbeddedAppLauncher.RUN_ASYNC, true);
    EnricherAppWithJSONFile enricherAppWithJSONFile = new EnricherAppWithJSONFile();
    enricherAppWithJSONFile.outputFn = outputFn;
    Launcher.AppHandle appHandle = launcher.launchApp(enricherAppWithJSONFile, conf, launchAttributes);
    int sleepTimeCounterForLoopExit = 0;
    int sleepTimePerIteration = 500;
    // wait until expected result count or timeout
    while (results.size() < enricherAppWithJSONFile.getDataGenerator().getLimit()) {
        sleepTimeCounterForLoopExit += sleepTimePerIteration;
        if (sleepTimeCounterForLoopExit > 30000) {
            break;
        }
        Thread.sleep(sleepTimePerIteration);
    }
    appHandle.shutdown(ShutdownMode.KILL);
    assertTrue(results.size() >= enricherAppWithJSONFile.getDataGenerator().getLimit());
    assertEnrichedOutput();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Attribute(com.datatorrent.api.Attribute) Launcher(org.apache.apex.api.Launcher) EmbeddedAppLauncher(org.apache.apex.api.EmbeddedAppLauncher) Test(org.junit.Test)

Example 2 with EmbeddedAppLauncher

use of org.apache.apex.api.EmbeddedAppLauncher in project apex-malhar by apache.

the class SimpleTransformApplicationTest method testApplication.

@Test
public void testApplication() throws Exception {
    Configuration conf = new Configuration(false);
    conf.addResource(this.getClass().getResourceAsStream("/META-INF/properties.xml"));
    EmbeddedAppLauncher<?> launcher = Launcher.getLauncher(Launcher.LaunchMode.EMBEDDED);
    Attribute.AttributeMap launchAttributes = new Attribute.AttributeMap.DefaultAttributeMap();
    launchAttributes.put(EmbeddedAppLauncher.RUN_ASYNC, true);
    SimpleTransformApplication simpleTransformApplication = new SimpleTransformApplication();
    simpleTransformApplication.outputFn = outputFn;
    Launcher.AppHandle appHandle = launcher.launchApp(simpleTransformApplication, conf, launchAttributes);
    int sleepTimeCounterForLoopExit = 0;
    int sleepTimePerIteration = 500;
    // wait until expected result count or timeout
    while (results.size() < simpleTransformApplication.pojoDataGenerator.getMaxTuples()) {
        sleepTimeCounterForLoopExit += sleepTimePerIteration;
        if (sleepTimeCounterForLoopExit > 30000) {
            break;
        }
        Thread.sleep(sleepTimePerIteration);
    }
    appHandle.shutdown(Launcher.ShutdownMode.KILL);
    assertEquals(results.size(), simpleTransformApplication.pojoDataGenerator.getMaxTuples());
    assertTransformationsGenerated(simpleTransformApplication);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Attribute(com.datatorrent.api.Attribute) Launcher(org.apache.apex.api.Launcher) EmbeddedAppLauncher(org.apache.apex.api.EmbeddedAppLauncher) Test(org.junit.Test)

Example 3 with EmbeddedAppLauncher

use of org.apache.apex.api.EmbeddedAppLauncher in project apex-malhar by apache.

the class PythonExecutorApplicationTest method testApplication.

@JepPythonTestContext(jepPythonBasedTest = true)
@Test
public void testApplication() throws Exception {
    Configuration conf = new Configuration(false);
    conf.addResource(this.getClass().getResourceAsStream("/META-INF/properties.xml"));
    EmbeddedAppLauncher<?> launcher = Launcher.getLauncher(Launcher.LaunchMode.EMBEDDED);
    Attribute.AttributeMap launchAttributes = new Attribute.AttributeMap.DefaultAttributeMap();
    launchAttributes.put(EmbeddedAppLauncher.RUN_ASYNC, true);
    PythonExecutorApplication pythonExecutorApplication = new PythonExecutorApplication();
    pythonExecutorApplication.outputFn = outputFn;
    Launcher.AppHandle appHandle = launcher.launchApp(pythonExecutorApplication, conf, launchAttributes);
    int sleepTimeCounterForLoopExit = 0;
    int sleepTimePerIteration = 1000;
    // wait until expected result count or timeout
    while (results.size() < pythonExecutorApplication.pojoDataGenerator.getMaxTuples()) {
        sleepTimeCounterForLoopExit += sleepTimePerIteration;
        if (sleepTimeCounterForLoopExit > 30000) {
            break;
        }
        LOG.info("Test sleeping until the application time out is reached");
        Thread.sleep(sleepTimePerIteration);
    }
    appHandle.shutdown(Launcher.ShutdownMode.KILL);
    assertEquals(pythonExecutorApplication.pojoDataGenerator.getMaxTuples(), results.size());
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Attribute(com.datatorrent.api.Attribute) Launcher(org.apache.apex.api.Launcher) EmbeddedAppLauncher(org.apache.apex.api.EmbeddedAppLauncher) JepPythonTestContext(org.apache.apex.malhar.python.test.JepPythonTestContext) Test(org.junit.Test)

Aggregations

Attribute (com.datatorrent.api.Attribute)3 EmbeddedAppLauncher (org.apache.apex.api.EmbeddedAppLauncher)3 Launcher (org.apache.apex.api.Launcher)3 Configuration (org.apache.hadoop.conf.Configuration)3 Test (org.junit.Test)3 JepPythonTestContext (org.apache.apex.malhar.python.test.JepPythonTestContext)1