I want to test one Apache Camel route in a Spring Boot integration test, but the integration test doens't finish. ProducerTemplate#sendBody
doesn't return.
Spring Boot application
@SpringBootApplication
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
@Bean
public EndpointRouteBuilder routeBuilder() {
return new EndpointRouteBuilder() {
@Override
public void configure() throws Exception {
from(direct("in")).multicast().to(direct("route"), direct("request"));
from(direct("route")).setHeader("id", constant("1")).to(direct("aggregate"));
from(direct("response")).log("Response: ${body}").to(direct("aggregate"));
from(direct("aggregate"))
.log("Aggregation-In: ${body}")
.aggregate(header("id"), AggregationStrategies.useLatest())
.completionSize(2)
.log("Aggregation-out: ${body}")
.to(direct("out"));
}
};
}
}
Spring Boot integration test
@SpringBootTest
@CamelSpringBootTest
@MockEndpointsAndSkip("(direct:request|direct:out)")
class TextRouteBuilderIT {
@EndpointInject("mock:direct:out")
private MockEndpoint outRoute;
@EndpointInject("direct:response")
private Endpoint responseRoute;
@EndpointInject("mock:direct:request")
private MockEndpoint requestRoute;
@Autowired private ProducerTemplate template;
@Test
void test() throws CamelExecutionException, InterruptedException {
requestRoute.whenAnyExchangeReceived(
new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("Response");
exchange.getIn().setHeader("id", "1");
responseRoute.createProducer().process(exchange);
}
});
template.sendBody("direct:in", "test");
throw new RuntimeException();
}
}
Logs
o.a.c.t.s.j.CamelAnnotationsHandler : Enabling auto mocking and skipping of endpoints matching pattern [(direct:request|direct:out)] on CamelContext with name [camelContext].
c.t.s.j.CamelSpringBootExecutionListener : CamelSpringBootExecutionListener before: class test.TextRouteBuilderIT.test
c.t.s.j.CamelSpringBootExecutionListener : Initialized CamelSpringBootExecutionListener now ready to start CamelContext
o.a.c.t.s.j.CamelAnnotationsHandler : Starting CamelContext with name [camelContext].
.i.e.InterceptSendToMockEndpointStrategy : Adviced endpoint [direct://request] with mock endpoint [mock:direct:request]
.i.e.InterceptSendToMockEndpointStrategy : Adviced endpoint [direct://out] with mock endpoint [mock:direct:out]
o.a.c.impl.engine.AbstractCamelContext : Apache Camel 3.5.0 (camel-1) is starting
o.a.c.impl.engine.AbstractCamelContext : StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
o.a.c.impl.engine.AbstractCamelContext : Using HealthCheck: camel-spring-boot
o.a.c.p.aggregate.AggregateProcessor : Defaulting to MemoryAggregationRepository
o.a.c.i.e.InternalRouteStartupManager : Route: route1 started and consuming from: direct://in
o.a.c.i.e.InternalRouteStartupManager : Route: route2 started and consuming from: direct://route
o.a.c.i.e.InternalRouteStartupManager : Route: route3 started and consuming from: direct://response
o.a.c.i.e.InternalRouteStartupManager : Route: route4 started and consuming from: direct://aggregate
o.a.c.impl.engine.AbstractCamelContext : Total 4 routes, of which 4 are started
o.a.c.impl.engine.AbstractCamelContext : Apache Camel 3.5.0 (camel-1) started in 0.015 seconds
route4 : Aggregation-In: test
route3 : Response: Response
route4 : Aggregation-In: Response
route4 : Aggregation-out: Response
It looks like the last route is finished, but the Spring Boot integration test is still running. The RuntimeException
is not thrown.
Research
I followed
What did I do wrong?