orpiske commented on code in PR #9972:
URL: https://github.com/apache/camel/pull/9972#discussion_r1182699209


##########
core/camel-core/src/test/java/org/apache/camel/impl/DefaultEndpointRegistryTest.java:
##########
@@ -68,4 +76,50 @@ public void configure() throws Exception {
         assertTrue(reg.isStatic("file:error"));
     }
 
+    //Testing the issue https://issues.apache.org/jira/browse/CAMEL-19295
+    @Test
+    public void testConcurrency() throws InterruptedException {
+
+        SimpleCamelContext context = new SimpleCamelContext();
+        context.start();
+
+        ProducerTemplate producerTemplate = context.createProducerTemplate();
+        EndpointRegistry<NormalizedUri> endpointRegistry = 
context.getEndpointRegistry();
+
+        int nThreads = 4;
+        ExecutorService executorService = 
Executors.newFixedThreadPool(nThreads);
+        int iterations = 500;
+
+        for (int j = 0; j < iterations; j++) {
+            CountDownLatch allThreadCompletionSemaphore = new 
CountDownLatch(nThreads);
+            for (int i = 0; i < nThreads; i++) {
+
+                executorService.submit(() -> {
+
+                    
producerTemplate.requestBody("controlbus:route?routeId=route1&action=ACTION_STATUS&loggingLevel=off",
 null,
+                            ServiceStatus.class);
+                    
producerTemplate.requestBody("controlbus:route?routeId=route2&action=ACTION_STATUS&loggingLevel=off",
 null,
+                            ServiceStatus.class);
+                    
producerTemplate.requestBody("controlbus:route?routeId=route3&action=ACTION_STATUS&loggingLevel=off",
 null,
+                            ServiceStatus.class);
+                    
producerTemplate.requestBody("controlbus:route?routeId=route4&action=ACTION_STATUS&loggingLevel=off",
 null,
+                            ServiceStatus.class);
+                    
producerTemplate.requestBody("controlbus:route?routeId=route5&action=ACTION_STATUS&loggingLevel=off",
 null,
+                            ServiceStatus.class);
+
+                    allThreadCompletionSemaphore.countDown();
+
+                });

Review Comment:
   Are you sure this is enough to trigger the issue? It looks a bit sequential 
too me. Maybe it would be better to use a Phaser here so that you can ensure 
all the requests are sent at the same time. 
   
   Additionally, it may be good to do something like:
   
   ```
   final Endpoint endpoint = 
getCamelContext().getEndpoint(""controlbus:route?routeId=route5&action=ACTION_STATUS&loggingLevel=off");
 ---> do this outside the loop. 
   
   /// then, inside the submit:
   
   producerTemplate.sendBody(endpoint, ServiceStatus.class);
   
   ```
   
   There is an associated cost with resolving the endpoint when calling via 
`producerTemplate.requestBody`  using a URI. This may reduce the chance of the 
same sections of code running truly concurrently.



-- 
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: commits-unsubscr...@camel.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to