Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-11045

onCompletion does not trigger on failure if split is in route

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 2.19.4, 2.20.1, 2.21.0
    • camel-core
    • None
    • Unknown

    Description

      I created a test to reproduce the problem:

      import org.apache.camel.CamelExecutionException;
      import org.apache.camel.Endpoint;
      import org.apache.camel.EndpointInject;
      import org.apache.camel.RoutesBuilder;
      import org.apache.camel.builder.RouteBuilder;
      import org.apache.camel.component.mock.MockEndpoint;
      import org.apache.camel.test.junit4.CamelTestSupport;
      import org.junit.Test;
      
      import java.util.Arrays;
      
      public class OnCompletionTest extends CamelTestSupport{
      
          @EndpointInject(uri = "direct:in")
          private Endpoint in;
          @EndpointInject(uri = "mock:completion")
          private MockEndpoint mockComp;
          @EndpointInject(uri = "mock:out")
          private MockEndpoint mockOut;
      
          @Test
          public void good() throws InterruptedException {
              mockComp.setExpectedMessageCount(1);
              mockOut.setExpectedMessageCount(2);
              //
              context.createProducerTemplate().sendBody(in, Arrays.asList("1","2"));
              //
              assertMockEndpointsSatisfied();
          }
      
          @Test
          public void exception() throws InterruptedException {
              mockComp.setExpectedMessageCount(1);
              mockOut.setExpectedMessageCount(2);
      
              //
              mockOut.whenAnyExchangeReceived(exchange -> {throw new IllegalArgumentException("");});
              try {
                  context.createProducerTemplate().sendBody(in, Arrays.asList("1","2"));
                  fail();
              } catch (CamelExecutionException e){
      
              }
              //
              mockOut.assertIsSatisfied();
              mockComp.assertIsSatisfied();
          }
      
      
          @Override
          public boolean isUseRouteBuilder() {
              return true;
          }
      
          @Override
          protected RoutesBuilder createRouteBuilder() throws Exception {
              return new RouteBuilder() {
                  @Override
                  public void configure() throws Exception {
                      // @formatter:off
                      from(in)
                              .onCompletion().to(mockComp).end()
                              .split().body()
                                  //.stopOnException()
                                  //.shareUnitOfWork()
                      .to(mockOut)
                      ;
                      // @formatter:on
                  }
              };
          }
      }
      

      I would expect that both tests pass. In case of exception the onCompletion is not triggered. Documentation says it should trigger in all cases. "onFailureOnly()" doesn't help either. I also tried "stopOnException()" and "shareUnitOfWork()" in some combinations with no avail.

      If this works as intended there should be at least a hint in the documentation.
      For the sake of completeness i also asked here for a solution/ workaround: http://stackoverflow.com/questions/42928208/camel-oncompletion-not-working-on-exception-after-a-split-bug

      Attachments

        Activity

          People

            davsclaus Claus Ibsen
            dermoritz moritz löser
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: