Search in sources :

Example 1 with SkipPastLastStrategy

use of org.apache.flink.cep.nfa.aftermatch.SkipPastLastStrategy in project flink by apache.

the class AfterMatchSkipITCase method testSharedBufferIsProperlyCleared.

@Test
public void testSharedBufferIsProperlyCleared() throws Exception {
    List<StreamRecord<Event>> inputEvents = new ArrayList<>();
    for (int i = 0; i < 4; i++) {
        inputEvents.add(new StreamRecord<>(new Event(1, "a", 1.0), i));
    }
    SkipPastLastStrategy matchSkipStrategy = AfterMatchSkipStrategy.skipPastLastEvent();
    Pattern<Event, ?> pattern = Pattern.<Event>begin("start", matchSkipStrategy).where(new SimpleCondition<Event>() {

        private static final long serialVersionUID = 5726188262756267490L;

        @Override
        public boolean filter(Event value) throws Exception {
            return true;
        }
    }).times(2);
    SharedBuffer<Event> sharedBuffer = TestSharedBuffer.createTestBuffer(Event.createTypeSerializer());
    NFATestHarness nfaTestHarness = NFATestHarness.forPattern(pattern).withSharedBuffer(sharedBuffer).build();
    nfaTestHarness.feedRecords(inputEvents);
    assertThat(sharedBuffer.isEmpty(), Matchers.is(true));
}
Also used : StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) SkipPastLastStrategy(org.apache.flink.cep.nfa.aftermatch.SkipPastLastStrategy) SimpleCondition(org.apache.flink.cep.pattern.conditions.SimpleCondition) ArrayList(java.util.ArrayList) NFATestHarness(org.apache.flink.cep.utils.NFATestHarness) Event(org.apache.flink.cep.Event) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 Event (org.apache.flink.cep.Event)1 SkipPastLastStrategy (org.apache.flink.cep.nfa.aftermatch.SkipPastLastStrategy)1 SimpleCondition (org.apache.flink.cep.pattern.conditions.SimpleCondition)1 NFATestHarness (org.apache.flink.cep.utils.NFATestHarness)1 StreamRecord (org.apache.flink.streaming.runtime.streamrecord.StreamRecord)1 Test (org.junit.Test)1