Search in sources :

Example 6 with Window

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

the class SessionWindowOperatorTest method testSessionWindowOperatorGetState.

/**
 * Test getting state of the SessionWindowOperator.
 */
@Test
public void testSessionWindowOperatorGetState() throws InterruptedException {
    final int sessionInterval = 500;
    // Generate the current SessionWindowOperator.
    final SessionWindowOperator<Integer> sessionWindowOperator = new SessionWindowOperator<>(sessionInterval);
    sessionWindowOperator.processLeftData(d6);
    sessionWindowOperator.processLeftWatermark(w3);
    // Generate the expected SessionWindowOperator's state.
    final Window expectedCurrentWindow = new WindowImpl<>(d6.getTimestamp(), Long.MAX_VALUE, new LinkedList<>());
    expectedCurrentWindow.putData(d6);
    expectedCurrentWindow.putWatermark(w3);
    expectedCurrentWindow.setEnd(w3.getTimestamp());
    final long expectedLatestDataTimestamp = d6.getTimestamp();
    final boolean expectedStartedNewWindow = true;
    // Get the current SessionWindowOperator's state.
    final Map<String, Object> operatorState = sessionWindowOperator.getStateSnapshot();
    final Window<Integer> currentWindow = (Window<Integer>) operatorState.get("currentWindow");
    final long latestDataTimestamp = (long) operatorState.get("latestDataTimestamp");
    final boolean startedNewWindow = (boolean) operatorState.get("startedNewWindow");
    // Compare the expected and original operator's state.
    Assert.assertEquals(expectedCurrentWindow, currentWindow);
    Assert.assertEquals(expectedLatestDataTimestamp, latestDataTimestamp);
    Assert.assertEquals(expectedStartedNewWindow, startedNewWindow);
}
Also used : SessionWindowOperator(edu.snu.mist.core.operators.window.SessionWindowOperator) Window(edu.snu.mist.core.operators.window.Window) WindowImpl(edu.snu.mist.core.operators.window.WindowImpl) Test(org.junit.Test)

Example 7 with Window

use of edu.snu.mist.core.operators.window.Window 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

Window (edu.snu.mist.core.operators.window.Window)7 WindowImpl (edu.snu.mist.core.operators.window.WindowImpl)7 Test (org.junit.Test)7 MistEvent (edu.snu.mist.core.MistEvent)3 OutputBufferEmitter (edu.snu.mist.core.utils.OutputBufferEmitter)3 CountWindowOperator (edu.snu.mist.core.operators.window.CountWindowOperator)2 SessionWindowOperator (edu.snu.mist.core.operators.window.SessionWindowOperator)2 TimeWindowOperator (edu.snu.mist.core.operators.window.TimeWindowOperator)2 MistWatermarkEvent (edu.snu.mist.core.MistWatermarkEvent)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Queue (java.util.Queue)1