Search in sources :

Example 26 with OutputBufferEmitter

use of edu.snu.mist.core.utils.OutputBufferEmitter in project mist by snuspl.

the class StateTransitionOperatorTest method testStateTransitionOperator.

/**
 * Test StateTransitionOperator.
 * Final states are "1" and "4".
 */
@Test
public void testStateTransitionOperator() throws InterruptedException {
    // input events
    // expected state transitions: 0 -- 1 -- 0 -- 3 -- 4, "1" and "4" are emitted.
    final Map<String, Integer> value1 = new HashMap<>();
    value1.put("number", 1);
    final MistDataEvent data1 = new MistDataEvent(value1, 0L);
    final Map<String, Integer> value2 = new HashMap<>();
    value2.put("number", 2);
    final MistDataEvent data2 = new MistDataEvent(value2, 1L);
    final MistWatermarkEvent watermarkEvent = new MistWatermarkEvent(7L);
    final Map<String, Integer> value3 = new HashMap<>();
    value3.put("number", 3);
    final MistDataEvent data3 = new MistDataEvent(value3, 10L);
    final Map<String, Integer> value4 = new HashMap<>();
    value4.put("number", 4);
    final MistDataEvent data4 = new MistDataEvent(value4, 11L);
    // make a set of final states
    final Set<String> finalSet = new HashSet<>();
    finalSet.add("1");
    finalSet.add("4");
    // make a state table
    final Map<String, Collection<Tuple2<MISTPredicate, String>>> stateTable = new HashMap<>();
    final Collection<Tuple2<MISTPredicate, String>> list0 = new ArrayList<>();
    list0.add(new Tuple2<>(new RuleBasedEQPredicate("number", 1), "1"));
    list0.add(new Tuple2<>(new RuleBasedEQPredicate("number", 3), "3"));
    final Collection<Tuple2<MISTPredicate, String>> list1 = new ArrayList<>();
    list1.add(new Tuple2<>(new RuleBasedEQPredicate("number", 2), "0"));
    final Collection<Tuple2<MISTPredicate, String>> list3 = new ArrayList<>();
    list3.add(new Tuple2<>(new RuleBasedEQPredicate("number", 4), "4"));
    stateTable.put("0", list0);
    stateTable.put("1", list1);
    stateTable.put("3", list3);
    // make a state transition operator
    final StateTransitionOperator stateTransitionOperator = new StateTransitionOperator("0", finalSet, stateTable);
    final List<MistEvent> result = new LinkedList<>();
    stateTransitionOperator.setOutputEmitter(new OutputBufferEmitter(result));
    stateTransitionOperator.processLeftData(data1);
    Assert.assertEquals(1, result.size());
    Assert.assertEquals(data1, result.get(0));
    Assert.assertEquals("1", stateTransitionOperator.getStateSnapshot().get("stateTransitionOperatorState"));
    stateTransitionOperator.processLeftData(data2);
    Assert.assertEquals(1, result.size());
    Assert.assertEquals("0", stateTransitionOperator.getStateSnapshot().get("stateTransitionOperatorState"));
    stateTransitionOperator.processLeftWatermark(watermarkEvent);
    Assert.assertEquals(2, result.size());
    Assert.assertEquals(watermarkEvent, result.get(1));
    Assert.assertEquals("0", stateTransitionOperator.getStateSnapshot().get("stateTransitionOperatorState"));
    stateTransitionOperator.processLeftData(data3);
    Assert.assertEquals(2, result.size());
    Assert.assertEquals("3", stateTransitionOperator.getStateSnapshot().get("stateTransitionOperatorState"));
    stateTransitionOperator.processLeftData(data4);
    Assert.assertEquals(3, result.size());
    Assert.assertEquals(data4, result.get(2));
    Assert.assertEquals("4", stateTransitionOperator.getStateSnapshot().get("stateTransitionOperatorState"));
}
Also used : RuleBasedEQPredicate(edu.snu.mist.common.predicates.RuleBasedEQPredicate) MistEvent(edu.snu.mist.core.MistEvent) OutputBufferEmitter(edu.snu.mist.core.utils.OutputBufferEmitter) MISTPredicate(edu.snu.mist.common.functions.MISTPredicate) MistDataEvent(edu.snu.mist.core.MistDataEvent) Tuple2(edu.snu.mist.common.types.Tuple2) MistWatermarkEvent(edu.snu.mist.core.MistWatermarkEvent) Test(org.junit.Test)

Aggregations

MistEvent (edu.snu.mist.core.MistEvent)26 OutputBufferEmitter (edu.snu.mist.core.utils.OutputBufferEmitter)26 Test (org.junit.Test)25 MistDataEvent (edu.snu.mist.core.MistDataEvent)17 LinkedList (java.util.LinkedList)15 Tuple2 (edu.snu.mist.common.types.Tuple2)7 MistWatermarkEvent (edu.snu.mist.core.MistWatermarkEvent)6 WindowImpl (edu.snu.mist.core.operators.window.WindowImpl)6 List (java.util.List)5 Assert (org.junit.Assert)5 CepEventPattern (edu.snu.mist.common.cep.CepEventPattern)4 CepExampleClass (edu.snu.mist.core.utils.CepExampleClass)4 FindMaxIntFunction (edu.snu.mist.core.utils.FindMaxIntFunction)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 ImmutableList (com.google.common.collect.ImmutableList)3 ApplyStatefulFunction (edu.snu.mist.common.functions.ApplyStatefulFunction)3 MISTBiFunction (edu.snu.mist.common.functions.MISTBiFunction)3 MISTPredicate (edu.snu.mist.common.functions.MISTPredicate)3 RuleBasedEQPredicate (edu.snu.mist.common.predicates.RuleBasedEQPredicate)3