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


##########
core/camel-core/src/test/java/org/apache/camel/impl/engine/DefaultBeanIntrospectionTest.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.impl.engine;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Another thread (such as the cli-connector, which is started early) can use 
the bean introspection while Camel is
+ * starting, when the log lines from before the start are logged.
+ */
+public class DefaultBeanIntrospectionTest {
+
+    @Test
+    public void testUsedByAnotherThreadWhileStarting() throws Exception {
+        for (int i = 0; i < 20; i++) {
+            DefaultBeanIntrospection introspection = new 
DefaultBeanIntrospection();
+            // many log lines from before the start, so logging them takes a 
while
+            for (int j = 0; j < 10000; j++) {
+                introspection.cacheClass(String.class);
+            }
+
+            AtomicBoolean done = new AtomicBoolean();
+            AtomicReference<Throwable> failure = new AtomicReference<>();
+            CountDownLatch using = new CountDownLatch(1);
+            Thread other = new Thread(() -> {
+                try {
+                    while (!done.get()) {
+                        introspection.cacheClass(Integer.class);
+                        using.countDown();
+                    }
+                } catch (Throwable e) {
+                    failure.set(e);
+                }
+            }, "other");
+            other.start();
+            try {
+                assertTrue(using.await(5, TimeUnit.SECONDS));
+                assertDoesNotThrow(() -> 
introspection.afterPropertiesConfigured(null));
+            } finally {
+                done.set(true);
+                other.join(5000);

Review Comment:
   Applied in c2c12ea04069, with the assertion after the try/finally rather 
than inside the finally block, so a timeout cannot hide the failure of the 
assertion before it.
   
   _Claude Code on behalf of davsclaus_



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