Search in sources :

Example 11 with MistWatermarkEvent

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

the class ConditionalBranchOperatorTest method testConditionalBranchOperator.

/**
 * Test conditional branch operation.
 * It classifies the input string according to it's length.
 */
@Test
public void testConditionalBranchOperator() throws InjectionException {
    // input stream events
    final MistDataEvent d1 = new MistDataEvent("1", 1L);
    final MistDataEvent d2 = new MistDataEvent("22", 2L);
    final MistDataEvent d3 = new MistDataEvent("333", 3L);
    final MistDataEvent d4 = new MistDataEvent("4444", 4L);
    final MistDataEvent d5 = new MistDataEvent("55555", 5L);
    final MistWatermarkEvent w1 = new MistWatermarkEvent(6L);
    // classify the string according to it's length
    final List<MISTPredicate<String>> predicates = new ArrayList<>();
    // "1" will be passed with index 1
    predicates.add((input) -> input.length() < 2);
    // "22" will be passed with index 2
    predicates.add((input) -> input.length() < 3);
    // "333", "4444" will be passed with index 3
    predicates.add((input) -> input.length() < 5);
    // "55555" will not be passed
    final List<Tuple<MistEvent, Integer>> result = new LinkedList<>();
    final ConditionalBranchOperator<String> conditionalBranchOperator = new ConditionalBranchOperator<>(predicates);
    conditionalBranchOperator.setOutputEmitter(new IndexOutputEmitter(result));
    conditionalBranchOperator.processLeftData(d1);
    conditionalBranchOperator.processLeftData(d2);
    conditionalBranchOperator.processLeftData(d3);
    conditionalBranchOperator.processLeftData(d4);
    conditionalBranchOperator.processLeftData(d5);
    conditionalBranchOperator.processLeftWatermark(w1);
    Assert.assertEquals(5, result.size());
    Assert.assertEquals(new Tuple<>(d1, 1), result.get(0));
    Assert.assertEquals(new Tuple<>(d2, 2), result.get(1));
    Assert.assertEquals(new Tuple<>(d3, 3), result.get(2));
    Assert.assertEquals(new Tuple<>(d4, 3), result.get(3));
    Assert.assertEquals(new Tuple<>(w1, 0), result.get(4));
}
Also used : ArrayList(java.util.ArrayList) IndexOutputEmitter(edu.snu.mist.core.utils.IndexOutputEmitter) LinkedList(java.util.LinkedList) MISTPredicate(edu.snu.mist.common.functions.MISTPredicate) MistDataEvent(edu.snu.mist.core.MistDataEvent) MistWatermarkEvent(edu.snu.mist.core.MistWatermarkEvent) Tuple(org.apache.reef.io.Tuple) Test(org.junit.Test)

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