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 2015/03/04 08:27:09 UTC

[2/3] camel git commit: CAMEL-8421: Polished and deleted the ftp tests as ftp severs do not have seconds in timestamp so min age testing is harder.

CAMEL-8421: Polished and deleted the ftp tests as ftp severs do not have seconds in timestamp so min age testing is harder.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/772e3375
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/772e3375
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/772e3375

Branch: refs/heads/master
Commit: 772e33753b16b6a8a31babe965937e91d275a95e
Parents: fa04c07
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Mar 4 08:26:19 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Mar 4 08:26:19 2015 +0100

----------------------------------------------------------------------
 .../component/file/GenericFileEndpoint.java     | 22 +++--
 ...tpChangedReadLockMinAgeShortCircuitTest.java | 80 ------------------
 .../remote/FtpChangedReadLockMinAgeTest.java    | 87 --------------------
 3 files changed, 14 insertions(+), 175 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/772e3375/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
index 5108fee..797fe40 100644
--- a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
@@ -890,6 +890,20 @@ public abstract class GenericFileEndpoint<T> extends ScheduledPollEndpoint imple
         this.readLockMinLength = readLockMinLength;
     }
 
+    public long getReadLockMinAge() {
+        return readLockMinAge;
+    }
+
+    /**
+     * This option applied only for readLock=change.
+     * This options allows to specify a minimum age the file must be before attempting to acquire the read lock.
+     * For example use readLockMinAge=300s to require the file is at last 5 minutes old.
+     * This can speedup the changed read lock as it will only attempt to acquire files which are at least that given age.
+     */
+    public void setReadLockMinAge(long readLockMinAge) {
+        this.readLockMinAge = readLockMinAge;
+    }
+
     public int getBufferSize() {
         return bufferSize;
     }
@@ -1083,14 +1097,6 @@ public abstract class GenericFileEndpoint<T> extends ScheduledPollEndpoint imple
         this.allowNullBody = allowNullBody;
     }
 
-    public long getReadLockMinAge() {
-        return readLockMinAge;
-    }
-
-    public void setReadLockMinAge(long readLockMinAge) {
-        this.readLockMinAge = readLockMinAge;
-    }
-
     /**
      * Configures the given message with the file which sets the body to the
      * file object.

http://git-wip-us.apache.org/repos/asf/camel/blob/772e3375/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpChangedReadLockMinAgeShortCircuitTest.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpChangedReadLockMinAgeShortCircuitTest.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpChangedReadLockMinAgeShortCircuitTest.java
deleted file mode 100644
index 4ce6492..0000000
--- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpChangedReadLockMinAgeShortCircuitTest.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/**
- * 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.remote;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.util.Date;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- *
- */
-public class FtpChangedReadLockMinAgeShortCircuitTest extends FtpServerTestSupport {
-
-    private static final Logger LOG = LoggerFactory.getLogger(FtpChangedReadLockMinAgeShortCircuitTest.class);
-
-    protected String getFtpUrl() {
-        return "ftp://admin@localhost:" + getPort() + "/changed?password=admin&readLock=changed&readLockMinAge=500&readLockCheckInterval=30000&readLockTimeout=90000&delete=true";
-    }
-
-    @Override
-    public void setUp() throws Exception {
-        super.setUp();
-        writeFile();
-        Thread.sleep(1000);
-    }
-
-    @Test
-    public void testChangedReadLock() throws Exception {
-        MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedMessageCount(1);
-        mock.expectedFileExists("target/changed/out/slowfile.dat");
-        // We should get the file on the first poll
-        mock.expectedMessagesMatches(property(Exchange.RECEIVED_TIMESTAMP).isLessThan(new Date().getTime() + 15000));
-
-        assertMockEndpointsSatisfied();
-    }
-
-    private void writeFile() throws Exception {
-        LOG.debug("Writing file...");
-
-        createDirectory(FTP_ROOT_DIR + "/changed");
-        FileOutputStream fos = new FileOutputStream(FTP_ROOT_DIR + "/changed/slowfile.dat", true);
-        fos.write("Line".getBytes());
-        fos.flush();
-        fos.close();
-        LOG.debug("Writing file DONE...");
-    }
-
-    @Override
-    protected RouteBuilder createRouteBuilder() throws Exception {
-        return new RouteBuilder() {
-            @Override
-            public void configure() throws Exception {
-                from(getFtpUrl()).to("file:target/changed/out", "mock:result");
-            }
-        };
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/772e3375/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpChangedReadLockMinAgeTest.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpChangedReadLockMinAgeTest.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpChangedReadLockMinAgeTest.java
deleted file mode 100644
index 28b1f95..0000000
--- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpChangedReadLockMinAgeTest.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- * 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.remote;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.util.Date;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- *
- */
-public class FtpChangedReadLockMinAgeTest extends FtpServerTestSupport {
-
-    private static final Logger LOG = LoggerFactory.getLogger(FtpChangedReadLockMinAgeTest.class);
-
-    protected String getFtpUrl() {
-        return "ftp://admin@localhost:" + getPort() + "/changed?password=admin&readLock=changed&readLockCheckInterval=1000&readLockMinAge=3000&delete=true";
-    }
-
-    @Test
-    public void testChangedReadLock() throws Exception {
-        MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedMessageCount(1);
-        mock.expectedFileExists("target/changed/out/slowfile.dat");
-        // writing takes ~2 seconds, and then it has to age for at least minAge milliseconds (3 seconds)
-        mock.expectedMessagesMatches(property(Exchange.RECEIVED_TIMESTAMP).isGreaterThan(new Date().getTime() + 5000));
-
-        writeSlowFile();
-
-        assertMockEndpointsSatisfied();
-
-        String content = context.getTypeConverter().convertTo(String.class, new File("target/changed/out/slowfile.dat"));
-        String[] lines = content.split(LS);
-        assertEquals("There should be 20 lines in the file", 20, lines.length);
-        for (int i = 0; i < 20; i++) {
-            assertEquals("Line " + i, lines[i]);
-        }
-    }
-
-    private void writeSlowFile() throws Exception {
-        LOG.debug("Writing slow file...");
-
-        createDirectory(FTP_ROOT_DIR + "/changed");
-        FileOutputStream fos = new FileOutputStream(FTP_ROOT_DIR + "/changed/slowfile.dat", true);
-        for (int i = 0; i < 20; i++) {
-            fos.write(("Line " + i + LS).getBytes());
-            LOG.debug("Writing line " + i);
-            Thread.sleep(100);
-        }
-
-        fos.flush();
-        fos.close();
-        LOG.debug("Writing slow file DONE...");
-    }
-
-    @Override
-    protected RouteBuilder createRouteBuilder() throws Exception {
-        return new RouteBuilder() {
-            @Override
-            public void configure() throws Exception {
-                from(getFtpUrl()).to("file:target/changed/out", "mock:result");
-            }
-        };
-    }
-
-}