use of org.apache.camel.CamelExecutionException in project camel by apache.
the class VmInOutChainedTimeoutTest method testVmInOutChainedTimeout.
public void testVmInOutChainedTimeout() throws Exception {
StopWatch watch = new StopWatch();
try {
template2.requestBody("vm:a?timeout=1000", "Hello World");
fail("Should have thrown an exception");
} catch (CamelExecutionException e) {
// the chained vm caused the timeout
ExchangeTimedOutException cause = assertIsInstanceOf(ExchangeTimedOutException.class, e.getCause());
assertEquals(200, cause.getTimeout());
}
long delta = watch.stop();
assertTrue("Should be faster than 1 sec, was: " + delta, delta < 1100);
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class RecipientListFineGrainedErrorHandlingTest method testRecipientListAsBeanError.
public void testRecipientListAsBeanError() throws Exception {
counter = 0;
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
context.setTracing(true);
onException(Exception.class).maximumRedeliveries(2);
from("direct:start").to("mock:a").bean(MyRecipientBean.class);
}
});
context.start();
getMockEndpoint("mock:a").expectedMessageCount(1);
getMockEndpoint("mock:foo").expectedMessageCount(1);
getMockEndpoint("mock:bar").expectedMessageCount(1);
getMockEndpoint("mock:baz").expectedMessageCount(0);
try {
template.sendBody("direct:start", "Hello World");
fail("Should throw exception");
} catch (CamelExecutionException e) {
// expected
assertIsInstanceOf(CamelExchangeException.class, e.getCause());
assertIsInstanceOf(IllegalArgumentException.class, e.getCause().getCause());
assertEquals("Damn", e.getCause().getCause().getMessage());
}
assertMockEndpointsSatisfied();
assertEquals(3, counter);
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class OnCompletionAsyncTest method testAsyncFailureUseOriginalBody.
public void testAsyncFailureUseOriginalBody() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
onCompletion().useOriginalBody().parallelProcessing().to("mock:before").delay(1000).setBody(simple("OnComplete:${body}")).to("mock:after");
from("direct:start").transform(body().prepend("Before:${body}")).process(new MyProcessor()).to("mock:result");
}
});
context.start();
getMockEndpoint("mock:before").expectedBodiesReceived("Kabom");
getMockEndpoint("mock:before").expectedPropertyReceived(Exchange.ON_COMPLETION, true);
getMockEndpoint("mock:after").expectedBodiesReceived("OnComplete:Kabom");
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(0);
try {
template.requestBody("direct:start", "Kabom");
fail("Should throw exception");
} catch (CamelExecutionException e) {
assertEquals("Kabom", e.getCause().getMessage());
}
assertMockEndpointsSatisfied();
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class OnCompletionGlobalTraceTest method testSynchronizeFailure.
public void testSynchronizeFailure() throws Exception {
getMockEndpoint("mock:sync").expectedMessageCount(1);
getMockEndpoint("mock:sync").expectedPropertyReceived(Exchange.ON_COMPLETION, true);
getMockEndpoint("mock:trace").expectedMessageCount(3);
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(0);
try {
template.sendBody("direct:start", "Kabom");
fail("Should throw exception");
} catch (CamelExecutionException e) {
assertEquals("Kabom", e.getCause().getMessage());
}
assertMockEndpointsSatisfied();
TraceEventMessage msg1 = getMockEndpoint("mock:trace").getReceivedExchanges().get(0).getIn().getBody(TraceEventMessage.class);
TraceEventMessage msg2 = getMockEndpoint("mock:trace").getReceivedExchanges().get(1).getIn().getBody(TraceEventMessage.class);
TraceEventMessage msg3 = getMockEndpoint("mock:trace").getReceivedExchanges().get(2).getIn().getBody(TraceEventMessage.class);
assertEquals("direct://start", msg1.getFromEndpointUri());
assertEquals("ref:myProcessor", msg1.getToNode());
assertTrue(msg2.getPreviousNode().startsWith("OnCompletion"));
assertEquals("log://global", msg2.getToNode());
assertEquals("log://global", msg3.getPreviousNode());
assertEquals("mock://sync", msg3.getToNode());
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class RedeliveryErrorHandlerLogHandledTest method testRedeliveryErrorHandlerAllOptions.
public void testRedeliveryErrorHandlerAllOptions() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
errorHandler(defaultErrorHandler().maximumRedeliveries(3).logExhausted(true).logHandled(true).logRetryStackTrace(true).logStackTrace(true).retryAttemptedLogLevel(LoggingLevel.WARN).retriesExhaustedLogLevel(LoggingLevel.ERROR));
from("direct:bar").throwException(new CamelException("Camel rocks"));
}
});
context.start();
getMockEndpoint("mock:handled").expectedMessageCount(0);
try {
template.sendBody("direct:bar", "Hello World");
fail("Should thrown an exception");
} catch (CamelExecutionException e) {
CamelException cause = assertIsInstanceOf(CamelException.class, e.getCause());
assertEquals("Camel rocks", cause.getMessage());
}
assertMockEndpointsSatisfied();
}
Aggregations