Search in sources :

Example 26 with CamelExecutionException

use of org.apache.camel.CamelExecutionException in project camel by apache.

the class OnCompletionTest method testSynchronizeFailure.

public void testSynchronizeFailure() throws Exception {
    getMockEndpoint("mock:sync").expectedMessageCount(1);
    getMockEndpoint("mock:sync").expectedPropertyReceived(Exchange.ON_COMPLETION, true);
    getMockEndpoint("mock:sync").message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isInstanceOf(IllegalArgumentException.class);
    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();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 27 with CamelExecutionException

use of org.apache.camel.CamelExecutionException in project camel by apache.

the class OnCompletionAndInterceptGlobalTest method testSynchronizeFailure.

public void testSynchronizeFailure() throws Exception {
    getMockEndpoint("mock:intercept").expectedMinimumMessageCount(4);
    getMockEndpoint("mock:sync").expectedMessageCount(1);
    getMockEndpoint("mock:sync").expectedPropertyReceived(Exchange.ON_COMPLETION, true);
    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();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 28 with CamelExecutionException

use of org.apache.camel.CamelExecutionException in project camel by apache.

the class OnCompletionOnCompleteOnlyTest method testSynchronizeFailure.

public void testSynchronizeFailure() throws Exception {
    // do not expect a message since we only do onCompleteOnly
    getMockEndpoint("mock:sync").expectedMessageCount(0);
    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();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 29 with CamelExecutionException

use of org.apache.camel.CamelExecutionException in project camel by apache.

the class AggregateClosedCorrelationKeyTest method testAggregateClosedCorrelationKey.

public void testAggregateClosedCorrelationKey() throws Exception {
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").aggregate(header("id"), new BodyInAggregatingStrategy()).completionSize(2).closeCorrelationKeyOnCompletion(1000).to("mock:result");
        }
    });
    context.start();
    getMockEndpoint("mock:result").expectedBodiesReceived("A+B");
    template.sendBodyAndHeader("direct:start", "A", "id", 1);
    template.sendBodyAndHeader("direct:start", "B", "id", 1);
    // should be closed
    try {
        template.sendBodyAndHeader("direct:start", "C", "id", 1);
        fail("Should throw an exception");
    } catch (CamelExecutionException e) {
        ClosedCorrelationKeyException cause = assertIsInstanceOf(ClosedCorrelationKeyException.class, e.getCause());
        assertEquals("1", cause.getCorrelationKey());
        assertTrue(cause.getMessage().startsWith("The correlation key [1] has been closed."));
    }
    assertMockEndpointsSatisfied();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) RouteBuilder(org.apache.camel.builder.RouteBuilder) BodyInAggregatingStrategy(org.apache.camel.processor.BodyInAggregatingStrategy) ClosedCorrelationKeyException(org.apache.camel.processor.aggregate.ClosedCorrelationKeyException) CamelExecutionException(org.apache.camel.CamelExecutionException) ClosedCorrelationKeyException(org.apache.camel.processor.aggregate.ClosedCorrelationKeyException)

Example 30 with CamelExecutionException

use of org.apache.camel.CamelExecutionException in project camel by apache.

the class AggregateClosedCorrelationKeyTest method testAggregateClosedCorrelationKeyCache.

public void testAggregateClosedCorrelationKeyCache() throws Exception {
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").aggregate(header("id"), new BodyInAggregatingStrategy()).completionSize(2).closeCorrelationKeyOnCompletion(2).to("mock:result");
        }
    });
    context.start();
    getMockEndpoint("mock:result").expectedBodiesReceived("A+B", "C+D", "E+F");
    template.sendBodyAndHeader("direct:start", "A", "id", 1);
    template.sendBodyAndHeader("direct:start", "B", "id", 1);
    template.sendBodyAndHeader("direct:start", "C", "id", 2);
    template.sendBodyAndHeader("direct:start", "D", "id", 2);
    template.sendBodyAndHeader("direct:start", "E", "id", 3);
    template.sendBodyAndHeader("direct:start", "F", "id", 3);
    // 2 of them should now be closed
    int closed = 0;
    // should NOT be closed because only 2 and 3 is remembered as they are the two last used
    try {
        template.sendBodyAndHeader("direct:start", "G", "id", 1);
    } catch (CamelExecutionException e) {
        closed++;
        ClosedCorrelationKeyException cause = assertIsInstanceOf(ClosedCorrelationKeyException.class, e.getCause());
        assertEquals("1", cause.getCorrelationKey());
        assertTrue(cause.getMessage().startsWith("The correlation key [1] has been closed."));
    }
    // should be closed
    try {
        template.sendBodyAndHeader("direct:start", "H", "id", 2);
    } catch (CamelExecutionException e) {
        closed++;
        ClosedCorrelationKeyException cause = assertIsInstanceOf(ClosedCorrelationKeyException.class, e.getCause());
        assertEquals("2", cause.getCorrelationKey());
        assertTrue(cause.getMessage().startsWith("The correlation key [2] has been closed."));
    }
    // should be closed
    try {
        template.sendBodyAndHeader("direct:start", "I", "id", 3);
    } catch (CamelExecutionException e) {
        closed++;
        ClosedCorrelationKeyException cause = assertIsInstanceOf(ClosedCorrelationKeyException.class, e.getCause());
        assertEquals("3", cause.getCorrelationKey());
        assertTrue(cause.getMessage().startsWith("The correlation key [3] has been closed."));
    }
    assertMockEndpointsSatisfied();
    assertEquals("There should be 2 closed", 2, closed);
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) RouteBuilder(org.apache.camel.builder.RouteBuilder) BodyInAggregatingStrategy(org.apache.camel.processor.BodyInAggregatingStrategy) ClosedCorrelationKeyException(org.apache.camel.processor.aggregate.ClosedCorrelationKeyException) CamelExecutionException(org.apache.camel.CamelExecutionException) ClosedCorrelationKeyException(org.apache.camel.processor.aggregate.ClosedCorrelationKeyException)

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