This is an automated email from the ASF dual-hosted git repository. orpiske pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit 9dc039f4429a25e1d469955de9c60f414e7d0a62 Author: Otavio Rodolfo Piske <angusyo...@gmail.com> AuthorDate: Fri Mar 1 12:47:27 2024 +0100 CAMEL-20477: split flaky transacted test --- .../spring/tx/JmsToJmsTransactedIT.java | 43 +++--------- .../tx/JmsToJmsTransactedMarkRollbackIT.java | 79 ++++++++++++++++++++++ .../spring/tx/JmsToJmsTransactedMarkRollbackIT.xml | 56 +++++++++++++++ 3 files changed, 143 insertions(+), 35 deletions(-) diff --git a/components/camel-jms/src/test/java/org/apache/camel/component/jms/integration/spring/tx/JmsToJmsTransactedIT.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/integration/spring/tx/JmsToJmsTransactedIT.java index 348c1cc64cc..10591e5451c 100644 --- a/components/camel-jms/src/test/java/org/apache/camel/component/jms/integration/spring/tx/JmsToJmsTransactedIT.java +++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/integration/spring/tx/JmsToJmsTransactedIT.java @@ -21,11 +21,13 @@ import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.test.infra.artemis.services.ArtemisService; import org.apache.camel.test.infra.artemis.services.ArtemisServiceFactory; import org.apache.camel.test.spring.junit5.CamelSpringTestSupport; -import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tags; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -33,8 +35,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @TestInstance(TestInstance.Lifecycle.PER_METHOD) @Tags({ @Tag("not-parallel"), @Tag("spring"), @Tag("tx") }) +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) public final class JmsToJmsTransactedIT extends CamelSpringTestSupport { + @Order(0) @RegisterExtension public static ArtemisService service = ArtemisServiceFactory.createVMService(); @@ -47,18 +51,13 @@ public final class JmsToJmsTransactedIT extends CamelSpringTestSupport { return service.serviceAddress(); } - @BeforeEach - public void beforeEach() { - service.shutdown(); - service.initialize(); - } - @Override protected ClassPathXmlApplicationContext createApplicationContext() { return new ClassPathXmlApplicationContext( "/org/apache/camel/component/jms/integration/spring/tx/JmsToJmsTransactedIT.xml"); } + @Order(1) @Test public void testJmsToJmsTestOK() throws Exception { context.addRoutes(new RouteBuilder() { @@ -77,6 +76,7 @@ public final class JmsToJmsTransactedIT extends CamelSpringTestSupport { assertEquals("Hello World", reply); } + @Order(2) @Test public void testJmsToJmsTestRollbackDueToException() throws Exception { context.addRoutes(new RouteBuilder() { @@ -104,6 +104,7 @@ public final class JmsToJmsTransactedIT extends CamelSpringTestSupport { MockEndpoint.assertIsSatisfied(context); } + @Order(3) @Test public void testJmsToJmsTestRollbackDueToRollback() throws Exception { context.addRoutes(new RouteBuilder() { @@ -134,32 +135,4 @@ public final class JmsToJmsTransactedIT extends CamelSpringTestSupport { Object body = consumer.receiveBody("activemq:queue:DLQ", 2000); assertEquals("Hello World", body); } - - @Test - public void testJmsToJmsTestRollbackDueToMarkRollbackOnly() throws Exception { - context.addRoutes(new RouteBuilder() { - @Override - public void configure() { - from("activemq:queue:JmsToJmsTransactedIT") - .transacted() - .to("mock:start") - .to("activemq:queue:JmsToJmsTransactedIT.reply") - .markRollbackOnly(); - - from("activemq:queue:JmsToJmsTransactedIT.reply").to("log:bar").to("mock:bar"); - } - }); - context.start(); - - MockEndpoint bar = getMockEndpoint("mock:bar"); - bar.expectedMessageCount(0); - - MockEndpoint start = getMockEndpoint("mock:start"); - start.expectedMessageCount(7); // default number of redeliveries by AMQ is 6 so we get 6+1 - - template.sendBody("activemq:queue:JmsToJmsTransactedIT", "Hello World"); - - MockEndpoint.assertIsSatisfied(context); - } - } diff --git a/components/camel-jms/src/test/java/org/apache/camel/component/jms/integration/spring/tx/JmsToJmsTransactedMarkRollbackIT.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/integration/spring/tx/JmsToJmsTransactedMarkRollbackIT.java new file mode 100644 index 00000000000..b69c53ca0b6 --- /dev/null +++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/integration/spring/tx/JmsToJmsTransactedMarkRollbackIT.java @@ -0,0 +1,79 @@ +/* + * 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.integration.spring.tx; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.infra.artemis.services.ArtemisService; +import org.apache.camel.test.infra.artemis.services.ArtemisServiceFactory; +import org.apache.camel.test.spring.junit5.CamelSpringTestSupport; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Tags; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +@Tags({ @Tag("not-parallel"), @Tag("spring"), @Tag("tx") }) +public final class JmsToJmsTransactedMarkRollbackIT extends CamelSpringTestSupport { + + @Order(0) + @RegisterExtension + public static ArtemisService service = ArtemisServiceFactory.createVMService(); + + /** + * Used by spring xml configurations + * + * @return + */ + public static String getServiceAddress() { + return service.serviceAddress(); + } + + @Override + protected ClassPathXmlApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext( + "/org/apache/camel/component/jms/integration/spring/tx/JmsToJmsTransactedMarkRollbackIT.xml"); + } + + @Test + public void testJmsToJmsTestRollbackDueToMarkRollbackOnly() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() { + from("activemq:queue:JmsToJmsTransactedMarkRollbackIT") + .transacted() + .to("mock:start") + .to("activemq:queue:JmsToJmsTransactedMarkRollbackIT.reply") + .markRollbackOnly(); + + from("activemq:queue:JmsToJmsTransactedMarkRollbackIT.reply").to("log:bar").to("mock:bar"); + } + }); + context.start(); + + MockEndpoint bar = getMockEndpoint("mock:bar"); + bar.expectedMessageCount(0); + + MockEndpoint start = getMockEndpoint("mock:start"); + start.expectedMessageCount(7); // default number of redeliveries by AMQ is 6 so we get 6+1 + + template.sendBody("activemq:queue:JmsToJmsTransactedMarkRollbackIT", "Hello World"); + + MockEndpoint.assertIsSatisfied(context); + } +} diff --git a/components/camel-jms/src/test/resources/org/apache/camel/component/jms/integration/spring/tx/JmsToJmsTransactedMarkRollbackIT.xml b/components/camel-jms/src/test/resources/org/apache/camel/component/jms/integration/spring/tx/JmsToJmsTransactedMarkRollbackIT.xml new file mode 100644 index 00000000000..ea308535586 --- /dev/null +++ b/components/camel-jms/src/test/resources/org/apache/camel/component/jms/integration/spring/tx/JmsToJmsTransactedMarkRollbackIT.xml @@ -0,0 +1,56 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:camel="http://camel.apache.org/schema/spring" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> + + <bean id="poolConnectionFactory" class="org.messaginghub.pooled.jms.JmsPoolConnectionFactory" init-method="start" destroy-method="stop"> + <property name="maxConnections" value="8"/> + <property name="connectionFactory" ref="jmsConnectionFactory"/> + </bean> + + <bean id="jmsConnectionFactory" class="org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory"> + <property name="brokerURL"> + <bean class="org.apache.camel.component.jms.integration.spring.tx.JmsToJmsTransactedMarkRollbackIT" factory-method="getServiceAddress"/> + </property> + </bean> + + <bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager"> + <property name="connectionFactory" ref="poolConnectionFactory"/> + </bean> + + <bean id="activemq" class="org.apache.camel.component.jms.JmsComponent"> + <property name="connectionFactory" ref="poolConnectionFactory"/> + <property name="transacted" value="true"/> + <property name="transactionManager" ref="jmsTransactionManager"/> + </bean> + + <bean id="activemq2" class="org.apache.camel.component.jms.JmsComponent"> + <property name="connectionFactory"> + <bean class="org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory"> + <property name="brokerURL" value="vm://localhost?broker.persistent=false&broker.useJmx=false"/> + </bean> + </property> + </bean> + +</beans>