private void updateNFA(NFAState nfaState) throws IOException { if (nfaState.isStateChanged()) { nfaState.resetStateChanged(); computationStates.update(nfaState); } }
@Test public void testNFAChangedOnTimeoutWithoutPrune() throws Exception { Pattern<Event, ?> pattern = Pattern.<Event>begin("start").where(new IterativeCondition<Event>() { @Override public boolean filter(Event value, Context<Event> ctx) throws Exception { return value.getName().equals("start"); } }).followedBy("end").where(new IterativeCondition<Event>() { private static final long serialVersionUID = 8061969839441121955L; @Override public boolean filter(Event value, Context<Event> ctx) throws Exception { return value.getName().equals("end"); } }).within(Time.milliseconds(10)); NFA<Event> nfa = compile(pattern, true); NFAState nfaState = nfa.createInitialNFAState(); nfaState.resetStateChanged(); nfa.advanceTime(sharedBufferAccessor, nfaState, 6L); nfa.process(sharedBufferAccessor, nfaState, new Event(6, "start", 1.0), 6L, skipStrategy, timerService); nfaState.resetStateChanged(); nfa.advanceTime(sharedBufferAccessor, nfaState, 17L); assertTrue(nfaState.isStateChanged()); } }
@Test public void testNFAChangedOnOneNewComputationState() throws Exception { Pattern<Event, ?> pattern = Pattern.<Event>begin("start").where(new SimpleCondition<Event>() { @Override public boolean filter(Event value) throws Exception { return value.getName().equals("start"); } }).followedBy("a*").where(new SimpleCondition<Event>() { private static final long serialVersionUID = 1858562682635302605L; @Override public boolean filter(Event value) throws Exception { return value.getName().equals("a"); } }).oneOrMore().optional().next("end").where(new IterativeCondition<Event>() { private static final long serialVersionUID = 8061969839441121955L; @Override public boolean filter(Event value, Context<Event> ctx) throws Exception { return value.getName().equals("b"); } }).within(Time.milliseconds(10)); NFA<Event> nfa = compile(pattern, true); NFAState nfaState = nfa.createInitialNFAState(); nfaState.resetStateChanged(); nfa.process(sharedBufferAccessor, nfaState, new Event(6, "start", 1.0), 6L, skipStrategy, timerService); nfaState.resetStateChanged(); nfa.process(sharedBufferAccessor, nfaState, new Event(6, "a", 1.0), 7L, skipStrategy, timerService); assertTrue(nfaState.isStateChanged()); }
nfaState.resetStateChanged(); nfa.process(sharedBufferAccessor, nfaState, new Event(2, "a", 1.0), 2L, skipStrategy, timerService); assertTrue("NFA status should change as the event matches the take condition of the 'start' state", nfaState.isStateChanged()); nfaState.resetStateChanged(); nfa.process(sharedBufferAccessor, nfaState, new Event(3, "f", 1.0), 3L, skipStrategy, timerService); assertTrue("NFA status should change as the event matches the ignore condition and proceed condition of the 'middle:1' state", nfaState.isStateChanged()); nfaState.resetStateChanged(); nfa.process(sharedBufferAccessor, nfaState, new Event(4, "f", 1.0), 4L, skipStrategy, timerService); assertFalse("NFA status should not change as the event only matches the ignore condition of the 'middle:2' state and the target state is still 'middle:2'", nfaState.isStateChanged()); nfaState.resetStateChanged(); nfa.process(sharedBufferAccessor, nfaState, new Event(5, "b", 1.0), 5L, skipStrategy, timerService); assertTrue("NFA status should change as the event matches the take condition of 'middle:2' state", nfaState.isStateChanged()); nfaState.resetStateChanged(); nfa.process(sharedBufferAccessor, nfaState, new Event(6, "d", 1.0), 6L, skipStrategy, timerService); assertTrue("NFA status should change as the event matches the take condition of 'middle2' state", nfaState.isStateChanged()); nfaState.resetStateChanged(); nfa.advanceTime(sharedBufferAccessor, nfaState, 8L); assertFalse("NFA status should not change as the timestamp is within the window", nfaState.isStateChanged()); nfaState.resetStateChanged(); Collection<Tuple2<Map<String, List<Event>>, Long>> timeoutResults = nfa.advanceTime(sharedBufferAccessor, nfaState, 12L); assertTrue("NFA status should change as timeout happens", nfaState.isStateChanged() && !timeoutResults.isEmpty());
private void updateNFA(NFAState nfaState) throws IOException { if (nfaState.isStateChanged()) { nfaState.resetStateChanged(); computationStates.update(nfaState); } }
private void updateNFA(NFAState nfaState) throws IOException { if (nfaState.isStateChanged()) { nfaState.resetStateChanged(); computationStates.update(nfaState); } }