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 2018/03/20 09:39:11 UTC
[camel] branch camel-2.21.x updated: CAMEL-12370: Fixed sftp
changed readLock type cast problem.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-2.21.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-2.21.x by this push:
new 5035fba CAMEL-12370: Fixed sftp changed readLock type cast problem.
5035fba is described below
commit 5035fba480e489a121efad44751a39e17581a632
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Mar 20 10:38:24 2018 +0100
CAMEL-12370: Fixed sftp changed readLock type cast problem.
---
.../SftpChangedExclusiveReadLockStrategy.java | 14 ++--
.../file/remote/sftp/SftpChangedReadLockTest.java | 98 ++++++++++++++++++++++
2 files changed, 106 insertions(+), 6 deletions(-)
diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/SftpChangedExclusiveReadLockStrategy.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/SftpChangedExclusiveReadLockStrategy.java
index 49b8363..516db35 100644
--- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/SftpChangedExclusiveReadLockStrategy.java
+++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/SftpChangedExclusiveReadLockStrategy.java
@@ -26,6 +26,7 @@ import org.apache.camel.component.file.GenericFile;
import org.apache.camel.component.file.GenericFileEndpoint;
import org.apache.camel.component.file.GenericFileExclusiveReadLockStrategy;
import org.apache.camel.component.file.GenericFileOperations;
+import org.apache.camel.component.file.remote.SftpRemoteFile;
import org.apache.camel.util.CamelLogger;
import org.apache.camel.util.StopWatch;
import org.slf4j.Logger;
@@ -69,7 +70,7 @@ public class SftpChangedExclusiveReadLockStrategy implements GenericFileExclusiv
long newLastModified = 0;
long newLength = 0;
- List<ChannelSftp.LsEntry> files;
+ List files; // operations.listFiles returns List<SftpRemoteFile> so do not use generic in the List files
if (fastExistsCheck) {
// use the absolute file path to only pickup the file we want to check, this avoids expensive
// list operations if we have a lot of files in the directory
@@ -94,17 +95,18 @@ public class SftpChangedExclusiveReadLockStrategy implements GenericFileExclusiv
}
}
LOG.trace("List files {} found {} files", file.getAbsoluteFilePath(), files.size());
- for (ChannelSftp.LsEntry f : files) {
+ for (Object f : files) {
+ SftpRemoteFile rf = (SftpRemoteFile) f;
boolean match;
if (fastExistsCheck) {
// uses the absolute file path as well
- match = f.getFilename().equals(file.getAbsoluteFilePath()) || f.getFilename().equals(file.getFileNameOnly());
+ match = rf.getFilename().equals(file.getAbsoluteFilePath()) || rf.getFilename().equals(file.getFileNameOnly());
} else {
- match = f.getFilename().equals(file.getFileNameOnly());
+ match = rf.getFilename().equals(file.getFileNameOnly());
}
if (match) {
- newLastModified = f.getAttrs().getMTime() * 1000L;
- newLength = f.getAttrs().getSize();
+ newLastModified = rf.getLastModified();
+ newLength = rf.getFileLength();
}
}
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpChangedReadLockTest.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpChangedReadLockTest.java
new file mode 100644
index 0000000..7ad710c
--- /dev/null
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpChangedReadLockTest.java
@@ -0,0 +1,98 @@
+/**
+ * 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.sftp;
+
+import java.io.File;
+import java.io.FileOutputStream;
+
+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 SftpChangedReadLockTest extends SftpServerTestSupport {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SftpChangedReadLockTest.class);
+
+ protected String getFtpUrl() {
+ return "sftp://localhost:" + getPort() + "/" + FTP_ROOT_DIR
+ + "/changed?username=admin&password=admin&readLock=changed&readLockCheckInterval=1000&delete=true";
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ deleteDirectory("target/changed");
+ super.setUp();
+ }
+
+ @Test
+ public void testChangedReadLock() throws Exception {
+ if (!canTest()) {
+ return;
+ }
+
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+ mock.expectedFileExists("target/changed/out/slowfile.dat");
+
+ context.startRoute("foo");
+
+ 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(200);
+ }
+
+ 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())
+ .routeId("foo").noAutoStartup()
+ .to("file:target/changed/out", "mock:result");
+ }
+ };
+ }
+
+}
--
To stop receiving notification emails like this one, please contact
davsclaus@apache.org.