use of org.apache.apex.malhar.lib.testbench.CollectorTestSink in project apex-malhar by apache.
the class InConditionTest method testSqlSelect.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testSqlSelect() {
// create operator
SelectOperator oper = new SelectOperator();
oper.addIndex(new ColumnIndex("b", null));
oper.addIndex(new ColumnIndex("c", null));
InCondition cond = new InCondition("a");
cond.addInValue(0);
cond.addInValue(1);
oper.setCondition(cond);
CollectorTestSink sink = new CollectorTestSink();
oper.outport.setSink(sink);
oper.setup(null);
oper.beginWindow(1);
HashMap<String, Object> tuple = new HashMap<String, Object>();
tuple.put("a", 0);
tuple.put("b", 1);
tuple.put("c", 2);
oper.inport.process(tuple);
tuple = new HashMap<String, Object>();
tuple.put("a", 1);
tuple.put("b", 3);
tuple.put("c", 4);
oper.inport.process(tuple);
tuple = new HashMap<String, Object>();
tuple.put("a", 2);
tuple.put("b", 5);
tuple.put("c", 6);
oper.inport.process(tuple);
tuple = new HashMap<String, Object>();
tuple.put("a", 3);
tuple.put("b", 7);
tuple.put("c", 8);
oper.inport.process(tuple);
oper.endWindow();
oper.teardown();
LOG.debug("{}", sink.collectedTuples);
}
use of org.apache.apex.malhar.lib.testbench.CollectorTestSink in project apex-malhar by apache.
the class SelectCountTest method testSqlSelect.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testSqlSelect() {
// create operator
SelectFunctionOperator oper = new SelectFunctionOperator();
oper.addSqlFunction(new CountFunction("b", null));
CollectorTestSink sink = new CollectorTestSink();
oper.outport.setSink(sink);
oper.setup(null);
oper.beginWindow(1);
HashMap<String, Object> tuple = new HashMap<String, Object>();
tuple.put("a", 0);
tuple.put("b", null);
tuple.put("c", 2);
oper.inport.process(tuple);
tuple = new HashMap<String, Object>();
tuple.put("a", 1);
tuple.put("b", null);
tuple.put("c", 4);
oper.inport.process(tuple);
tuple = new HashMap<String, Object>();
tuple.put("a", 1);
tuple.put("b", 5);
tuple.put("c", 6);
oper.inport.process(tuple);
oper.endWindow();
oper.teardown();
LOG.debug("{}", sink.collectedTuples);
}
use of org.apache.apex.malhar.lib.testbench.CollectorTestSink in project apex-malhar by apache.
the class MongoDBInputOperatorTest method MongoDBInputOperatorTest.
@Test
public void MongoDBInputOperatorTest() {
MyMongoDBInputOperator oper = new MyMongoDBInputOperator();
oper.setHostName("localhost");
oper.setDataBase("test");
oper.setUserName("test");
oper.setPassWord("123");
oper.setTable("t1");
// AttributeMap<DAGContext> attrmap = new DefaultAttributeMap<DAGContext>();
// attrmap.attr(DAG.STRAM_APP_ID).set("myMongoDBInputOperatorAppId");
oper.setup(mockOperatorContext(1));
oper.beginWindow(0);
CollectorTestSink sink = new CollectorTestSink();
oper.outputPort.setSink(sink);
oper.emitTuples();
oper.endWindow();
oper.teardown();
}
use of org.apache.apex.malhar.lib.testbench.CollectorTestSink in project apex-malhar by apache.
the class CountKeyValTest method testNodeProcessing.
/**
* Test operator logic emits correct results.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testNodeProcessing() {
CountKeyVal<String, Double> oper = new CountKeyVal<String, Double>();
CollectorTestSink countSink = new CollectorTestSink();
oper.count.setSink(countSink);
//
oper.beginWindow(0);
oper.data.process(new KeyValPair("a", 2.0));
oper.data.process(new KeyValPair("b", 20.0));
oper.data.process(new KeyValPair("c", 1000.0));
oper.data.process(new KeyValPair("a", 1.0));
oper.data.process(new KeyValPair("a", 10.0));
oper.data.process(new KeyValPair("b", 5.0));
oper.data.process(new KeyValPair("d", 55.0));
oper.data.process(new KeyValPair("b", 12.0));
oper.data.process(new KeyValPair("d", 22.0));
oper.data.process(new KeyValPair("d", 14.2));
oper.data.process(new KeyValPair("d", 46.0));
oper.data.process(new KeyValPair("e", 2.0));
oper.data.process(new KeyValPair("a", 23.0));
oper.data.process(new KeyValPair("d", 4.0));
//
oper.endWindow();
// payload should be 1 bag of tuples with keys "a", "b", "c", "d", "e"
Assert.assertEquals("number emitted tuples", 5, countSink.collectedTuples.size());
for (Object o : countSink.collectedTuples) {
KeyValPair<String, Integer> e = (KeyValPair<String, Integer>) o;
Integer val = (Integer) e.getValue();
if (e.getKey().equals("a")) {
Assert.assertEquals("emitted value for 'a' was ", 4, val.intValue());
} else if (e.getKey().equals("b")) {
Assert.assertEquals("emitted tuple for 'b' was ", 3, val.intValue());
} else if (e.getKey().equals("c")) {
Assert.assertEquals("emitted tuple for 'c' was ", 1, val.intValue());
} else if (e.getKey().equals("d")) {
Assert.assertEquals("emitted tuple for 'd' was ", 5, val.intValue());
} else if (e.getKey().equals("e")) {
Assert.assertEquals("emitted tuple for 'e' was ", 1, val.intValue());
}
}
}
use of org.apache.apex.malhar.lib.testbench.CollectorTestSink in project apex-malhar by apache.
the class LeftOuterJoinOperatorTest method testSqlSelect.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testSqlSelect() {
// create operator
OuterJoinOperator oper = new OuterJoinOperator();
CollectorTestSink sink = new CollectorTestSink();
oper.outport.setSink(sink);
// set column join condition
Condition cond = new JoinColumnEqualCondition("a", "a");
oper.setJoinCondition(cond);
// add columns
oper.selectTable1Column(new ColumnIndex("b", null));
oper.selectTable2Column(new ColumnIndex("c", null));
oper.setup(null);
oper.beginWindow(1);
HashMap<String, Object> tuple = new HashMap<String, Object>();
tuple.put("a", 0);
tuple.put("b", 1);
tuple.put("c", 2);
oper.inport1.process(tuple);
tuple = new HashMap<String, Object>();
tuple.put("a", 1);
tuple.put("b", 3);
tuple.put("c", 4);
oper.inport1.process(tuple);
tuple = new HashMap<String, Object>();
tuple.put("a", 2);
tuple.put("b", 11);
tuple.put("c", 12);
oper.inport1.process(tuple);
tuple = new HashMap<String, Object>();
tuple.put("a", 0);
tuple.put("b", 7);
tuple.put("c", 8);
oper.inport2.process(tuple);
tuple = new HashMap<String, Object>();
tuple.put("a", 1);
tuple.put("b", 5);
tuple.put("c", 6);
oper.inport2.process(tuple);
oper.endWindow();
oper.teardown();
LOG.debug("{}", sink.collectedTuples);
}
Aggregations