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


##########
core/camel-core/src/test/java/org/apache/camel/processor/throttle/concurrent/ConcurrentRequestsThrottlerTest.java:
##########
@@ -199,32 +190,59 @@ public void configure() {
 
                 
from("direct:a").throttle(CONCURRENT_REQUESTS).concurrentRequestsMode()
                         .process(exchange -> {
-                            assertTrue(semaphore.tryAcquire(), "'direct:a' too 
many requests");
+                            Semaphore s = semaphore;
+                            assertTrue(s.tryAcquire(), "'direct:a' too many 
requests");
+                            
exchange.getExchangeExtension().addOnCompletion(new SynchronizationAdapter() {
+                                @Override
+                                public void onComplete(Exchange ex) {
+                                    s.release();
+                                }
+
+                                @Override
+                                public void onFailure(Exchange ex) {
+                                    s.release();
+                                }
+                            });
                         })
                         .delay(100)
-                        .process(exchange -> {
-                            semaphore.release();
-                        })
                         .to("log:result", "mock:result");
 
                 
from("direct:expressionConstant").throttle(constant(CONCURRENT_REQUESTS)).concurrentRequestsMode()
                         .process(exchange -> {
-                            assertTrue(semaphore.tryAcquire(), 
"'direct:expressionConstant' too many requests");
+                            Semaphore s = semaphore;
+                            assertTrue(s.tryAcquire(), 
"'direct:expressionConstant' too many requests");
+                            
exchange.getExchangeExtension().addOnCompletion(new SynchronizationAdapter() {
+                                @Override
+                                public void onComplete(Exchange ex) {
+                                    s.release();
+                                }
+
+                                @Override
+                                public void onFailure(Exchange ex) {
+                                    s.release();
+                                }
+                            });
                         })
                         .delay(100)

Review Comment:
   `SynchronizationAdapter.onComplete()` and `onFailure()` both delegate to 
`onDone()` (see `SynchronizationAdapter.java:29-38`), so overriding just 
`onDone()` achieves the same result with less code. Same applies to the other 
two routes in this file and `SpringThrottlerTest.IncrementProcessor`.
   
   ```suggestion
                               
exchange.getExchangeExtension().addOnCompletion(new SynchronizationAdapter() {
                                   @Override
                                   public void onDone(Exchange ex) {
                                       s.release();
                                   }
                               });
   ```



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