You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/03/11 18:19:13 UTC

svn commit: r752532 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/builder/ camel-core/src/main/java/org/apache/camel/component/file/ camel-core/src/main/java/org/apache/camel/component/file/strategy/ camel-core/src/main/java/org/apache/c...

Author: davsclaus
Date: Wed Mar 11 17:19:12 2009
New Revision: 752532

URL: http://svn.apache.org/viewvc?rev=752532&view=rev
Log:
CAMEL-1449: Camel VFS does not delete/move files in case of any failure. Polished code a bit.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFileDoNotDeleteFileIfProcessFailsTest.java   (with props)
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFileDoNotMoveFileIfProcessFailsTest.java   (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFailureHandledTest.java
    camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpDoNotDeleteFileIfProcessFailsTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java?rev=752532&r1=752531&r2=752532&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java Wed Mar 11 17:19:12 2009
@@ -124,6 +124,11 @@
         return this;
     }
 
+    public DeadLetterChannelBuilder logStackTrace(boolean logStackTrace) {
+        getRedeliveryPolicy().setLogStackTrace(logStackTrace);
+        return this;
+    }
+
     /**
      * Sets the logger used for caught exceptions
      */

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java?rev=752532&r1=752531&r2=752532&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java Wed Mar 11 17:19:12 2009
@@ -39,7 +39,7 @@
         File directory = new File(fileName);
 
         if (!directory.exists() || !directory.isDirectory()) {
-            log.warn("Cannot poll directory as file does not exists or is not a directory: " + directory);
+            log.warn("Cannot poll as directory does not exists or its not a directory: " + directory);
             return;
         }
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java?rev=752532&r1=752531&r2=752532&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java Wed Mar 11 17:19:12 2009
@@ -158,18 +158,16 @@
                     public void done(boolean sync) {
                         final GenericFile<T> file = exchange.getGenericFile();
                         boolean failed = exchange.isFailed();
-                        boolean handled = DeadLetterChannel.isFailureHandled(exchange);
 
                         if (log.isDebugEnabled()) {
-                            log.debug("Done processing file: " + file + ". Status is: "
-                                    + (failed ? "failed: " + failed + ", handled by failure processor: " + handled : "processed OK"));
+                            log.debug("Done processing file: " + file + " using exchange: " + exchange);
                         }
 
                         boolean committed = false;
                         try {
-                            if (!failed || handled) {
+                            if (!failed) {
                                 // commit the file strategy if there was no failure or already handled by the DeadLetterChannel
-                                processStrategyCommit(processStrategy, exchange, file, handled);
+                                processStrategyCommit(processStrategy, exchange, file);
                                 committed = true;
                             } else {
                                 // there was an exception but it was not handled by the DeadLetterChannel
@@ -197,13 +195,10 @@
      * @param processStrategy the strategy to perform the commit
      * @param exchange        the exchange
      * @param file            the file processed
-     * @param failureHandled  is <tt>false</tt> if the exchange was processed succesfully,
-     *                        <tt>true</tt> if an exception occured during processing but it
-     *                        was handled by the failure processor (usually the DeadLetterChannel).
      */
     @SuppressWarnings("unchecked")
     protected void processStrategyCommit(GenericFileProcessStrategy<T> processStrategy,
-                                         GenericFileExchange<T> exchange, GenericFile<T> file, boolean failureHandled) {
+                                         GenericFileExchange<T> exchange, GenericFile<T> file) {
         if (endpoint.isIdempotent()) {
             // only add to idempotent repository if we could process the file
             // only use the filename as the key as the file could be moved into a done folder
@@ -211,9 +206,8 @@
         }
 
         try {
-            if (log.isDebugEnabled()) {
-                log.debug("Committing remote file strategy: " + processStrategy + " for file: " + file
-                        + (failureHandled ? " that was handled by the failure processor." : ""));
+            if (log.isTraceEnabled()) {
+                log.trace("Committing remote file strategy: " + processStrategy + " for file: " + file);
             }
             processStrategy.commit(operations, endpoint, exchange, file);
         } catch (Exception e) {
@@ -232,8 +226,8 @@
      */
     protected void processStrategyRollback(GenericFileProcessStrategy<T> processStrategy,
                                            GenericFileExchange<T> exchange, GenericFile<T> file) {
-        if (log.isDebugEnabled()) {
-            log.debug("Rolling back remote file strategy: " + processStrategy + " for file: " + file);
+        if (log.isWarnEnabled()) {
+            log.warn("Rolling back remote file strategy: " + processStrategy + " for file: " + file);
         }
         try {
             processStrategy.rollback(operations, endpoint, exchange, file);

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java?rev=752532&r1=752531&r2=752532&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java Wed Mar 11 17:19:12 2009
@@ -122,11 +122,11 @@
             // must close channel first
             ObjectHelper.close(channel, "while acquiring exclusive read lock for file: " + lockFileName, LOG);
             // need to delete the lock file
-            if (LOG.isTraceEnabled()) {
-                LOG.trace("Deleting (releasing) exclusive lock file: " + lockFileName);
-            }            
             File lockfile = new File(lockFileName);
-            lockfile.delete();
+            boolean deleted = lockfile.delete();
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("Exclusive lock file: " + lockFileName + " was deleted: " + deleted);
+            }
         }
     }
 
@@ -136,7 +136,7 @@
             Thread.sleep(1000);
             return true;
         } catch (InterruptedException e) {
-            LOG.debug("Sleep interrupted while waiting for exclusive read lock");
+            LOG.debug("Sleep interrupted while waiting for exclusive read lock, so breaking out");
             return false;
         }
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java?rev=752532&r1=752531&r2=752532&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java Wed Mar 11 17:19:12 2009
@@ -90,7 +90,7 @@
             Thread.sleep(1000);
             return true;
         } catch (InterruptedException e) {
-            LOG.debug("Sleep interrupted while waiting for exclusive read lock");
+            LOG.debug("Sleep interrupted while waiting for exclusive read lock, so breaking out");
             return false;
         }
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java?rev=752532&r1=752531&r2=752532&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java Wed Mar 11 17:19:12 2009
@@ -74,11 +74,11 @@
             // must close channel
             ObjectHelper.close(channel, "Closing channel", LOG);
             
+            File lockfile = new File(lockFileName);
+            boolean deleted = lockfile.delete();
             if (LOG.isTraceEnabled()) {
-                LOG.trace("Deleting lock file: " + lockFileName);
+                LOG.trace("Lock file: " + lockFileName + " was deleted: " + deleted);
             }
-            File lockfile = new File(lockFileName);
-            lockfile.delete();            
         }
     }
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java?rev=752532&r1=752531&r2=752532&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java Wed Mar 11 17:19:12 2009
@@ -31,6 +31,7 @@
 import org.apache.camel.model.OnExceptionDefinition;
 import org.apache.camel.processor.exceptionpolicy.ExceptionPolicyStrategy;
 import org.apache.camel.util.AsyncProcessorHelper;
+import org.apache.camel.util.ExchangeHelper;
 import org.apache.camel.util.MessageHelper;
 import org.apache.camel.util.ServiceHelper;
 import org.apache.commons.logging.Log;
@@ -91,7 +92,7 @@
                     data.sync = false;
                     // only process if the exchange hasn't failed
                     // and it has not been handled by the error processor
-                    if (exchange.getException() != null && !isFailureHandled(exchange)) {
+                    if (exchange.getException() != null && !ExchangeHelper.isFailureHandled(exchange)) {
                         // if we are redelivering then sleep before trying again
                         asyncProcess(exchange, callback, data);
                     } else {
@@ -200,7 +201,7 @@
                     data.sync = false;
                     // only process if the exchange hasn't failed
                     // and it has not been handled by the error processor
-                    if (exchange.getException() != null && !isFailureHandled(exchange)) {                        
+                    if (exchange.getException() != null && !ExchangeHelper.isFailureHandled(exchange)) {
                         //TODO Call the Timer for the asyncProcessor
                         asyncProcess(exchange, callback, data);
                     } else {
@@ -212,7 +213,7 @@
                 // It is going to be processed async..
                 return false;
             }
-            if (exchange.getException() == null || isFailureHandled(exchange)) {
+            if (exchange.getException() == null || ExchangeHelper.isFailureHandled(exchange)) {
                 // If everything went well.. then we exit here..
                 callback.done(true);
                 return true;
@@ -328,7 +329,7 @@
     private boolean deliverToFaultProcessor(final Exchange exchange, final AsyncCallback callback,
                                             final RedeliveryData data) {
         // we did not success with the redelivery so now we let the failure processor handle it
-        setFailureHandled(exchange);
+        ExchangeHelper.setFailureHandled(exchange);
         // must decrement the redelivery counter as we didn't process the redelivery but is
         // handling by the failure handler. So we must -1 to not let the counter be out-of-sync
         decrementRedeliveryCounter(exchange);
@@ -352,17 +353,6 @@
     // Properties
     // -------------------------------------------------------------------------
 
-    public static boolean isFailureHandled(Exchange exchange) {
-        Boolean handled = exchange.getProperty(Exchange.FAILURE_HANDLED, Boolean.class);
-        return handled != null && handled;
-    }
-
-    public static void setFailureHandled(Exchange exchange) {
-        exchange.setProperty(Exchange.FAILURE_HANDLED, Boolean.TRUE);
-        // clear exception since its failure handled
-        exchange.setException(null);
-    }
-
     /**
      * Returns the output processor
      */

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java?rev=752532&r1=752531&r2=752532&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java Wed Mar 11 17:19:12 2009
@@ -58,7 +58,7 @@
             e = exchange.getException();
 
             // Ignore it if it was handled by the dead letter channel.
-            if (e != null && DeadLetterChannel.isFailureHandled(exchange)) {
+            if (e != null && ExchangeHelper.isFailureHandled(exchange)) {
                 e = null;
             }
         } catch (Exception ex) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java?rev=752532&r1=752531&r2=752532&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java Wed Mar 11 17:19:12 2009
@@ -422,4 +422,16 @@
         }
         return null;
     }
+
+    public static boolean isFailureHandled(Exchange exchange) {
+        Boolean handled = exchange.getProperty(Exchange.FAILURE_HANDLED, Boolean.class);
+        return handled != null && handled;
+    }
+
+    public static void setFailureHandled(Exchange exchange) {
+        exchange.setProperty(Exchange.FAILURE_HANDLED, Boolean.TRUE);
+        // clear exception since its failure handled
+        exchange.setException(null);
+    }
+
 }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFailureHandledTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFailureHandledTest.java?rev=752532&r1=752531&r2=752532&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFailureHandledTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFailureHandledTest.java Wed Mar 11 17:19:12 2009
@@ -33,22 +33,22 @@
 public class FileConsumerFailureHandledTest extends ContextTestSupport {
 
     @Override
-    protected void tearDown() throws Exception {
+    protected void setUp() throws Exception {
         deleteDirectory("target/messages");
-        super.tearDown();
+        super.setUp();
     }
 
     public void testParis() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:valid");
         mock.expectedBodiesReceived("Hello Paris");
 
-        template.sendBodyAndHeader("file:target/messages/input/?delete=true", "Paris", Exchange.FILE_NAME, "paris.txt");
+        template.sendBodyAndHeader("file:target/messages/input/?delete=true&delay=5000", "Paris", Exchange.FILE_NAME, "paris.txt");
         mock.assertIsSatisfied();
 
         // sleep otherwise the file assertions below could fail
         Thread.sleep(200);
 
-        asserFiles("paris.txt");
+        asserFiles("paris.txt", true);
     }
 
     public void testLondon() throws Exception {
@@ -56,47 +56,70 @@
         // we get the original input so its not Hello London but only London
         mock.expectedBodiesReceived("London");
 
-        template.sendBodyAndHeader("file:target/messages/input/?delete=true", "London", Exchange.FILE_NAME, "london.txt");
+        template.sendBodyAndHeader("file:target/messages/input/?delete=true&delay=5000", "London", Exchange.FILE_NAME, "london.txt");
         mock.assertIsSatisfied();
 
         // sleep otherwise the file assertions below could fail
         Thread.sleep(200);
 
-        asserFiles("london.txt");
+        // london should be delated as we have failure handled it
+        asserFiles("london.txt", true);
     }
     
+    public void testDublin() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:beer");
+        // we get the original input so its not Hello London but only London
+        mock.expectedBodiesReceived("Dublin");
+
+        template.sendBodyAndHeader("file:target/messages/input/?delete=true&delay=5000", "Dublin", Exchange.FILE_NAME, "dublin.txt");
+        mock.assertIsSatisfied();
+
+        // sleep otherwise the file assertions below could fail
+        Thread.sleep(200);
+
+        // dublin should NOT be deleted, but should be retired on next consumer
+        asserFiles("dublin.txt", false);
+    }
+
     public void testMadrid() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:error");
         // we get the original input so its not Hello London but only London
         mock.expectedBodiesReceived("Madrid");
 
-        template.sendBodyAndHeader("file:target/messages/input/?delete=true", "Madrid", Exchange.FILE_NAME, "madrid.txt");
+        template.sendBodyAndHeader("file:target/messages/input/?delete=true&delay=5000", "Madrid", Exchange.FILE_NAME, "madrid.txt");
         mock.assertIsSatisfied();
 
         // sleep otherwise the file assertions below could fail
         Thread.sleep(200);
 
-        asserFiles("madrid.txt");
+        // madrid should NOT be deleted, but should be retired on next consumer
+        asserFiles("madrid.txt", false);
     }
 
-    private static void asserFiles(String filename) {
+    private static void asserFiles(String filename, boolean deleted) throws InterruptedException {
         // file should be deleted as deleted=true in parameter in the route below
         File file = new File("target/messages/input/" + filename);
-        assertEquals("File " + filename + " should be deleted", false, file.exists());
+        assertEquals("File " + filename + " should be deleted: " + deleted, deleted, !file.exists());
 
         // and no lock files
-        file = new File("target/messages/input/" + filename + FileComponent.DEFAULT_LOCK_FILE_POSTFIX);
-        assertEquals("File " + filename + " lock should be deleted", false, file.exists());
+        String lock = filename + FileComponent.DEFAULT_LOCK_FILE_POSTFIX;
+        file = new File("target/messages/input/" + lock);
+        assertFalse("File " + lock + " should be deleted", file.exists());
     }
 
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
                 // make sure mock:error is the dead letter channel
-                errorHandler(deadLetterChannel("mock:error").maximumRedeliveries(2));
+                // use no delay for fast unit testing
+                errorHandler(deadLetterChannel("mock:error").maximumRedeliveries(2).delay(0).logStackTrace(false));
+
+                // special for not handled when we got beer
+                onException(ValidationException.class).onWhen(exceptionMessage().contains("beer"))
+                    .handled(false).to("mock:beer");
 
                 // special failure handler for ValidationException
-                onException(ValidationException.class).to("mock:invalid");
+                onException(ValidationException.class).handled(true).to("mock:invalid");
 
                 // our route logic to process files from the input folder
                 from("file:target/messages/input/?delete=true").
@@ -113,6 +136,8 @@
                 throw new ValidationException(exchange, "Forced exception by unit test");
             } else if ("Madrid".equals(body)) {
                 throw new RuntimeCamelException("Madrid is not a supported city");
+            } else if ("Dublin".equals(body)) {
+                throw new ValidationException(exchange, "Dublin have good beer");
             }
             exchange.getOut().setBody("Hello " + body);
         }

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFileDoNotDeleteFileIfProcessFailsTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFileDoNotDeleteFileIfProcessFailsTest.java?rev=752532&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFileDoNotDeleteFileIfProcessFailsTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFileDoNotDeleteFileIfProcessFailsTest.java Wed Mar 11 17:19:12 2009
@@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.file;
+
+import java.io.File;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version $Revision$
+ */
+public class FromFileDoNotDeleteFileIfProcessFailsTest extends ContextTestSupport {
+
+    private String body = "Hello World this file will NOT be deleted";
+
+    @Override
+    protected void setUp() throws Exception {
+        deleteDirectory("./target/deletefile");
+        super.setUp();
+    }
+
+    public void testPollFileAndShouldNotBeDeleted() throws Exception {
+        template.sendBodyAndHeader("file://target/deletefile", body, Exchange.FILE_NAME, "hello.txt");
+
+        MockEndpoint mock = getMockEndpoint("mock:error");
+        mock.expectedBodiesReceived(body);
+
+        mock.assertIsSatisfied();
+
+        // give time to NOT delete file
+        Thread.sleep(200);
+
+        // assert the file is deleted
+        File file = new File("./target/deletefile/hello.txt");
+        file = file.getAbsoluteFile();
+        assertTrue("The file should NOT have been deleted", file.exists());
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                errorHandler(deadLetterChannel("mock:error").maximumRedeliveries(2).delay(100).logStackTrace(false));
+
+                from("file://target/deletefile?delete=true").process(new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        throw new IllegalArgumentException("Forced by unittest");
+                    }
+                });
+            }
+        };
+    }
+
+
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFileDoNotDeleteFileIfProcessFailsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFileDoNotDeleteFileIfProcessFailsTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFileDoNotMoveFileIfProcessFailsTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFileDoNotMoveFileIfProcessFailsTest.java?rev=752532&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFileDoNotMoveFileIfProcessFailsTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFileDoNotMoveFileIfProcessFailsTest.java Wed Mar 11 17:19:12 2009
@@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.file;
+
+import java.io.File;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version $Revision$
+ */
+public class FromFileDoNotMoveFileIfProcessFailsTest extends ContextTestSupport {
+
+    private String body = "Hello World this file will NOT be moved";
+
+    @Override
+    protected void setUp() throws Exception {
+        deleteDirectory("./target/movefile");
+        super.setUp();
+    }
+
+    public void testPollFileAndShouldNotBeMoved() throws Exception {
+        template.sendBodyAndHeader("file://target/movefile", body, Exchange.FILE_NAME, "hello.txt");
+
+        MockEndpoint mock = getMockEndpoint("mock:error");
+        mock.expectedBodiesReceived(body);
+
+        mock.assertIsSatisfied();
+
+        // give time to NOT delete file
+        Thread.sleep(200);
+
+        // assert the file is not moved
+        File file = new File("./target/movefile/hello.txt");
+        file = file.getAbsoluteFile();
+        assertTrue("The file should NOT have been moved", file.exists());
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                errorHandler(deadLetterChannel("mock:error").maximumRedeliveries(2).delay(100).logStackTrace(false));
+
+                from("file://target/movefile?move=done").process(new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        throw new IllegalArgumentException("Forced by unittest");
+                    }
+                });
+            }
+        };
+    }
+
+
+}
\ No newline at end of file

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFileDoNotMoveFileIfProcessFailsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFileDoNotMoveFileIfProcessFailsTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpDoNotDeleteFileIfProcessFailsTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpDoNotDeleteFileIfProcessFailsTest.java?rev=752532&r1=752531&r2=752532&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpDoNotDeleteFileIfProcessFailsTest.java (original)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpDoNotDeleteFileIfProcessFailsTest.java Wed Mar 11 17:19:12 2009
@@ -68,17 +68,17 @@
         // give time to NOT delete file
         Thread.sleep(200);
 
-        // TODO: CAMEL-1449
         // assert the file is deleted
-        //File file = new File("./res/home/deletefile/hello.txt");
-        //file = file.getAbsoluteFile();
-        //assertTrue("The file should NOT have been deleted", file.exists());
+        File file = new File("./res/home/deletefile/hello.txt");
+        file = file.getAbsoluteFile();
+        assertTrue("The file should NOT have been deleted", file.exists());
     }
 
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
-                errorHandler(deadLetterChannel("mock:error").maximumRedeliveries(2).delay(100));
+                // use no delay for fast unit testing
+                errorHandler(deadLetterChannel("mock:error").maximumRedeliveries(2).delay(0));
 
                 from(getFtpUrl()).process(new Processor() {
                     public void process(Exchange exchange) throws Exception {