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


##########
core/camel-core/src/test/java/org/apache/camel/impl/ProducerCacheNonSingletonEvictionTest.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * 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;
+
+import java.util.Map;
+
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.Component;
+import org.apache.camel.Consumer;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.support.DefaultAsyncProducer;
+import org.apache.camel.support.DefaultComponent;
+import org.apache.camel.support.DefaultEndpoint;
+import org.apache.camel.support.cache.DefaultProducerCache;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Non-singleton producers are pooled per endpoint. When one of them is 
evicted from the producer cache, it must not be
+ * handed out again once it is stopped, and it must not be stopped while it is 
in use.
+ */
+class ProducerCacheNonSingletonEvictionTest extends ContextTestSupport {

Review Comment:
   Both tests use a cache size of 2 with 2 endpoints, so `pool.size() > 
capacity` in `onEvict` never fires and `MultiplePool.stop()` is never called 
while a producer is in use. That leaves the new non-singleton `p == null` 
branch in `onEvict`, the `stopped` checks in `release`/`evict`, and the 
`cleanupEvicts()` added to `stop()` without a test. Could you add a third case: 
cache size 1 and a third endpoint, so that a pool is stopped while one of its 
producers is acquired? Then assert the producer is still started, and is 
stopped (and not pooled again) once it is released.



##########
core/camel-support/src/main/java/org/apache/camel/support/cache/ServicePool.java:
##########
@@ -92,9 +93,13 @@ protected void onEvict(S s) {
                 // the pool is growing too large, so we need to stop (stop 
will remove itself from pool)
                 p.stop();
             }
-        } else {
+        } else if (e.isSingletonProducer()) {
             // service no longer in a pool (such as being released twice, or 
can happen during shutdown of Camel etc)
             stopAndRemove(s);
+        } else {
+            // the pool has been stopped, which stopped its idle services, so 
this service is either stopped already

Review Comment:
   Nit: `p == null` can also happen when `getEndpoint.apply(s)` isn't the same 
instance as the endpoint used as the pool key, not only when the pool has been 
stopped. Doing nothing is still the safe choice then (the producer may be idle 
in a live pool's queue), so the code is fine. Maybe reword the comment so it 
doesn't claim the pool was stopped.



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