Return-Path: X-Original-To: apmail-camel-dev-archive@www.apache.org Delivered-To: apmail-camel-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 43888972E for ; Tue, 10 Apr 2012 06:21:43 +0000 (UTC) Received: (qmail 51845 invoked by uid 500); 10 Apr 2012 06:21:43 -0000 Delivered-To: apmail-camel-dev-archive@camel.apache.org Received: (qmail 51524 invoked by uid 500); 10 Apr 2012 06:21:39 -0000 Mailing-List: contact dev-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list dev@camel.apache.org Delivered-To: moderator for dev@camel.apache.org Received: (qmail 25217 invoked by uid 99); 10 Apr 2012 06:10:36 -0000 X-ASF-Spam-Status: No, hits=2.0 required=5.0 tests=SPF_NEUTRAL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: 216.139.236.26 is neither permitted nor denied by domain of tenderice@gmail.com) Date: Mon, 9 Apr 2012 23:10:07 -0700 (PDT) From: tenderice To: dev@camel.apache.org Message-ID: <1334038207084-5629063.post@n5.nabble.com> In-Reply-To: <1333994513733-5627926.post@n5.nabble.com> References: <1333994513733-5627926.post@n5.nabble.com> Subject: Re: camel-netty bug and the need of best practice for creating referenced parameter object on looking-up MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org below is a very simple testcase for this problem, due to the random nature of the bug, you can get different result each time you run the program. However, if you create a new decoder in the pipelinefactory each time, you get the correct result. The idea of the test is: create two endpoint, listening on two port, send data to these ports, first send port of data to port1, the send some thing to port two, then send rest data to port1. we expect that port1 receive all data correctly. ///////////////////////////////////////////////////////////////////////////////////////////// package org.apache.camel.component.netty; import java.io.BufferedOutputStream; import java.io.IOException; import java.io.OutputStream; import java.net.Socket; import java.net.UnknownHostException; import java.util.Arrays; import java.util.concurrent.TimeUnit; import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.impl.JndiRegistry; import org.jboss.netty.buffer.BigEndianHeapChannelBuffer; import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; import org.jboss.netty.handler.codec.frame.LengthFieldPrepender; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class UnsharableCodecsConflictsTest extends BaseNettyTest { private static final Logger logger = LoggerFactory .getLogger(UnsharableCodecsConflictsTest.class); static final byte[] lengthHeader = { 0x00, 0x00, 0x40, 0x00 }; // 4096 bytes private Processor processor = new P(); @Override protected JndiRegistry createRegistry() throws Exception { JndiRegistry registry = super.createRegistry(); // START SNIPPET: registry-beans LengthFieldBasedFrameDecoder lengthDecoder = new LengthFieldBasedFrameDecoder( 1048576, 0, 4, 0, 4); registry.bind("length-decoder", lengthDecoder); LengthFieldPrepender lengthEncoder = new LengthFieldPrepender(4); registry.bind("length-encoder", lengthEncoder); // END SNIPPET: registry-beans return registry; } @Test public void canSupplyMultipleCodecsToEndpointPipeline() throws Exception { byte[] s8888 = new byte[8192]; byte[] s9999 = new byte[16383]; Arrays.fill(s8888, (byte) 0x38); Arrays.fill(s9999, (byte) 0x39); byte[] body8888 = (new String(lengthHeader) + new String(s8888)) .getBytes(); byte[] body9999 = (new String(lengthHeader) + new String(s9999)) .getBytes(); MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedBodiesReceived(new String(s9999)+"9"); Socket server1 = getSocket("localhost", 8888); Socket server2 = getSocket("localhost", 9999); try { sendSopBuffer(body9999, server2); sendSopBuffer(body8888, server1); sendSopBuffer(new String("9").getBytes(), server2); } catch (Exception e) { logger.error("", e); } server1.close(); server2.close(); mock.await(10, TimeUnit.SECONDS); mock.assertIsSatisfied(); } protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() throws Exception { from( "netty:tcp://localhost:8888?decoder=#length-decoder&sync=false") .process(processor); from( "netty:tcp://localhost:9999?decoder=#length-decoder&sync=false") .process(processor).to("mock:result"); } }; } private static Socket getSocket(String host, int port) throws UnknownHostException, IOException { Socket s = new Socket(host, port); s.setSoTimeout(60000); return s; } public static void sendSopBuffer(byte[] buf, Socket server) throws Exception { OutputStream netOut = server.getOutputStream(); OutputStream dataOut = new BufferedOutputStream(netOut); try { dataOut.write(buf, 0, buf.length); dataOut.flush(); } catch (Exception e) { server.close(); throw (e); } finally { } } class P implements Processor { @Override public void process(Exchange exchange) throws Exception { System.out.println(exchange.getIn().getHeaders()); System.out.println(new String( ((BigEndianHeapChannelBuffer) exchange.getIn().getBody()) .array())); exchange.getOut().setBody( new String(((BigEndianHeapChannelBuffer) exchange.getIn() .getBody()).array())); } } } -- View this message in context: http://camel.465427.n5.nabble.com/camel-netty-bug-and-the-need-of-best-practice-for-creating-referenced-parameter-object-on-looking-up-tp5627926p5629063.html Sent from the Camel Development mailing list archive at Nabble.com.