luigidemasi commented on code in PR #27494:
URL: https://github.com/apache/camel/pull/27494#discussion_r4210337790
##########
components/camel-ai/camel-semantic/src/test/java/org/apache/camel/semantic/SemanticInitializationTest.java:
##########
@@ -77,6 +76,38 @@ void concurrentQuestionRegistryCreationReturnsOneInstance()
throws Exception {
}
}
+ @Test
+ void cachedRegistryLookupDoesNotWaitForAnotherContext() throws Exception {
+ ExecutorService callers = Executors.newFixedThreadPool(2);
+ CountDownLatch entered = new CountDownLatch(1);
+ CountDownLatch release = new CountDownLatch(1);
+ try (var creating = new DefaultCamelContext(); var cached = new
DefaultCamelContext()) {
+ var expected = SemanticEvaluations.get(cached);
+
creating.getCamelContextExtension().lazyAddContextPlugin(SemanticEvaluations.class,
() -> {
+ entered.countDown();
+ try {
+ assertThat(release.await(30, TimeUnit.SECONDS)).isTrue();
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new IllegalStateException(e);
+ }
+ return null;
Review Comment:
Added an explanatory comment in
[384c0e7f7de1](https://github.com/apache/camel/commit/384c0e7f7de14a473b201a4ef05f6d8ee0a0423d).
The supplier intentionally leaves the plugin absent after releasing the lookup
gate. `DefaultContextPluginManager` removes the null-producing lazy entry;
`SemanticEvaluations.get()` then creates and registers a real registry, which
is what the non-null assertion verifies.
Returning a stub would bypass that creation path, while asserting null would
contradict `get()`'s behavior. The initialization tests pass with the existing
assertion retained.
_AI-generated by Codex on behalf of @luigidemasi._
--
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]