You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2024/03/14 08:25:00 UTC
(camel) 02/04: CAMEL-20477: rework a shared topic test to allow tests to run concurrently
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 ddddb412468b6361240a896c005e31e90bc03d12
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Wed Mar 13 10:59:14 2024 +0100
CAMEL-20477: rework a shared topic test to allow tests to run concurrently
---
.../component/jms/TwoConsumerOnSameTopicTest.java | 132 ---------------------
.../consumers/MultipleMessagesSameTopicIT.java | 66 +++++++++++
.../consumers/SingleMessageSameTopicIT.java | 110 +++++++++++++++++
3 files changed, 176 insertions(+), 132 deletions(-)
diff --git a/components/camel-jms/src/test/java/org/apache/camel/component/jms/TwoConsumerOnSameTopicTest.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/TwoConsumerOnSameTopicTest.java
deleted file mode 100644
index 4d5fda5ed46..00000000000
--- a/components/camel-jms/src/test/java/org/apache/camel/component/jms/TwoConsumerOnSameTopicTest.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * 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;
-
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.awaitility.Awaitility;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Nested;
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-public class TwoConsumerOnSameTopicTest extends AbstractPersistentJMSTest {
-
- @Nested
- class MultipleMessagesTest {
- @Test
- public void testMultipleMessagesOnSameTopic() throws Exception {
- getMockEndpoint("mock:a").expectedBodiesReceived("Hello Camel 1", "Hello Camel 2", "Hello Camel 3",
- "Hello Camel 4");
- getMockEndpoint("mock:b").expectedBodiesReceived("Hello Camel 1", "Hello Camel 2", "Hello Camel 3",
- "Hello Camel 4");
-
- template.sendBody("activemq:topic:TwoConsumerOnSameTopicTest", "Hello Camel 1");
- template.sendBody("activemq:topic:TwoConsumerOnSameTopicTest", "Hello Camel 2");
- template.sendBody("activemq:topic:TwoConsumerOnSameTopicTest", "Hello Camel 3");
- template.sendBody("activemq:topic:TwoConsumerOnSameTopicTest", "Hello Camel 4");
-
- MockEndpoint.assertIsSatisfied(context);
- }
- }
-
- @Nested
- class SingleMessageTest {
-
- @BeforeEach
- void prepare() {
- getMockEndpoint("mock:a").expectedBodiesReceived("Hello World");
- getMockEndpoint("mock:b").expectedBodiesReceived("Hello World");
-
- template.sendBody("activemq:topic:TwoConsumerOnSameTopicTest", "Hello World");
- }
-
- @Test
- void testTwoConsumerOnSameTopic() throws Exception {
- MockEndpoint.assertIsSatisfied(context);
- }
-
- @Test
- void testStopAndStartOneRoute() throws Exception {
- MockEndpoint.assertIsSatisfied(context);
-
- // now stop route A
- context.getRouteController().stopRoute("a");
-
- // send new message should go to B only
- MockEndpoint.resetMocks(context);
-
- getMockEndpoint("mock:a").expectedMessageCount(0);
- getMockEndpoint("mock:b").expectedBodiesReceived("Bye World");
-
- template.sendBody("activemq:topic:TwoConsumerOnSameTopicTest", "Bye World");
-
- MockEndpoint.assertIsSatisfied(context);
-
- // send new message should go to both A and B
- MockEndpoint.resetMocks(context);
-
- // now start route A
- context.getRouteController().startRoute("a");
-
- getMockEndpoint("mock:a").expectedBodiesReceived("Hello World");
- getMockEndpoint("mock:b").expectedBodiesReceived("Hello World");
-
- template.sendBody("activemq:topic:TwoConsumerOnSameTopicTest", "Hello World");
- }
-
- @Test
- void testRemoveOneRoute() throws Exception {
- MockEndpoint.assertIsSatisfied(context);
-
- // now stop and remove route A
- context.getRouteController().stopRoute("a");
- assertTrue(context.removeRoute("a"));
-
- // send new message should go to B only
- MockEndpoint.resetMocks(context);
-
- getMockEndpoint("mock:a").expectedMessageCount(0);
- getMockEndpoint("mock:b").expectedBodiesReceived("Bye World");
-
- template.sendBody("activemq:topic:TwoConsumerOnSameTopicTest", "Bye World");
-
- MockEndpoint.assertIsSatisfied(context);
- }
- }
-
- @BeforeEach
- void waitForConnections() {
- Awaitility.await().until(() -> context.getRoute("a").getUptimeMillis() > 200);
- Awaitility.await().until(() -> context.getRoute("a").getUptimeMillis() > 200);
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() {
- return new RouteBuilder() {
- @Override
- public void configure() {
- from("activemq:topic:TwoConsumerOnSameTopicTest").routeId("a")
- .to("log:a", "mock:a");
-
- from("activemq:topic:TwoConsumerOnSameTopicTest").routeId("b")
- .to("log:b", "mock:b");
- }
- };
- }
-}
diff --git a/components/camel-jms/src/test/java/org/apache/camel/component/jms/integration/consumers/MultipleMessagesSameTopicIT.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/integration/consumers/MultipleMessagesSameTopicIT.java
new file mode 100644
index 00000000000..2ff59fe3de7
--- /dev/null
+++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/integration/consumers/MultipleMessagesSameTopicIT.java
@@ -0,0 +1,66 @@
+/*
+ * 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.consumers;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jms.AbstractPersistentJMSTest;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.awaitility.Awaitility;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests the behavior of 2 consumers consuming multiple messages from the topic
+ */
+public class MultipleMessagesSameTopicIT extends AbstractPersistentJMSTest {
+
+ @Test
+ public void testMultipleMessagesOnSameTopic() throws Exception {
+ getMockEndpoint("mock:a").expectedBodiesReceived("Hello Camel 1", "Hello Camel 2", "Hello Camel 3",
+ "Hello Camel 4");
+ getMockEndpoint("mock:b").expectedBodiesReceived("Hello Camel 1", "Hello Camel 2", "Hello Camel 3",
+ "Hello Camel 4");
+
+ template.sendBody("activemq:topic:MultipleMessagesSameTopicIT", "Hello Camel 1");
+ template.sendBody("activemq:topic:MultipleMessagesSameTopicIT", "Hello Camel 2");
+ template.sendBody("activemq:topic:MultipleMessagesSameTopicIT", "Hello Camel 3");
+ template.sendBody("activemq:topic:MultipleMessagesSameTopicIT", "Hello Camel 4");
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+ @BeforeEach
+ void waitForConnections() {
+ Awaitility.await().until(() -> context.getRoute("a").getUptimeMillis() > 200);
+ Awaitility.await().until(() -> context.getRoute("b").getUptimeMillis() > 200);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("activemq:topic:MultipleMessagesSameTopicIT").routeId("a")
+ .to("log:a", "mock:a");
+
+ from("activemq:topic:MultipleMessagesSameTopicIT").routeId("b")
+ .to("log:b", "mock:b");
+ }
+ };
+ }
+}
diff --git a/components/camel-jms/src/test/java/org/apache/camel/component/jms/integration/consumers/SingleMessageSameTopicIT.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/integration/consumers/SingleMessageSameTopicIT.java
new file mode 100644
index 00000000000..af5e162603d
--- /dev/null
+++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/integration/consumers/SingleMessageSameTopicIT.java
@@ -0,0 +1,110 @@
+/*
+ * 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.consumers;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jms.AbstractPersistentJMSTest;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.awaitility.Awaitility;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class SingleMessageSameTopicIT extends AbstractPersistentJMSTest {
+
+ @BeforeEach
+ void prepare() {
+ getMockEndpoint("mock:a").expectedBodiesReceived("Hello World");
+ getMockEndpoint("mock:b").expectedBodiesReceived("Hello World");
+
+ template.sendBody("activemq:topic:SingleMessageSameTopicIT", "Hello World");
+ }
+
+ @Test
+ void testTwoConsumerOnSameTopic() throws Exception {
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+ @Test
+ void testStopAndStartOneRoute() throws Exception {
+ MockEndpoint.assertIsSatisfied(context);
+
+ // now stop route A
+ context.getRouteController().stopRoute("a");
+
+ // send a new message should go to B only
+ MockEndpoint.resetMocks(context);
+
+ getMockEndpoint("mock:a").expectedMessageCount(0);
+ getMockEndpoint("mock:b").expectedBodiesReceived("Bye World");
+
+ template.sendBody("activemq:topic:SingleMessageSameTopicIT", "Bye World");
+
+ MockEndpoint.assertIsSatisfied(context);
+
+ // send new message should go to both A and B
+ MockEndpoint.resetMocks(context);
+
+ // now start route A
+ context.getRouteController().startRoute("a");
+
+ getMockEndpoint("mock:a").expectedBodiesReceived("Hello World");
+ getMockEndpoint("mock:b").expectedBodiesReceived("Hello World");
+
+ template.sendBody("activemq:topic:SingleMessageSameTopicIT", "Hello World");
+ }
+
+ @Test
+ void testRemoveOneRoute() throws Exception {
+ MockEndpoint.assertIsSatisfied(context);
+
+ // now stop and remove route A
+ context.getRouteController().stopRoute("a");
+ assertTrue(context.removeRoute("a"));
+
+ // send new message should go to B only
+ MockEndpoint.resetMocks(context);
+
+ getMockEndpoint("mock:a").expectedMessageCount(0);
+ getMockEndpoint("mock:b").expectedBodiesReceived("Bye World");
+
+ template.sendBody("activemq:topic:SingleMessageSameTopicIT", "Bye World");
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+ @BeforeEach
+ void waitForConnections() {
+ Awaitility.await().until(() -> context.getRoute("a").getUptimeMillis() > 200);
+ Awaitility.await().until(() -> context.getRoute("b").getUptimeMillis() > 200);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("activemq:topic:SingleMessageSameTopicIT").routeId("a")
+ .to("log:a", "mock:a");
+
+ from("activemq:topic:SingleMessageSameTopicIT").routeId("b")
+ .to("log:b", "mock:b");
+ }
+ };
+ }
+}