Repository: camel
Updated Branches:
  refs/heads/master 9378d293e -> 7761061fa


CAMEL-7998 Clean up the unit test and polish the NettyProducer in camel-netty


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

Branch: refs/heads/master
Commit: e510be4a3d5583ef2f287a6a2a6c9b3c13395ea6
Parents: 9378d29
Author: Willem Jiang <willem.ji...@gmail.com>
Authored: Wed Nov 12 17:36:04 2014 +0800
Committer: Willem Jiang <willem.ji...@gmail.com>
Committed: Wed Nov 12 17:55:45 2014 +0800

----------------------------------------------------------------------
 .../apache/camel/component/netty/NettyProducer.java |  4 ++--
 .../component/netty/NettyUdpConnectedSendTest.java  | 16 ++++------------
 .../netty/NettyUdpConnectionlessSendTest.java       | 16 ++++------------
 3 files changed, 10 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e510be4a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyProducer.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyProducer.java
 
b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyProducer.java
index cad1ca8..491ee38 100644
--- 
a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyProducer.java
+++ 
b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyProducer.java
@@ -246,8 +246,8 @@ public class NettyProducer extends DefaultAsyncProducer {
         channel.setAttachment(new NettyCamelState(producerCallback, exchange));
 
         InetSocketAddress remoteAddress = null;
-        if (!isTcp() && configuration.isUdpConnectionlessSending()) {
-            // Need to specify the remoteAddress here
+        if (!isTcp()) {
+            // Need to specify the remoteAddress for udp connection
             remoteAddress = new InetSocketAddress(configuration.getHost(), 
configuration.getPort()); 
         }
         

http://git-wip-us.apache.org/repos/asf/camel/blob/e510be4a/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyUdpConnectedSendTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyUdpConnectedSendTest.java
 
b/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyUdpConnectedSendTest.java
index aef3ae2..bcda6eb 100644
--- 
a/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyUdpConnectedSendTest.java
+++ 
b/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyUdpConnectedSendTest.java
@@ -35,7 +35,7 @@ import org.junit.Test;
 public class NettyUdpConnectedSendTest extends BaseNettyTest {
     private static final String SEND_STRING = "***<We all love camel>***";
     private static final int SEND_COUNT = 20;
-    private int receivedCount;
+    private volatile int receivedCount;
     private ConnectionlessBootstrap bootstrap;
 
     public void createNettyUdpReceiver() {
@@ -54,7 +54,7 @@ public class NettyUdpConnectedSendTest extends BaseNettyTest {
 
 
     public void bind() {
-        bootstrap.bind(new InetSocketAddress(8601));
+        bootstrap.bind(new InetSocketAddress(getPort()));
     }
 
     public void stop() {
@@ -64,18 +64,10 @@ public class NettyUdpConnectedSendTest extends 
BaseNettyTest {
     @Test
     public void sendConnectedUdp() throws Exception {
         createNettyUdpReceiver();
-        Thread t = new Thread(new Runnable() {
-            @Override
-            public void run() {
-                bind();
-            }
-        });
-        t.start();
-        Thread.sleep(1000);
+        bind();
         for (int i = 0; i < SEND_COUNT; ++i) {
             template.sendBody("direct:in", SEND_STRING);
         }
-        Thread.sleep(1000);
         stop();
         assertTrue("We should have received some datagrams", receivedCount > 
0);
     }
@@ -98,7 +90,7 @@ public class NettyUdpConnectedSendTest extends BaseNettyTest {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                
from("direct:in").to("netty:udp://localhost:8601?sync=false&textline=true");
+                
from("direct:in").to("netty:udp://localhost:{{port}}?sync=false&textline=true");
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/e510be4a/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyUdpConnectionlessSendTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyUdpConnectionlessSendTest.java
 
b/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyUdpConnectionlessSendTest.java
index bd36e4a..c572796 100644
--- 
a/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyUdpConnectionlessSendTest.java
+++ 
b/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyUdpConnectionlessSendTest.java
@@ -35,7 +35,7 @@ import org.junit.Test;
 public class NettyUdpConnectionlessSendTest extends BaseNettyTest {
     private static final String SEND_STRING = "***<We all love camel>***";
     private static final int SEND_COUNT = 20;
-    private int receivedCount;
+    private volatile int receivedCount;
     private ConnectionlessBootstrap bootstrap;
 
     public void createNettyUdpReceiver() {
@@ -54,7 +54,7 @@ public class NettyUdpConnectionlessSendTest extends 
BaseNettyTest {
 
 
     public void bind() {
-        bootstrap.bind(new InetSocketAddress(8601));
+        bootstrap.bind(new InetSocketAddress(getPort()));
     }
 
     public void stop() {
@@ -64,18 +64,10 @@ public class NettyUdpConnectionlessSendTest extends 
BaseNettyTest {
     @Test
     public void sendConnectionlessUdp() throws Exception {
         createNettyUdpReceiver();
-        Thread t = new Thread(new Runnable() {
-            @Override
-            public void run() {
-                bind();
-            }
-        });
-        t.start();
-        Thread.sleep(1000);
+        bind();
         for (int i = 0; i < SEND_COUNT; ++i) {
             template.sendBody("direct:in", SEND_STRING);
         }
-        Thread.sleep(1000);
         stop();
         assertTrue("We should have received some datagrams", receivedCount > 
0);
 
@@ -99,7 +91,7 @@ public class NettyUdpConnectionlessSendTest extends 
BaseNettyTest {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                
from("direct:in").to("netty:udp://localhost:8601?sync=false&textline=true&udpConnectionlessSending=true");
+                
from("direct:in").to("netty:udp://localhost:{{port}}?sync=false&textline=true&udpConnectionlessSending=true");
             }
         };
     }

Reply via email to