Search in sources :

Example 6 with MistEvent

use of edu.snu.mist.core.MistEvent 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 7 with MistEvent

use of edu.snu.mist.core.MistEvent 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 8 with MistEvent

use of edu.snu.mist.core.MistEvent 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 9 with MistEvent

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

the class FixedSizeWindowOperatorTest method testHoppingTimeWindowOperator.

/**
 * Test TimeWindowOperator creating hopping window.
 * It receives some continuous data stream and groups them as a collection.
 */
@Test
public void testHoppingTimeWindowOperator() throws InterruptedException {
    final int windowSize = 500;
    final int emissionInterval = 750;
    final TimeWindowOperator<Integer> timeWindowOperator = new TimeWindowOperator<>(windowSize, emissionInterval);
    final List<MistEvent> result = new LinkedList<>();
    timeWindowOperator.setOutputEmitter(new OutputBufferEmitter(result));
    // (1000)Window1------------------(1499):
    // (1750)Window2------------------(2249):
    // d1-----------------------d2---------------d3-w1------------d4-w2-----------------w3------w4:
    // expected results:
    // d1, d2 in Window1
    // d4, w3 in Window2
    timeWindowOperator.processLeftData(d1);
    timeWindowOperator.processLeftData(d2);
    Assert.assertEquals(0, result.size());
    timeWindowOperator.processLeftData(d3);
    timeWindowOperator.processLeftWatermark(w1);
    Assert.assertEquals(1, result.size());
    final Collection<Integer> expectedResult1 = new LinkedList<>();
    expectedResult1.add(1);
    expectedResult1.add(2);
    OperatorTestUtils.checkWindowData(result.get(0), expectedResult1, d1.getTimestamp(), windowSize, d2.getTimestamp());
    timeWindowOperator.processLeftData(d4);
    timeWindowOperator.processLeftWatermark(w2);
    timeWindowOperator.processLeftWatermark(w3);
    Assert.assertEquals(1, result.size());
    timeWindowOperator.processLeftWatermark(w4);
    Assert.assertEquals(3, result.size());
    final Collection<Integer> expectedResult2 = new LinkedList<>();
    expectedResult2.add(4);
    OperatorTestUtils.checkWindowData(result.get(1), expectedResult2, d1.getTimestamp() + emissionInterval, windowSize, w3.getTimestamp());
    Assert.assertEquals(w3, result.get(2));
}
Also used : OutputBufferEmitter(edu.snu.mist.core.utils.OutputBufferEmitter) TimeWindowOperator(edu.snu.mist.core.operators.window.TimeWindowOperator) MistEvent(edu.snu.mist.core.MistEvent) Test(org.junit.Test)

Example 10 with MistEvent

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

the class FixedSizeWindowOperatorTest method testHoppingCountWindowOperator.

/**
 * Test CountWindowOperator creating hopping window.
 * It receives some continuous data stream and groups them as a collection.
 */
@Test
public void testHoppingCountWindowOperator() throws InterruptedException {
    final int windowSize = 3;
    final int emissionInterval = 5;
    final CountWindowOperator<Integer> countWindowOperator = new CountWindowOperator<>(windowSize, emissionInterval);
    final List<MistEvent> result = new LinkedList<>();
    countWindowOperator.setOutputEmitter(new OutputBufferEmitter(result));
    // (1)Window1-(3):
    // (6)Window2--(8):
    // d1--d2-w1--d3--d4--d5--d6-w2-d7-w3-d8:
    // expected results:
    // d1, d2, d3, w1 in Window1
    // d6, d7, d8, w3 in Window2
    countWindowOperator.processLeftData(d1);
    countWindowOperator.processLeftData(d2);
    countWindowOperator.processLeftWatermark(w1);
    Assert.assertEquals(0, result.size());
    countWindowOperator.processLeftData(d3);
    Assert.assertEquals(2, result.size());
    final Collection<Integer> expectedResult1 = new LinkedList<>();
    expectedResult1.add(1);
    expectedResult1.add(2);
    expectedResult1.add(3);
    OperatorTestUtils.checkWindowData(result.get(0), expectedResult1, 1L, windowSize, d3.getTimestamp());
    Assert.assertEquals(w1, result.get(1));
    countWindowOperator.processLeftData(d4);
    countWindowOperator.processLeftData(d5);
    countWindowOperator.processLeftData(d6);
    countWindowOperator.processLeftWatermark(w2);
    countWindowOperator.processLeftData(d7);
    countWindowOperator.processLeftWatermark(w3);
    Assert.assertEquals(2, result.size());
    countWindowOperator.processLeftData(d8);
    Assert.assertEquals(4, result.size());
    final Collection<Integer> expectedResult2 = new LinkedList<>();
    expectedResult2.add(6);
    expectedResult2.add(7);
    expectedResult2.add(8);
    OperatorTestUtils.checkWindowData(result.get(2), expectedResult2, emissionInterval + 1L, windowSize, d8.getTimestamp());
    Assert.assertEquals(w3, result.get(3));
}
Also used : OutputBufferEmitter(edu.snu.mist.core.utils.OutputBufferEmitter) CountWindowOperator(edu.snu.mist.core.operators.window.CountWindowOperator) MistEvent(edu.snu.mist.core.MistEvent) Test(org.junit.Test)

Aggregations

MistEvent (edu.snu.mist.core.MistEvent)30 OutputBufferEmitter (edu.snu.mist.core.utils.OutputBufferEmitter)29 Test (org.junit.Test)28 MistDataEvent (edu.snu.mist.core.MistDataEvent)20 LinkedList (java.util.LinkedList)18 List (java.util.List)8 Assert (org.junit.Assert)8 Tuple2 (edu.snu.mist.common.types.Tuple2)7 ImmutableList (com.google.common.collect.ImmutableList)6 MISTPredicate (edu.snu.mist.common.functions.MISTPredicate)6 MistWatermarkEvent (edu.snu.mist.core.MistWatermarkEvent)6 WindowImpl (edu.snu.mist.core.operators.window.WindowImpl)6 Logger (java.util.logging.Logger)6 InjectionException (org.apache.reef.tang.exceptions.InjectionException)6 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 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4