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);
}
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);
}
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);
}
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));
}
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);
}
Aggregations