davsclaus commented on code in PR #27039:
URL: https://github.com/apache/camel/pull/27039#discussion_r4130730446


##########
components/camel-sql/src/test/java/org/apache/camel/processor/aggregate/jdbc/JdbcAggregateOptimisticCompletedGroupTest.java:
##########
@@ -0,0 +1,178 @@
+/*
+ * 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.camel.processor.aggregate.jdbc;
+
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.camel.AggregationStrategy;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.awaitility.Awaitility.await;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Aggregate EIP with optimistic locking: a message that is aggregated on a 
group while the group is completed by
+ * another message or the completion timeout must start a new group, and must 
not store the completed group again
+ * (duplicates) or overwrite a new group of the same key (lost messages).
+ */
+public class JdbcAggregateOptimisticCompletedGroupTest extends 
AbstractJdbcAggregationTestSupport {
+
+    private final AtomicBoolean hold = new AtomicBoolean();
+    private volatile CountDownLatch aggregating;
+    private volatile CountDownLatch release;
+    private JdbcAggregationRepository repo2;
+
+    @BeforeEach
+    public void resetLatches() {
+        aggregating = new CountDownLatch(1);
+        release = new CountDownLatch(1);
+        hold.set(true);
+    }
+
+    @Test
+    public void testGroupCompletedByAnotherMessage() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:aggregated");
+        mock.expectedMessageCount(2);
+
+        template.sendBodyAndHeader("direct:predicate", "x", "id", "k1");
+        Thread threadA = sendAndHold("direct:predicate", "k1");
+        // the group [x] is completed while thread A aggregates on it
+        sendLast("direct:predicate", "b", "k1");
+        await().atMost(5, TimeUnit.SECONDS).until(() -> 
repo.scan(context).isEmpty());
+
+        release.countDown();
+        threadA.join(10000);

Review Comment:
   Nit (also at lines 87 and 107): `join(10000)` does not assert that the 
thread actually finished, so a hang would only show up later as a confusing 
mock or body mismatch. Consider `assertFalse(threadA.isAlive())` after the join.



-- 
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]

Reply via email to