Return-Path: Delivered-To: apmail-camel-commits-archive@www.apache.org Received: (qmail 22227 invoked from network); 4 Nov 2009 12:47:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 4 Nov 2009 12:47:30 -0000 Received: (qmail 45685 invoked by uid 500); 4 Nov 2009 12:47:30 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 45637 invoked by uid 500); 4 Nov 2009 12:47:30 -0000 Mailing-List: contact commits-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 commits@camel.apache.org Received: (qmail 45627 invoked by uid 99); 4 Nov 2009 12:47:30 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Nov 2009 12:47:30 +0000 X-ASF-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Nov 2009 12:47:27 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5A0F323888BD; Wed, 4 Nov 2009 12:47:06 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r832726 - in /camel/trunk/components/camel-jms/src/test: java/org/apache/camel/component/jms/tx/TransactedAsyncUsingThreadsTest.java resources/org/apache/camel/component/jms/tx/TransactedAsyncUsingThreadsTest.xml Date: Wed, 04 Nov 2009 12:47:06 -0000 To: commits@camel.apache.org From: davsclaus@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091104124706.5A0F323888BD@eris.apache.org> Author: davsclaus Date: Wed Nov 4 12:47:05 2009 New Revision: 832726 URL: http://svn.apache.org/viewvc?rev=832726&view=rev Log: Added JMS test for async processing which is still done in a TX Added: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/TransactedAsyncUsingThreadsTest.java (with props) camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/TransactedAsyncUsingThreadsTest.xml (contents, props changed) - copied, changed from r832658, camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/RouteIdTransactedTest.xml Added: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/TransactedAsyncUsingThreadsTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/TransactedAsyncUsingThreadsTest.java?rev=832726&view=auto ============================================================================== --- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/TransactedAsyncUsingThreadsTest.java (added) +++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/TransactedAsyncUsingThreadsTest.java Wed Nov 4 12:47:05 2009 @@ -0,0 +1,124 @@ +/** + * 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.jms.tx; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.WaitForTaskToComplete; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit4.CamelSpringTestSupport; +import org.junit.Before; +import org.junit.Test; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @version $Revision$ + */ +public class TransactedAsyncUsingThreadsTest extends CamelSpringTestSupport { + + protected ClassPathXmlApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext( + "/org/apache/camel/component/jms/tx/TransactedAsyncUsingThreadsTest.xml"); + } + + protected int getExpectedRouteCount() { + return 0; + } + + private static int counter; + private static String thread1; + private static String thread2; + + @Before + public void init() { + counter = 0; + thread1 = ""; + thread2 = ""; + } + + @Test + public void testConsumeAsyncOK() throws Exception { + counter = 1; + + getMockEndpoint("mock:result").expectedMessageCount(1); + getMockEndpoint("mock:async").expectedMessageCount(1); + + template.sendBody("activemq:queue:foo", "Hello World"); + + assertMockEndpointsSatisfied(); + + assertNotSame("Should use a different thread when doing async routing", thread1, thread2); + } + + @Test + public void testConsumeAsyncFail() throws Exception { + counter = 0; + + getMockEndpoint("mock:result").expectedMessageCount(1); + // we need a retry attempt so we get 2 messages + getMockEndpoint("mock:async").expectedMessageCount(2); + + // the 1st message is the original message + getMockEndpoint("mock:async").message(0).header("JMSRedelivered").isEqualTo(false); + + // the 2nd message is the redelivered by the JMS broker + getMockEndpoint("mock:async").message(1).header("JMSRedelivered").isEqualTo(true); + + template.sendBody("activemq:queue:foo", "Bye World"); + + assertMockEndpointsSatisfied(); + + assertNotSame("Should use a different thread when doing async routing", thread1, thread2); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("activemq:queue:foo") + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + thread1 = Thread.currentThread().getName(); + } + }) + // use transacted routing + .transacted() + // use async threads to process the exchange from this point forward + // but let the consumer wait until the async routing is complete + // so we can let the transaction commit or rollback depending how it went + .threads(5).waitForTaskToComplete(WaitForTaskToComplete.Always) + // send to mock for verification + .to("mock:async") + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + thread2 = Thread.currentThread().getName(); + + if (counter++ == 0) { + // simulate error so we can test rollback and have the JMS broker + // do redelivery + throw new IllegalAccessException("Damn"); + } + } + }).to("mock:result"); + + } + }; + } + + +} \ No newline at end of file Propchange: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/TransactedAsyncUsingThreadsTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/TransactedAsyncUsingThreadsTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Copied: camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/TransactedAsyncUsingThreadsTest.xml (from r832658, camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/RouteIdTransactedTest.xml) URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/TransactedAsyncUsingThreadsTest.xml?p2=camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/TransactedAsyncUsingThreadsTest.xml&p1=camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/RouteIdTransactedTest.xml&r1=832658&r2=832726&rev=832726&view=diff ============================================================================== (empty) Propchange: camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/TransactedAsyncUsingThreadsTest.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/TransactedAsyncUsingThreadsTest.xml ------------------------------------------------------------------------------ svn:keywords = Rev Date Propchange: camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/TransactedAsyncUsingThreadsTest.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml