use of org.apache.apex.malhar.lib.testbench.CollectorTestSink in project apex-malhar by apache.
the class RightOuterJoinOperatorTest method testSqlSelect.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testSqlSelect() {
// create operator
OuterJoinOperator oper = new OuterJoinOperator();
oper.setRighttJoin();
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", 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);
tuple = new HashMap<String, Object>();
tuple.put("a", 2);
tuple.put("b", 11);
tuple.put("c", 12);
oper.inport2.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 AbstractMemsqlInputOperatorTest method TestMemsqlPOJOInputOperator.
/*
* This test can be run against memsql installation on node17.
*/
@Test
public void TestMemsqlPOJOInputOperator() throws SQLException {
cleanDatabase();
populateDatabase(createStore(null, true));
Attribute.AttributeMap attributeMap = new Attribute.AttributeMap.DefaultAttributeMap();
attributeMap.put(Context.OperatorContext.SPIN_MILLIS, 500);
OperatorContext context = mockOperatorContext(OPERATOR_ID, attributeMap);
MemsqlPOJOInputOperator inputOperator = new MemsqlPOJOInputOperator();
createStore((MemsqlStore) inputOperator.getStore(), true);
inputOperator.setBatchSize(10);
inputOperator.setTablename(FQ_TABLE);
inputOperator.setPrimaryKeyColumn(INDEX_COLUMN);
ArrayList<String> expressions = new ArrayList<String>();
expressions.add("id");
expressions.add("name");
inputOperator.setExpressions(expressions);
ArrayList<String> columns = new ArrayList<String>();
columns.add("data_index");
columns.add("data2");
inputOperator.setColumns(columns);
inputOperator.setQuery("select * from " + FQ_TABLE + ";");
inputOperator.setOutputClass("org.apache.apex.malhar.contrib.memsql.TestInputPojo");
CollectorTestSink<Object> sink = new CollectorTestSink<Object>();
inputOperator.outputPort.setSink(sink);
inputOperator.setup(context);
inputOperator.beginWindow(0);
inputOperator.emitTuples();
inputOperator.endWindow();
Assert.assertEquals("rows from db", 100, sink.collectedTuples.size());
for (int i = 0; i < 10; i++) {
TestInputPojo object = (TestInputPojo) sink.collectedTuples.get(i);
Assert.assertEquals("id set in testpojo", i, object.getId());
Assert.assertEquals("name set in testpojo", "Testname" + i, object.getName());
}
sink.clear();
inputOperator.setQuery("select * from " + FQ_TABLE + " where " + "%p " + ">= " + "%s" + ";");
inputOperator.setStartRow(10);
inputOperator.setup(context);
inputOperator.beginWindow(0);
inputOperator.emitTuples();
inputOperator.endWindow();
Assert.assertEquals("rows from db", 90, sink.collectedTuples.size());
sink.clear();
inputOperator.setQuery("select * from " + FQ_TABLE + " where " + "%p " + ">= " + "%s" + " LIMIT " + "%l" + ";");
inputOperator.setStartRow(1);
inputOperator.setBatchSize(10);
inputOperator.setup(context);
inputOperator.beginWindow(0);
inputOperator.emitTuples();
inputOperator.endWindow();
Assert.assertEquals("rows from db", 10, sink.collectedTuples.size());
}
use of org.apache.apex.malhar.lib.testbench.CollectorTestSink in project apex-malhar by apache.
the class FilterKeysMapTest method testNodeProcessing.
/**
* Test node logic emits correct results
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testNodeProcessing() throws Exception {
FilterKeysMap<String, Number> oper = new FilterKeysMap<String, Number>();
CollectorTestSink sortSink = new CollectorTestSink();
oper.filter.setSink(sortSink);
oper.setKey("b");
oper.clearKeys();
String[] keys = new String[3];
keys[0] = "e";
keys[1] = "f";
keys[2] = "blah";
oper.setKey("a");
oper.setKeys(keys);
oper.beginWindow(0);
HashMap<String, Number> input = new HashMap<String, Number>();
input.put("a", 2);
input.put("b", 5);
input.put("c", 7);
input.put("d", 42);
input.put("e", 200);
input.put("f", 2);
oper.data.process(input);
Assert.assertEquals("number emitted tuples", 1, sortSink.collectedTuples.size());
Assert.assertEquals("Total filtered value is ", 204, getTotal(sortSink.collectedTuples.get(0)));
sortSink.clear();
input.clear();
input.put("a", 5);
oper.data.process(input);
Assert.assertEquals("number emitted tuples", 1, sortSink.collectedTuples.size());
Assert.assertEquals("Total filtered value is ", 5, getTotal(sortSink.collectedTuples.get(0)));
sortSink.clear();
input.clear();
input.put("a", 2);
input.put("b", 33);
input.put("f", 2);
oper.data.process(input);
Assert.assertEquals("number emitted tuples", 1, sortSink.collectedTuples.size());
Assert.assertEquals("Total filtered value is ", 4, getTotal(sortSink.collectedTuples.get(0)));
sortSink.clear();
input.clear();
input.put("b", 6);
input.put("a", 2);
input.put("j", 6);
input.put("e", 2);
input.put("dd", 6);
input.put("blah", 2);
input.put("another", 6);
input.put("notmakingit", 2);
oper.data.process(input);
Assert.assertEquals("number emitted tuples", 1, sortSink.collectedTuples.size());
Assert.assertEquals("Total filtered value is ", 6, getTotal(sortSink.collectedTuples.get(0)));
sortSink.clear();
input.clear();
input.put("c", 9);
oper.setInverse(true);
oper.data.process(input);
Assert.assertEquals("number emitted tuples", 1, sortSink.collectedTuples.size());
Assert.assertEquals("Total filtered value is ", 9, getTotal(sortSink.collectedTuples.get(0)));
oper.endWindow();
}
use of org.apache.apex.malhar.lib.testbench.CollectorTestSink in project apex-malhar by apache.
the class FirstNTest method testNodeProcessingSchema.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testNodeProcessingSchema(FirstN oper) {
CollectorTestSink sortSink = new CollectorTestSink();
oper.first.setSink(sortSink);
oper.setN(3);
oper.beginWindow(0);
HashMap<String, Number> input = new HashMap<String, Number>();
input.put("a", 2);
oper.data.process(input);
input.clear();
input.put("a", 20);
oper.data.process(input);
input.clear();
input.put("a", 1000);
oper.data.process(input);
input.clear();
input.put("a", 5);
oper.data.process(input);
input.clear();
input.put("a", 20);
input.put("b", 33);
oper.data.process(input);
input.clear();
input.put("a", 33);
input.put("b", 34);
oper.data.process(input);
input.clear();
input.put("b", 34);
input.put("a", 1001);
oper.data.process(input);
input.clear();
input.put("b", 6);
input.put("a", 1);
oper.data.process(input);
input.clear();
input.put("c", 9);
oper.data.process(input);
oper.endWindow();
Assert.assertEquals("number emitted tuples", 7, sortSink.collectedTuples.size());
int aval = 0;
int bval = 0;
int cval = 0;
for (Object o : sortSink.collectedTuples) {
for (Map.Entry<String, Number> e : ((HashMap<String, Number>) o).entrySet()) {
if (e.getKey().equals("a")) {
aval += e.getValue().intValue();
} else if (e.getKey().equals("b")) {
bval += e.getValue().intValue();
} else if (e.getKey().equals("c")) {
cval += e.getValue().intValue();
}
}
}
Assert.assertEquals("Value of \"a\" was ", 1022, aval);
Assert.assertEquals("Value of \"a\" was ", 101, bval);
Assert.assertEquals("Value of \"a\" was ", 9, cval);
log.debug("Done testing round\n");
}
use of org.apache.apex.malhar.lib.testbench.CollectorTestSink in project apex-malhar by apache.
the class InvertIndexArrayTest method testNodeProcessing.
/**
* Test oper logic emits correct results
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testNodeProcessing() throws Exception {
InvertIndexArray<String, String> oper = new InvertIndexArray<String, String>();
CollectorTestSink indexSink = new CollectorTestSink();
Sink inSink = oper.data.getSink();
oper.index.setSink(indexSink);
oper.beginWindow(0);
HashMap<String, ArrayList> input = new HashMap<String, ArrayList>();
ArrayList<String> alist = new ArrayList<String>();
alist.add("str");
alist.add("str1");
input.put("a", alist);
input.put("b", alist);
inSink.put(input);
alist = new ArrayList<String>();
input = new HashMap<String, ArrayList>();
alist.add("blah");
alist.add("str1");
input.put("c", alist);
inSink.put(input);
oper.endWindow();
Assert.assertEquals("number emitted tuples", 3, indexSink.collectedTuples.size());
for (Object o : indexSink.collectedTuples) {
log.debug(o.toString());
HashMap<String, ArrayList<String>> output = (HashMap<String, ArrayList<String>>) o;
for (Map.Entry<String, ArrayList<String>> e : output.entrySet()) {
String key = e.getKey();
alist = e.getValue();
if (key.equals("str1")) {
Assert.assertEquals("Index for \"str1\" contains \"a\"", true, alist.contains("a"));
Assert.assertEquals("Index for \"str1\" contains \"b\"", true, alist.contains("b"));
Assert.assertEquals("Index for \"str1\" contains \"c\"", true, alist.contains("c"));
} else if (key.equals("str")) {
Assert.assertEquals("Index for \"str1\" contains \"a\"", true, alist.contains("a"));
Assert.assertEquals("Index for \"str1\" contains \"b\"", true, alist.contains("b"));
Assert.assertEquals("Index for \"str1\" contains \"c\"", false, alist.contains("c"));
} else if (key.equals("blah")) {
Assert.assertEquals("Index for \"str1\" contains \"a\"", false, alist.contains("a"));
Assert.assertEquals("Index for \"str1\" contains \"b\"", false, alist.contains("b"));
Assert.assertEquals("Index for \"str1\" contains \"c\"", true, alist.contains("c"));
}
}
}
}
Aggregations