Search in sources :

Example 1 with ApplyStatefulWindowOperator

use of edu.snu.mist.core.operators.window.ApplyStatefulWindowOperator in project mist by snuspl.

the class ApplyStatefulWindowOperatorTest method testApplyStatefulWindowOperator.

/**
 * Test ApplyStatefulWindowOperator.
 * It calculates the maximum value from the collection.
 */
@Test
public void testApplyStatefulWindowOperator() {
    // input stream events
    final WindowImpl<Integer> window1 = new WindowImpl<>(0L, 100L);
    final WindowImpl<Integer> window2 = new WindowImpl<>(100L, 100L);
    window1.putData(new MistDataEvent(10, 10));
    window1.putData(new MistDataEvent(20, 20));
    window1.putData(new MistDataEvent(30, 30));
    window1.putData(new MistDataEvent(15, 90));
    window2.putData(new MistDataEvent(10, 110));
    window2.putData(new MistDataEvent(20, 120));
    final MistDataEvent dataEvent1 = new MistDataEvent(window1, 90L);
    final MistDataEvent dataEvent2 = new MistDataEvent(window2, 190L);
    final MistWatermarkEvent watermarkEvent = new MistWatermarkEvent(201L);
    // the state finding maximum integer value among received inputs
    final ApplyStatefulFunction<Integer, Integer> applyStatefulFunction = new FindMaxIntFunction();
    final ApplyStatefulWindowOperator<Integer, Integer> applyStatefulWindowOperator = new ApplyStatefulWindowOperator<>(applyStatefulFunction);
    final List<MistEvent> result = new LinkedList<>();
    applyStatefulWindowOperator.setOutputEmitter(new OutputBufferEmitter(result));
    // check that the operator processes a window input properly
    applyStatefulWindowOperator.processLeftData(dataEvent1);
    Assert.assertEquals(1, result.size());
    Assert.assertTrue(result.get(0).isData());
    Assert.assertEquals(30, ((MistDataEvent) result.get(0)).getValue());
    Assert.assertEquals(90L, result.get(0).getTimestamp());
    // check that the operator processes another window separately
    applyStatefulWindowOperator.processLeftData(dataEvent2);
    Assert.assertEquals(2, result.size());
    Assert.assertTrue(result.get(1).isData());
    Assert.assertEquals(20, ((MistDataEvent) result.get(1)).getValue());
    Assert.assertEquals(190L, result.get(1).getTimestamp());
    // check that the operator processes watermark event well
    applyStatefulWindowOperator.processLeftWatermark(watermarkEvent);
    Assert.assertEquals(3, result.size());
    Assert.assertEquals(watermarkEvent, result.get(2));
}
Also used : WindowImpl(edu.snu.mist.core.operators.window.WindowImpl) ApplyStatefulWindowOperator(edu.snu.mist.core.operators.window.ApplyStatefulWindowOperator) MistEvent(edu.snu.mist.core.MistEvent) LinkedList(java.util.LinkedList) OutputBufferEmitter(edu.snu.mist.core.utils.OutputBufferEmitter) MistDataEvent(edu.snu.mist.core.MistDataEvent) FindMaxIntFunction(edu.snu.mist.core.utils.FindMaxIntFunction) MistWatermarkEvent(edu.snu.mist.core.MistWatermarkEvent) Test(org.junit.Test)

Aggregations

MistDataEvent (edu.snu.mist.core.MistDataEvent)1 MistEvent (edu.snu.mist.core.MistEvent)1 MistWatermarkEvent (edu.snu.mist.core.MistWatermarkEvent)1 ApplyStatefulWindowOperator (edu.snu.mist.core.operators.window.ApplyStatefulWindowOperator)1 WindowImpl (edu.snu.mist.core.operators.window.WindowImpl)1 FindMaxIntFunction (edu.snu.mist.core.utils.FindMaxIntFunction)1 OutputBufferEmitter (edu.snu.mist.core.utils.OutputBufferEmitter)1 LinkedList (java.util.LinkedList)1 Test (org.junit.Test)1