use of org.apache.apex.malhar.lib.testbench.CollectorTestSink in project apex-malhar by apache.
the class TopNUniqueTest method testNodeProcessingSchema.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testNodeProcessingSchema(TopNUnique oper) {
CollectorTestSink sortSink = new CollectorTestSink();
oper.top.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", 1);
oper.data.process(input);
input.clear();
input.put("b", 6);
input.put("a", 1001);
oper.data.process(input);
input.clear();
input.put("c", 9);
input.put("a", 5);
oper.data.process(input);
oper.endWindow();
Assert.assertEquals("number emitted tuples", 3, sortSink.collectedTuples.size());
for (Object o : sortSink.collectedTuples) {
log.debug(o.toString());
for (Map.Entry<String, ArrayList<HashMap<Number, Integer>>> e : ((HashMap<String, ArrayList<HashMap<Number, Integer>>>) o).entrySet()) {
if (e.getKey().equals("a")) {
Assert.assertEquals("emitted value for 'a' was ", 3, e.getValue().size());
} else if (e.getKey().equals("b")) {
Assert.assertEquals("emitted tuple for 'b' was ", 3, e.getValue().size());
} else if (e.getKey().equals("c")) {
Assert.assertEquals("emitted tuple for 'c' was ", 1, e.getValue().size());
}
}
}
log.debug("Done testing round\n");
}
use of org.apache.apex.malhar.lib.testbench.CollectorTestSink in project apex-malhar by apache.
the class BottomNUniqueMapTest method testNodeProcessingSchema.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testNodeProcessingSchema(BottomNUniqueMap oper) {
CollectorTestSink sortSink = new CollectorTestSink();
oper.bottom.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);
input.put("a", 5);
oper.data.process(input);
oper.endWindow();
Assert.assertEquals("number emitted tuples", 3, sortSink.collectedTuples.size());
for (Object o : sortSink.collectedTuples) {
log.debug(o.toString());
for (Map.Entry<String, ArrayList<HashMap<Number, Integer>>> e : ((HashMap<String, ArrayList<HashMap<Number, Integer>>>) o).entrySet()) {
if (e.getKey().equals("a")) {
Assert.assertEquals("emitted value for 'a' was ", 3, e.getValue().size());
} else if (e.getKey().equals("b")) {
Assert.assertEquals("emitted tuple for 'b' was ", 3, e.getValue().size());
} else if (e.getKey().equals("c")) {
Assert.assertEquals("emitted tuple for 'c' was ", 1, e.getValue().size());
}
}
}
log.debug("Done testing round\n");
}
use of org.apache.apex.malhar.lib.testbench.CollectorTestSink in project apex-malhar by apache.
the class InsertSortTest method testNodeProcessingSchema.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testNodeProcessingSchema(InsertSort oper, String debug) {
CollectorTestSink sortSink = new CollectorTestSink();
oper.sort.setSink(sortSink);
ArrayList input = new ArrayList();
oper.beginWindow(0);
input.add(2);
oper.datalist.process(input);
oper.data.process(20);
input.clear();
input.add(1000);
input.add(5);
input.add(20);
input.add(33);
input.add(33);
input.add(34);
oper.datalist.process(input);
input.clear();
input.add(34);
input.add(1001);
input.add(6);
input.add(1);
input.add(33);
input.add(9);
oper.datalist.process(input);
oper.endWindow();
Assert.assertEquals("number emitted tuples", 1, sortSink.collectedTuples.size());
input = (ArrayList) sortSink.collectedTuples.get(0);
}
use of org.apache.apex.malhar.lib.testbench.CollectorTestSink in project apex-malhar by apache.
the class AppDataSnapshotServerMapTest method simpleTest.
@Test
public void simpleTest() throws Exception {
AppDataSnapshotServerMap snapshotServer = new AppDataSnapshotServerMap();
snapshotServer.setSnapshotSchemaJSON(SIMPLE_SCHEMA);
// // Input Data
List<Map<String, Object>> dataList = Lists.newArrayList();
Map<String, Object> data = Maps.newHashMap();
data.put("word", "a");
data.put("count", 2);
Map<String, Object> data1 = Maps.newHashMap();
data1.put("word", "b");
data1.put("count", 3);
dataList.add(data);
dataList.add(data1);
// //
CollectorTestSink<String> resultSink = new CollectorTestSink<String>();
@SuppressWarnings({ "unchecked", "rawtypes" }) CollectorTestSink<Object> tempResultSink = (CollectorTestSink) resultSink;
snapshotServer.queryResult.setSink(tempResultSink);
snapshotServer.setup(null);
snapshotServer.beginWindow(0L);
snapshotServer.input.put(dataList);
snapshotServer.endWindow();
snapshotServer.beginWindow(1L);
snapshotServer.query.put(SIMPLE_QUERY);
snapshotServer.endWindow();
String result = (String) tempResultSink.collectedTuples.get(0);
Assert.assertEquals("Should get only 1 result back", 1, tempResultSink.collectedTuples.size());
Assert.assertEquals("Countdown incorrect", 10, new JSONObject(result).getInt("countdown"));
Assert.assertEquals("Num results", 2, new JSONObject(result).getJSONArray("data").length());
JSONObject firstRow = new JSONObject(result).getJSONArray("data").getJSONObject(0);
JSONObject secondRow = new JSONObject(result).getJSONArray("data").getJSONObject(1);
Assert.assertEquals(2, firstRow.getInt("count"));
Assert.assertEquals("a", firstRow.getString("word"));
Assert.assertEquals(3, secondRow.getInt("count"));
Assert.assertEquals("b", secondRow.getString("word"));
// Test serialization
KryoCloneUtils.cloneObject(snapshotServer);
}
use of org.apache.apex.malhar.lib.testbench.CollectorTestSink in project apex-malhar by apache.
the class ReduceOperatorTest method testNodeProcessingSchema.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testNodeProcessingSchema(ReduceOperator<Text, IntWritable, Text, IntWritable> oper) {
oper.setReduceClass(WordCount.Reduce.class);
oper.setConfigFile(null);
oper.setup(null);
CollectorTestSink sortSink = new CollectorTestSink();
oper.output.setSink(sortSink);
oper.beginWindow(0);
oper.inputCount.process(new KeyHashValPair<Integer, Integer>(1, 1));
oper.input.process(new KeyHashValPair<Text, IntWritable>(new Text("one"), new IntWritable(1)));
oper.input.process(new KeyHashValPair<Text, IntWritable>(new Text("one"), new IntWritable(1)));
oper.input.process(new KeyHashValPair<Text, IntWritable>(new Text("two"), new IntWritable(1)));
oper.endWindow();
oper.beginWindow(1);
oper.input.process(new KeyHashValPair<Text, IntWritable>(new Text("one"), new IntWritable(1)));
oper.input.process(new KeyHashValPair<Text, IntWritable>(new Text("two"), new IntWritable(1)));
oper.input.process(new KeyHashValPair<Text, IntWritable>(new Text("two"), new IntWritable(1)));
oper.inputCount.process(new KeyHashValPair<Integer, Integer>(1, -1));
oper.endWindow();
Assert.assertEquals("number emitted tuples", 2, sortSink.collectedTuples.size());
for (Object o : sortSink.collectedTuples) {
logger.debug(o.toString());
}
logger.debug("Done testing round\n");
}
Aggregations