Skip to content

Commit

Permalink
chore: Fix flaky synchronous JMS topic tests
Browse files Browse the repository at this point in the history
- Use async test container instead of nested parallel/sequential
- Do not consume the same topic message multiple times
  • Loading branch information
christophd committed Jan 24, 2025
1 parent d84629c commit 975ff58
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@

import static org.citrusframework.actions.ReceiveMessageAction.Builder.receive;
import static org.citrusframework.actions.SendMessageAction.Builder.send;
import static org.citrusframework.actions.SleepAction.Builder.sleep;
import static org.citrusframework.container.Parallel.Builder.parallel;
import static org.citrusframework.container.Sequence.Builder.sequential;
import static org.citrusframework.actions.SleepAction.Builder.delay;
import static org.citrusframework.container.Async.Builder.async;

@Test
public class SyncJmsTopicJavaIT extends TestNGCitrusSpringSupport {
Expand All @@ -35,58 +34,43 @@ public void syncJmsTopic() {
variable("messageId", "citrus:randomNumber(10)");
variable("user", "Christoph");

given(parallel().actions(
sequential().actions(
sleep().milliseconds(2000L),
send("syncJmsTopicEndpoint")
.message()
.body("<HelloRequest xmlns=\"http://citrusframework.org/schemas/samples/HelloService.xsd\">" +
"<MessageId>${messageId}</MessageId>" +
"<CorrelationId>${correlationId}</CorrelationId>" +
"<User>${user}</User>" +
"<Text>Hello TestFramework</Text>" +
"</HelloRequest>")
.header("Operation", "sayHello")
.header("CorrelationId", "${correlationId}")
),
sequential().actions(
parallel().actions(
receive("syncJmsTopicSubscriberEndpoint")
.message()
.body("<HelloRequest xmlns=\"http://citrusframework.org/schemas/samples/HelloService.xsd\">" +
"<MessageId>${messageId}</MessageId>" +
"<CorrelationId>${correlationId}</CorrelationId>" +
"<User>${user}</User>" +
"<Text>Hello TestFramework</Text>" +
"</HelloRequest>")
.header("Operation", "sayHello")
.header("CorrelationId", "${correlationId}"),
sequential().actions(
sleep().milliseconds(500L),
receive("syncJmsTopicSubscriberEndpoint")
.message()
.body("<HelloRequest xmlns=\"http://citrusframework.org/schemas/samples/HelloService.xsd\">" +
"<MessageId>${messageId}</MessageId>" +
"<CorrelationId>${correlationId}</CorrelationId>" +
"<User>${user}</User>" +
"<Text>Hello TestFramework</Text>" +
"</HelloRequest>")
.header("Operation", "sayHello")
.header("CorrelationId", "${correlationId}")
)
),
send("syncJmsTopicSubscriberEndpoint")
.message()
.body("<HelloResponse xmlns=\"http://citrusframework.org/schemas/samples/HelloService.xsd\">" +
"<MessageId>${messageId}</MessageId>" +
"<CorrelationId>${correlationId}</CorrelationId>" +
"<User>HelloService</User>" +
"<Text>Hello ${user}</Text>" +
"</HelloResponse>")
.header("Operation", "sayHello")
.header("CorrelationId", "${correlationId}")
)
));
given(
async().actions(receive("syncJmsTopicSubscriberEndpoint")
.message()
.body("<HelloRequest xmlns=\"http://citrusframework.org/schemas/samples/HelloService.xsd\">" +
"<MessageId>${messageId}</MessageId>" +
"<CorrelationId>${correlationId}</CorrelationId>" +
"<User>${user}</User>" +
"<Text>Hello TestFramework</Text>" +
"</HelloRequest>")
.header("Operation", "sayHello")
.header("CorrelationId", "${correlationId}"))
);

then(delay().milliseconds(2000));

when(send("syncJmsTopicEndpoint")
.fork(true)
.message()
.body("<HelloRequest xmlns=\"http://citrusframework.org/schemas/samples/HelloService.xsd\">" +
"<MessageId>${messageId}</MessageId>" +
"<CorrelationId>${correlationId}</CorrelationId>" +
"<User>${user}</User>" +
"<Text>Hello TestFramework</Text>" +
"</HelloRequest>")
.header("Operation", "sayHello")
.header("CorrelationId", "${correlationId}"));

then(send("syncJmsTopicSubscriberEndpoint")
.message()
.body("<HelloResponse xmlns=\"http://citrusframework.org/schemas/samples/HelloService.xsd\">" +
"<MessageId>${messageId}</MessageId>" +
"<CorrelationId>${correlationId}</CorrelationId>" +
"<User>HelloService</User>" +
"<Text>Hello ${user}</Text>" +
"</HelloResponse>")
.header("Operation", "sayHello")
.header("CorrelationId", "${correlationId}"));

then(receive("syncJmsTopicEndpoint")
.message()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,6 @@
<element name="CorrelationId" value="${correlationId}"/>
</header>
</receive>

<receive endpoint="syncJmsTopicSubscriberEndpoint">
<description>
Receive sync hello request from jms topic
</description>
<message>
<data>
<![CDATA[
<HelloRequest xmlns="http://citrusframework.org/schemas/samples/HelloService.xsd">
<MessageId>${messageId}</MessageId>
<CorrelationId>${correlationId}</CorrelationId>
<User>${user}</User>
<Text>Hello TestFramework</Text>
</HelloRequest>
]]>
</data>
</message>
<header>
<element name="Operation" value="sayHello"/>
<element name="CorrelationId" value="${correlationId}"/>
</header>
</receive>
</parallel>

<send endpoint="syncJmsTopicSubscriberEndpoint">
Expand Down

0 comments on commit 975ff58

Please sign in to comment.