MartijnVisser commented on code in PR #30022:
URL: https://github.com/apache/flink/pull/30022#discussion_r4720593540
##########
flink-libraries/flink-cep/src/test/java/org/apache/flink/cep/nfa/sharedbuffer/SharedBufferTest.java:
##########
@@ -302,6 +305,51 @@ void testSharedBufferCountersClearing() throws Exception {
assertThat(counters).isExhausted();
}
+ @TestTemplate
+ void testEventIdNotReusedWhileAnEventWithTheSameTimestampIsInUse() throws
Exception {
+ SharedBuffer<Event> sharedBuffer =
+
TestSharedBuffer.createTestBuffer(Event.createTypeSerializer(), cacheConfig);
+
+ EventId first = sharedBuffer.registerEvent(new Event(1, "a", 1.0), 1L);
+ EventId second = sharedBuffer.registerEvent(new Event(2, "b", 2.0),
1L);
+ try (SharedBufferAccessor<Event> sharedBufferAccessor =
sharedBuffer.getAccessor()) {
+ sharedBufferAccessor.releaseEvent(first);
+ }
+ EventId third = sharedBuffer.registerEvent(new Event(3, "c", 3.0), 1L);
+
+ assertThat(third).isNotEqualTo(first).isNotEqualTo(second);
Review Comment:
Agreed, it only needs to differ from `second`. Changed.
##########
flink-libraries/flink-cep/src/test/java/org/apache/flink/cep/nfa/sharedbuffer/SharedBufferTest.java:
##########
@@ -302,6 +305,51 @@ void testSharedBufferCountersClearing() throws Exception {
assertThat(counters).isExhausted();
}
+ @TestTemplate
+ void testEventIdNotReusedWhileAnEventWithTheSameTimestampIsInUse() throws
Exception {
Review Comment:
Added `testEventIdOfAReleasedEventIsReused`.
##########
flink-libraries/flink-cep/src/test/java/org/apache/flink/cep/operator/CepOperatorLateEventsAfterRestoreTest.java:
##########
@@ -0,0 +1,341 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.cep.operator;
+
+import org.apache.flink.api.common.serialization.SerializerConfigImpl;
+import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.cep.functions.PatternProcessFunction;
+import org.apache.flink.cep.nfa.aftermatch.AfterMatchSkipStrategy;
+import org.apache.flink.cep.nfa.compiler.NFACompiler;
+import org.apache.flink.cep.pattern.Pattern;
+import org.apache.flink.cep.pattern.conditions.IterativeCondition;
+import org.apache.flink.runtime.checkpoint.OperatorSubtaskState;
+import org.apache.flink.runtime.state.hashmap.HashMapStateBackend;
+import org.apache.flink.state.rocksdb.EmbeddedRocksDBStateBackend;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+import org.apache.flink.streaming.util.KeyedOneInputStreamOperatorTestHarness;
+import org.apache.flink.util.Collector;
+import org.apache.flink.util.OutputTag;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import java.time.Duration;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Late events after a restore (FLINK-41553). */
+class CepOperatorLateEventsAfterRestoreTest {
+
+ private static final OutputTag<Event> LATE = new OutputTag<Event>("late")
{};
+
+ @ParameterizedTest(name = "rocksdb = {0}")
+ @ValueSource(booleans = {false, true})
+ void testLateEventsAfterRestoreGoToSideOutput(boolean rocksDb) throws
Exception {
Review Comment:
Added `middle#5` at 4000 to this test; it ends up in the match.
##########
flink-libraries/flink-cep/src/test/java/org/apache/flink/cep/nfa/sharedbuffer/SharedBufferTest.java:
##########
@@ -302,6 +305,51 @@ void testSharedBufferCountersClearing() throws Exception {
assertThat(counters).isExhausted();
}
+ @TestTemplate
+ void testEventIdNotReusedWhileAnEventWithTheSameTimestampIsInUse() throws
Exception {
+ SharedBuffer<Event> sharedBuffer =
+
TestSharedBuffer.createTestBuffer(Event.createTypeSerializer(), cacheConfig);
+
+ EventId first = sharedBuffer.registerEvent(new Event(1, "a", 1.0), 1L);
+ EventId second = sharedBuffer.registerEvent(new Event(2, "b", 2.0),
1L);
+ try (SharedBufferAccessor<Event> sharedBufferAccessor =
sharedBuffer.getAccessor()) {
+ sharedBufferAccessor.releaseEvent(first);
+ }
+ EventId third = sharedBuffer.registerEvent(new Event(3, "c", 3.0), 1L);
+
+ assertThat(third).isNotEqualTo(first).isNotEqualTo(second);
+
+ try (SharedBufferAccessor<Event> sharedBufferAccessor =
sharedBuffer.getAccessor()) {
+ sharedBufferAccessor.releaseEvent(second);
+ sharedBufferAccessor.releaseEvent(third);
+ }
+ assertThat(sharedBuffer.getEventCounters()).isExhausted();
+ }
+
+ @TestTemplate
+ void testReleasingEventsWithTheSameTimestampInOrderReadsLinearly() throws
Exception {
+ TestSharedBuffer<Event> sharedBuffer =
+
TestSharedBuffer.createTestBuffer(Event.createTypeSerializer(), cacheConfig);
+ int numberEvents = 64;
+ EventId[] eventIds = new EventId[numberEvents];
+ // closing the accessor flushes the cache, in which events are found
without a state read
+ try (SharedBufferAccessor<Event> sharedBufferAccessor =
sharedBuffer.getAccessor()) {
+ for (int i = 0; i < numberEvents; i++) {
+ eventIds[i] = sharedBufferAccessor.registerEvent(new Event(i,
"e", i), 1L);
+ }
+ }
+
+ long readsBefore = sharedBuffer.getStateReads();
+ try (SharedBufferAccessor<Event> sharedBufferAccessor =
sharedBuffer.getAccessor()) {
+ for (EventId eventId : eventIds) {
+ sharedBufferAccessor.releaseEvent(eventId);
+ }
+ }
+
+ assertThat(sharedBuffer.getStateReads() - readsBefore).isLessThan(4L *
numberEvents);
Review Comment:
Added. It's 3n - 1 reads, so 4n leaves some room.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]