use of edu.snu.mist.core.MistEvent 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));
}
use of edu.snu.mist.core.MistEvent 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));
}
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());
}
use of edu.snu.mist.core.MistEvent 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());
}
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());
}
Aggregations