Search in sources :

Example 6 with MistDataEvent

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

the class CepOperatorTest method testCepOperatorNDRContiguity.

/**
 * Test for cep operator with non-deterministic contiguity.
 * Pattern: A(2 or more, ndr contiguity)
 * Input: A1, A2, A3
 * Result: A1-A2, A1-A2-A3, A1-A3, A2-A3
 */
@Test
public void testCepOperatorNDRContiguity() {
    final CepEventPattern<CepExampleClass> event1 = new CepEventPattern.Builder<CepExampleClass>().setName("first").setCondition(conditionA).setClass(exampleClassType).setContiguity(ndrContiguity).setNOrMore(2).setInnerContiguity(ndrContiguity).build();
    final long exampleWindowTime = 1000L;
    final List<CepEventPattern<CepExampleClass>> exampleEventSequence = new ArrayList<>();
    exampleEventSequence.add(event1);
    final CepExampleClass value1 = new CepExampleClass("A", 1);
    final CepExampleClass value2 = new CepExampleClass("A", 2);
    final CepExampleClass value3 = new CepExampleClass("A", 3);
    final MistDataEvent data1 = new MistDataEvent(value1, 1L);
    final MistDataEvent data2 = new MistDataEvent(value2, 2L);
    final MistDataEvent data3 = new MistDataEvent(value3, 3L);
    final CepOperator cepOperator = new CepOperator(exampleEventSequence, exampleWindowTime);
    final List<MistEvent> result = new LinkedList<>();
    cepOperator.setOutputEmitter(new OutputBufferEmitter(result));
    cepOperator.processLeftData(data1);
    cepOperator.processLeftData(data2);
    cepOperator.processLeftData(data3);
    // 4
    Assert.assertEquals(4, result.size());
    // A1-A2
    final CepExampleClass a01 = getCepExampleClass(result, 0, "first", 0);
    final CepExampleClass a02 = getCepExampleClass(result, 0, "first", 1);
    Assert.assertEquals("A", a01.getName());
    Assert.assertEquals(1, a01.getAge());
    Assert.assertEquals("A", a02.getName());
    Assert.assertEquals(2, a02.getAge());
    // A1-A2-A3
    final CepExampleClass a11 = getCepExampleClass(result, 1, "first", 0);
    final CepExampleClass a12 = getCepExampleClass(result, 1, "first", 1);
    final CepExampleClass a13 = getCepExampleClass(result, 1, "first", 2);
    Assert.assertEquals("A", a11.getName());
    Assert.assertEquals(1, a11.getAge());
    Assert.assertEquals("A", a12.getName());
    Assert.assertEquals(2, a12.getAge());
    Assert.assertEquals("A", a13.getName());
    Assert.assertEquals(3, a13.getAge());
    // A1-A3
    final CepExampleClass a22 = getCepExampleClass(result, 2, "first", 0);
    final CepExampleClass a23 = getCepExampleClass(result, 2, "first", 1);
    Assert.assertEquals("A", a22.getName());
    Assert.assertEquals(1, a22.getAge());
    Assert.assertEquals("A", a23.getName());
    Assert.assertEquals(3, a23.getAge());
    // A2-A3
    final CepExampleClass a31 = getCepExampleClass(result, 3, "first", 0);
    final CepExampleClass a33 = getCepExampleClass(result, 3, "first", 1);
    Assert.assertEquals("A", a31.getName());
    Assert.assertEquals(2, a31.getAge());
    Assert.assertEquals("A", a33.getName());
    Assert.assertEquals(3, a33.getAge());
}
Also used : CepEventPattern(edu.snu.mist.common.cep.CepEventPattern) ArrayList(java.util.ArrayList) MistEvent(edu.snu.mist.core.MistEvent) LinkedList(java.util.LinkedList) OutputBufferEmitter(edu.snu.mist.core.utils.OutputBufferEmitter) CepExampleClass(edu.snu.mist.core.utils.CepExampleClass) MistDataEvent(edu.snu.mist.core.MistDataEvent) Test(org.junit.Test)

Example 7 with MistDataEvent

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

the class CepOperatorTest method testCepOperatorStrictContiguity.

/**
 * Test for cep operator with strict contiguity.
 * Pattern: A(2 or more, strict inner contiguity)
 * Input: A1, A2, A3
 * Result: A1-A2, A1-A2-A3, A2-A3
 */
@Test
public void testCepOperatorStrictContiguity() {
    final CepEventPattern<CepExampleClass> event1 = new CepEventPattern.Builder<CepExampleClass>().setName("first").setCondition(conditionA).setClass(exampleClassType).setContiguity(strictContiguity).setNOrMore(2).setInnerContiguity(strictContiguity).build();
    final long exampleWindowTime = 1000L;
    final List<CepEventPattern<CepExampleClass>> exampleEventSequence = new ArrayList<>();
    exampleEventSequence.add(event1);
    final CepExampleClass value1 = new CepExampleClass("A", 1);
    final CepExampleClass value2 = new CepExampleClass("A", 2);
    final CepExampleClass value3 = new CepExampleClass("A", 3);
    final MistDataEvent data1 = new MistDataEvent(value1, 1L);
    final MistDataEvent data2 = new MistDataEvent(value2, 2L);
    final MistDataEvent data3 = new MistDataEvent(value3, 3L);
    final CepOperator cepOperator = new CepOperator(exampleEventSequence, exampleWindowTime);
    final List<MistEvent> result = new LinkedList<>();
    cepOperator.setOutputEmitter(new OutputBufferEmitter(result));
    cepOperator.processLeftData(data1);
    cepOperator.processLeftData(data2);
    cepOperator.processLeftData(data3);
    // number of matched event patterns: 3
    Assert.assertEquals(3, result.size());
    // A1-A2
    final CepExampleClass a01 = getCepExampleClass(result, 0, "first", 0);
    final CepExampleClass a02 = getCepExampleClass(result, 0, "first", 1);
    Assert.assertEquals("A", a01.getName());
    Assert.assertEquals(1, a01.getAge());
    Assert.assertEquals("A", a02.getName());
    Assert.assertEquals(2, a02.getAge());
    // A1-A2-A3
    final CepExampleClass a11 = getCepExampleClass(result, 1, "first", 0);
    final CepExampleClass a12 = getCepExampleClass(result, 1, "first", 1);
    final CepExampleClass a13 = getCepExampleClass(result, 1, "first", 2);
    Assert.assertEquals("A", a11.getName());
    Assert.assertEquals(1, a11.getAge());
    Assert.assertEquals("A", a12.getName());
    Assert.assertEquals(2, a12.getAge());
    Assert.assertEquals("A", a13.getName());
    Assert.assertEquals(3, a13.getAge());
    // A2-A3
    final CepExampleClass a22 = getCepExampleClass(result, 2, "first", 0);
    final CepExampleClass a23 = getCepExampleClass(result, 2, "first", 1);
    Assert.assertEquals("A", a22.getName());
    Assert.assertEquals(2, a22.getAge());
    Assert.assertEquals("A", a23.getName());
    Assert.assertEquals(3, a23.getAge());
}
Also used : CepEventPattern(edu.snu.mist.common.cep.CepEventPattern) ArrayList(java.util.ArrayList) MistEvent(edu.snu.mist.core.MistEvent) LinkedList(java.util.LinkedList) OutputBufferEmitter(edu.snu.mist.core.utils.OutputBufferEmitter) CepExampleClass(edu.snu.mist.core.utils.CepExampleClass) MistDataEvent(edu.snu.mist.core.MistDataEvent) Test(org.junit.Test)

Example 8 with MistDataEvent

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

the class CepOperatorTest method testCepOperatorMixedContiguity.

/**
 * Test for cep operator with both strict & non-deterministic contiguity.
 * Pattern: A --(Strict)-- A --(NDR) -- A
 * Input: A1, A2, A3, A4, A5
 * Result : A1-A2-A3, A1-A2-A4, A2-A3-A4, A1-A2-A5, A2-A3-A5, A3-A4-A5
 */
@Test
public void testCepOperatorMixedContiguity() {
    final CepEventPattern<CepExampleClass> event1 = new CepEventPattern.Builder<CepExampleClass>().setName("first").setCondition(conditionA).setClass(exampleClassType).setContiguity(strictContiguity).build();
    final CepEventPattern<CepExampleClass> event2 = new CepEventPattern.Builder<CepExampleClass>().setName("second").setCondition(conditionA).setClass(exampleClassType).setContiguity(strictContiguity).build();
    final CepEventPattern<CepExampleClass> event3 = new CepEventPattern.Builder<CepExampleClass>().setName("third").setCondition(conditionA).setClass(exampleClassType).setContiguity(ndrContiguity).build();
    final long exampleWindowTime = 1000L;
    final List<CepEventPattern<CepExampleClass>> exampleEventSequence = new ArrayList<>();
    exampleEventSequence.add(event1);
    exampleEventSequence.add(event2);
    exampleEventSequence.add(event3);
    final CepExampleClass value1 = new CepExampleClass("A", 1);
    final CepExampleClass value2 = new CepExampleClass("A", 2);
    final CepExampleClass value3 = new CepExampleClass("A", 3);
    final CepExampleClass value4 = new CepExampleClass("A", 4);
    final CepExampleClass value5 = new CepExampleClass("A", 5);
    final MistDataEvent data1 = new MistDataEvent(value1, 1L);
    final MistDataEvent data2 = new MistDataEvent(value2, 2L);
    final MistDataEvent data3 = new MistDataEvent(value3, 3L);
    final MistDataEvent data4 = new MistDataEvent(value4, 4L);
    final MistDataEvent data5 = new MistDataEvent(value5, 5L);
    final CepOperator cepOperator = new CepOperator(exampleEventSequence, exampleWindowTime);
    final List<MistEvent> result = new LinkedList<>();
    cepOperator.setOutputEmitter(new OutputBufferEmitter(result));
    cepOperator.processLeftData(data1);
    cepOperator.processLeftData(data2);
    cepOperator.processLeftData(data3);
    cepOperator.processLeftData(data4);
    cepOperator.processLeftData(data5);
    // 6
    Assert.assertEquals(6, result.size());
    // A1-A2-A3
    final CepExampleClass a01 = getCepExampleClass(result, 0, "first", 0);
    final CepExampleClass a02 = getCepExampleClass(result, 0, "second", 0);
    final CepExampleClass a03 = getCepExampleClass(result, 0, "third", 0);
    Assert.assertEquals("A", a01.getName());
    Assert.assertEquals(1, a01.getAge());
    Assert.assertEquals("A", a02.getName());
    Assert.assertEquals(2, a02.getAge());
    Assert.assertEquals("A", a03.getName());
    Assert.assertEquals(3, a03.getAge());
    // A1-A2-A4
    final CepExampleClass a11 = getCepExampleClass(result, 1, "first", 0);
    final CepExampleClass a12 = getCepExampleClass(result, 1, "second", 0);
    final CepExampleClass a14 = getCepExampleClass(result, 1, "third", 0);
    Assert.assertEquals("A", a11.getName());
    Assert.assertEquals(1, a11.getAge());
    Assert.assertEquals("A", a12.getName());
    Assert.assertEquals(2, a12.getAge());
    Assert.assertEquals("A", a14.getName());
    Assert.assertEquals(4, a14.getAge());
    // A2-A3-A4
    final CepExampleClass a22 = getCepExampleClass(result, 2, "first", 0);
    final CepExampleClass a23 = getCepExampleClass(result, 2, "second", 0);
    final CepExampleClass a24 = getCepExampleClass(result, 2, "third", 0);
    Assert.assertEquals("A", a22.getName());
    Assert.assertEquals(2, a22.getAge());
    Assert.assertEquals("A", a23.getName());
    Assert.assertEquals(3, a23.getAge());
    Assert.assertEquals("A", a24.getName());
    Assert.assertEquals(4, a24.getAge());
    // A1-A2-A5
    final CepExampleClass a31 = getCepExampleClass(result, 3, "first", 0);
    final CepExampleClass a32 = getCepExampleClass(result, 3, "second", 0);
    final CepExampleClass a35 = getCepExampleClass(result, 3, "third", 0);
    Assert.assertEquals("A", a31.getName());
    Assert.assertEquals(1, a31.getAge());
    Assert.assertEquals("A", a32.getName());
    Assert.assertEquals(2, a32.getAge());
    Assert.assertEquals("A", a35.getName());
    Assert.assertEquals(5, a35.getAge());
    // A2-A3-A5
    final CepExampleClass a42 = getCepExampleClass(result, 4, "first", 0);
    final CepExampleClass a43 = getCepExampleClass(result, 4, "second", 0);
    final CepExampleClass a45 = getCepExampleClass(result, 4, "third", 0);
    Assert.assertEquals("A", a42.getName());
    Assert.assertEquals(2, a42.getAge());
    Assert.assertEquals("A", a43.getName());
    Assert.assertEquals(3, a43.getAge());
    Assert.assertEquals("A", a45.getName());
    Assert.assertEquals(5, a45.getAge());
    // A3-A4-A5
    final CepExampleClass a53 = getCepExampleClass(result, 5, "first", 0);
    final CepExampleClass a54 = getCepExampleClass(result, 5, "second", 0);
    final CepExampleClass a55 = getCepExampleClass(result, 5, "third", 0);
    Assert.assertEquals("A", a53.getName());
    Assert.assertEquals(3, a53.getAge());
    Assert.assertEquals("A", a54.getName());
    Assert.assertEquals(4, a54.getAge());
    Assert.assertEquals("A", a55.getName());
    Assert.assertEquals(5, a55.getAge());
}
Also used : CepEventPattern(edu.snu.mist.common.cep.CepEventPattern) ArrayList(java.util.ArrayList) MistEvent(edu.snu.mist.core.MistEvent) LinkedList(java.util.LinkedList) OutputBufferEmitter(edu.snu.mist.core.utils.OutputBufferEmitter) CepExampleClass(edu.snu.mist.core.utils.CepExampleClass) MistDataEvent(edu.snu.mist.core.MistDataEvent) Test(org.junit.Test)

Example 9 with MistDataEvent

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

the class CepOperatorTest method testCepOperatorWindowTime.

/**
 * Test for cep operator with window time.
 * Window time: 10L
 * Pattern: A --(Strict)-- A
 * Input: A1(1L), A2(9L), A3(20L), A4(23L)
 * Result: A1-A2, A3-A4
 */
@Test
public void testCepOperatorWindowTime() {
    final CepEventPattern<CepExampleClass> event1 = new CepEventPattern.Builder<CepExampleClass>().setName("first").setCondition(conditionA).setClass(exampleClassType).setContiguity(strictContiguity).build();
    final CepEventPattern<CepExampleClass> event2 = new CepEventPattern.Builder<CepExampleClass>().setName("second").setCondition(conditionA).setClass(exampleClassType).setContiguity(strictContiguity).build();
    final long exampleWindowTime = 10L;
    final List<CepEventPattern<CepExampleClass>> exampleEventSequence = new ArrayList<>();
    exampleEventSequence.add(event1);
    exampleEventSequence.add(event2);
    final CepExampleClass value1 = new CepExampleClass("A", 1);
    final CepExampleClass value2 = new CepExampleClass("A", 2);
    final CepExampleClass value3 = new CepExampleClass("A", 3);
    final CepExampleClass value4 = new CepExampleClass("A", 4);
    final MistDataEvent data1 = new MistDataEvent(value1, 1L);
    final MistDataEvent data2 = new MistDataEvent(value2, 9L);
    final MistDataEvent data3 = new MistDataEvent(value3, 20L);
    final MistDataEvent data4 = new MistDataEvent(value4, 23L);
    final CepOperator cepOperator = new CepOperator(exampleEventSequence, exampleWindowTime);
    final List<MistEvent> result = new LinkedList<>();
    cepOperator.setOutputEmitter(new OutputBufferEmitter(result));
    cepOperator.processLeftData(data1);
    cepOperator.processLeftData(data2);
    cepOperator.processLeftData(data3);
    cepOperator.processLeftData(data4);
    // 2
    Assert.assertEquals(2, result.size());
    // A1-A2
    final CepExampleClass a01 = getCepExampleClass(result, 0, "first", 0);
    final CepExampleClass a02 = getCepExampleClass(result, 0, "second", 0);
    Assert.assertEquals("A", a01.getName());
    Assert.assertEquals(1, a01.getAge());
    Assert.assertEquals("A", a02.getName());
    Assert.assertEquals(2, a02.getAge());
    // A3-A4
    final CepExampleClass a13 = getCepExampleClass(result, 1, "first", 0);
    final CepExampleClass a14 = getCepExampleClass(result, 1, "second", 0);
    Assert.assertEquals("A", a13.getName());
    Assert.assertEquals(3, a13.getAge());
    Assert.assertEquals("A", a14.getName());
    Assert.assertEquals(4, a14.getAge());
}
Also used : CepEventPattern(edu.snu.mist.common.cep.CepEventPattern) ArrayList(java.util.ArrayList) MistEvent(edu.snu.mist.core.MistEvent) LinkedList(java.util.LinkedList) OutputBufferEmitter(edu.snu.mist.core.utils.OutputBufferEmitter) CepExampleClass(edu.snu.mist.core.utils.CepExampleClass) MistDataEvent(edu.snu.mist.core.MistDataEvent) Test(org.junit.Test)

Example 10 with MistDataEvent

use of edu.snu.mist.core.MistDataEvent 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)

Aggregations

MistDataEvent (edu.snu.mist.core.MistDataEvent)30 Test (org.junit.Test)21 MistEvent (edu.snu.mist.core.MistEvent)20 OutputBufferEmitter (edu.snu.mist.core.utils.OutputBufferEmitter)20 LinkedList (java.util.LinkedList)18 MistWatermarkEvent (edu.snu.mist.core.MistWatermarkEvent)9 List (java.util.List)9 Assert (org.junit.Assert)8 MISTPredicate (edu.snu.mist.common.functions.MISTPredicate)7 Tuple2 (edu.snu.mist.common.types.Tuple2)7 ImmutableList (com.google.common.collect.ImmutableList)6 Logger (java.util.logging.Logger)6 InjectionException (org.apache.reef.tang.exceptions.InjectionException)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 CepEventPattern (edu.snu.mist.common.cep.CepEventPattern)4 MISTFunction (edu.snu.mist.common.functions.MISTFunction)4 CepExampleClass (edu.snu.mist.core.utils.CepExampleClass)4 FindMaxIntFunction (edu.snu.mist.core.utils.FindMaxIntFunction)4 HashMap (java.util.HashMap)4