Search in sources :

Example 1 with MistWatermarkEvent

use of edu.snu.mist.core.MistWatermarkEvent in project mist by snuspl.

the class FixedSizeWindowOperator method emitElapsedWindow.

/**
 * Checks whether the window emission count is elapsed, and emits some windows if so.
 * @param currentEventPoint the point of received event
 */
protected void emitElapsedWindow(final long currentEventPoint) {
    // Checks the window emission time is elapsed
    while (!windowQueue.isEmpty() && ((Window) windowQueue.peek()).getEnd() < currentEventPoint) {
        final Window<T> window = windowQueue.poll();
        outputEmitter.emitData(new MistDataEvent(window, window.getLatestTimestamp()));
        final MistWatermarkEvent latestWatermark = window.getLatestWatermark();
        if (latestWatermark.getTimestamp() != 0L) {
            outputEmitter.emitWatermark(latestWatermark);
        }
    }
}
Also used : MistDataEvent(edu.snu.mist.core.MistDataEvent) MistWatermarkEvent(edu.snu.mist.core.MistWatermarkEvent)

Example 2 with MistWatermarkEvent

use of edu.snu.mist.core.MistWatermarkEvent in project mist by snuspl.

the class ApplyStatefulOperatorTest method testApplyStatefulOperator.

/**
 * Test ApplyStatefulOperator.
 * It calculates the maximum value through some inputs.
 */
@Test
public void testApplyStatefulOperator() {
    // input events
    // expected results: 10--20--20--30--watermark--
    final MistDataEvent data10 = new MistDataEvent(10, 0L);
    final MistDataEvent data20 = new MistDataEvent(20, 1L);
    final MistDataEvent data15 = new MistDataEvent(15, 2L);
    final MistDataEvent data30 = new MistDataEvent(30, 3L);
    final MistWatermarkEvent watermarkEvent = new MistWatermarkEvent(4L);
    // the state managing function finding maximum integer value among received inputs
    final ApplyStatefulFunction applyStatefulFunction = new FindMaxIntFunction();
    final ApplyStatefulOperator<Integer, Integer> applyStatefulOperator = new ApplyStatefulOperator<>(applyStatefulFunction);
    final List<MistEvent> result = new LinkedList<>();
    applyStatefulOperator.setOutputEmitter(new OutputBufferEmitter(result));
    applyStatefulOperator.processLeftData(data10);
    Assert.assertEquals(1, result.size());
    Assert.assertEquals(data10, result.get(0));
    applyStatefulOperator.processLeftData(data20);
    Assert.assertEquals(2, result.size());
    Assert.assertEquals(data20, result.get(1));
    applyStatefulOperator.processLeftData(data15);
    Assert.assertEquals(3, result.size());
    Assert.assertTrue(result.get(2) instanceof MistDataEvent);
    Assert.assertEquals(20, ((MistDataEvent) result.get(2)).getValue());
    Assert.assertEquals(2L, result.get(2).getTimestamp());
    applyStatefulOperator.processLeftData(data30);
    Assert.assertEquals(4, result.size());
    Assert.assertEquals(data30, result.get(3));
    applyStatefulOperator.processLeftWatermark(watermarkEvent);
    Assert.assertEquals(5, result.size());
    Assert.assertEquals(watermarkEvent, result.get(4));
}
Also used : ApplyStatefulFunction(edu.snu.mist.common.functions.ApplyStatefulFunction) OutputBufferEmitter(edu.snu.mist.core.utils.OutputBufferEmitter) MistDataEvent(edu.snu.mist.core.MistDataEvent) FindMaxIntFunction(edu.snu.mist.core.utils.FindMaxIntFunction) MistWatermarkEvent(edu.snu.mist.core.MistWatermarkEvent) MistEvent(edu.snu.mist.core.MistEvent) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 3 with MistWatermarkEvent

use of edu.snu.mist.core.MistWatermarkEvent 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));
}
Also used : WindowImpl(edu.snu.mist.core.operators.window.WindowImpl) ApplyStatefulWindowOperator(edu.snu.mist.core.operators.window.ApplyStatefulWindowOperator) MistEvent(edu.snu.mist.core.MistEvent) LinkedList(java.util.LinkedList) OutputBufferEmitter(edu.snu.mist.core.utils.OutputBufferEmitter) MistDataEvent(edu.snu.mist.core.MistDataEvent) FindMaxIntFunction(edu.snu.mist.core.utils.FindMaxIntFunction) MistWatermarkEvent(edu.snu.mist.core.MistWatermarkEvent) Test(org.junit.Test)

Example 4 with MistWatermarkEvent

use of edu.snu.mist.core.MistWatermarkEvent 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));
}
Also used : Iterator(java.util.Iterator) Tuple2(edu.snu.mist.common.types.Tuple2) Collection(java.util.Collection) MistEvent(edu.snu.mist.core.MistEvent) Test(org.junit.Test) WindowImpl(edu.snu.mist.core.operators.window.WindowImpl) MistDataEvent(edu.snu.mist.core.MistDataEvent) List(java.util.List) MistWatermarkEvent(edu.snu.mist.core.MistWatermarkEvent) MISTBiPredicate(edu.snu.mist.common.functions.MISTBiPredicate) OutputBufferEmitter(edu.snu.mist.core.utils.OutputBufferEmitter) WindowData(edu.snu.mist.common.windows.WindowData) Assert(org.junit.Assert) LinkedList(java.util.LinkedList) WindowImpl(edu.snu.mist.core.operators.window.WindowImpl) MistEvent(edu.snu.mist.core.MistEvent) LinkedList(java.util.LinkedList) OutputBufferEmitter(edu.snu.mist.core.utils.OutputBufferEmitter) WindowData(edu.snu.mist.common.windows.WindowData) MistDataEvent(edu.snu.mist.core.MistDataEvent) Tuple2(edu.snu.mist.common.types.Tuple2) Iterator(java.util.Iterator) MistWatermarkEvent(edu.snu.mist.core.MistWatermarkEvent) Test(org.junit.Test)

Example 5 with MistWatermarkEvent

use of edu.snu.mist.core.MistWatermarkEvent in project mist by snuspl.

the class PeriodicEventGenerator method startRemain.

@Override
protected void startRemain() {
    result = scheduler.scheduleAtFixedRate(new Runnable() {

        public void run() {
            latestWatermarkTimestamp = getCurrentTimestamp() - expectedDelay;
            outputEmitter.emitWatermark(new MistWatermarkEvent(latestWatermarkTimestamp));
        }
    }, period, period, timeUnit);
    super.startRemain();
}
Also used : MistWatermarkEvent(edu.snu.mist.core.MistWatermarkEvent)

Aggregations

MistWatermarkEvent (edu.snu.mist.core.MistWatermarkEvent)11 MistDataEvent (edu.snu.mist.core.MistDataEvent)9 Test (org.junit.Test)8 LinkedList (java.util.LinkedList)7 MistEvent (edu.snu.mist.core.MistEvent)6 OutputBufferEmitter (edu.snu.mist.core.utils.OutputBufferEmitter)6 WindowImpl (edu.snu.mist.core.operators.window.WindowImpl)4 MISTPredicate (edu.snu.mist.common.functions.MISTPredicate)2 Tuple2 (edu.snu.mist.common.types.Tuple2)2 WindowData (edu.snu.mist.common.windows.WindowData)2 FindMaxIntFunction (edu.snu.mist.core.utils.FindMaxIntFunction)2 List (java.util.List)2 Assert (org.junit.Assert)2 ApplyStatefulFunction (edu.snu.mist.common.functions.ApplyStatefulFunction)1 MISTBiPredicate (edu.snu.mist.common.functions.MISTBiPredicate)1 MISTFunction (edu.snu.mist.common.functions.MISTFunction)1 RuleBasedEQPredicate (edu.snu.mist.common.predicates.RuleBasedEQPredicate)1 AggregateWindowOperator (edu.snu.mist.core.operators.window.AggregateWindowOperator)1 ApplyStatefulWindowOperator (edu.snu.mist.core.operators.window.ApplyStatefulWindowOperator)1 Window (edu.snu.mist.core.operators.window.Window)1