use of org.apache.camel.CamelExecutionException in project camel by apache.
the class CharlesSplitAndTryCatchRollbackIssueTest method testSplitWithTryCatchAndRollbacILEAndException.
public void testSplitWithTryCatchAndRollbacILEAndException() throws Exception {
MockEndpoint split = getMockEndpoint("mock:split");
MockEndpoint ile = getMockEndpoint("mock:ile");
MockEndpoint exception = getMockEndpoint("mock:exception");
split.expectedBodiesReceived("A", "B");
ile.expectedMessageCount(1);
exception.expectedMessageCount(1);
try {
template.sendBody("direct:start", "A,Forced,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 3."));
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 ManagedErrorHandlerOptionsTest method testManagedErrorHandlerOptions.
public void testManagedErrorHandlerOptions() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
counter = 0;
MBeanServer mbeanServer = getMBeanServer();
Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=errorhandlers,*"), null);
assertEquals(1, set.size());
ObjectName on = set.iterator().next();
mbeanServer.setAttribute(on, new Attribute("MaximumRedeliveries", 3));
Integer max = (Integer) mbeanServer.getAttribute(on, "MaximumRedeliveries");
assertEquals(3, max.intValue());
mbeanServer.setAttribute(on, new Attribute("MaximumRedeliveryDelay", Long.valueOf("20000")));
Long delay = (Long) mbeanServer.getAttribute(on, "MaximumRedeliveryDelay");
assertEquals(20000, delay.longValue());
mbeanServer.setAttribute(on, new Attribute("RedeliveryDelay", Long.valueOf("250")));
delay = (Long) mbeanServer.getAttribute(on, "RedeliveryDelay");
assertEquals(250, delay.longValue());
String camelId = (String) mbeanServer.getAttribute(on, "CamelId");
assertEquals("camel-1", camelId);
mbeanServer.setAttribute(on, new Attribute("BackOffMultiplier", Double.valueOf("3.5")));
Double backoff = (Double) mbeanServer.getAttribute(on, "BackOffMultiplier");
assertNotNull(backoff);
mbeanServer.setAttribute(on, new Attribute("CollisionAvoidanceFactor", Double.valueOf("1.5")));
Double cf = (Double) mbeanServer.getAttribute(on, "CollisionAvoidanceFactor");
assertNotNull(cf);
mbeanServer.setAttribute(on, new Attribute("CollisionAvoidancePercent", Double.valueOf("75")));
Double cp = (Double) mbeanServer.getAttribute(on, "CollisionAvoidancePercent");
assertNotNull(cp);
mbeanServer.setAttribute(on, new Attribute("DelayPattern", "0:1000;5:5000"));
String dp = (String) mbeanServer.getAttribute(on, "DelayPattern");
assertNotNull(dp);
mbeanServer.setAttribute(on, new Attribute("RetriesExhaustedLogLevel", "WARN"));
String ell = (String) mbeanServer.getAttribute(on, "RetriesExhaustedLogLevel");
assertEquals(LoggingLevel.WARN.name(), ell);
mbeanServer.setAttribute(on, new Attribute("RetryAttemptedLogLevel", "WARN"));
String rll = (String) mbeanServer.getAttribute(on, "RetryAttemptedLogLevel");
assertEquals(LoggingLevel.WARN.name(), rll);
mbeanServer.setAttribute(on, new Attribute("LogStackTrace", Boolean.TRUE));
Boolean lst = (Boolean) mbeanServer.getAttribute(on, "LogStackTrace");
assertEquals(true, lst.booleanValue());
mbeanServer.setAttribute(on, new Attribute("UseCollisionAvoidance", Boolean.TRUE));
Boolean uca = (Boolean) mbeanServer.getAttribute(on, "UseCollisionAvoidance");
assertEquals(true, uca.booleanValue());
mbeanServer.setAttribute(on, new Attribute("UseExponentialBackOff", Boolean.TRUE));
Boolean uebf = (Boolean) mbeanServer.getAttribute(on, "UseExponentialBackOff");
assertEquals(true, uebf.booleanValue());
Boolean ne = (Boolean) mbeanServer.getAttribute(on, "DeadLetterHandleNewException");
assertEquals(false, ne.booleanValue());
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertEquals(3, counter);
assertMockEndpointsSatisfied();
// now change to 0 attempts and try again
counter = 0;
mock.reset();
mock.expectedMessageCount(0);
mbeanServer.setAttribute(on, new Attribute("MaximumRedeliveries", 0));
try {
template.sendBody("direct:start", "Bye World");
fail("Should have thrown exception");
} catch (CamelExecutionException e) {
IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
assertEquals("Forced", cause.getMessage());
}
assertEquals(1, counter);
// and should now be 0
max = (Integer) mbeanServer.getAttribute(on, "MaximumRedeliveries");
assertEquals(0, max.intValue());
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class RedeliveryErrorHandlerLogHandledTest method testRedeliveryErrorHandlerLogExhaustedDefault.
public void testRedeliveryErrorHandlerLogExhaustedDefault() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
errorHandler(defaultErrorHandler());
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();
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class RedeliveryErrorHandlerLogHandledTest method testRedeliveryErrorHandlerDoNotLogExhausted.
public void testRedeliveryErrorHandlerDoNotLogExhausted() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
errorHandler(defaultErrorHandler().logExhausted(false));
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();
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class AggregateIgnoreInvalidCorrelationKeysTest method testAggregateNotIgnoreInvalidCorrelationKeys.
public void testAggregateNotIgnoreInvalidCorrelationKeys() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").aggregate(header("id"), new BodyInAggregatingStrategy()).completionSize(2).to("mock:result");
}
});
context.start();
getMockEndpoint("mock:result").expectedBodiesReceived("A+C");
template.sendBodyAndHeader("direct:start", "A", "id", 1);
try {
template.sendBodyAndHeader("direct:start", "B", "id", null);
fail("Should throw an exception");
} catch (CamelExecutionException e) {
CamelExchangeException cause = assertIsInstanceOf(CamelExchangeException.class, e.getCause());
assertTrue(cause.getMessage().startsWith("Invalid correlation key"));
}
template.sendBodyAndHeader("direct:start", "C", "id", 1);
assertMockEndpointsSatisfied();
}
Aggregations