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 2012/12/21 13:44:05 UTC

svn commit: r1424897 - /camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/

Author: davsclaus
Date: Fri Dec 21 12:44:05 2012
New Revision: 1424897

URL: http://svn.apache.org/viewvc?rev=1424897&view=rev
Log:
CAMEL-5904: Fixed tests to better stop and cleanup resources as Netty 3.6.0 is not as tolerant as older releases

Modified:
    camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyCustomPipelineFactoryAsynchTest.java
    camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyCustomPipelineFactorySynchTest.java
    camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyTCPAsyncTest.java
    camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyTCPSyncNotLazyChannelTest.java
    camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyTCPSyncTest.java
    camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyTransferExchangeOptionTest.java

Modified: camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyCustomPipelineFactoryAsynchTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyCustomPipelineFactoryAsynchTest.java?rev=1424897&r1=1424896&r2=1424897&view=diff
==============================================================================
--- camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyCustomPipelineFactoryAsynchTest.java (original)
+++ camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyCustomPipelineFactoryAsynchTest.java Fri Dec 21 12:44:05 2012
@@ -18,8 +18,6 @@ package org.apache.camel.component.netty
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
-import org.apache.camel.Produce;
-import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.netty.handlers.ClientChannelHandler;
 import org.apache.camel.component.netty.handlers.ServerChannelHandler;
@@ -35,12 +33,9 @@ import org.junit.Test;
 
 public class NettyCustomPipelineFactoryAsynchTest extends BaseNettyTest {
 
-    @Produce(uri = "direct:start")
-    protected ProducerTemplate producerTemplate;
     private volatile boolean clientInvoked;
     private volatile boolean serverInvoked;
-    private String response;
-    
+
     @Override
     protected JndiRegistry createRegistry() throws Exception {
         JndiRegistry registry = super.createRegistry();
@@ -48,36 +43,28 @@ public class NettyCustomPipelineFactoryA
         registry.bind("spf", new TestServerChannelPipelineFactory(null));
         return registry;
     }
-    
+
     @Override
-    public boolean isUseRouteBuilder() {
-        return false;
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("netty:tcp://localhost:{{port}}?serverPipelineFactory=#spf&textline=true")
+                        .process(new Processor() {
+                            public void process(Exchange exchange) throws Exception {
+                                exchange.getOut().setBody("Forrest Gump: We was always taking long walks, and we was always looking for a guy named 'Charlie'");
+                            }
+                        });
+            }
+        };
     }
 
-    private void sendRequest() throws Exception {
-        // Async request
-        response = (String) producerTemplate.requestBody(
-            "netty:tcp://localhost:{{port}}?clientPipelineFactory=#cpf&textline=true",
-            "Forest Gump describing Vietnam...");        
-    }
-    
     @Test
     public void testCustomClientPipelineFactory() throws Exception {
-        context.addRoutes(new RouteBuilder() {
-            public void configure() {
-                from("netty:tcp://localhost:{{port}}?serverPipelineFactory=#spf&textline=true")
-                    .process(new Processor() {
-                        public void process(Exchange exchange) throws Exception {
-                            exchange.getOut().setBody("Forrest Gump: We was always taking long walks, and we was always looking for a guy named 'Charlie'");                           
-                        }
-                    });                
-            }
-        });
-        context.start();
+        String response = (String) template.requestBody(
+                "netty:tcp://localhost:{{port}}?clientPipelineFactory=#cpf&textline=true",
+                "Forest Gump describing Vietnam...");
 
-        sendRequest();
-        context.stop();
-        
         assertEquals("Forrest Gump: We was always taking long walks, and we was always looking for a guy named 'Charlie'", response);
         assertEquals(true, clientInvoked);
         assertEquals(true, serverInvoked);

Modified: camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyCustomPipelineFactorySynchTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyCustomPipelineFactorySynchTest.java?rev=1424897&r1=1424896&r2=1424897&view=diff
==============================================================================
--- camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyCustomPipelineFactorySynchTest.java (original)
+++ camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyCustomPipelineFactorySynchTest.java Fri Dec 21 12:44:05 2012
@@ -18,8 +18,6 @@ package org.apache.camel.component.netty
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
-import org.apache.camel.Produce;
-import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.netty.handlers.ClientChannelHandler;
 import org.apache.camel.component.netty.handlers.ServerChannelHandler;
@@ -35,12 +33,9 @@ import org.junit.Test;
 
 public class NettyCustomPipelineFactorySynchTest extends BaseNettyTest {
 
-    @Produce(uri = "direct:start")
-    protected ProducerTemplate producerTemplate;
     private volatile boolean clientInvoked;
     private volatile boolean serverInvoked;
-    private String response;
-    
+
     @Override
     protected JndiRegistry createRegistry() throws Exception {
         JndiRegistry registry = super.createRegistry();
@@ -50,34 +45,26 @@ public class NettyCustomPipelineFactoryS
     }
     
     @Override
-    public boolean isUseRouteBuilder() {
-        return false;
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("netty:tcp://localhost:{{port}}?serverPipelineFactory=#spf&sync=true&textline=true")
+                        .process(new Processor() {
+                            public void process(Exchange exchange) throws Exception {
+                                exchange.getOut().setBody("Forrest Gump: We was always taking long walks, and we was always looking for a guy named 'Charlie'");
+                            }
+                        });
+            }
+        };
     }
 
-    private void sendRequest() throws Exception {
-        // Async request
-        response = (String) producerTemplate.requestBody(
-            "netty:tcp://localhost:{{port}}?clientPipelineFactory=#cpf&sync=true&textline=true",
-            "Forest Gump describing Vietnam...");        
-    }
-    
     @Test
     public void testCustomClientPipelineFactory() throws Exception {
-        context.addRoutes(new RouteBuilder() {
-            public void configure() {
-                from("netty:tcp://localhost:{{port}}?serverPipelineFactory=#spf&sync=true&textline=true")
-                    .process(new Processor() {
-                        public void process(Exchange exchange) throws Exception {
-                            exchange.getOut().setBody("Forrest Gump: We was always taking long walks, and we was always looking for a guy named 'Charlie'");                           
-                        }
-                    });                
-            }
-        });
-        context.start();
-        
-        sendRequest();
-        context.stop();
-        
+        String response = (String) template.requestBody(
+                "netty:tcp://localhost:{{port}}?clientPipelineFactory=#cpf&sync=true&textline=true",
+                "Forest Gump describing Vietnam...");
+
         assertEquals("Forrest Gump: We was always taking long walks, and we was always looking for a guy named 'Charlie'", response);
         assertEquals(true, clientInvoked);
         assertEquals(true, serverInvoked);

Modified: camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyTCPAsyncTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyTCPAsyncTest.java?rev=1424897&r1=1424896&r2=1424897&view=diff
==============================================================================
--- camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyTCPAsyncTest.java (original)
+++ camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyTCPAsyncTest.java Fri Dec 21 12:44:05 2012
@@ -23,8 +23,6 @@ import org.apache.camel.EndpointInject;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.Processor;
-import org.apache.camel.Produce;
-import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.converter.IOConverter;
@@ -35,11 +33,9 @@ import org.junit.Test;
 public class NettyTCPAsyncTest extends BaseNettyTest {
     @EndpointInject(uri = "mock:result")
     protected MockEndpoint resultEndpoint;
-    @Produce(uri = "direct:start")
-    protected ProducerTemplate producerTemplate;
-    
+
     private void sendFile(String uri) throws Exception {
-        producerTemplate.send(uri, new Processor() {
+        template.send(uri, new Processor() {
             public void process(Exchange exchange) throws Exception {
                 // Read from an input stream
                 InputStream is = IOHelper.buffered(new FileInputStream("src/test/resources/test.txt"));

Modified: camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyTCPSyncNotLazyChannelTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyTCPSyncNotLazyChannelTest.java?rev=1424897&r1=1424896&r2=1424897&view=diff
==============================================================================
--- camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyTCPSyncNotLazyChannelTest.java (original)
+++ camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyTCPSyncNotLazyChannelTest.java Fri Dec 21 12:44:05 2012
@@ -18,19 +18,14 @@ package org.apache.camel.component.netty
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
-import org.apache.camel.Produce;
-import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
 import org.junit.Test;
 
 public class NettyTCPSyncNotLazyChannelTest extends BaseNettyTest {
 
-    @Produce(uri = "direct:start")
-    protected ProducerTemplate producerTemplate;
-
     @Test
     public void testTCPStringInOutWithNettyConsumer() throws Exception {
-        String response = producerTemplate.requestBody(
+        String response = template.requestBody(
             "netty:tcp://localhost:{{port}}?sync=true&lazyChannelCreation=false",
             "Epitaph in Kohima, India marking the WWII Battle of Kohima and Imphal, Burma Campaign - Attributed to John Maxwell Edmonds", String.class);
         assertEquals("When You Go Home, Tell Them Of Us And Say, For Your Tomorrow, We Gave Our Today.", response);
@@ -39,7 +34,7 @@ public class NettyTCPSyncNotLazyChannelT
     @Test
     public void testTCPObjectInOutWithNettyConsumer() throws Exception {
         Poetry poetry = new Poetry();
-        Poetry response = (Poetry) producerTemplate.requestBody("netty:tcp://localhost:{{port}}?sync=true&lazyChannelCreation=false", poetry);
+        Poetry response = (Poetry) template.requestBody("netty:tcp://localhost:{{port}}?sync=true&lazyChannelCreation=false", poetry);
         assertEquals("Dr. Sarojini Naidu", response.getPoet());
     }
 

Modified: camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyTCPSyncTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyTCPSyncTest.java?rev=1424897&r1=1424896&r2=1424897&view=diff
==============================================================================
--- camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyTCPSyncTest.java (original)
+++ camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyTCPSyncTest.java Fri Dec 21 12:44:05 2012
@@ -18,19 +18,14 @@ package org.apache.camel.component.netty
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
-import org.apache.camel.Produce;
-import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
 import org.junit.Test;
 
 public class NettyTCPSyncTest extends BaseNettyTest {
     
-    @Produce(uri = "direct:start")
-    protected ProducerTemplate producerTemplate;
-
     @Test
     public void testTCPStringInOutWithNettyConsumer() throws Exception {
-        String response = producerTemplate.requestBody(
+        String response = template.requestBody(
             "netty:tcp://localhost:{{port}}?sync=true",
             "Epitaph in Kohima, India marking the WWII Battle of Kohima and Imphal, Burma Campaign - Attributed to John Maxwell Edmonds", String.class);        
         assertEquals("When You Go Home, Tell Them Of Us And Say, For Your Tomorrow, We Gave Our Today.", response);
@@ -38,12 +33,12 @@ public class NettyTCPSyncTest extends Ba
 
     @Test
     public void testTCPStringInOutWithNettyConsumer2Times() throws Exception {
-        String response = producerTemplate.requestBody(
+        String response = template.requestBody(
             "netty:tcp://localhost:{{port}}?sync=true",
             "Epitaph in Kohima, India marking the WWII Battle of Kohima and Imphal, Burma Campaign - Attributed to John Maxwell Edmonds", String.class);
         assertEquals("When You Go Home, Tell Them Of Us And Say, For Your Tomorrow, We Gave Our Today.", response);
 
-        response = producerTemplate.requestBody(
+        response = template.requestBody(
             "netty:tcp://localhost:{{port}}?sync=true",
             "Hello World", String.class);
         assertEquals("When You Go Home, Tell Them Of Us And Say, For Your Tomorrow, We Gave Our Today.", response);
@@ -52,7 +47,7 @@ public class NettyTCPSyncTest extends Ba
     @Test
     public void testTCPObjectInOutWithNettyConsumer() throws Exception {
         Poetry poetry = new Poetry();
-        Poetry response = (Poetry) producerTemplate.requestBody("netty:tcp://localhost:{{port}}?sync=true", poetry);
+        Poetry response = (Poetry) template.requestBody("netty:tcp://localhost:{{port}}?sync=true", poetry);
         assertEquals("Dr. Sarojini Naidu", response.getPoet());
     }
     

Modified: camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyTransferExchangeOptionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyTransferExchangeOptionTest.java?rev=1424897&r1=1424896&r2=1424897&view=diff
==============================================================================
--- camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyTransferExchangeOptionTest.java (original)
+++ camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyTransferExchangeOptionTest.java Fri Dec 21 12:44:05 2012
@@ -57,7 +57,13 @@ public class NettyTransferExchangeOption
 
         Producer producer = endpoint.createProducer();
         producer.start();
-        producer.process(exchange);
+
+        // ensure to stop producer after usage
+        try {
+            producer.process(exchange);
+        } finally {
+            producer.stop();
+        }
 
         return exchange;
     }