You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2015/07/23 14:55:57 UTC

[2/2] camel git commit: CAMEL-9003 - Allow multiple producers with differing request timeouts

CAMEL-9003 - Allow multiple producers with differing request timeouts


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e8e89bb0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e8e89bb0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e8e89bb0

Branch: refs/heads/camel-2.15.x
Commit: e8e89bb084c13aac0542970be5a63a78a9b77047
Parents: 5640ba7
Author: Jonathan Anstey <ja...@gmail.com>
Authored: Thu Jul 23 10:22:03 2015 -0230
Committer: Jonathan Anstey <ja...@gmail.com>
Committed: Thu Jul 23 10:22:43 2015 -0230

----------------------------------------------------------------------
 .../camel/component/netty/NettyEndpoint.java    | 12 ++++-
 .../netty/NettyCachedRequestTimeoutTest.java    | 53 ++++++++++++++++++++
 .../camel/component/netty4/NettyEndpoint.java   | 12 ++++-
 .../netty4/NettyCachedRequestTimeoutTest.java   | 53 ++++++++++++++++++++
 4 files changed, 128 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e8e89bb0/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyEndpoint.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyEndpoint.java
index 24b9d50..81b8648 100644
--- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyEndpoint.java
+++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyEndpoint.java
@@ -98,10 +98,20 @@ public class NettyEndpoint extends DefaultEndpoint {
     @Override
     protected String createEndpointUri() {
         ObjectHelper.notNull(configuration, "configuration");
-        return "netty:" + getConfiguration().getProtocol() + "://" + getConfiguration().getHost() + ":" + getConfiguration().getPort();
+        return "netty:" + getConfiguration().getProtocol() + "://" + getConfiguration().getHost() + ":" + getConfiguration().getPort() 
+                + ((getConfiguration().getRequestTimeout() > 0) ? "?requestTimeout=" + getConfiguration().getRequestTimeout() : "");
     }
 
     @Override
+    public String getEndpointUri() {
+        if (getConfiguration().getRequestTimeout() > 0) {
+            return super.getEndpointUri() + "?requestTimeout=" + getConfiguration().getRequestTimeout();   
+        } else {
+            return super.getEndpointUri();    
+        }        
+    }
+    
+    @Override
     protected void doStart() throws Exception {
         ObjectHelper.notNull(timer, "timer");
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/e8e89bb0/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyCachedRequestTimeoutTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyCachedRequestTimeoutTest.java b/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyCachedRequestTimeoutTest.java
new file mode 100644
index 0000000..fcb7e37
--- /dev/null
+++ b/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyCachedRequestTimeoutTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.component.netty;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+/**
+ * @version 
+ */
+public class NettyCachedRequestTimeoutTest extends BaseNettyTest {
+
+    @Test
+    public void testRequestTimeoutKeyInProducerCache() throws Exception {        
+        assertEquals(0, template.getCurrentCacheSize());
+        String out = template.requestBody("netty:tcp://localhost:{{port}}?textline=true&sync=true&requestTimeout=1000", "Hello Camel", String.class);
+        assertEquals("Bye World", out);
+        out = template.requestBody("netty:tcp://localhost:{{port}}?textline=true&sync=true&requestTimeout=1000", "Hello Camel", String.class);
+        assertEquals("Bye World", out);       
+        assertEquals(1, template.getCurrentCacheSize());
+        
+        template.requestBody("netty:tcp://localhost:{{port}}?textline=true&sync=true&requestTimeout=1001", "Hello Camel", String.class);
+        assertEquals(2, template.getCurrentCacheSize());
+        template.requestBody("netty:tcp://localhost:{{port}}?textline=true&sync=true&requestTimeout=1002", "Hello Camel", String.class);
+        assertEquals(3, template.getCurrentCacheSize());        
+    }
+    
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("netty:tcp://localhost:{{port}}?textline=true&sync=true")
+                    .transform().constant("Bye World");
+
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/e8e89bb0/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyEndpoint.java b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyEndpoint.java
index 722504e..5669e9d 100644
--- a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyEndpoint.java
+++ b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyEndpoint.java
@@ -89,8 +89,18 @@ public class NettyEndpoint extends DefaultEndpoint {
     @Override
     protected String createEndpointUri() {
         ObjectHelper.notNull(configuration, "configuration");
-        return "netty4:" + getConfiguration().getProtocol() + "://" + getConfiguration().getHost() + ":" + getConfiguration().getPort();
+        return "netty4:" + getConfiguration().getProtocol() + "://" + getConfiguration().getHost() + ":" + getConfiguration().getPort() 
+                + ((getConfiguration().getRequestTimeout() > 0) ? "?requestTimeout=" + getConfiguration().getRequestTimeout() : "");
     }
+
+    @Override
+    public String getEndpointUri() {
+        if (getConfiguration().getRequestTimeout() > 0) {
+            return super.getEndpointUri() + "?requestTimeout=" + getConfiguration().getRequestTimeout();   
+        } else {
+            return super.getEndpointUri();    
+        }        
+    }    
     
     protected SSLSession getSSLSession(ChannelHandlerContext ctx) {
         final SslHandler sslHandler = ctx.pipeline().get(SslHandler.class);

http://git-wip-us.apache.org/repos/asf/camel/blob/e8e89bb0/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyCachedRequestTimeoutTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyCachedRequestTimeoutTest.java b/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyCachedRequestTimeoutTest.java
new file mode 100644
index 0000000..93765cd
--- /dev/null
+++ b/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyCachedRequestTimeoutTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.component.netty4;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+/**
+ * @version 
+ */
+public class NettyCachedRequestTimeoutTest extends BaseNettyTest {
+
+    @Test
+    public void testRequestTimeoutKeyInProducerCache() throws Exception {        
+        assertEquals(0, template.getCurrentCacheSize());
+        String out = template.requestBody("netty4:tcp://localhost:{{port}}?textline=true&sync=true&requestTimeout=1000", "Hello Camel", String.class);
+        assertEquals("Bye World", out);
+        out = template.requestBody("netty4:tcp://localhost:{{port}}?textline=true&sync=true&requestTimeout=1000", "Hello Camel", String.class);
+        assertEquals("Bye World", out);       
+        assertEquals(1, template.getCurrentCacheSize());
+        
+        template.requestBody("netty4:tcp://localhost:{{port}}?textline=true&sync=true&requestTimeout=1001", "Hello Camel", String.class);
+        assertEquals(2, template.getCurrentCacheSize());
+        template.requestBody("netty4:tcp://localhost:{{port}}?textline=true&sync=true&requestTimeout=1002", "Hello Camel", String.class);
+        assertEquals(3, template.getCurrentCacheSize());        
+    }
+    
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("netty4:tcp://localhost:{{port}}?textline=true&sync=true")
+                    .transform().constant("Bye World");
+
+            }
+        };
+    }
+}