Search in sources :

Example 1 with MatchMap

use of org.apache.apex.malhar.lib.algo.MatchMap in project apex-malhar by apache.

the class MatchMapTest method testNodeProcessingSchema.

@SuppressWarnings({ "rawtypes", "unchecked" })
public void testNodeProcessingSchema(MatchMap oper) {
    CountAndLastTupleTestSink matchSink = new CountAndLastTupleTestSink();
    oper.match.setSink(matchSink);
    oper.setKey("a");
    oper.setValue(3.0);
    oper.setTypeNEQ();
    oper.beginWindow(0);
    HashMap<String, Number> input = new HashMap<String, Number>();
    input.put("a", 2);
    input.put("b", 20);
    input.put("c", 1000);
    oper.data.process(input);
    input.clear();
    input.put("a", 3);
    oper.data.process(input);
    oper.endWindow();
    // One for each key
    Assert.assertEquals("number emitted tuples", 1, matchSink.count);
    for (Map.Entry<String, Number> e : ((HashMap<String, Number>) matchSink.tuple).entrySet()) {
        if (e.getKey().equals("a")) {
            Assert.assertEquals("emitted value for 'a' was ", new Double(2), new Double(e.getValue().doubleValue()));
        } else if (e.getKey().equals("b")) {
            Assert.assertEquals("emitted tuple for 'b' was ", new Double(20), new Double(e.getValue().doubleValue()));
        } else if (e.getKey().equals("c")) {
            Assert.assertEquals("emitted tuple for 'c' was ", new Double(1000), new Double(e.getValue().doubleValue()));
        }
    }
}
Also used : HashMap(java.util.HashMap) CountAndLastTupleTestSink(org.apache.apex.malhar.lib.testbench.CountAndLastTupleTestSink) MatchMap(org.apache.apex.malhar.lib.algo.MatchMap) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 MatchMap (org.apache.apex.malhar.lib.algo.MatchMap)1 CountAndLastTupleTestSink (org.apache.apex.malhar.lib.testbench.CountAndLastTupleTestSink)1