GH-2112 Fix clear operation on TestBinder

Resolves #2112
This commit is contained in:
Oleg Zhurakousky
2021-02-10 08:30:44 +01:00
parent cbe16cd12e
commit 1c4ac7368e
2 changed files with 28 additions and 3 deletions

View File

@@ -55,7 +55,7 @@ public class OutputDestination extends AbstractDestination {
* @since 3.0.6
*/
public void clear() {
this.messageQueues.clear();
this.messageQueues.values().forEach(v -> v.clear());
}
/**
@@ -66,8 +66,9 @@ public class OutputDestination extends AbstractDestination {
* @since 3.0.6
*/
public boolean clear(String destinationName) {
if (StringUtils.hasText(destinationName) && this.messageQueues.containsKey(destinationName)) {
this.messageQueues.clear();
String queueName = destinationName.endsWith(".destination") ? destinationName : destinationName + ".destination";
if (StringUtils.hasText(destinationName) && this.messageQueues.containsKey(queueName)) {
this.messageQueues.get(queueName).clear();
return true;
}
return false;

View File

@@ -74,6 +74,30 @@ public class ScenarioTests {
}
}
@Test
public void test2112() {
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
TestChannelBinderConfiguration.getCompleteConfiguration(TestConfiguration.class))
.web(WebApplicationType.NONE)
.run("--spring.jmx.enabled=false",
"--spring.cloud.function.definition=messageFunction")) {
InputDestination input = context.getBean(InputDestination.class);
OutputDestination output = context.getBean(OutputDestination.class);
input.send(new GenericMessage<byte[]>("hello-1".getBytes()), "messageFunction-in-0");
output.clear("messageFunction-out-0");
input.send(new GenericMessage<byte[]>("hello-2".getBytes()), "messageFunction-in-0");
assertThat(new String(output.receive(1000, "messageFunction-out-0").getPayload())).isEqualTo("hello-2");
input.send(new GenericMessage<byte[]>("hello-1".getBytes()), "messageFunction-in-0");
input.send(new GenericMessage<byte[]>("hello-2".getBytes()), "messageFunction-in-0");
output.clear();
input.send(new GenericMessage<byte[]>("hello-3".getBytes()), "messageFunction-in-0");
assertThat(new String(output.receive(1000, "messageFunction-out-0").getPayload())).isEqualTo("hello-3");
}
}
@EnableAutoConfiguration
@Configuration
public static class TestConfiguration {