@VisibleForTesting boolean hasNonEmptySharedBuffer(KEY key) throws Exception { setCurrentKey(key); return !partialMatches.isEmpty(); }
if (!sortedTimestamps.isEmpty() || !partialMatches.isEmpty()) { saveRegisterWatermarkTimer();
assertTrue(sharedBuffer.isEmpty());
@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)); } }
@Test public void testClearingSharedBufferWithMultipleEdgesBetweenEntries() throws Exception { SharedBuffer<Event> sharedBuffer = TestSharedBuffer.createTestBuffer(Event.createTypeSerializer()); int numberEvents = 8; Event[] events = new Event[numberEvents]; EventId[] eventIds = new EventId[numberEvents]; final long timestamp = 1L; for (int i = 0; i < numberEvents; i++) { events[i] = new Event(i + 1, "e" + (i + 1), i); eventIds[i] = sharedBuffer.registerEvent(events[i], timestamp); } try (SharedBufferAccessor<Event> sharedBufferAccessor = sharedBuffer.getAccessor()) { NodeId start = sharedBufferAccessor.put("start", eventIds[1], null, DeweyNumber.fromString("1")); NodeId b0 = sharedBufferAccessor.put("branching", eventIds[2], start, DeweyNumber.fromString("1.0")); NodeId b1 = sharedBufferAccessor.put("branching", eventIds[3], start, DeweyNumber.fromString("1.1")); NodeId b00 = sharedBufferAccessor.put("branching", eventIds[3], b0, DeweyNumber.fromString("1.0.0")); sharedBufferAccessor.put("branching", eventIds[4], b00, DeweyNumber.fromString("1.0.0.0")); NodeId b10 = sharedBufferAccessor.put("branching", eventIds[4], b1, DeweyNumber.fromString("1.1.0")); //simulate IGNORE (next event can point to events[2]) sharedBufferAccessor.lockNode(b0); sharedBufferAccessor.releaseNode(b10); for (EventId eventId : eventIds) { sharedBufferAccessor.releaseEvent(eventId); } } //There should be still events[1] and events[2] in the buffer assertFalse(sharedBuffer.isEmpty()); }
@VisibleForTesting public boolean hasNonEmptySharedBuffer(KEY key) throws Exception { setCurrentKey(key); return !partialMatches.isEmpty(); }
@VisibleForTesting public boolean hasNonEmptySharedBuffer(KEY key) throws Exception { setCurrentKey(key); return !partialMatches.isEmpty(); }
if (!sortedTimestamps.isEmpty() || !partialMatches.isEmpty()) { saveRegisterWatermarkTimer();
if (!sortedTimestamps.isEmpty() || !partialMatches.isEmpty()) { saveRegisterWatermarkTimer();