Search in sources :

Example 1 with CountWindowOperator

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

the class FixedSizeWindowOperatorTest method testHoppingCountWindowOperator.

/**
 * Test CountWindowOperator creating hopping window.
 * It receives some continuous data stream and groups them as a collection.
 */
@Test
public void testHoppingCountWindowOperator() throws InterruptedException {
    final int windowSize = 3;
    final int emissionInterval = 5;
    final CountWindowOperator<Integer> countWindowOperator = new CountWindowOperator<>(windowSize, emissionInterval);
    final List<MistEvent> result = new LinkedList<>();
    countWindowOperator.setOutputEmitter(new OutputBufferEmitter(result));
    // (1)Window1-(3):
    // (6)Window2--(8):
    // d1--d2-w1--d3--d4--d5--d6-w2-d7-w3-d8:
    // expected results:
    // d1, d2, d3, w1 in Window1
    // d6, d7, d8, w3 in Window2
    countWindowOperator.processLeftData(d1);
    countWindowOperator.processLeftData(d2);
    countWindowOperator.processLeftWatermark(w1);
    Assert.assertEquals(0, result.size());
    countWindowOperator.processLeftData(d3);
    Assert.assertEquals(2, result.size());
    final Collection<Integer> expectedResult1 = new LinkedList<>();
    expectedResult1.add(1);
    expectedResult1.add(2);
    expectedResult1.add(3);
    OperatorTestUtils.checkWindowData(result.get(0), expectedResult1, 1L, windowSize, d3.getTimestamp());
    Assert.assertEquals(w1, result.get(1));
    countWindowOperator.processLeftData(d4);
    countWindowOperator.processLeftData(d5);
    countWindowOperator.processLeftData(d6);
    countWindowOperator.processLeftWatermark(w2);
    countWindowOperator.processLeftData(d7);
    countWindowOperator.processLeftWatermark(w3);
    Assert.assertEquals(2, result.size());
    countWindowOperator.processLeftData(d8);
    Assert.assertEquals(4, result.size());
    final Collection<Integer> expectedResult2 = new LinkedList<>();
    expectedResult2.add(6);
    expectedResult2.add(7);
    expectedResult2.add(8);
    OperatorTestUtils.checkWindowData(result.get(2), expectedResult2, emissionInterval + 1L, windowSize, d8.getTimestamp());
    Assert.assertEquals(w3, result.get(3));
}
Also used : OutputBufferEmitter(edu.snu.mist.core.utils.OutputBufferEmitter) CountWindowOperator(edu.snu.mist.core.operators.window.CountWindowOperator) MistEvent(edu.snu.mist.core.MistEvent) Test(org.junit.Test)

Example 2 with CountWindowOperator

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

the class FixedSizeWindowOperatorTest method testCountWindowOperatorGetState.

/**
 * Test getting state of the CountWindowOperator.
 */
@Test
public void testCountWindowOperatorGetState() throws InterruptedException {
    final int windowSize = 5;
    final int emissionInterval = 3;
    // Generate the current CountWindowOperator.
    final CountWindowOperator<Integer> countWindowOperator = new CountWindowOperator<>(windowSize, emissionInterval);
    countWindowOperator.processLeftData(d1);
    countWindowOperator.processLeftData(d2);
    // Generate the expected CountWindowOperator's state.
    final Window expectedWindow1 = new WindowImpl<>(1L, emissionInterval, new LinkedList<Integer>());
    expectedWindow1.putData(d1);
    expectedWindow1.putData(d2);
    final Window expectedWindow2 = new WindowImpl<>(2L, windowSize, new LinkedList<Integer>());
    expectedWindow2.putData(d2);
    final Queue<Window<Integer>> expectedWindowQueue = new LinkedList<>();
    expectedWindowQueue.add(expectedWindow1);
    expectedWindowQueue.add(expectedWindow2);
    final long expectedWindowCreationPoint = 2L + emissionInterval;
    final long expectedCount = 3L;
    // Get the current CountWindowOperator's state.
    final Map<String, Object> operatorState = countWindowOperator.getStateSnapshot();
    final Queue<Window<Integer>> windowQueue = (LinkedList<Window<Integer>>) operatorState.get("windowQueue");
    final long windowCreationPoint = (long) operatorState.get("windowCreationPoint");
    final long count = (long) operatorState.get("count");
    // Compare the expected and original operator's state.
    Assert.assertEquals(expectedWindowQueue, windowQueue);
    Assert.assertEquals(expectedWindowCreationPoint, windowCreationPoint);
    Assert.assertEquals(expectedCount, count);
}
Also used : Window(edu.snu.mist.core.operators.window.Window) WindowImpl(edu.snu.mist.core.operators.window.WindowImpl) CountWindowOperator(edu.snu.mist.core.operators.window.CountWindowOperator) Test(org.junit.Test)

Example 3 with CountWindowOperator

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

the class FixedSizeWindowOperatorTest method testSlidingCountWindowOperator.

/**
 * Test CountWindowOperator creating sliding window.
 * It receives some continuous data stream and groups them as a collection.
 */
@Test
public void testSlidingCountWindowOperator() throws InterruptedException {
    final int windowSize = 5;
    final int emissionInterval = 3;
    final CountWindowOperator<Integer> countWindowOperator = new CountWindowOperator<>(windowSize, emissionInterval);
    final List<MistEvent> result = new LinkedList<>();
    countWindowOperator.setOutputEmitter(new OutputBufferEmitter(result));
    // (1)Window1(3):
    // (2)Window2--------(6):
    // (5)Window3-------(9):
    // (8)Window4--------------: (will not be emitted)
    // d1----d2--d3--d4-w1-d5--d6--d7-w2-d8-d9:
    // expected results:
    // d1, d2, d3 in Window1
    // d2, d3, d4, d5, d6, w1 in Window2
    // d5, d6, d7, d8, d9, w2 in Window3
    countWindowOperator.processLeftData(d1);
    countWindowOperator.processLeftData(d2);
    Assert.assertEquals(0, result.size());
    countWindowOperator.processLeftData(d3);
    Assert.assertEquals(1, result.size());
    final Collection<Integer> expectedResult1 = new LinkedList<>();
    expectedResult1.add(1);
    expectedResult1.add(2);
    expectedResult1.add(3);
    OperatorTestUtils.checkWindowData(result.get(0), expectedResult1, 1L, emissionInterval, d3.getTimestamp());
    countWindowOperator.processLeftData(d4);
    countWindowOperator.processLeftWatermark(w1);
    countWindowOperator.processLeftData(d5);
    Assert.assertEquals(1, result.size());
    countWindowOperator.processLeftData(d6);
    Assert.assertEquals(3, result.size());
    final Collection<Integer> expectedResult2 = new LinkedList<>();
    expectedResult2.add(2);
    expectedResult2.add(3);
    expectedResult2.add(4);
    expectedResult2.add(5);
    expectedResult2.add(6);
    OperatorTestUtils.checkWindowData(result.get(1), expectedResult2, 2L, windowSize, d6.getTimestamp());
    Assert.assertEquals(w1, result.get(2));
    countWindowOperator.processLeftData(d7);
    countWindowOperator.processLeftWatermark(w2);
    countWindowOperator.processLeftData(d8);
    Assert.assertEquals(3, result.size());
    countWindowOperator.processLeftData(d9);
    Assert.assertEquals(5, result.size());
    final Collection<Integer> expectedResult3 = new LinkedList<>();
    expectedResult3.add(5);
    expectedResult3.add(6);
    expectedResult3.add(7);
    expectedResult3.add(8);
    expectedResult3.add(9);
    OperatorTestUtils.checkWindowData(result.get(3), expectedResult3, 5L, windowSize, d9.getTimestamp());
    Assert.assertEquals(w2, result.get(4));
}
Also used : OutputBufferEmitter(edu.snu.mist.core.utils.OutputBufferEmitter) CountWindowOperator(edu.snu.mist.core.operators.window.CountWindowOperator) MistEvent(edu.snu.mist.core.MistEvent) Test(org.junit.Test)

Example 4 with CountWindowOperator

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

the class FixedSizeWindowOperatorTest method testCountWindowOperatorSetState.

/**
 * Test setting state of the CountWindowOperator.
 */
@Test
public void testCountWindowOperatorSetState() throws InterruptedException {
    final int windowSize = 5;
    final int emissionInterval = 3;
    // Generate a new state and set it to a new CountWindowOperator.
    final Window expectedWindow1 = new WindowImpl<>(1L, emissionInterval, new LinkedList<Integer>());
    expectedWindow1.putData(d1);
    expectedWindow1.putData(d2);
    final Window expectedWindow2 = new WindowImpl<>(2L, windowSize, new LinkedList<Integer>());
    expectedWindow2.putData(d2);
    final Queue<Window<Integer>> expectedWindowQueue = new LinkedList<>();
    expectedWindowQueue.add(expectedWindow1);
    expectedWindowQueue.add(expectedWindow2);
    final long expectedWindowCreationPoint = 2L + emissionInterval;
    final long expectedCount = 3L;
    final Map<String, Object> loadStateMap = new HashMap<>();
    loadStateMap.put("windowQueue", expectedWindowQueue);
    loadStateMap.put("windowCreationPoint", expectedWindowCreationPoint);
    loadStateMap.put("count", expectedCount);
    final CountWindowOperator<Integer> countWindowOperator = new CountWindowOperator<>(windowSize, emissionInterval);
    countWindowOperator.setState(loadStateMap);
    // Compare the original and the set operator.
    final Map<String, Object> operatorState = countWindowOperator.getStateSnapshot();
    final Queue<Window<Integer>> windowQueue = (Queue<Window<Integer>>) operatorState.get("windowQueue");
    final long windowCreationPoint = (long) operatorState.get("windowCreationPoint");
    final long count = (long) operatorState.get("count");
    Assert.assertEquals(expectedWindowQueue, windowQueue);
    Assert.assertEquals(expectedWindowCreationPoint, windowCreationPoint);
    Assert.assertEquals(expectedCount, count);
    // Test if the operator can properly process data.
    final List<MistEvent> result = new LinkedList<>();
    countWindowOperator.setOutputEmitter(new OutputBufferEmitter(result));
    countWindowOperator.processLeftData(d3);
    Assert.assertEquals(1, result.size());
    final Collection<Integer> expectedResult1 = new LinkedList<>();
    expectedResult1.add(1);
    expectedResult1.add(2);
    expectedResult1.add(3);
    OperatorTestUtils.checkWindowData(result.get(0), expectedResult1, 1L, emissionInterval, d3.getTimestamp());
}
Also used : Window(edu.snu.mist.core.operators.window.Window) WindowImpl(edu.snu.mist.core.operators.window.WindowImpl) CountWindowOperator(edu.snu.mist.core.operators.window.CountWindowOperator) MistEvent(edu.snu.mist.core.MistEvent) OutputBufferEmitter(edu.snu.mist.core.utils.OutputBufferEmitter) Test(org.junit.Test)

Aggregations

CountWindowOperator (edu.snu.mist.core.operators.window.CountWindowOperator)4 Test (org.junit.Test)4 MistEvent (edu.snu.mist.core.MistEvent)3 OutputBufferEmitter (edu.snu.mist.core.utils.OutputBufferEmitter)3 Window (edu.snu.mist.core.operators.window.Window)2 WindowImpl (edu.snu.mist.core.operators.window.WindowImpl)2