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/08/24 07:33:44 UTC
svn commit: r807078 - in /camel/trunk/camel-core/src:
main/java/org/apache/camel/component/file/
test/java/org/apache/camel/component/file/
Author: davsclaus
Date: Mon Aug 24 05:33:43 2009
New Revision: 807078
URL: http://svn.apache.org/viewvc?rev=807078&view=rev
Log:
CAMEL-1927: Fixed file consumer option preMove not remoing correct name from idempotent repository.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveTest.java (with props)
Modified:
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/GenericFileOnCompletion.java
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=807078&r1=807077&r2=807078&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 Mon Aug 24 05:33:43 2009
@@ -192,7 +192,8 @@
// register on completion callback that does the completiom stategies
// (for instance to move the file after we have processed it)
- exchange.addOnCompletion(new GenericFileOnCompletion<T>(endpoint, operations, target));
+ String originalFileName = file.getFileName();
+ exchange.addOnCompletion(new GenericFileOnCompletion<T>(endpoint, operations, target, originalFileName));
// process the exchange
getProcessor().process(exchange);
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOnCompletion.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOnCompletion.java?rev=807078&r1=807077&r2=807078&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOnCompletion.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOnCompletion.java Mon Aug 24 05:33:43 2009
@@ -38,11 +38,14 @@
private GenericFileOperations<T> operations;
private ExceptionHandler exceptionHandler;
private GenericFile<T> file;
+ private String originalFileName;
- public GenericFileOnCompletion(GenericFileEndpoint<T> endpoint, GenericFileOperations<T> operations, GenericFile<T> file) {
+ public GenericFileOnCompletion(GenericFileEndpoint<T> endpoint, GenericFileOperations<T> operations,
+ GenericFile<T> file, String originalFileName) {
this.endpoint = endpoint;
this.operations = operations;
this.file = file;
+ this.originalFileName = originalFileName;
}
@SuppressWarnings("unchecked")
@@ -93,7 +96,9 @@
}
// remove file from the in progress list as its no longer in progress
- endpoint.getInProgressRepository().remove(file.getFileName());
+ // use the original file name that was used to add it to the repository
+ // as the name can be different when using preMove option
+ endpoint.getInProgressRepository().remove(originalFileName);
}
}
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveTest.java?rev=807078&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveTest.java Mon Aug 24 05:33:43 2009
@@ -0,0 +1,75 @@
+/**
+ * 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 FileConsumerPreMoveTest extends ContextTestSupport {
+
+ @Override
+ protected void setUp() throws Exception {
+ deleteDirectory("target/premove");
+ super.setUp();
+ }
+
+ public void testPreMove() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+
+ template.sendBodyAndHeader("file://target/premove", "Hello World", Exchange.FILE_NAME, "hello.txt");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testPreMoveSameFileTwice() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceivedInAnyOrder("Hello World", "Hello Again World");
+
+ template.sendBodyAndHeader("file://target/premove", "Hello World", Exchange.FILE_NAME, "hello.txt");
+ // give time for consumer to process this file before we drop the next file
+ Thread.sleep(2000);
+ template.sendBodyAndHeader("file://target/premove", "Hello Again World", Exchange.FILE_NAME, "hello.txt");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("file://target/premove?preMove=work/work-${file:name}")
+ .process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ File pre = new File("target/premove/work/work-hello.txt").getAbsoluteFile();
+ assertTrue("Pre move file should exist", pre.exists());
+ }
+ })
+ .to("mock:result");
+ }
+ };
+ }
+}
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date