Search in sources :

Example 16 with KeyValue

use of org.apache.heron.streamlet.KeyValue in project heron by twitter.

the class ReduceByKeyAndWindowOperatorTest method testReduceByWindowOperator.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testReduceByWindowOperator() {
    ReduceByKeyAndWindowOperator<String, String, Integer> reduceOperator = getReduceByWindowOperator();
    TupleWindow tupleWindow = getTupleWindow(3, 5);
    HashMap<String, Integer> expectedResults = new HashMap<>();
    expectedResults.put("0", 5);
    expectedResults.put("1", 5);
    expectedResults.put("2", 5);
    reduceOperator.execute(tupleWindow);
    Assert.assertEquals(3, emittedTuples.size());
    for (Object object : emittedTuples) {
        KeyValue<KeyedWindow<String>, Integer> tuple = (KeyValue<KeyedWindow<String>, Integer>) object;
        KeyedWindow<String> window = tuple.getKey();
        String key = window.getKey();
        Assert.assertEquals(5, window.getWindow().getCount());
        Assert.assertEquals(startTime, window.getWindow().getStartTime());
        Assert.assertEquals(endTime, window.getWindow().getEndTime());
        Assert.assertEquals(expectedResults.get(key), tuple.getValue());
    }
}
Also used : KeyValue(org.apache.heron.streamlet.KeyValue) HashMap(java.util.HashMap) KeyedWindow(org.apache.heron.streamlet.KeyedWindow) TupleWindow(org.apache.heron.api.windowing.TupleWindow) Test(org.junit.Test)

Aggregations

KeyValue (org.apache.heron.streamlet.KeyValue)16 TupleWindow (org.apache.heron.api.windowing.TupleWindow)11 KeyedWindow (org.apache.heron.streamlet.KeyedWindow)9 Values (org.apache.heron.api.tuple.Values)8 Test (org.junit.Test)7 Tuple (org.apache.heron.api.tuple.Tuple)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 LinkedList (java.util.LinkedList)4 TopologyAPI (org.apache.heron.api.generated.TopologyAPI)3 Fields (org.apache.heron.api.tuple.Fields)3 TupleWindowImpl (org.apache.heron.api.windowing.TupleWindowImpl)3 Collection (java.util.Collection)2 List (java.util.List)2 Config (org.apache.heron.api.Config)2 IOutputCollector (org.apache.heron.api.bolt.IOutputCollector)2 OutputCollector (org.apache.heron.api.bolt.OutputCollector)2 TopologyContext (org.apache.heron.api.topology.TopologyContext)2 Window (org.apache.heron.streamlet.Window)2 DecimalFormat (java.text.DecimalFormat)1