Message Channel should be closed in specified cases : application shutdown, unbinding or exceeding cache size.

checkstyle fixes

Resolves #2869
Resolves #3026
This commit is contained in:
Ömer Çelik
2024-11-02 19:03:26 +03:00
committed by Oleg Zhurakousky
parent a9fe0c2c3c
commit dccf8ae16a
7 changed files with 184 additions and 54 deletions

View File

@@ -90,12 +90,13 @@ import static org.mockito.Mockito.when;
* @author Chris Bono
* @author Artem Bilan
* @author Kotaro Matsumoto
* @author Omer Celik
*/
class BindingServiceTests {
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
void defaultGroup() throws Exception {
void defaultGroup() {
BindingServiceProperties properties = new BindingServiceProperties();
Map<String, BindingProperties> bindingProperties = new HashMap<>();
BindingProperties props = new BindingProperties();
@@ -175,7 +176,7 @@ class BindingServiceTests {
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
void multipleConsumerBindingsFromIndexList() throws Exception {
void multipleConsumerBindingsFromIndexList() {
BindingServiceProperties properties = new BindingServiceProperties();
Map<String, BindingProperties> bindingProperties = new HashMap<>();
BindingProperties props = new BindingProperties();
@@ -236,7 +237,7 @@ class BindingServiceTests {
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
void consumerBindingWhenMultiplexingIsEnabled() throws Exception {
void consumerBindingWhenMultiplexingIsEnabled() {
BindingServiceProperties properties = new BindingServiceProperties();
Map<String, BindingProperties> bindingProperties = new HashMap<>();
BindingProperties props = new BindingProperties();
@@ -282,7 +283,7 @@ class BindingServiceTests {
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
void explicitGroup() throws Exception {
void explicitGroup() {
BindingServiceProperties properties = new BindingServiceProperties();
Map<String, BindingProperties> bindingProperties = new HashMap<>();
BindingProperties props = new BindingProperties();
@@ -528,7 +529,7 @@ class BindingServiceTests {
assertThat(service.getProducerBinding("output")).isSameAs(binding);
service.unbindProducers(outputChannelName);
service.unbindProducers(null, outputChannelName);
verify(binder, times(2)).bindProducer(eq("foo"), same(outputChannel),
any(ProducerProperties.class));
verify(delegate).unbind();
@@ -552,9 +553,8 @@ class BindingServiceTests {
assertThat(inputBinding.isRunning()).isFalse();
}
@SuppressWarnings("unchecked")
@Test
void bindingNameAsTopLevelProperty() throws Exception {
void bindingNameAsTopLevelProperty() {
ApplicationContext context = new SpringApplicationBuilder(BarConfiguration.class)
.web(WebApplicationType.NONE).run();

View File

@@ -84,6 +84,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
*
* @author Oleg Zhurakousky
* @author Soby Chacko
* @author Omer Celik
*
*/
class StreamBridgeTests {
@@ -384,7 +385,7 @@ class StreamBridgeTests {
// See this issue for more details: https://github.com/spring-cloud/spring-cloud-stream/issues/2805
@Test
void streamBridgeSendWithBinderNameAndCustomContentType() throws Exception {
void streamBridgeSendWithBinderNameAndCustomContentType() {
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration
.getCompleteConfiguration(ConsumerConfiguration.class, EmptyConfigurationWithCustomConverters.class))
.web(WebApplicationType.NONE).run(
@@ -767,6 +768,45 @@ class StreamBridgeTests {
assertThat(bindingService.getProducerBindingNames().length).isEqualTo(0);
}
@Test
void dynamicDestinationWithBinderNameDestroy() {
BindingService bindingService;
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration
.getCompleteConfiguration(InterceptorConfiguration.class))
.web(WebApplicationType.NONE).run(
"--spring.jmx.enabled=false",
"--spring.cloud.stream.binders.kafka1.type=kafka",
"--spring.cloud.stream.binders.anotherKafka.type=kafka"
)) {
StreamBridge bridge = context.getBean(StreamBridge.class);
bridge.send("binding1", "kafka1", "Omer Celik");
bridge.send("binding2", "anotherKafka", "Omer Celik");
bindingService = context.getBean(BindingService.class);
}
assertThat(bindingService.getProducerBindingNames().length).isEqualTo(0);
}
@Test
void dynamicDestinationWithBinderNameDestroyForCacheSize() {
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.binders.kafka1.type=kafka",
"--spring.cloud.stream.binders.anotherKafka.type=kafka"
)) {
StreamBridge bridge = context.getBean(StreamBridge.class);
bridge.send("binding1", "kafka1", "Omer Celik");
bridge.send("binding2", "anotherKafka", "Omer Celik");
BindingService bindingService = context.getBean(BindingService.class);
assertThat(bindingService.getProducerBindingNames().length).isEqualTo(1);
assertThat(bindingService.getProducerBindingNames()[0]).isEqualTo("anotherKafka:binding2");
}
}
@Test
void withIntegrationFlowBecauseMarcinSaidSo() {
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration