use of edu.snu.mist.core.operators.window.AggregateWindowOperator in project mist by snuspl.
the class AggregateWindowOperatorTest method testAggregateWindowOperator.
/**
* Test AggregateWindowOperator.
* It calculates the maximum value from the collection.
*/
@Test
public void testAggregateWindowOperator() {
// input stream events
final WindowImpl<Integer> window = new WindowImpl<>(0L, 100L);
window.putData(new MistDataEvent(10, 10));
window.putData(new MistDataEvent(20, 20));
window.putData(new MistDataEvent(15, 30));
window.putData(new MistDataEvent(30, 90));
final MistDataEvent dataEvent = new MistDataEvent(window, 90L);
final MistWatermarkEvent watermarkEvent = new MistWatermarkEvent(101L);
// functions that dealing with input WindowData
final MISTFunction<WindowData<Integer>, String> aggregateFunc = (windowData) -> {
return windowData.getDataCollection().toString() + ", " + windowData.getStart() + ", " + windowData.getEnd();
};
final AggregateWindowOperator<Integer, String> aggregateWindowOperator = new AggregateWindowOperator<>(aggregateFunc);
final List<MistEvent> result = new LinkedList<>();
aggregateWindowOperator.setOutputEmitter(new OutputBufferEmitter(result));
aggregateWindowOperator.processLeftData(dataEvent);
Assert.assertEquals(1, result.size());
Assert.assertTrue(result.get(0).isData());
Assert.assertEquals("[10, 20, 15, 30], 0, 99", ((MistDataEvent) result.get(0)).getValue());
Assert.assertEquals(90L, result.get(0).getTimestamp());
aggregateWindowOperator.processLeftWatermark(watermarkEvent);
Assert.assertEquals(2, result.size());
Assert.assertEquals(watermarkEvent, result.get(1));
}
Aggregations