use of edu.snu.mist.core.MistEvent 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));
}
use of edu.snu.mist.core.MistEvent in project mist by snuspl.
the class JoinOperatorTest method testAggregateWindowOperator.
/**
* Tests JoinOperator.
* It joins a pair of inputs in two streams that has same key.
*/
@Test
public void testAggregateWindowOperator() {
// input stream events
final WindowImpl<Integer> window = new WindowImpl<>(0L, 100L);
window.putData(new MistDataEvent(new Tuple2<>(new Tuple2<>("Hello", 1), null), 10));
window.putData(new MistDataEvent(new Tuple2<>(new Tuple2<>("MIST", 2), null), 20));
window.putData(new MistDataEvent(new Tuple2<>(null, new Tuple2<>(1, 3000L)), 30));
window.putData(new MistDataEvent(new Tuple2<>(new Tuple2<>("SNUCMS", 3), null), 40));
window.putData(new MistDataEvent(new Tuple2<>(null, new Tuple2<>(1, 4000L)), 50));
window.putData(new MistDataEvent(new Tuple2<>(null, new Tuple2<>(2, 5000L)), 60));
final MistDataEvent dataEvent = new MistDataEvent(window, 60L);
final MistWatermarkEvent watermarkEvent = new MistWatermarkEvent(101L);
// predicate that tests whether two input data have same key or not
final MISTBiPredicate<Tuple2<String, Integer>, Tuple2<Integer, Long>> joinPredicate = (tuple1, tuple2) -> tuple1.get(1).equals(tuple2.get(0));
final JoinOperator<Tuple2<String, Integer>, Tuple2<Integer, Long>> joinOperator = new JoinOperator<>(joinPredicate);
// expected pairs
// {Hello, 1} and {1, 3000L}
// {Hello, 1} and {1, 4000L}
// {MIST, 2} and {2, 5000L}
final List<MistEvent> result = new LinkedList<>();
joinOperator.setOutputEmitter(new OutputBufferEmitter(result));
joinOperator.processLeftData(dataEvent);
Assert.assertEquals(1, result.size());
Assert.assertTrue(result.get(0).isData());
Assert.assertTrue(((MistDataEvent) result.get(0)).getValue() instanceof WindowData);
final WindowData windowData = (WindowData) ((MistDataEvent) result.get(0)).getValue();
Assert.assertEquals(0L, windowData.getStart());
Assert.assertEquals(99L, windowData.getEnd());
final Collection<Tuple2<Tuple2<String, Integer>, Tuple2<Integer, Long>>> dataCollection = windowData.getDataCollection();
final Iterator iterator = dataCollection.iterator();
Assert.assertEquals(3, dataCollection.size());
Assert.assertEquals(new Tuple2<>(new Tuple2<>("Hello", 1), new Tuple2<>(1, 3000L)), iterator.next());
Assert.assertEquals(new Tuple2<>(new Tuple2<>("Hello", 1), new Tuple2<>(1, 4000L)), iterator.next());
Assert.assertEquals(new Tuple2<>(new Tuple2<>("MIST", 2), new Tuple2<>(2, 5000L)), iterator.next());
Assert.assertEquals(60L, result.get(0).getTimestamp());
joinOperator.processLeftWatermark(watermarkEvent);
Assert.assertEquals(2, result.size());
Assert.assertEquals(watermarkEvent, result.get(1));
}
use of edu.snu.mist.core.MistEvent in project mist by snuspl.
the class NonBlockingQueueSourceOutputEmitter method processAllEvent.
@Override
public int processAllEvent() {
int numProcessedEvent = 0;
MistEvent event = queue.poll();
while (event != null) {
numEvents.decrementAndGet();
for (final Map.Entry<ExecutionVertex, MISTEdge> entry : nextOperators.entrySet()) {
process(event, entry.getValue().getDirection(), (PhysicalOperator) entry.getKey());
}
numProcessedEvent += 1;
event = queue.poll();
}
return numProcessedEvent;
}
use of edu.snu.mist.core.MistEvent in project mist by snuspl.
the class SessionWindowOperatorTest method testSessionWindowOperator.
/**
* Test whether SessionWindowOperator creates windows properly.
* It receives some continuous data stream and groups them as a collection.
*/
@Test
public void testSessionWindowOperator() throws InterruptedException {
final int sessionInterval = 500;
final SessionWindowOperator<Integer> sessionWindowOperator = new SessionWindowOperator<>(sessionInterval);
final List<MistEvent> result = new LinkedList<>();
sessionWindowOperator.setOutputEmitter(new OutputBufferEmitter(result));
// (200)Window1-(1200):
// (1750)Window2-----(2000):
// (2700)Window3-(3100):
// (3700)Window5---: (will not be emitted)
// d1-----d2-----w1---------d3--------d4-------d5-------d6----w2------w3-------w4:
// expected results:
// d1, d2, w1 in Window1
// d3, d4, d5 in Window2
// d6, w3 in Window3
sessionWindowOperator.processLeftData(d1);
sessionWindowOperator.processLeftData(d2);
sessionWindowOperator.processLeftWatermark(w1);
Assert.assertEquals(0, result.size());
sessionWindowOperator.processLeftData(d3);
Assert.assertEquals(2, result.size());
final Collection<Integer> expectedResult1 = new LinkedList<>();
expectedResult1.add(1);
expectedResult1.add(2);
OperatorTestUtils.checkWindowData(result.get(0), expectedResult1, d1.getTimestamp(), w1.getTimestamp() - d1.getTimestamp() + 1, w1.getTimestamp());
Assert.assertEquals(w1, result.get(1));
sessionWindowOperator.processLeftData(d4);
sessionWindowOperator.processLeftData(d5);
Assert.assertEquals(2, result.size());
sessionWindowOperator.processLeftData(d6);
Assert.assertEquals(3, result.size());
final Collection<Integer> expectedResult2 = new LinkedList<>();
expectedResult2.add(3);
expectedResult2.add(4);
expectedResult2.add(5);
OperatorTestUtils.checkWindowData(result.get(2), expectedResult2, d3.getTimestamp(), d5.getTimestamp() - d3.getTimestamp() + 1, d5.getTimestamp());
sessionWindowOperator.processLeftWatermark(w2);
sessionWindowOperator.processLeftWatermark(w3);
Assert.assertEquals(3, result.size());
sessionWindowOperator.processLeftWatermark(w4);
Assert.assertEquals(5, result.size());
final Collection<Integer> expectedResult3 = new LinkedList<>();
expectedResult3.add(6);
OperatorTestUtils.checkWindowData(result.get(3), expectedResult3, d6.getTimestamp(), w3.getTimestamp() - d6.getTimestamp() + 1, w3.getTimestamp());
Assert.assertEquals(w3, result.get(4));
}
use of edu.snu.mist.core.MistEvent in project mist by snuspl.
the class StatelessOperatorTest method testStatelessOperator.
private void testStatelessOperator(final List<MistDataEvent> inputStream, final List<MistEvent> expected, final Operator operator) {
final List<MistEvent> result = new LinkedList<>();
operator.setOutputEmitter(new OutputBufferEmitter(result));
inputStream.stream().forEach(operator::processLeftData);
LOG.info("expected: " + expected);
LOG.info("result: " + result);
Assert.assertEquals(expected, result);
}
Aggregations