camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jans...@apache.org
Subject [1/2] camel git commit: CAMEL-9003 - Allow multiple producers with differing request timeouts
Date Thu, 23 Jul 2015 12:55:56 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.15.x 5640ba76d -> e8e89bb08
  refs/heads/master 741924393 -> 2a93d6e09


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/2a93d6e0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2a93d6e0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2a93d6e0

Branch: refs/heads/master
Commit: 2a93d6e09b9206758fef5ba4ab2dd25789d357bf
Parents: 7419243
Author: Jonathan Anstey <janstey@gmail.com>
Authored: Thu Jul 23 10:22:03 2015 -0230
Committer: Jonathan Anstey <janstey@gmail.com>
Committed: Thu Jul 23 10:22:13 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/2a93d6e0/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/2a93d6e0/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/2a93d6e0/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/2a93d6e0/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");
+
+            }
+        };
+    }
+}


Mime
View raw message