Search in sources :

Example 6 with CamelExecutionException

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();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) CamelExchangeException(org.apache.camel.CamelExchangeException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) RollbackExchangeException(org.apache.camel.RollbackExchangeException)

Example 7 with CamelExecutionException

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());
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) Attribute(javax.management.Attribute) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 8 with CamelExecutionException

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();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) RouteBuilder(org.apache.camel.builder.RouteBuilder) CamelException(org.apache.camel.CamelException) CamelExecutionException(org.apache.camel.CamelExecutionException) CamelException(org.apache.camel.CamelException)

Example 9 with CamelExecutionException

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();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) RouteBuilder(org.apache.camel.builder.RouteBuilder) CamelException(org.apache.camel.CamelException) CamelExecutionException(org.apache.camel.CamelExecutionException) CamelException(org.apache.camel.CamelException)

Example 10 with CamelExecutionException

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();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) CamelExchangeException(org.apache.camel.CamelExchangeException) RouteBuilder(org.apache.camel.builder.RouteBuilder) BodyInAggregatingStrategy(org.apache.camel.processor.BodyInAggregatingStrategy) CamelExecutionException(org.apache.camel.CamelExecutionException) CamelExchangeException(org.apache.camel.CamelExchangeException)

Aggregations

CamelExecutionException (org.apache.camel.CamelExecutionException)140 RouteBuilder (org.apache.camel.builder.RouteBuilder)60 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)58 Test (org.junit.Test)48 Exchange (org.apache.camel.Exchange)23 Processor (org.apache.camel.Processor)17 CamelExchangeException (org.apache.camel.CamelExchangeException)13 IOException (java.io.IOException)12 Date (java.util.Date)11 StopWatch (org.apache.camel.util.StopWatch)10 ExchangeTimedOutException (org.apache.camel.ExchangeTimedOutException)7 QuartzComponent (org.apache.camel.component.quartz.QuartzComponent)5 File (java.io.File)4 Set (java.util.Set)4 ConstraintViolation (javax.validation.ConstraintViolation)4 CamelContext (org.apache.camel.CamelContext)4 NoTypeConversionAvailableException (org.apache.camel.NoTypeConversionAvailableException)4 QuartzComponent (org.apache.camel.component.quartz2.QuartzComponent)4 List (java.util.List)3 JSONException (net.sf.json.JSONException)3