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


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

Branch: refs/heads/master
Commit: 7761061fa26027a7cc10e62fe87d110b8acba0b9
Parents: e510be4
Author: Willem Jiang <willem.ji...@gmail.com>
Authored: Wed Nov 12 17:56:28 2014 +0800
Committer: Willem Jiang <willem.ji...@gmail.com>
Committed: Wed Nov 12 18:41:42 2014 +0800

----------------------------------------------------------------------
 .../netty4/NettyUdpConnectedSendTest.java       | 18 +++++------------
 .../netty4/NettyUdpConnectionlessSendTest.java  | 21 ++++++--------------
 2 files changed, 11 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7761061f/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyUdpConnectedSendTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyUdpConnectedSendTest.java
 
b/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyUdpConnectedSendTest.java
index b24ab82..579e46b 100644
--- 
a/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyUdpConnectedSendTest.java
+++ 
b/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyUdpConnectedSendTest.java
@@ -38,7 +38,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 EventLoopGroup group;
     private Bootstrap bootstrap;
 
@@ -53,12 +53,12 @@ public class NettyUdpConnectedSendTest extends 
BaseNettyTest {
                         channel.pipeline().addLast(new UdpHandler());
                         channel.pipeline().addLast(new ContentHandler());
                     }
-                }).localAddress(new InetSocketAddress(8601));
+                }).localAddress(new InetSocketAddress(getPort()));
     }
 
 
     public void bind() {
-        
bootstrap.bind().syncUninterruptibly().channel().closeFuture().syncUninterruptibly();
+        bootstrap.bind().syncUninterruptibly();
     }
 
     public void stop() {
@@ -68,18 +68,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);
     }
@@ -102,7 +94,7 @@ public class NettyUdpConnectedSendTest extends BaseNettyTest 
{
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                
from("direct:in").to("netty4:udp://localhost:8601?sync=false&textline=true");
+                
from("direct:in").to("netty4:udp://localhost:{{port}}?sync=false&textline=true");
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/7761061f/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyUdpConnectionlessSendTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyUdpConnectionlessSendTest.java
 
b/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyUdpConnectionlessSendTest.java
index 557f9bb..f4af775 100644
--- 
a/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyUdpConnectionlessSendTest.java
+++ 
b/components/camel-netty4/src/test/java/org/apache/camel/component/netty4/NettyUdpConnectionlessSendTest.java
@@ -30,7 +30,6 @@ import io.netty.channel.socket.DatagramPacket;
 import io.netty.channel.socket.nio.NioDatagramChannel;
 import io.netty.handler.codec.MessageToMessageDecoder;
 import io.netty.util.CharsetUtil;
-
 import org.apache.camel.builder.RouteBuilder;
 import org.junit.Test;
 
@@ -38,7 +37,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 EventLoopGroup group;
     private Bootstrap bootstrap;
 
@@ -53,33 +52,25 @@ public class NettyUdpConnectionlessSendTest extends 
BaseNettyTest {
                         channel.pipeline().addLast(new UdpHandler());
                         channel.pipeline().addLast(new ContentHandler());
                     }
-                }).localAddress(new InetSocketAddress(8601));
+                }).localAddress(new InetSocketAddress(getPort()));
     }
 
 
     public void bind() {
-        
bootstrap.bind().syncUninterruptibly().channel().closeFuture().syncUninterruptibly();
+        bootstrap.bind().syncUninterruptibly();
     }
 
     public void stop() {
-        group.shutdownGracefully();
+        group.shutdownGracefully().syncUninterruptibly();
     }
 
     @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);
 
@@ -103,7 +94,7 @@ public class NettyUdpConnectionlessSendTest extends 
BaseNettyTest {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                
from("direct:in").to("netty4:udp://localhost:8601?sync=false&textline=true&udpConnectionlessSending=true");
+                
from("direct:in").to("netty4:udp://localhost:{{port}}?sync=false&textline=true&udpConnectionlessSending=true");
             }
         };
     }

Reply via email to