You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2008/05/08 11:29:38 UTC
svn commit: r654456 - in /activemq/camel/trunk/camel-core/src:
main/java/org/apache/camel/component/file/
test/java/org/apache/camel/component/file/
Author: jstrachan
Date: Thu May 8 02:29:38 2008
New Revision: 654456
URL: http://svn.apache.org/viewvc?rev=654456&view=rev
Log:
added test case and fix for https://issues.apache.org/activemq/browse/CAMEL-498
Added:
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/MoveFilesToDirectoryWithNoopTest.java (with props)
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/MoveFilesToDirectoryTest.java
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java?rev=654456&r1=654455&r2=654456&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java Thu May 8 02:29:38 2008
@@ -36,6 +36,7 @@
private FileEndpoint endpoint;
private ConcurrentHashMap<File, File> filesBeingProcessed = new ConcurrentHashMap<File, File>();
private ConcurrentHashMap<File, Long> fileSizes = new ConcurrentHashMap<File, Long>();
+ private ConcurrentHashMap<File, Long> noopMap = new ConcurrentHashMap<File, Long>();
private boolean generateEmptyExchangeWhenIdle;
private boolean recursive = true;
@@ -44,6 +45,7 @@
private long lastPollTime;
private int unchangedDelay;
private boolean unchangedSize;
+
public FileConsumer(final FileEndpoint endpoint, Processor processor) {
super(endpoint, processor);
@@ -105,14 +107,22 @@
// we only care about file modified times if we are not deleting/moving
// files
if (endpoint.isNoop()) {
+ // do nothing now as isValidFile() filters unmodified files
+/*
long fileModified = file.lastModified();
- if (fileModified <= lastPollTime) {
+ Long previousModified = noopMap.get(file);
+ noopMap.put(file, fileModified);
+ if (previousModified == null || fileModified > previousModified) {
+ return 1;
+ }
+ else {
if (LOG.isDebugEnabled()) {
LOG.debug("Ignoring file: " + file + " as modified time: " + fileModified
- + " less than last poll time: " + lastPollTime);
+ + " less than the previous modified time: " + previousModified);
}
return 0;
}
+*/
} else {
if (filesBeingProcessed.contains(file)) {
return 1;
@@ -185,6 +195,13 @@
lastModifiedCheck = modifiedDuration >= getUnchangedDelay();
}
+ long fileModified = file.lastModified();
+ Long previousModified = noopMap.get(file);
+ noopMap.put(file, fileModified);
+ boolean modifiedChanged = previousModified == null || fileModified > previousModified;
+
+
+
boolean sizeCheck = true;
long sizeDifference = 0;
if (isUnchangedSize()) {
@@ -193,7 +210,7 @@
sizeCheck = sizeDifference == 0;
}
- boolean answer = lastModifiedCheck && sizeCheck;
+ boolean answer = lastModifiedCheck && sizeCheck && !modifiedChanged;
if (LOG.isDebugEnabled()) {
LOG.debug("file:" + file + " isUnchanged:" + answer + " " + "sizeCheck:" + sizeCheck + "("
Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/MoveFilesToDirectoryTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/MoveFilesToDirectoryTest.java?rev=654456&r1=654455&r2=654456&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/MoveFilesToDirectoryTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/MoveFilesToDirectoryTest.java Thu May 8 02:29:38 2008
@@ -31,6 +31,7 @@
protected String outputDirectory = testDirectory + "/output";
protected String fileName = "foo.txt";
protected Object expectedBody = "Hello there!";
+ protected boolean noop = false;
public void testFileRoute() throws Exception {
template.sendBodyAndHeader("file:" + inputDirectory, expectedBody, FileComponent.HEADER_FILE_NAME, fileName);
@@ -49,7 +50,11 @@
Thread.sleep(5000);
File file = new File(inputDirectory + "/" + fileName);
- File newFile = new File(outputDirectory + "/" + fileName);
+
+ File outDir = new File(outputDirectory);
+ outDir.mkdirs();
+
+ File newFile = new File(outDir, fileName);
assertFileExists(file);
assertFileNotExists(newFile);
@@ -81,8 +86,12 @@
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
- from("file:" + outputDirectory).to("mock:result");
+ from(getOutputEndpointUri()).to("mock:result");
}
};
}
+
+ protected String getOutputEndpointUri() {
+ return "file:" + outputDirectory;
+ }
}
\ No newline at end of file
Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/MoveFilesToDirectoryWithNoopTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/MoveFilesToDirectoryWithNoopTest.java?rev=654456&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/MoveFilesToDirectoryWithNoopTest.java (added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/MoveFilesToDirectoryWithNoopTest.java Thu May 8 02:29:38 2008
@@ -0,0 +1,29 @@
+/**
+ *
+ * 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;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class MoveFilesToDirectoryWithNoopTest extends MoveFilesToDirectoryTest {
+
+ @Override
+ protected String getOutputEndpointUri() {
+ return super.getOutputEndpointUri() + "?noop=true";
+ }
+}
Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/MoveFilesToDirectoryWithNoopTest.java
------------------------------------------------------------------------------
svn:eol-style = native