Search in sources :

Example 51 with StramLocalCluster

use of com.datatorrent.stram.StramLocalCluster in project apex-malhar by apache.

the class FunctionOperatorTest method testFilterOperator.

@Test
public void testFilterOperator() throws Exception {
    LocalMode lma = LocalMode.newInstance();
    DAG dag = lma.getDAG();
    FunctionOperator.FilterFunctionOperator<Integer> filter0 = new FunctionOperator.FilterFunctionOperator<Integer>(new Function.FilterFunction<Integer>() {

        @Override
        public boolean f(Integer in) {
            return in % divider == 0;
        }
    });
    NumberGenerator numGen = dag.addOperator("numGen", new NumberGenerator());
    FunctionOperator.FilterFunctionOperator<Integer> filter = dag.addOperator("filter", filter0);
    ResultCollector collector = dag.addOperator("collector", new ResultCollector());
    dag.addStream("raw numbers", numGen.output, filter.input);
    dag.addStream("filtered results", filter.output, collector.input);
    // Create local cluster
    LocalMode.Controller lc = lma.getController();
    lc.setHeartbeatMonitoringEnabled(false);
    ((StramLocalCluster) lc).setExitCondition(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return TupleCount == NumTuples / divider;
        }
    });
    lc.run(5000);
    Assert.assertEquals(sum, 20);
}
Also used : DAG(com.datatorrent.api.DAG) StramLocalCluster(com.datatorrent.stram.StramLocalCluster) FunctionOperator(org.apache.apex.malhar.lib.function.FunctionOperator) Function(org.apache.apex.malhar.lib.function.Function) LocalMode(com.datatorrent.api.LocalMode) Test(org.junit.Test)

Example 52 with StramLocalCluster

use of com.datatorrent.stram.StramLocalCluster in project apex-malhar by apache.

the class FunctionOperatorTest method testFlatMapOperator.

@Test
public void testFlatMapOperator() throws Exception {
    LocalMode lma = LocalMode.newInstance();
    DAG dag = lma.getDAG();
    NumberListGenerator numGen = dag.addOperator("numGen", new NumberListGenerator());
    FunctionOperator.FlatMapFunctionOperator<List<Integer>, Integer> fm = dag.addOperator("flatmap", new FunctionOperator.FlatMapFunctionOperator<>(new FmFunction()));
    ResultCollector collector = dag.addOperator("collector", new ResultCollector());
    dag.addStream("raw numbers", numGen.output, fm.input);
    dag.addStream("flatmap results", fm.output, collector.input);
    // Create local cluster
    LocalMode.Controller lc = lma.getController();
    lc.setHeartbeatMonitoringEnabled(false);
    ((StramLocalCluster) lc).setExitCondition(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return TupleCount == 13;
        }
    });
    lc.run(5000);
    Assert.assertEquals(sum, 39555);
}
Also used : DAG(com.datatorrent.api.DAG) StramLocalCluster(com.datatorrent.stram.StramLocalCluster) FunctionOperator(org.apache.apex.malhar.lib.function.FunctionOperator) LocalMode(com.datatorrent.api.LocalMode) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 53 with StramLocalCluster

use of com.datatorrent.stram.StramLocalCluster in project apex-malhar by apache.

the class FunctionOperatorTest method testMapOperator.

@Test
public void testMapOperator() throws Exception {
    LocalMode lma = LocalMode.newInstance();
    DAG dag = lma.getDAG();
    NumberGenerator numGen = dag.addOperator("numGen", new NumberGenerator());
    FunctionOperator.MapFunctionOperator<Integer, Integer> mapper = dag.addOperator("mapper", new FunctionOperator.MapFunctionOperator<Integer, Integer>(new Square()));
    ResultCollector collector = dag.addOperator("collector", new ResultCollector());
    dag.addStream("raw numbers", numGen.output, mapper.input);
    dag.addStream("mapped results", mapper.output, collector.input);
    // Create local cluster
    LocalMode.Controller lc = lma.getController();
    lc.setHeartbeatMonitoringEnabled(false);
    ((StramLocalCluster) lc).setExitCondition(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return TupleCount == NumTuples;
        }
    });
    lc.run(5000);
    Assert.assertEquals(sum, 285);
}
Also used : DAG(com.datatorrent.api.DAG) StramLocalCluster(com.datatorrent.stram.StramLocalCluster) FunctionOperator(org.apache.apex.malhar.lib.function.FunctionOperator) LocalMode(com.datatorrent.api.LocalMode) Test(org.junit.Test)

Example 54 with StramLocalCluster

use of com.datatorrent.stram.StramLocalCluster in project apex-malhar by apache.

the class ApexStreamImpl method runEmbedded.

@Override
public void runEmbedded(boolean async, long duration, Callable<Boolean> exitCondition) {
    LocalMode lma = LocalMode.newInstance();
    populateDag(lma.getDAG());
    DAG dag = lma.getDAG();
    LocalMode.Controller lc = lma.getController();
    if (lc instanceof StramLocalCluster) {
        ((StramLocalCluster) lc).setExitCondition(exitCondition);
    }
    if (async) {
        lc.runAsync();
    } else {
        if (duration >= 0) {
            lc.run(duration);
        } else {
            lc.run();
        }
    }
}
Also used : LocalMode(com.datatorrent.api.LocalMode) DAG(com.datatorrent.api.DAG) StramLocalCluster(com.datatorrent.stram.StramLocalCluster)

Example 55 with StramLocalCluster

use of com.datatorrent.stram.StramLocalCluster in project apex-malhar by apache.

the class PojoInnerJoinTestApplication method testApplication.

@Test
public void testApplication() throws Exception {
    LocalMode lma = LocalMode.newInstance();
    Configuration conf = new Configuration(false);
    lma.prepareDAG(new PojoInnerJoinTestApplication(), conf);
    LocalMode.Controller lc = lma.getController();
    ((StramLocalCluster) lc).setExitCondition(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return SalesCount == 1 && ProductCount == 1 && records == 2;
        }
    });
    lc.run(20000);
    Assert.assertEquals(2, records);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) LocalMode(com.datatorrent.api.LocalMode) StramLocalCluster(com.datatorrent.stram.StramLocalCluster) Test(org.junit.Test)

Aggregations

StramLocalCluster (com.datatorrent.stram.StramLocalCluster)57 Test (org.junit.Test)46 LocalMode (com.datatorrent.api.LocalMode)21 LogicalPlan (com.datatorrent.stram.plan.logical.LogicalPlan)20 Configuration (org.apache.hadoop.conf.Configuration)19 File (java.io.File)15 AsyncFSStorageAgent (com.datatorrent.common.util.AsyncFSStorageAgent)12 IOException (java.io.IOException)8 DAG (com.datatorrent.api.DAG)6 StreamMeta (com.datatorrent.stram.plan.logical.LogicalPlan.StreamMeta)6 MemoryStorageAgent (com.datatorrent.stram.support.StramTestSupport.MemoryStorageAgent)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 ConstraintViolationException (javax.validation.ConstraintViolationException)5 StreamMeta (com.datatorrent.api.DAG.StreamMeta)4 PartitioningTest (com.datatorrent.stram.PartitioningTest)4 StreamingContainerManagerTest (com.datatorrent.stram.StreamingContainerManagerTest)4 TestGeneratorInputOperator (com.datatorrent.stram.engine.TestGeneratorInputOperator)4 LogicalPlanConfiguration (com.datatorrent.stram.plan.logical.LogicalPlanConfiguration)4 StramTestSupport (com.datatorrent.stram.support.StramTestSupport)4 SQLException (java.sql.SQLException)4