From 5d1fd5db581e0e40b53708aa3c7fbbffd2085be3 Mon Sep 17 00:00:00 2001 From: onobc Date: Thu, 27 Jan 2022 20:33:46 -0600 Subject: [PATCH] Fix rabbit sink IT OwnConnectionTest * Check boot connection factory destroyed earlier in test * Check rabbit template not using boot connection factory --- .../app/sink/rabbit/OwnConnectionTest.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/applications/sink/rabbit-sink/src/test/java/org/springframework/cloud/stream/app/sink/rabbit/OwnConnectionTest.java b/applications/sink/rabbit-sink/src/test/java/org/springframework/cloud/stream/app/sink/rabbit/OwnConnectionTest.java index d6680795..aaba0346 100644 --- a/applications/sink/rabbit-sink/src/test/java/org/springframework/cloud/stream/app/sink/rabbit/OwnConnectionTest.java +++ b/applications/sink/rabbit-sink/src/test/java/org/springframework/cloud/stream/app/sink/rabbit/OwnConnectionTest.java @@ -25,6 +25,10 @@ import org.springframework.test.context.TestPropertySource; import static org.assertj.core.api.Assertions.assertThat; +/** + * @author Soby Chacko + * @author Chris Bono + */ @TestPropertySource(properties = {"rabbit.routingKey=scsapp-testOwn", "rabbit.own-connection=true"}) public class OwnConnectionTest extends RabbitSinkIntegrationTests { @@ -33,12 +37,18 @@ public class OwnConnectionTest extends RabbitSinkIntegrationTests { public void test() { this.rabbitAdmin.declareQueue( new Queue("scsapp-testOwn", false, false, true)); - this.bootFactory.resetConnection(); - this.channels.send(MessageBuilder.withPayload("foo".getBytes()) - .build()); + + // Destroy the boot connection factory - should not matter to outbound adapter as it SHOULD be using its own connection factory + this.bootFactory.destroy(); + assertThat(this.bootFactory.getCacheProperties().getProperty("localPort")).isEqualTo("0"); + + // Send to the channel - should still be consumed by outbound adapter as its using its own connection factory + this.channels.send(MessageBuilder.withPayload("foo".getBytes()).build()); + + // RabbitTemplate also using its own connection factory - should still be able to get the message + assertThat(this.rabbitTemplate.getConnectionFactory()).isNotSameAs(bootFactory); this.rabbitTemplate.setReceiveTimeout(10000); Message received = this.rabbitTemplate.receive("scsapp-testOwn"); assertThat(new String(received.getBody())).isEqualTo("foo"); - assertThat(this.bootFactory.getCacheProperties().getProperty("localPort")).isEqualTo("0"); } }