You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/01/03 05:50:39 UTC

[camel] branch master updated (4699cf9 -> 0458101)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from 4699cf9  Regen
     new 12214d6  CAMEL-14345: camel-core - Optimize SendProcessor to not use ProducerCache when not needed
     new a293dd5  CAMEL-14340: Improve tests
     new 5312b16  CAMEL-14345: camel-core - Optimize SendProcessor to not use ProducerCache when not needed
     new 101382e  CAMEL-14349: camel-core - Transformer and Validator registry should be on-demand
     new 2f8a4e7  CAMEL-14345: camel-core - Optimize SendProcessor to not use ProducerCache when not needed
     new 7419ece  CAMEL-14347: Optimize ServicePool to avoid Key object and endpoint singleton check can be faster
     new 0458101  CAMEL-14351: camel-rest producer may detect multiple rest producer factory. Lets fallback and use the consumer configured name if any and see if its a producer too.

The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/camel/component/avro/AvroEndpoint.java  |  6 ++-
 .../component/file/remote/RemoteFileEndpoint.java  |  6 +++
 .../apache/camel/component/mina/MinaEndpoint.java  |  7 +++
 .../apache/camel/component/rest/RestEndpoint.java  | 21 +++++++--
 .../component/servlet/HttpClientRouteTest.java     |  3 +-
 .../apache/camel/component/ssh/SshEndpoint.java    |  6 +++
 .../src/main/java/org/apache/camel/Endpoint.java   |  7 +++
 .../org/apache/camel/impl/engine/ServicePool.java  | 31 ++------------
 .../org/apache/camel/processor/SendProcessor.java  | 50 +++++++++++-----------
 .../camel/impl/DefaultConsumerCacheTest.java       | 10 ++---
 .../camel/impl/DefaultProducerCacheTest.java       | 20 +++++----
 .../camel/commands/ValidatorListCommandTest.java   |  9 ++++
 12 files changed, 104 insertions(+), 72 deletions(-)


[camel] 06/07: CAMEL-14347: Optimize ServicePool to avoid Key object and endpoint singleton check can be faster

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 7419ece55acfe586fcda50c028ad4d5481135813
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Jan 3 05:35:39 2020 +0100

    CAMEL-14347: Optimize ServicePool to avoid Key object and endpoint singleton check can be faster
---
 .../org/apache/camel/impl/engine/ServicePool.java  | 26 ++--------------------
 1 file changed, 2 insertions(+), 24 deletions(-)

diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/ServicePool.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/ServicePool.java
index 18a604b..55d6f93 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/ServicePool.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/ServicePool.java
@@ -19,7 +19,6 @@ package org.apache.camel.impl.engine;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.ConcurrentHashMap;
@@ -27,7 +26,6 @@ import java.util.concurrent.ConcurrentMap;
 import java.util.function.Function;
 
 import org.apache.camel.Endpoint;
-import org.apache.camel.IsSingleton;
 import org.apache.camel.NonManagedService;
 import org.apache.camel.Service;
 import org.apache.camel.support.LRUCache;
@@ -49,7 +47,7 @@ abstract class ServicePool<S extends Service> extends ServiceSupport implements
     private final Function<S, Endpoint> getEndpoint;
     private final ConcurrentMap<Endpoint, Pool<S>> pool = new ConcurrentHashMap<>();
     private int capacity;
-    private Map<Key<S>, S> cache;
+    private Map<S, S> cache;
 
     private interface Pool<S> {
         S acquire() throws Exception;
@@ -60,21 +58,6 @@ abstract class ServicePool<S extends Service> extends ServiceSupport implements
         void cleanUp();
     }
 
-    private static class Key<S> {
-        private final S s;
-        public Key(S s) {
-            this.s = Objects.requireNonNull(s);
-        }
-        @Override
-        public boolean equals(Object o) {
-            return o instanceof Key && ((Key) o).s == s;
-        }
-        @Override
-        public int hashCode() {
-            return s.hashCode();
-        }
-    }
-
     public ServicePool(ThrowingFunction<Endpoint, S, Exception> creator, Function<S, Endpoint> getEndpoint, int capacity) {
         this.creator = creator;
         this.getEndpoint = getEndpoint;
@@ -121,7 +104,7 @@ abstract class ServicePool<S extends Service> extends ServiceSupport implements
         }
         S s = getOrCreatePool(endpoint).acquire();
         if (s != null && cache != null) {
-            cache.putIfAbsent(new Key<>(s), s);
+            cache.putIfAbsent(s, s);
         }
         return s;
     }
@@ -144,11 +127,6 @@ abstract class ServicePool<S extends Service> extends ServiceSupport implements
     }
 
     private Pool<S> createPool(Endpoint endpoint) {
-        try {
-            S s = creator.apply(endpoint);
-        } catch (Exception e) {
-            // Ignore
-        }
         boolean singleton = endpoint.isSingletonProducer();
         if (singleton) {
             return new SinglePool(endpoint);


[camel] 03/07: CAMEL-14345: camel-core - Optimize SendProcessor to not use ProducerCache when not needed

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 5312b16686e8584871e7c993062eed9bd0304683
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Jan 2 20:02:35 2020 +0100

    CAMEL-14345: camel-core - Optimize SendProcessor to not use ProducerCache when not needed
---
 .../main/java/org/apache/camel/component/avro/AvroEndpoint.java    | 6 +++++-
 .../org/apache/camel/component/file/remote/RemoteFileEndpoint.java | 6 ++++++
 .../main/java/org/apache/camel/component/mina/MinaEndpoint.java    | 7 +++++++
 .../src/main/java/org/apache/camel/component/ssh/SshEndpoint.java  | 6 ++++++
 .../src/main/java/org/apache/camel/impl/engine/ServicePool.java    | 5 +----
 5 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/components/camel-avro/src/main/java/org/apache/camel/component/avro/AvroEndpoint.java b/components/camel-avro/src/main/java/org/apache/camel/component/avro/AvroEndpoint.java
index 9d4c048..91b252e 100644
--- a/components/camel-avro/src/main/java/org/apache/camel/component/avro/AvroEndpoint.java
+++ b/components/camel-avro/src/main/java/org/apache/camel/component/avro/AvroEndpoint.java
@@ -47,6 +47,11 @@ public abstract class AvroEndpoint extends DefaultEndpoint implements AsyncEndpo
         this.configuration = configuration;
     }
 
+    @Override
+    public boolean isSingletonProducer() {
+        return false;
+    }
+
     public Exchange createExchange(Protocol.Message message, Object request) {
         ExchangePattern pattern = ExchangePattern.InOut;
         if (message.getResponse().getType().equals(Schema.Type.NULL)) {
@@ -74,7 +79,6 @@ public abstract class AvroEndpoint extends DefaultEndpoint implements AsyncEndpo
         super.doStart();
 
         validateConfiguration(configuration);
-
     }
 
     /**
diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
index 727c668..f04f290 100644
--- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
+++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
@@ -70,6 +70,12 @@ public abstract class RemoteFileEndpoint<T> extends GenericFileEndpoint<T> {
     }
 
     @Override
+    public boolean isSingletonProducer() {
+        // this producer is stateful because the remote file operations is not thread safe
+        return false;
+    }
+
+    @Override
     public RemoteFileConfiguration getConfiguration() {
         return (RemoteFileConfiguration) this.configuration;
     }
diff --git a/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java b/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java
index b0f927b..fade4a1 100644
--- a/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java
+++ b/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java
@@ -46,6 +46,13 @@ public class MinaEndpoint extends DefaultEndpoint implements MultipleConsumersSu
     }
 
     @Override
+    public boolean isSingletonProducer() {
+        // the producer should not be singleton otherwise cannot use concurrent producers and safely
+        // use request/reply with correct correlation
+        return !configuration.isSync();
+    }
+
+    @Override
     public Producer createProducer() throws Exception {
         ObjectHelper.notNull(configuration, "configuration");
         return new MinaProducer(this);
diff --git a/components/camel-ssh/src/main/java/org/apache/camel/component/ssh/SshEndpoint.java b/components/camel-ssh/src/main/java/org/apache/camel/component/ssh/SshEndpoint.java
index e471f76..b0d8fae 100644
--- a/components/camel-ssh/src/main/java/org/apache/camel/component/ssh/SshEndpoint.java
+++ b/components/camel-ssh/src/main/java/org/apache/camel/component/ssh/SshEndpoint.java
@@ -50,6 +50,12 @@ public class SshEndpoint extends ScheduledPollEndpoint {
     }
 
     @Override
+    public boolean isSingletonProducer() {
+        // SshClient is not thread-safe to be shared
+        return false;
+    }
+
+    @Override
     public Producer createProducer() throws Exception {
         return new SshProducer(this);
     }
diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/ServicePool.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/ServicePool.java
index a4c89cf..18a604b 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/ServicePool.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/ServicePool.java
@@ -144,15 +144,12 @@ abstract class ServicePool<S extends Service> extends ServiceSupport implements
     }
 
     private Pool<S> createPool(Endpoint endpoint) {
-        boolean singleton = endpoint.isSingleton();
         try {
             S s = creator.apply(endpoint);
-            if (s instanceof IsSingleton) {
-                singleton = ((IsSingleton) s).isSingleton();
-            }
         } catch (Exception e) {
             // Ignore
         }
+        boolean singleton = endpoint.isSingletonProducer();
         if (singleton) {
             return new SinglePool(endpoint);
         } else {


[camel] 01/07: CAMEL-14345: camel-core - Optimize SendProcessor to not use ProducerCache when not needed

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 12214d6d15fa25135fa533de3231e62e924678ad
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Jan 2 19:37:10 2020 +0100

    CAMEL-14345: camel-core - Optimize SendProcessor to not use ProducerCache when not needed
---
 .../src/main/java/org/apache/camel/Endpoint.java   |  7 +++
 .../org/apache/camel/processor/SendProcessor.java  | 50 +++++++++++-----------
 .../camel/impl/DefaultProducerCacheTest.java       |  6 +--
 3 files changed, 34 insertions(+), 29 deletions(-)

diff --git a/core/camel-api/src/main/java/org/apache/camel/Endpoint.java b/core/camel-api/src/main/java/org/apache/camel/Endpoint.java
index 38fad93..3be060f 100644
--- a/core/camel-api/src/main/java/org/apache/camel/Endpoint.java
+++ b/core/camel-api/src/main/java/org/apache/camel/Endpoint.java
@@ -83,6 +83,13 @@ public interface Endpoint extends IsSingleton, Service {
     Producer createProducer() throws Exception;
 
     /**
+     * Whether this endpoint creates singleton producers
+     */
+    default boolean isSingletonProducer() {
+        return isSingleton();
+    }
+
+    /**
      * Creates a new producer which is used send messages into the endpoint
      *
      * @return a newly created producer
diff --git a/core/camel-base/src/main/java/org/apache/camel/processor/SendProcessor.java b/core/camel-base/src/main/java/org/apache/camel/processor/SendProcessor.java
index 299592a..1885347 100644
--- a/core/camel-base/src/main/java/org/apache/camel/processor/SendProcessor.java
+++ b/core/camel-base/src/main/java/org/apache/camel/processor/SendProcessor.java
@@ -164,18 +164,18 @@ public class SendProcessor extends AsyncProcessorSupport implements Traceable, E
             }
 
             return true;
+        } else {
+            configureExchange(exchange, pattern);
+            log.debug(">>>> {} {}", destination, exchange);
+
+            // send the exchange to the destination using the producer cache for the non optimized producers
+            return producerCache.doInAsyncProducer(destination, exchange, callback, (producer, ex, cb) -> producer.process(ex, doneSync -> {
+                // restore previous MEP
+                exchange.setPattern(existingPattern);
+                // signal we are done
+                cb.done(doneSync);
+            }));
         }
-
-        configureExchange(exchange, pattern);
-        log.debug(">>>> {} {}", destination, exchange);
-
-        // send the exchange to the destination using the producer cache for the non optimized producers
-        return producerCache.doInAsyncProducer(destination, exchange, callback, (producer, ex, cb) -> producer.process(ex, doneSync -> {
-            // restore previous MEP
-            exchange.setPattern(existingPattern);
-            // signal we are done
-            cb.done(doneSync);
-        }));
     }
     
     public Endpoint getDestination() {
@@ -208,7 +208,8 @@ public class SendProcessor extends AsyncProcessorSupport implements Traceable, E
 
     @Override
     protected void doInit() throws Exception {
-        if (producerCache == null) {
+        // if the producer is not singleton we need to use a producer cache
+        if (!destination.isSingletonProducer() && producerCache == null) {
             // use a single producer cache as we need to only hold reference for one destination
             // and use a regular HashMap as we do not want a soft reference store that may get re-claimed when low on memory
             // as we want to ensure the producer is kept around, to ensure its lifecycle is fully managed,
@@ -220,30 +221,27 @@ public class SendProcessor extends AsyncProcessorSupport implements Traceable, E
 
     @Override
     protected void doStart() throws Exception {
-        ServiceHelper.startService(producerCache);
-
         // warm up the producer by starting it so we can fail fast if there was a problem
         // however must start endpoint first
         ServiceHelper.startService(destination);
 
-        // this SendProcessor is used a lot in Camel (eg every .to in the route DSL) and therefore we
-        // want to optimize for regular producers, by using the producer directly instead of the ProducerCache.
-        // Only for pooled and non-singleton producers we have to use the ProducerCache as it supports these
-        // kind of producer better (though these kind of producer should be rare)
-
-        AsyncProducer producer = producerCache.acquireProducer(destination);
-        if (!producer.isSingleton()) {
-            // no we cannot optimize it - so release the producer back to the producer cache
-            // and use the producer cache for sending
-            producerCache.releaseProducer(destination, producer);
+        // yes we can optimize and use the producer directly for sending
+        if (destination.isSingletonProducer()) {
+            this.producer = destination.createAsyncProducer();
+            // ensure the producer is managed and started
+            camelContext.addService(this.producer, true, true);
         } else {
-            // yes we can optimize and use the producer directly for sending
-            this.producer = producer;
+            // no we need the producer cache for pooled non-singleton producers
+            ServiceHelper.startService(producerCache);
         }
     }
 
     @Override
     protected void doStop() throws Exception {
+        // ensure the producer is removed before its stopped
+        if (this.producer != null) {
+            camelContext.removeService(this.producer);
+        }
         ServiceHelper.stopService(producerCache, producer);
     }
 
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerCacheTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerCacheTest.java
index 1e7c0a7..f93542f 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerCacheTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerCacheTest.java
@@ -69,7 +69,7 @@ public class DefaultProducerCacheTest extends ContextTestSupport {
         // the eviction is async so force cleanup
         cache.cleanUp();
 
-        await().atMost(1, TimeUnit.SECONDS).untilAsserted(() -> assertEquals("Size should be 1000", 1000, cache.size()));
+        await().atMost(3, TimeUnit.SECONDS).untilAsserted(() -> assertEquals("Size should be 1000", 1000, cache.size()));
 
         cache.stop();
 
@@ -93,8 +93,8 @@ public class DefaultProducerCacheTest extends ContextTestSupport {
         // the eviction is async so force cleanup
         cache.cleanUp();
 
-        await().atMost(3, TimeUnit.SECONDS).untilAsserted(() -> assertEquals("Size should be 5", 5, cache.size()));
-        await().atMost(3, TimeUnit.SECONDS).untilAsserted(() -> assertEquals(3, stopCounter.get()));
+        await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> assertEquals("Size should be 5", 5, cache.size()));
+        await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> assertEquals(3, stopCounter.get()));
 
         cache.stop();
 


[camel] 05/07: CAMEL-14345: camel-core - Optimize SendProcessor to not use ProducerCache when not needed

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 2f8a4e7d144b413ab7fd08f5d5a31a881c5aee7a
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Jan 3 05:35:05 2020 +0100

    CAMEL-14345: camel-core - Optimize SendProcessor to not use ProducerCache when not needed
---
 .../java/org/apache/camel/component/servlet/HttpClientRouteTest.java   | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/HttpClientRouteTest.java b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/HttpClientRouteTest.java
index 469ef50..16dec00 100644
--- a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/HttpClientRouteTest.java
+++ b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/HttpClientRouteTest.java
@@ -29,6 +29,7 @@ import com.meterware.httpunit.WebResponse;
 import com.meterware.servletunit.ServletUnitClient;
 import org.apache.camel.Exchange;
 import org.apache.camel.FailedToCreateProducerException;
+import org.apache.camel.FailedToStartRouteException;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.junit.Test;
@@ -123,7 +124,7 @@ public class HttpClientRouteTest extends ServletCamelRouterTestSupport {
             });
             fail("Excepts exception here");
         } catch (Exception ex) {
-            assertTrue("Get a wrong exception.", ex.getCause() instanceof FailedToCreateProducerException);
+            assertTrue("Get a wrong exception.", ex instanceof FailedToStartRouteException);
             assertTrue("Get a wrong cause of exception.", ex.getCause().getCause() instanceof UnsupportedOperationException);
         }
     }


[camel] 04/07: CAMEL-14349: camel-core - Transformer and Validator registry should be on-demand

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 101382e8b18123c963fae8eef95a5404e1a60dc1
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Jan 3 05:30:18 2020 +0100

    CAMEL-14349: camel-core - Transformer and Validator registry should be on-demand
---
 .../java/org/apache/camel/commands/ValidatorListCommandTest.java | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/ValidatorListCommandTest.java b/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/ValidatorListCommandTest.java
index 7bafb93..aa1566b 100644
--- a/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/ValidatorListCommandTest.java
+++ b/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/ValidatorListCommandTest.java
@@ -24,6 +24,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.Message;
 import org.apache.camel.ValidationException;
 import org.apache.camel.builder.ExpressionBuilder;
+import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.engine.ExplicitCamelContextNameStrategy;
 import org.apache.camel.model.Model;
@@ -88,6 +89,14 @@ public class ValidatorListCommandTest {
         context.setNameStrategy(new ExplicitCamelContextNameStrategy("foobar"));
         context.start();
 
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:foo")
+                        .to("mock:foo");
+            }
+        });
+
         CamelController controller = new DummyCamelController(context);
 
         OutputStream os = new ByteArrayOutputStream();


[camel] 07/07: CAMEL-14351: camel-rest producer may detect multiple rest producer factory. Lets fallback and use the consumer configured name if any and see if its a producer too.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 045810164223c493180f1092aa69291ffb8a31f8
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Jan 3 05:56:52 2020 +0100

    CAMEL-14351: camel-rest producer may detect multiple rest producer factory. Lets fallback and use the consumer configured name if any and see if its a producer too.
---
 .../apache/camel/component/rest/RestEndpoint.java   | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestEndpoint.java b/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
index bfacd29..5826271 100644
--- a/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
+++ b/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
@@ -311,7 +311,7 @@ public class RestEndpoint extends DefaultEndpoint {
 
         String pname = getProducerComponentName();
         if (pname != null) {
-            Object comp = getCamelContext().getRegistry().lookupByName(getProducerComponentName());
+            Object comp = getCamelContext().getRegistry().lookupByName(pname);
             if (comp instanceof RestProducerFactory) {
                 factory = (RestProducerFactory) comp;
             } else {
@@ -323,12 +323,11 @@ public class RestEndpoint extends DefaultEndpoint {
 
             if (factory == null) {
                 if (comp != null) {
-                    throw new IllegalArgumentException("Component " + getProducerComponentName() + " is not a RestProducerFactory");
+                    throw new IllegalArgumentException("Component " + pname + " is not a RestProducerFactory");
                 } else {
                     throw new NoSuchBeanException(getProducerComponentName(), RestProducerFactory.class.getName());
                 }
             }
-            pname = getProducerComponentName();
         }
 
         // try all components
@@ -343,6 +342,22 @@ public class RestEndpoint extends DefaultEndpoint {
             }
         }
 
+        // fallback to use consumer name as it may be producer capable too
+        if (pname == null && getConsumerComponentName() != null) {
+            String cname = getConsumerComponentName();
+            Object comp = getCamelContext().getRegistry().lookupByName(cname);
+            if (comp instanceof RestProducerFactory) {
+                factory = (RestProducerFactory) comp;
+                pname = cname;
+            } else {
+                comp = setupComponent(cname, getCamelContext(), (Map<String, Object>) parameters.get("component"));
+                if (comp instanceof RestProducerFactory) {
+                    factory = (RestProducerFactory) comp;
+                    pname = cname;
+                }
+            }
+        }
+
         parameters.put("producerComponentName", pname);
 
         // lookup in registry


[camel] 02/07: CAMEL-14340: Improve tests

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit a293dd5602aa93b63474f4d35955a2b6d260de8d
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Jan 2 19:40:59 2020 +0100

    CAMEL-14340: Improve tests
---
 .../apache/camel/impl/DefaultConsumerCacheTest.java    | 10 +++++-----
 .../apache/camel/impl/DefaultProducerCacheTest.java    | 18 +++++++++++-------
 2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultConsumerCacheTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultConsumerCacheTest.java
index 92f9fda..de6d2be 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultConsumerCacheTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultConsumerCacheTest.java
@@ -42,11 +42,11 @@ public class DefaultConsumerCacheTest extends ContextTestSupport {
             assertNotNull("the polling consumer should not be null", p);
         }
 
-        // the eviction is async so force cleanup
-        cache.cleanUp();
-
-        await().atMost(3, TimeUnit.SECONDS).until(() -> cache.size() == 1000);
-        assertEquals("Size should be 1000", 1000, cache.size());
+        await().atMost(3, TimeUnit.SECONDS).untilAsserted(() -> {
+            // the eviction is async so force cleanup
+            cache.cleanUp();
+            assertEquals("Size should be 1000", 1000, cache.size());
+        });
 
         cache.stop();
     }
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerCacheTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerCacheTest.java
index f93542f..c473110 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerCacheTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerCacheTest.java
@@ -66,10 +66,11 @@ public class DefaultProducerCacheTest extends ContextTestSupport {
             cache.releaseProducer(e, p);
         }
 
-        // the eviction is async so force cleanup
-        cache.cleanUp();
-
-        await().atMost(3, TimeUnit.SECONDS).untilAsserted(() -> assertEquals("Size should be 1000", 1000, cache.size()));
+        await().atMost(3, TimeUnit.SECONDS).untilAsserted(() -> {
+            // the eviction is async so force cleanup
+            cache.cleanUp();
+            assertEquals("Size should be 1000", 1000, cache.size());
+        });
 
         cache.stop();
 
@@ -90,10 +91,12 @@ public class DefaultProducerCacheTest extends ContextTestSupport {
             cache.releaseProducer(e, p);
         }
 
-        // the eviction is async so force cleanup
-        cache.cleanUp();
+        await().atMost(3, TimeUnit.SECONDS).untilAsserted(() -> {
+            // the eviction is async so force cleanup
+            cache.cleanUp();
+            assertEquals("Size should be 5", 5, cache.size());
+        });
 
-        await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> assertEquals("Size should be 5", 5, cache.size()));
         await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> assertEquals(3, stopCounter.get()));
 
         cache.stop();
@@ -248,6 +251,7 @@ public class DefaultProducerCacheTest extends ContextTestSupport {
     }
 
     private final class MyComponent extends DefaultComponent {
+
         public MyComponent(CamelContext context) {
             super(context);
         }