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);
}
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);
}
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);
}
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();
}
}
}
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);
}
Aggregations