Updated Branches: refs/heads/master 021e75e28 -> 41510d914
CAMEL-5883 fixed the issue of dynamic done file name Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/41510d91 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/41510d91 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/41510d91 Branch: refs/heads/master Commit: 41510d91416c7e16608ca905ebc2740c1663c734 Parents: 021e75e Author: Willem Jiang <ningji...@apache.org> Authored: Thu Jul 11 14:40:01 2013 +0800 Committer: Willem Jiang <ningji...@apache.org> Committed: Thu Jul 11 15:23:56 2013 +0800 ---------------------------------------------------------------------- .../component/file/GenericFileOnCompletion.java | 22 ++++++------ .../file/FileConsumeDoneFileIssueTest.java | 35 ++++++++++++++++++++ 2 files changed, 47 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/41510d91/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOnCompletion.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOnCompletion.java b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOnCompletion.java index 181b9a6..9b0701b 100644 --- a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOnCompletion.java +++ b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOnCompletion.java @@ -122,20 +122,22 @@ public class GenericFileOnCompletion<T> implements Synchronization { // must be last in batch to delete the done file name // delete done file if used (and not noop=true) boolean complete = exchange.getProperty(Exchange.BATCH_COMPLETE, false, Boolean.class); - if (endpoint.getDoneFileName() != null && !endpoint.isNoop() && complete) { + if (endpoint.getDoneFileName() != null && !endpoint.isNoop()) { // done file must be in same path as the original input file String doneFileName = endpoint.createDoneFileName(absoluteFileName); ObjectHelper.notEmpty(doneFileName, "doneFileName", endpoint); - - try { - // delete done file - boolean deleted = operations.deleteFile(doneFileName); - log.trace("Done file: {} was deleted: {}", doneFileName, deleted); - if (!deleted) { - log.warn("Done file: " + doneFileName + " could not be deleted"); + // we should delete the dynamic done file + if (endpoint.getDoneFileName().indexOf("{file:name") > 0 || complete) { + try { + // delete done file + boolean deleted = operations.deleteFile(doneFileName); + log.trace("Done file: {} was deleted: {}", doneFileName, deleted); + if (!deleted) { + log.warn("Done file: " + doneFileName + " could not be deleted"); + } + } catch (Exception e) { + handleException(e); } - } catch (Exception e) { - handleException(e); } } http://git-wip-us.apache.org/repos/asf/camel/blob/41510d91/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeDoneFileIssueTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeDoneFileIssueTest.java b/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeDoneFileIssueTest.java index e26d281..d57781a 100644 --- a/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeDoneFileIssueTest.java +++ b/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeDoneFileIssueTest.java @@ -59,6 +59,36 @@ public class FileConsumeDoneFileIssueTest extends ContextTestSupport { // the done file should be deleted assertFalse("Done file should be deleted", new File("target/done/foo.done").exists()); } + + public void testFileConsumseDynamicDoneFileName() throws Exception { + NotifyBuilder notify = new NotifyBuilder(context).whenDone(3).create(); + + template.sendBodyAndHeader("file:target/done2", "A", Exchange.FILE_NAME, "a.txt"); + template.sendBodyAndHeader("file:target/done2", "B", Exchange.FILE_NAME, "b.txt"); + template.sendBodyAndHeader("file:target/done2", "C", Exchange.FILE_NAME, "c.txt"); + template.sendBodyAndHeader("file:target/done2", "a", Exchange.FILE_NAME, "a.txt.done"); + template.sendBodyAndHeader("file:target/done2", "b", Exchange.FILE_NAME, "b.txt.done"); + template.sendBodyAndHeader("file:target/done2", "c", Exchange.FILE_NAME, "c.txt.done"); + + assertTrue("Done file should exists", new File("target/done2/a.txt.done").exists()); + assertTrue("Done file should exists", new File("target/done2/b.txt.done").exists()); + assertTrue("Done file should exists", new File("target/done2/c.txt.done").exists()); + + getMockEndpoint("mock:result").expectedBodiesReceivedInAnyOrder("A", "B", "C"); + + context.startRoute("bar"); + + assertMockEndpointsSatisfied(); + assertTrue(notify.matchesMockWaitTime()); + + Thread.sleep(250); + + // the done file should be deleted + assertFalse("Done file should be deleted", new File("target/done2/a.txt.done").exists()); + assertFalse("Done file should be deleted", new File("target/done2/b.txt.done").exists()); + assertFalse("Done file should be deleted", new File("target/done2/c.txt.done").exists()); + + } @Override protected RouteBuilder createRouteBuilder() throws Exception { @@ -68,6 +98,11 @@ public class FileConsumeDoneFileIssueTest extends ContextTestSupport { from("file:target/done?doneFileName=foo.done").routeId("foo").noAutoStartup() .convertBodyTo(String.class) .to("mock:result"); + + from("file:target/done2?doneFileName=${file:name}.done") + .routeId("bar").noAutoStartup() + .convertBodyTo(String.class) + .to("mock:result"); } }; }