use of org.apache.camel.CamelExecutionException in project camel by apache.
the class SedaNoConsumerTest method testInOut.
public void testInOut() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").to("seda:foo?timeout=1000");
}
});
context.start();
try {
template.requestBody("direct:start", "Hello World");
fail("Should throw an exception");
} catch (CamelExecutionException e) {
assertIsInstanceOf(ExchangeTimedOutException.class, e.getCause());
}
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class ExceptionThrownFromOnExceptionNoEndlessLoopTest method testExceptionThrownFromOnExceptionNoEndlessLoopTest.
public void testExceptionThrownFromOnExceptionNoEndlessLoopTest() throws Exception {
RETRY.set(0);
ON_EXCEPTION_RETRY.set(0);
ON_EXCEPTION_2_RETRY.set(0);
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
onException(IOException.class).maximumRedeliveries(3).to("mock:b").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
ON_EXCEPTION_RETRY.incrementAndGet();
// then go into endless loop
throw new IllegalArgumentException("Not supported");
}
}).to("mock:c");
onException(IllegalArgumentException.class).to("mock:d").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
ON_EXCEPTION_2_RETRY.incrementAndGet();
throw new IOException("Some other IOException");
}
}).to("mock:e");
from("direct:start").to("direct:intermediate").to("mock:result");
from("direct:intermediate").to("mock:a").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
RETRY.incrementAndGet();
throw new IOException("IO error");
}
}).to("mock:end");
}
});
context.start();
getMockEndpoint("mock:a").expectedMessageCount(1);
getMockEndpoint("mock:b").expectedMessageCount(1);
getMockEndpoint("mock:c").expectedMessageCount(0);
getMockEndpoint("mock:d").expectedMessageCount(0);
getMockEndpoint("mock:e").expectedMessageCount(0);
getMockEndpoint("mock:result").expectedMessageCount(0);
getMockEndpoint("mock:end").expectedMessageCount(0);
try {
template.sendBody("direct:start", "Hello World");
fail("Should have thrown an exception");
} catch (CamelExecutionException e) {
IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
assertEquals("Not supported", cause.getMessage());
}
assertMockEndpointsSatisfied();
assertEquals("Should try 4 times (1 first, 3 retry)", 4, RETRY.get());
assertEquals("Should only invoke onException once", 1, ON_EXCEPTION_RETRY.get());
assertEquals("Should not be invoked", 0, ON_EXCEPTION_2_RETRY.get());
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class ExceptionThrownFromOnExceptionTest method testExceptionThrownFromOnExceptionAndHandledWithDeadLetterChannel.
public void testExceptionThrownFromOnExceptionAndHandledWithDeadLetterChannel() throws Exception {
RETRY.set(0);
ON_EXCEPTION_RETRY.set(0);
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
// DLC
deadLetterChannel("mock:error").redeliveryDelay(0).maximumRedeliveries(3);
// on exception to catch all IO exceptions and handle them specially
onException(IOException.class).maximumRedeliveries(3).handled(true).to("mock:b").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
ON_EXCEPTION_RETRY.incrementAndGet();
throw new IOException("Some other IOException");
}
}).to("mock:c");
from("direct:start").to("direct:intermediate").to("mock:result");
from("direct:intermediate").to("mock:a").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
RETRY.incrementAndGet();
throw new IOException("IO error");
}
}).to("mock:end");
}
});
context.start();
getMockEndpoint("mock:a").expectedMessageCount(1);
getMockEndpoint("mock:b").expectedMessageCount(1);
getMockEndpoint("mock:c").expectedMessageCount(0);
getMockEndpoint("mock:result").expectedMessageCount(0);
getMockEndpoint("mock:end").expectedMessageCount(0);
// the error will not be handled by DLC since we had an onException, and that failed,
// so the exchange will throw an exception
getMockEndpoint("mock:error").expectedMessageCount(0);
try {
template.sendBody("direct:start", "Hello World");
fail("Should have thrown an exception");
} catch (CamelExecutionException e) {
IOException cause = assertIsInstanceOf(IOException.class, e.getCause());
assertEquals("Some other IOException", cause.getMessage());
}
assertMockEndpointsSatisfied();
assertEquals("Should try 4 times (1 first, 3 retry)", 4, RETRY.get());
assertEquals("Should only invoke onException once", 1, ON_EXCEPTION_RETRY.get());
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class CharlesSplitAndTryCatchRollbackIssueTest method testSplitWithTryCatchAndRollbackException.
public void testSplitWithTryCatchAndRollbackException() throws Exception {
MockEndpoint split = getMockEndpoint("mock:split");
MockEndpoint ile = getMockEndpoint("mock:ile");
MockEndpoint exception = getMockEndpoint("mock:exception");
split.expectedBodiesReceived("A", "B");
ile.expectedMessageCount(0);
exception.expectedMessageCount(1);
try {
template.sendBody("direct:start", "A,B,Kaboom,C");
fail("Should thrown an exception");
} catch (CamelExecutionException e) {
CamelExchangeException ee = assertIsInstanceOf(CamelExchangeException.class, e.getCause());
assertTrue(ee.getMessage().startsWith("Sequential processing failed for number 2."));
RollbackExchangeException re = assertIsInstanceOf(RollbackExchangeException.class, ee.getCause());
assertTrue(re.getMessage().startsWith("Intended rollback"));
}
assertMockEndpointsSatisfied();
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class EvaluateExpressionProcessorTest method testFail.
public void testFail() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(0);
try {
template.sendBody("direct:fail", "World");
fail("Should have thrown exception");
} catch (CamelExecutionException e) {
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
assertEquals("Forced", e.getCause().getMessage());
}
assertMockEndpointsSatisfied();
}
Aggregations