Search in sources :

Example 1 with Window

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

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

the class FixedSizeWindowOperatorTest method testTimeWindowOperatorSetState.

/**
 * Test setting state of the TimeWindowOperator.
 */
@Test
public void testTimeWindowOperatorSetState() throws InterruptedException {
    final int windowSize = 500;
    final int emissionInterval = 250;
    // Generate a new state and set it to a new TimeWindowOperator.
    final Window expectedWindow1 = new WindowImpl<>(d4.getTimestamp(), emissionInterval, new LinkedList<Integer>());
    expectedWindow1.putData(d4);
    expectedWindow1.putWatermark(w2);
    final Window expectedWindow2 = new WindowImpl<>(d4.getTimestamp(), windowSize, new LinkedList<Integer>());
    expectedWindow2.putData(d4);
    expectedWindow2.putWatermark(w2);
    final Queue<Window<Integer>> expectedWindowQueue = new LinkedList<>();
    expectedWindowQueue.add(expectedWindow1);
    expectedWindowQueue.add(expectedWindow2);
    final long expectedWindowCreationPoint = d4.getTimestamp() + emissionInterval;
    final Map<String, Object> loadStateMap = new HashMap<>();
    loadStateMap.put("windowQueue", expectedWindowQueue);
    loadStateMap.put("windowCreationPoint", expectedWindowCreationPoint);
    final TimeWindowOperator<Integer> timeWindowOperator = new TimeWindowOperator<>(windowSize, emissionInterval);
    timeWindowOperator.setState(loadStateMap);
    // Get the current TimeWindowOperator's state.
    final Map<String, Object> operatorState = timeWindowOperator.getStateSnapshot();
    final Queue<Window<Integer>> windowQueue = (Queue<Window<Integer>>) operatorState.get("windowQueue");
    final long windowCreationPoint = (long) operatorState.get("windowCreationPoint");
    // Compare the original and the set operator.
    Assert.assertEquals(expectedWindowQueue, windowQueue);
    Assert.assertEquals(expectedWindowCreationPoint, windowCreationPoint);
    // Test if the operator can properly process data.
    final List<MistEvent> result = new LinkedList<>();
    timeWindowOperator.setOutputEmitter(new OutputBufferEmitter(result));
    timeWindowOperator.processLeftData(d10);
    Assert.assertEquals(2, result.size());
    final Collection<Integer> expectedResult1 = new LinkedList<>();
    expectedResult1.add(4);
    OperatorTestUtils.checkWindowData(result.get(0), expectedResult1, d4.getTimestamp(), emissionInterval, w2.getTimestamp());
    Assert.assertEquals(result.get(1), w2);
}
Also used : Window(edu.snu.mist.core.operators.window.Window) WindowImpl(edu.snu.mist.core.operators.window.WindowImpl) TimeWindowOperator(edu.snu.mist.core.operators.window.TimeWindowOperator) MistEvent(edu.snu.mist.core.MistEvent) OutputBufferEmitter(edu.snu.mist.core.utils.OutputBufferEmitter) Test(org.junit.Test)

Example 3 with Window

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

the class FixedSizeWindowOperatorTest method testTimeWindowOperatorGetState.

/**
 * Test getting state of the TimeWindowOperator.
 */
@Test
public void testTimeWindowOperatorGetState() throws InterruptedException {
    final int windowSize = 500;
    final int emissionInterval = 250;
    // Generate the current TimeWindowOperator.
    final TimeWindowOperator<Integer> timeWindowOperator = new TimeWindowOperator<>(windowSize, emissionInterval);
    timeWindowOperator.processLeftData(d4);
    timeWindowOperator.processLeftWatermark(w2);
    // Generate the expected TimeWindowOperator's state.
    final Window expectedWindow1 = new WindowImpl<>(d4.getTimestamp(), emissionInterval, new LinkedList<Integer>());
    expectedWindow1.putData(d4);
    expectedWindow1.putWatermark(w2);
    final Window expectedWindow2 = new WindowImpl<>(d4.getTimestamp(), windowSize, new LinkedList<Integer>());
    expectedWindow2.putData(d4);
    expectedWindow2.putWatermark(w2);
    final Queue<Window<Integer>> expectedWindowQueue = new LinkedList<>();
    expectedWindowQueue.add(expectedWindow1);
    expectedWindowQueue.add(expectedWindow2);
    final long expectedWindowCreationPoint = d4.getTimestamp() + emissionInterval;
    // Get the current TimeWindowOperator's state.
    final Map<String, Object> operatorState = timeWindowOperator.getStateSnapshot();
    final Queue<Window<Integer>> windowQueue = (Queue<Window<Integer>>) operatorState.get("windowQueue");
    final long windowCreationPoint = (long) operatorState.get("windowCreationPoint");
    // Compare the expected and original operator's state.
    Assert.assertEquals(expectedWindowQueue, windowQueue);
    Assert.assertEquals(expectedWindowCreationPoint, windowCreationPoint);
}
Also used : Window(edu.snu.mist.core.operators.window.Window) WindowImpl(edu.snu.mist.core.operators.window.WindowImpl) TimeWindowOperator(edu.snu.mist.core.operators.window.TimeWindowOperator) Test(org.junit.Test)

Example 4 with Window

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

the class SessionWindowOperatorTest method testSessionWindowOperatorSetState.

/**
 * Test setting state of the SessionWindowOperator.
 */
@Test
public void testSessionWindowOperatorSetState() throws InterruptedException {
    final int sessionInterval = 500;
    // Generate a new state and set it to a new SessionWindowOperator.
    final Window expectedCurrentWindow = new WindowImpl<>(d5.getTimestamp(), Long.MAX_VALUE, new LinkedList<>());
    expectedCurrentWindow.putData(d5);
    expectedCurrentWindow.putWatermark(w2);
    expectedCurrentWindow.setEnd(w2.getTimestamp());
    final long expectedLatestDataTimestamp = d5.getTimestamp();
    final boolean expectedStartedNewWindow = true;
    final Map<String, Object> loadStateMap = new HashMap<>();
    loadStateMap.put("currentWindow", expectedCurrentWindow);
    loadStateMap.put("latestDataTimestamp", expectedLatestDataTimestamp);
    loadStateMap.put("startedNewWindow", expectedStartedNewWindow);
    final SessionWindowOperator sessionWindowOperator = new SessionWindowOperator(sessionInterval);
    sessionWindowOperator.setState(loadStateMap);
    // Compare the original and the set operator.
    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");
    Assert.assertEquals(expectedCurrentWindow, currentWindow);
    Assert.assertEquals(expectedLatestDataTimestamp, latestDataTimestamp);
    Assert.assertEquals(expectedStartedNewWindow, startedNewWindow);
    // Test if the operator can properly process data.
    final List<MistEvent> result = new LinkedList<>();
    sessionWindowOperator.setOutputEmitter(new OutputBufferEmitter(result));
    sessionWindowOperator.setState(operatorState);
    sessionWindowOperator.processLeftData(d6);
    Assert.assertEquals(2, result.size());
    final Collection<Integer> expectedResult = new LinkedList<>();
    expectedResult.add(5);
    OperatorTestUtils.checkWindowData(result.get(0), expectedResult, d5.getTimestamp(), w2.getTimestamp() - d5.getTimestamp() + 1, w2.getTimestamp());
    Assert.assertEquals(w2, result.get(1));
}
Also used : Window(edu.snu.mist.core.operators.window.Window) SessionWindowOperator(edu.snu.mist.core.operators.window.SessionWindowOperator) WindowImpl(edu.snu.mist.core.operators.window.WindowImpl) MistEvent(edu.snu.mist.core.MistEvent) OutputBufferEmitter(edu.snu.mist.core.utils.OutputBufferEmitter) Test(org.junit.Test)

Example 5 with Window

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

the class StateSerializerTest method testOtherStates.

@Test
public void testOtherStates() {
    // States to be serialized.
    final Map<String, Integer> testMap = new HashMap<>();
    testMap.put("Cheeseburgers", 6);
    testMap.put("Drinks", 3);
    final MistWatermarkEvent testWatermarkEvent = new MistWatermarkEvent(98L);
    final Window<String> testWindow = new WindowImpl<>(100L);
    final Queue<Window<String>> testQueue = new LinkedList<>();
    testQueue.add(testWindow);
    // The map that contains the above states.
    final Map<String, Object> testStateMap = new HashMap<>();
    testStateMap.put("testMap", testMap);
    testStateMap.put("testWatermarkEvent", testWatermarkEvent);
    testStateMap.put("testWindow", testWindow);
    testStateMap.put("testQueue", testQueue);
    // Serialize and deserialize the stateMap.
    final Map<String, Object> serializedStateMap = StateSerializer.serializeStateMap(testStateMap);
    final Map<String, Object> deserializedStateMap = StateSerializer.deserializeStateMap(serializedStateMap);
    final Map<String, Integer> deserializedMap = (Map<String, Integer>) deserializedStateMap.get("testMap");
    final MistWatermarkEvent deserializedWatermarkEvent = (MistWatermarkEvent) deserializedStateMap.get("testWatermarkEvent");
    final Window<String> deserializedWindow = (Window<String>) deserializedStateMap.get("testWindow");
    final Queue<Window<String>> deserializedQueue = (Queue<Window<String>>) deserializedStateMap.get("testQueue");
    // Compare the results.
    Assert.assertEquals(testMap, deserializedMap);
    Assert.assertEquals(testWatermarkEvent, deserializedWatermarkEvent);
    Assert.assertEquals(testWindow, deserializedWindow);
    Assert.assertEquals(testQueue, deserializedQueue);
}
Also used : Window(edu.snu.mist.core.operators.window.Window) WindowImpl(edu.snu.mist.core.operators.window.WindowImpl) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) MistWatermarkEvent(edu.snu.mist.core.MistWatermarkEvent) Map(java.util.Map) HashMap(java.util.HashMap) Queue(java.util.Queue) 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