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 2008/08/09 13:34:54 UTC
svn commit: r684230 - in /activemq/camel/trunk/camel-core/src:
main/java/org/apache/camel/component/file/
test/java/org/apache/camel/component/file/
Author: davsclaus
Date: Sat Aug 9 04:34:54 2008
New Revision: 684230
URL: http://svn.apache.org/viewvc?rev=684230&view=rev
Log:
CAMEL-790: Introduced alwaysConsume to FileConsumer so you can consume the file regardless if it hasn't changed since last time it was consumed.
Added:
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileAlwaysConsumeTest.java (contents, props changed)
- copied, changed from r684222, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeSingleDirectoryOnlyTest.java
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/FileConsumeSingleDirectoryOnlyTest.java (contents, props changed)
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=684230&r1=684229&r2=684230&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 Sat Aug 9 04:34:54 2008
@@ -52,6 +52,7 @@
private boolean recursive;
private String regexPattern = "";
private boolean exclusiveReadLock = true;
+ private boolean alwaysConsume;
public FileConsumer(final FileEndpoint endpoint, Processor processor) {
super(endpoint, processor);
@@ -233,7 +234,7 @@
boolean result = false;
if (file != null && file.exists()) {
// TODO: maybe use a configurable strategy instead of the hardcoded one based on last file change
- if (isMatched(file) && isChanged(file)) {
+ if (isMatched(file) && (alwaysConsume || isChanged(file))) {
result = true;
}
}
@@ -369,6 +370,9 @@
return unchangedDelay;
}
+ /**
+ * @deprecated will be removed in Camel 2.0
+ */
public void setUnchangedDelay(int unchangedDelay) {
this.unchangedDelay = unchangedDelay;
}
@@ -377,6 +381,9 @@
return unchangedSize;
}
+ /**
+ * @deprecated will be removed in Camel 2.0
+ */
public void setUnchangedSize(boolean unchangedSize) {
this.unchangedSize = unchangedSize;
}
@@ -388,4 +395,12 @@
public void setExclusiveReadLock(boolean exclusiveReadLock) {
this.exclusiveReadLock = exclusiveReadLock;
}
+
+ public boolean isAlwaysConsume() {
+ return alwaysConsume;
+ }
+
+ public void setAlwaysConsume(boolean alwaysConsume) {
+ this.alwaysConsume = alwaysConsume;
+ }
}
Copied: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileAlwaysConsumeTest.java (from r684222, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeSingleDirectoryOnlyTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileAlwaysConsumeTest.java?p2=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileAlwaysConsumeTest.java&p1=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeSingleDirectoryOnlyTest.java&r1=684222&r2=684230&rev=684230&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeSingleDirectoryOnlyTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileAlwaysConsumeTest.java Sat Aug 9 04:34:54 2008
@@ -1,52 +1,99 @@
-/**
- * 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 org.apache.camel.ContextTestSupport;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.builder.RouteBuilder;
-
-/**
- * Unit test for consuming the single directory only.
- */
-public class FileConsumeSingleDirectoryOnlyTest extends ContextTestSupport {
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- deleteDirectory("target/singledirectoryonly");
- template.sendBodyAndHeader("file://target/singledirectoryonly", "Hello World", FileComponent.HEADER_FILE_NAME, "report.txt");
- template.sendBodyAndHeader("file://target/singledirectoryonly", "Bye World", FileComponent.HEADER_FILE_NAME, "report2.txt");
- template.sendBodyAndHeader("file://target/singledirectoryonly/2008", "2008 Report", FileComponent.HEADER_FILE_NAME, "report2008.txt");
- }
-
- public void testConsumeFileOnly() throws Exception {
- MockEndpoint mock = getMockEndpoint("mock:result");
- mock.expectedBodiesReceived("Hello World", "Bye World");
-
- assertMockEndpointsSatisifed();
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- public void configure() throws Exception {
- from("file://target/singledirectoryonly/?consumer.recursive=false&delete=true").to("mock:result");
- }
- };
- }
+/**
+ * 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 org.apache.camel.ContextTestSupport;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.builder.RouteBuilder;
+
+import java.io.File;
+
+/**
+ * Unit test for the alwaysConsume option.
+ */
+public class FileAlwaysConsumeTest extends ContextTestSupport {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ deleteDirectory("target/alwaysconsume");
+ template.sendBodyAndHeader("file://target/alwaysconsume/", "Hello World", FileComponent.HEADER_FILE_NAME, "report.txt");
+ }
+
+ public void testAlwaysConsume() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ public void configure() throws Exception {
+ from("file://target/alwaysconsume/?consumer.alwaysConsume=true&moveNamePrefix=done/").to("mock:result");
+ }
+ });
+
+ // consume the file the first time
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("Hello World");
+ mock.expectedMessageCount(1);
+
+ assertMockEndpointsSatisifed();
+
+ Thread.sleep(1000);
+
+ // reset mock and set new expectations
+ mock.reset();
+ mock.expectedBodiesReceived("Hello World");
+ mock.expectedMessageCount(1);
+
+ // move file back
+ File file = new File("target/alwaysconsume/done/report.txt");
+ File renamed = new File("target/alwaysconsume/report.txt");
+ file = file.getAbsoluteFile();
+ file.renameTo(renamed.getAbsoluteFile());
+
+ // should consume the file again
+ assertMockEndpointsSatisifed();
+ }
+
+ public void testNotAlwaysConsume() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ public void configure() throws Exception {
+ from("file://target/alwaysconsume/?consumer.alwaysConsume=false&moveNamePrefix=done/").to("mock:result");
+ }
+ });
+
+ // consume the file the first time
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("Hello World");
+ mock.expectedMessageCount(1);
+
+ assertMockEndpointsSatisifed();
+
+ Thread.sleep(1000);
+
+ // reset mock and set new expectations
+ mock.reset();
+ mock.expectedMessageCount(0);
+
+ // move file back
+ File file = new File("target/alwaysconsume/done/report.txt");
+ File renamed = new File("target/alwaysconsume/report.txt");
+ file = file.getAbsoluteFile();
+ file.renameTo(renamed.getAbsoluteFile());
+
+ // should NOT consume the file again, let 2 secs pass to let the consuemr try to consume it but it should not
+ Thread.sleep(2000);
+ assertMockEndpointsSatisifed();
+ }
+
}
\ No newline at end of file
Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileAlwaysConsumeTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileAlwaysConsumeTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileAlwaysConsumeTest.java
------------------------------------------------------------------------------
svn:mergeinfo =
Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeSingleDirectoryOnlyTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeSingleDirectoryOnlyTest.java?rev=684230&r1=684229&r2=684230&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeSingleDirectoryOnlyTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeSingleDirectoryOnlyTest.java Sat Aug 9 04:34:54 2008
@@ -1,52 +1,52 @@
-/**
- * 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 org.apache.camel.ContextTestSupport;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.builder.RouteBuilder;
-
-/**
- * Unit test for consuming the single directory only.
- */
-public class FileConsumeSingleDirectoryOnlyTest extends ContextTestSupport {
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- deleteDirectory("target/singledirectoryonly");
- template.sendBodyAndHeader("file://target/singledirectoryonly", "Hello World", FileComponent.HEADER_FILE_NAME, "report.txt");
- template.sendBodyAndHeader("file://target/singledirectoryonly", "Bye World", FileComponent.HEADER_FILE_NAME, "report2.txt");
- template.sendBodyAndHeader("file://target/singledirectoryonly/2008", "2008 Report", FileComponent.HEADER_FILE_NAME, "report2008.txt");
- }
-
- public void testConsumeFileOnly() throws Exception {
- MockEndpoint mock = getMockEndpoint("mock:result");
- mock.expectedBodiesReceived("Hello World", "Bye World");
-
- assertMockEndpointsSatisifed();
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- public void configure() throws Exception {
- from("file://target/singledirectoryonly/?consumer.recursive=false&delete=true").to("mock:result");
- }
- };
- }
+/**
+ * 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 org.apache.camel.ContextTestSupport;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * Unit test for consuming the single directory only.
+ */
+public class FileConsumeSingleDirectoryOnlyTest extends ContextTestSupport {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ deleteDirectory("target/singledirectoryonly");
+ template.sendBodyAndHeader("file://target/singledirectoryonly", "Hello World", FileComponent.HEADER_FILE_NAME, "report.txt");
+ template.sendBodyAndHeader("file://target/singledirectoryonly", "Bye World", FileComponent.HEADER_FILE_NAME, "report2.txt");
+ template.sendBodyAndHeader("file://target/singledirectoryonly/2008", "2008 Report", FileComponent.HEADER_FILE_NAME, "report2008.txt");
+ }
+
+ public void testConsumeFileOnly() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("Hello World", "Bye World");
+
+ assertMockEndpointsSatisifed();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+ from("file://target/singledirectoryonly/?consumer.recursive=false&delete=true").to("mock:result");
+ }
+ };
+ }
}
\ No newline at end of file
Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeSingleDirectoryOnlyTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeSingleDirectoryOnlyTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date