Author: davsclaus
Date: Sun Nov 29 15:10:16 2009
New Revision: 885238
URL: http://svn.apache.org/viewvc?rev=885238&view=rev
Log:
Added TX unit test and tried to fix another test which occationally fails.
Added:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JmsToJmsTransactedTest.java
(with props)
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JmsToJmsTransactedTest.xml
(contents, props changed)
- copied, changed from r885196,
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/TransactionMinimalConfigurationTest.xml
Modified:
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsMultipleConsumersTest.java
Modified:
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java?rev=885238&r1=885237&r2=885238&view=diff
==============================================================================
---
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java
(original)
+++
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java
Sun Nov 29 15:10:16 2009
@@ -242,14 +242,14 @@
if (endpoint.isTransferException() && body instanceof
Exception) {
if (LOG.isDebugEnabled()) {
- LOG.debug("Reply recieved. Setting reply as an
Exception: " + body);
+ LOG.debug("Reply received. Setting reply as an
Exception: " + body);
}
// we got an exception back and endpoint was configured to
transfer exception
// therefore set response as exception
exchange.setException((Exception) body);
} else {
if (LOG.isDebugEnabled()) {
- LOG.debug("Reply recieved. Setting reply as OUT
message: " + body);
+ LOG.debug("Reply received. Setting reply as OUT
message: " + body);
}
// regular response
exchange.setOut(response);
@@ -295,7 +295,7 @@
destinationName = null;
}
- // we must honor these special flags to preverse QoS
+ // we must honor these special flags to preserve QoS
if (!endpoint.isPreserveMessageQos() &&
!endpoint.isExplicitQosEnabled()) {
Object replyTo = exchange.getIn().getHeader("JMSReplyTo");
if (replyTo != null) {
Modified:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsMultipleConsumersTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsMultipleConsumersTest.java?rev=885238&r1=885237&r2=885238&view=diff
==============================================================================
---
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsMultipleConsumersTest.java
(original)
+++
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsMultipleConsumersTest.java
Sun Nov 29 15:10:16 2009
@@ -42,6 +42,9 @@
});
context.start();
+ // give it a bit time to setup both topic listeners
+ Thread.sleep(2000);
+
getMockEndpoint("mock:foo").expectedMessageCount(1);
getMockEndpoint("mock:bar").expectedMessageCount(1);
getMockEndpoint("mock:result").expectedMessageCount(0);
Added:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JmsToJmsTransactedTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JmsToJmsTransactedTest.java?rev=885238&view=auto
==============================================================================
---
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JmsToJmsTransactedTest.java
(added)
+++
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JmsToJmsTransactedTest.java
Sun Nov 29 15:10:16 2009
@@ -0,0 +1,144 @@
+/**
+ * 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.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision$
+ */
+public class JmsToJmsTransactedTest extends CamelSpringTestSupport {
+
+ protected ClassPathXmlApplicationContext createApplicationContext() {
+ return new
ClassPathXmlApplicationContext("/org/apache/camel/component/jms/tx/JmsToJmsTransactedTest.xml");
+ }
+
+ protected int getExpectedRouteCount() {
+ return 0;
+ }
+
+ @Test
+ public void testJmsToJmsTestOK() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("activemq:queue:foo")
+ .transacted()
+ .to("activemq:queue:bar");
+ }
+ });
+ context.start();
+
+ template.sendBody("activemq:queue:foo", "Hello World");
+
+ String reply = consumer.receiveBody("activemq:queue:bar", 5000,
String.class);
+ assertEquals("Hello World", reply);
+ }
+
+ @Test
+ public void testJmsToJmsTestRollbackDueToException() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("activemq:queue:foo")
+ .transacted()
+ .to("mock:start")
+ .to("activemq:queue:bar")
+ .throwException(new IllegalArgumentException("Damn"));
+
+ from("activemq:queue:bar").to("log:bar").to("mock:bar");
+ }
+ });
+ context.start();
+
+ MockEndpoint bar = getMockEndpoint("mock:bar");
+ bar.expectedMessageCount(0);
+
+ MockEndpoint start = getMockEndpoint("mock:start");
+ start.expectedMessageCount(6); // default number of redeliveries by AMQ
+
+ template.sendBody("activemq:queue:foo", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testJmsToJmsTestRollbackDueToRollback() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("activemq:queue:foo")
+ .transacted()
+ .to("mock:start")
+ .to("activemq:queue:bar")
+ .rollback();
+
+ from("activemq:queue:bar").to("log:bar").to("mock:bar");
+ }
+ });
+ context.start();
+
+ MockEndpoint bar = getMockEndpoint("mock:bar");
+ bar.expectedMessageCount(0);
+
+ MockEndpoint start = getMockEndpoint("mock:start");
+ start.expectedMessageCount(6); // default number of redeliveries by AMQ
+
+ template.sendBody("activemq:queue:foo", "Hello World");
+
+ assertMockEndpointsSatisfied();
+
+ // it should be moved to DLQ in JMS broker
+ Object body = consumer.receiveBody("activemq:queue:ActiveMQ.DLQ",
2000);
+ assertEquals("Hello World", body);
+ }
+
+ @Test
+ @Ignore("markRollbackOnly causes Spring TX to not let JMS redeliver!")
+ public void testJmsToJmsTestRollbackDueToMarkRollbackOnly() throws
Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("activemq:queue:foo")
+ .transacted()
+ .to("mock:start")
+ .to("activemq:queue:bar")
+ .markRollbackOnly();
+
+ from("activemq:queue:bar").to("log:bar").to("mock:bar");
+ }
+ });
+ context.start();
+
+ MockEndpoint bar = getMockEndpoint("mock:bar");
+ bar.expectedMessageCount(0);
+
+ // TODO: mark rollback only causes Spring TX to not rollback on JMS
queue
+ MockEndpoint start = getMockEndpoint("mock:start");
+ start.expectedMessageCount(6);
+
+ template.sendBody("activemq:queue:foo", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+}
Propchange:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JmsToJmsTransactedTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JmsToJmsTransactedTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Copied:
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JmsToJmsTransactedTest.xml
(from r885196,
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/TransactionMinimalConfigurationTest.xml)
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JmsToJmsTransactedTest.xml?p2=camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JmsToJmsTransactedTest.xml&p1=camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/TransactionMinimalConfigurationTest.xml&r1=885196&r2=885238&rev=885238&view=diff
==============================================================================
---
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/TransactionMinimalConfigurationTest.xml
(original)
+++
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JmsToJmsTransactedTest.xml
Sun Nov 29 15:10:16 2009
@@ -22,45 +22,22 @@
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
- <!-- START SNIPPET: e1 -->
- <!-- setup JMS connection factory -->
<bean id="jmsConnectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL"
value="vm://localhost?broker.persistent=false&broker.useJmx=false"/>
</bean>
- <!-- setup spring jms TX manager -->
<bean id="jmsTransactionManager"
class="org.springframework.jms.connection.JmsTransactionManager">
<property name="connectionFactory" ref="jmsConnectionFactory"/>
</bean>
- <!-- define our activemq component -->
<bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="connectionFactory" ref="jmsConnectionFactory"/>
- <!-- define the jms consumer/producer as transacted -->
<property name="transacted" value="true"/>
- <!-- setup the transaction manager to use -->
- <!-- if not provided then Camel will automatic use a
JmsTransactionManager, however if you
- for instance use a JTA transaction manager then you must
configure it -->
<property name="transactionManager" ref="jmsTransactionManager"/>
</bean>
- <!-- END SNIPPET: e1 -->
-
- <!-- START SNIPPET: e2 -->
- <camelContext xmlns="http://camel.apache.org/schema/spring">
- <route>
- <!-- 1: from the jms queue -->
- <from uri="activemq:queue:okay"/>
- <!-- 2: mark this route as transacted -->
- <transacted/>
- <!-- 3: call our business logic that is myProcessor -->
- <process ref="myProcessor"/>
- <!-- 4: if success then send it to the mock -->
- <to uri="mock:result"/>
- </route>
- </camelContext>
-
- <bean id="myProcessor"
class="org.apache.camel.component.jms.tx.JMSTransactionalClientTest$MyProcessor"/>
- <!-- END SNIPPET: e2 -->
+ <bean id="activemq2"
class="org.apache.activemq.camel.component.ActiveMQComponent">
+ <property name="brokerURL"
value="vm://localhost?broker.persistent=false&broker.useJmx=false"/>
+ </bean>
</beans>
Propchange:
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JmsToJmsTransactedTest.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JmsToJmsTransactedTest.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JmsToJmsTransactedTest.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml