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

camel-file: file is renamed but error handling continues.

    XMLWordPrintableJSON

Details

    • Unknown

    Description

      Symptoms:

      1. Exception is thrown from the child route with NoErrorHandler configured.
      2. Parent and child routes are linked with async. endpoints (seda, vm, nmr, etc.), which are configured to behave synchronously (attribute waitForTaskToComplete=Always in seda, vm-endpoints and attribute synchronous=true in nmr-endpoint).

      The behavior with nmr endpoint is almost the same except for the next file is picked up before the lock on the previous one is released.

      Here is a unit test to reproduce the issue:

      org.foo.bar.FileRedeliveryWithoutErrorHandlerTest.java
      package org.foo.bar;
      
      import org.apache.camel.LoggingLevel;
      import org.apache.camel.builder.RouteBuilder;
      import org.apache.camel.component.mock.MockEndpoint;
      import org.apache.camel.impl.JndiRegistry;
      import org.apache.camel.processor.RedeliveryPolicy;
      import org.apache.camel.test.junit4.CamelTestSupport;
      import org.junit.After;
      import org.junit.Before;
      import org.junit.Test;
      
      import java.io.File;
      
      import static org.hamcrest.CoreMatchers.equalTo;
      
      public class FileRedeliveryWithoutErrorHandlerTest extends CamelTestSupport {
      
          private File newFile;
          private File errorFile;
          
          @Before
          @SuppressWarnings("ResultOfMethodCallIgnored")
          public void createFile() throws Exception {
              newFile = new File("target/files/in/newFile.txt");
              newFile.createNewFile();
              errorFile = new File("target/files/in/.error/newFile.txt");
          }
          
          @After
          @SuppressWarnings("ResultOfMethodCallIgnored")
          public void deleteFile() throws Exception {
              newFile.delete();
              errorFile.delete();
          }
          
          @Test
          public void testFileRedeliveryWithoutErrorHandler() throws Exception {
              MockEndpoint result = getMockEndpoint("mock:result");
              result.setExpectedMessageCount(1);
      
              result.assertIsNotSatisfied();
              
              // created file have to exist because redelivery attempts are not completed
              assertThat(newFile.exists(), equalTo(true));
              assertThat(errorFile.exists(), equalTo(false));
          }
      
          @Override
          protected JndiRegistry createRegistry() throws Exception {
              JndiRegistry registry = super.createRegistry();
      
              RedeliveryPolicy policy = new RedeliveryPolicy();
              policy.setAsyncDelayedRedelivery(false);
              policy.setLogRetryStackTrace(true);
              policy.setMaximumRedeliveries(100);
              policy.setMaximumRedeliveryDelay(30000);
              policy.setRedeliveryDelay(1000);
              policy.setUseExponentialBackOff(false);
              policy.setRetryAttemptedLogLevel(LoggingLevel.WARN);
              registry.bind("redeliveryPolicy", policy);
      
              return registry;
          }
      
          @Override
          protected RouteBuilder createRouteBuilder() throws Exception {
              return new RouteBuilder() {
                  @Override
                  public void configure() throws Exception {
                      errorHandler(defaultErrorHandler())
                          .onException(Exception.class)
                          .redeliveryPolicyRef("redeliveryPolicy")
                          .log(LoggingLevel.ERROR, "Error");
      
                      from("file:target/files/in?initialDelay=100&delay=100&move=.backup&moveFailed=.error")
                          .to("seda:async?waitForTaskToComplete=Always&size=1")
                          .to("mock:result");
                      from("seda:async")
                          .errorHandler(noErrorHandler())
                          .delay(1000)
                          .throwException(new RuntimeException("Hello World!"));
                  }
              };
          }
      }
      

      Attachments

        Issue Links

          Activity

            People

              davsclaus Claus Ibsen
              szhemzhitsky Sergey Zhemzhitsky
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: