Hello, using Camel 2.9.1 and Junit 4 unit tsts,
I ran into issues testing a simple route: when I add the threads() at the
beginning of the route the test hangs and I need to manually stop it.
Is this the route I am trying to test:
from(MAIN_INBOUND_QUEUE)
.threads(3)
.doTry()
.to(INBOUND_QUEUE1, INBOUND_QUEUE2)
.doCatch(Exception.class)
.process(new
CounterHeaderIncrementorProcessor(Constants.MY_REDELIVERIES_COUNTER_HEADER,
1))
.choice()
.when(header(Constants.MY_REDELIVERIES_COUNTER_HEADER).isLessThanOrEqualTo(redeliveriesCount))
.to(MAIN_INBOUND_QUEUE).stop()
.otherwise()
.to(DEAD_LETTER_QUEUE).stop()
.end()
.end()
;
and this is the unit test I am performing:
ublic class TopicSimulatorRoutesBuilderErrorHandlingTest
extends CamelTestSupport {
protected String mainInbound = "direct:MAIN_INBOUND_QUEUE";
protected String deadLetterQueue = "mock:INBOUND_DEADLETTER";
protected String inbound1 = "mock:INBOUND1";
protected String inbound2 = "mock:INBOUND2";
protected int maxRedeliveries = 3;
protected int redeliveryDelay = 0;
@Override
protected RouteBuilder createRouteBuilder() {
return new MyRouteBuilder(context.createProducerTemplate(),
mainInbound,
inbound2,
inbound1,
deadLetterQueue,
1, maxRedeliveries);
}
@Test
public void testErrorHandlingOnFirstDestination() throws Exception {
context.getRouteDefinitions().get(0).adviceWith(context, new
RouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint(inbound1)
.throwException(new Exception("Simulated error"));
}
});
context.start();
getMockEndpoint("mock:"+mainInbound).expectedMessageCount(1+maxRedeliveries);
getMockEndpoint(inbound2).expectedMessageCount(0);
getMockEndpoint(inbound1).expectedMessageCount(0);
getMockEndpoint(deadLetterQueue).expectedMessageCount(1);
template.sendBody(mainInbound,"msg");
assertNotNull(context.hasEndpoint(mainInbound));
assertNotNull(context.hasEndpoint(inbound1));
assertNotNull(context.hasEndpoint(inbound2));
assertNotNull(context.hasEndpoint(deadLetterQueue));
log.info("#### Received Messages Count: {} {} {} {} {} {} {} {}", new
Object[]{
mainInbound,getMockEndpoint("mock:"+mainInbound).getReceivedCounter(),
inbound2,getMockEndpoint(inbound2).getReceivedCounter(),
inbound1,getMockEndpoint(inbound1).getReceivedCounter(),
deadLetterQueue,getMockEndpoint(deadLetterQueue).getReceivedCounter()
});
assertMockEndpointsSatisfied();
}
@Override
public boolean isUseAdviceWith() {
return true;
}
@Override
public String isMockEndpoints() {
return "*";
}
@Override
public boolean isUseDebugger() {
return false;
}
@Override
protected void debugBefore(Exchange exchange, Processor processor,
ProcessorDefinition definition, String id,
String shortName) {
log.error("Before " + definition + " with exchange.getI() " +
exchange.getIn());
}
}
if I comment the threads() in the queue, the test works, otherwise it hangs.
--
View this message in context:
http://camel.465427.n5.nabble.com/Threads-EIP-hangs-Unit-Tests-JUnit4-tp5715031.html
Sent from the Camel - Users mailing list archive at Nabble.com.