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());
}
}
Aggregations