We use microservices and event driven architecture(more particular choreography). We use kafka and many services use Spring Cloud Stream as an abstraction over the message brokers.
After upgrading our Spring Cloud Stream related source to the new functional style, we started to have problems in our integration tests. The problem is related to the replacement of the old MessageCollector to OutputDestination(test-binder).
The problem appears in our integration tests, where we would like to verify if proper events are being produced. Many of our services produce to a topic and consume from it in another module(same service). The OutputDestination works on topic level now and not on channel as the old MessageCollector. It causes the OutputDestination to not consume any messages if there is already a listener for this topic in the prod code.
I created a simple project to present our problem https://github.com/dgyordanov/scs-functional-test
We have a simple service like:
@Service
public class OrderService {
.........
public void changeOrder() {
// Some order changes
streamBridge.send("orderEvents-out-0", "Test Order Change Event");
}
In another module we have a listener for these events in the production code:
@Bean
public Consumer<String> orderEvents() {
// React on order events
return e -> System.out.println("### Order Event: " + e);
}
I want to test the changeOrder() but nothing is being consumed:
@Test
void orderChangedTest() {
orderService.changeOrder();
Message<byte[]> event = outputDestination.receive(100, "edu.events.orderEvents");
assertNotNull(event);
}
When we run the test from above, we see the result from System.out.println("### Order Event: " + e);
The problem is that if we do not exclude the orderEvents() listener from the test context, the outputDestination will never receive messages, because the orderEvents() listener will consume them first. With the old MessageCollector, which worked on channel level, it was possible.
Could you help me how to make our big cucumber integration test suite work with the spring cloud stream test-binder?
We also tried to declare another channel for the same topic, but the outputDestination still consumed nothing.