From d3e5459c2cf30ba930b03143b6fa268d985a3b50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20NUSSBAUMER?= Date: Mon, 17 Jan 2022 08:36:08 +0100 Subject: [PATCH] GH-2266 Add test to ensure GlobalChannelInterceptor is not added multiple times to the MessageChannels --- .../stream/function/StreamBridgeTests.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/StreamBridgeTests.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/StreamBridgeTests.java index b314e2a23..67ff492d9 100644 --- a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/StreamBridgeTests.java +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/function/StreamBridgeTests.java @@ -41,6 +41,7 @@ import org.springframework.cloud.stream.binding.NewDestinationBindingCallback; import org.springframework.cloud.stream.config.BindingServiceProperties; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; +import org.springframework.integration.channel.AbstractMessageChannel; import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.config.GlobalChannelInterceptor; import org.springframework.integration.dsl.IntegrationFlow; @@ -185,6 +186,27 @@ public class StreamBridgeTests { } } + @Test + public void testInterceptorIsNotAddedMultipleTimesToTheMessageChannel() { + try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration + .getCompleteConfiguration(InterceptorConfiguration.class)) + .web(WebApplicationType.NONE).run( + "--spring.jmx.enabled=false", + "--spring.cloud.stream.dynamic-destination-cache-size=1", + "--spring.cloud.stream.source=outputA;outputB", + "--spring.cloud.stream.bindings.outputA-out-0.destination=outputA", + "--spring.cloud.stream.bindings.outputB-out-0.destination=outputB")) { + StreamBridge bridge = context.getBean(StreamBridge.class); + + bridge.send("outputA-out-0", "hello foo"); + bridge.send("outputA-out-0", "hello foo"); + + AbstractMessageChannel messageChannel = context.getBean("outputA-out-0", AbstractMessageChannel.class); + + assertThat(messageChannel.getInterceptors()).hasSize(1); + } + } + @Test public void testWithInterceptorsRegisteredOnlyOnOutputChannel() throws InterruptedException { try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration