fhueske commented on code in PR #30022:
URL: https://github.com/apache/flink/pull/30022#discussion_r4720009643
##########
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:
Should we also have a test that EventIds of released events can be reused
(same setup as in this test, but removing `second` instead of `first`)?
##########
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:
Nit:
this assertion is a bit too strict. `third.isEqualTo(first)` would be valid
because first is already gone.
##########
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:
I think we should also assert the behavior of a record between the newest in
state (2000) and the WM at the time of the snapshot. The record should be
processed as non-late record.
Can be another test or extending this one.
##########
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:
Add a short comment where the 4x factor is derived from.
--
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]