From a42f02ec2fcd7f00d4d334c1290379b96468cb0b Mon Sep 17 00:00:00 2001 From: Iwein Fuld Date: Mon, 11 Aug 2008 20:32:52 +0000 Subject: [PATCH] --- .../adapter/file/AbstractDirectorySource.java | 10 +- ...ectoryContentManager.java => Backlog.java} | 69 ++++--- .../integration/adapter/ftp/FtpSource.java | 7 +- .../integration/adapter/ftp/BacklogTests.java | 180 ++++++++++++++++++ .../ftp/DirectoryContentManagerTests.java | 179 ----------------- .../ftp/config/FtpTargetIntegrationTest.java | 70 +++++++ 6 files changed, 292 insertions(+), 223 deletions(-) rename org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/{DirectoryContentManager.java => Backlog.java} (55%) create mode 100644 org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/BacklogTests.java delete mode 100644 org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/DirectoryContentManagerTests.java create mode 100644 org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/FtpTargetIntegrationTest.java diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/AbstractDirectorySource.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/AbstractDirectorySource.java index df41747ffe..9442e341e5 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/AbstractDirectorySource.java +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/AbstractDirectorySource.java @@ -43,7 +43,7 @@ public abstract class AbstractDirectorySource implements PollableSource, M private final Log logger = LogFactory.getLog(this.getClass()); - private final DirectoryContentManager directoryContentManager = new DirectoryContentManager(); + private final Backlog directoryContentManager = new Backlog(); private final MessageCreator messageCreator; @@ -52,7 +52,7 @@ public abstract class AbstractDirectorySource implements PollableSource, M this.messageCreator = messageCreator; } - protected DirectoryContentManager getDirectoryContentManager() { + protected Backlog getDirectoryContentManager() { return this.directoryContentManager; } @@ -78,12 +78,12 @@ public abstract class AbstractDirectorySource implements PollableSource, M /** * Naive implementation that ignores thread safety. Subclasses that want to * be thread safe and use the reservation facilities of - * {@link DirectoryContentManager} override this method and call - * directoryContentManager.fileProcessing(...)directoryContentManager.fileProcessing(...) with the appropriate arguments. * @param directoryContentManager * @throws IOException */ - protected void refreshSnapshotAndMarkProcessing(DirectoryContentManager directoryContentManager) throws IOException { + protected void refreshSnapshotAndMarkProcessing(Backlog directoryContentManager) throws IOException { HashMap snapshot = new HashMap(); this.populateSnapshot(snapshot); directoryContentManager.processSnapshot(snapshot); diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/DirectoryContentManager.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/Backlog.java similarity index 55% rename from org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/DirectoryContentManager.java rename to org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/Backlog.java index ad68cf5fc0..0e09baf95d 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/DirectoryContentManager.java +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/Backlog.java @@ -20,41 +20,40 @@ import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.util.Assert; /** - * Tracks changes in a directory. This implementation is thread-safe as it + * Tracks changes in a collection. This implementation is thread-safe as it * allows to synchronously process a new directory structure. * * @author Marius Bogoevici * @author Mark Fisher - * @author iwein + * @author Iwein Fuld */ -public class DirectoryContentManager { +public class Backlog { private final Log logger = LogFactory.getLog(this.getClass()); - private Map previousSnapshot = new HashMap(); + private Map previousSnapshot = new HashMap(); - private final Map backlog = new HashMap(); + private final Map backlog = new HashMap(); /** * This is the storage for backlog that is being processed by a specific * thread. Not initialized means that we're not in thread safe mode (just * working directly on the backlog) */ - private ThreadLocal> processingBuffer = new ThreadLocal>() { + private ThreadLocal> processingBuffer = new ThreadLocal>() { @Override - protected Map initialValue() { - return new HashMap(); + protected Map initialValue() { + return new HashMap(); } }; - public synchronized void processSnapshot(Map currentSnapshot) { + public synchronized void processSnapshot(Map currentSnapshot) { /* * clear the threadLocal backlog. When the thread processes a new * snapshot it is done with the previous message. If there are still @@ -62,71 +61,71 @@ public class DirectoryContentManager { * were not processed, nor raised as failed. */ Assert.isTrue(processingBuffer.get().isEmpty(), "Processing buffer not emptied before poll."); - Iterator> iter = this.backlog.entrySet().iterator(); + Iterator> iter = this.backlog.entrySet().iterator(); while (iter.hasNext()) { - String fileName = iter.next().getKey(); - if (!currentSnapshot.containsKey(fileName)) { + String key = iter.next().getKey(); + if (!currentSnapshot.containsKey(key)) { if (logger.isDebugEnabled()) { - logger.debug("Removing file '" + fileName + logger.debug("Removing item '" + key + "' from backlog. It no longer exists in remote directory."); } iter.remove(); } } - for (String fileName : currentSnapshot.keySet()) { - if (!this.previousSnapshot.containsKey(fileName) - || (!this.previousSnapshot.get(fileName).equals(currentSnapshot.get(fileName)))) { + for (String key : currentSnapshot.keySet()) { + if (!this.previousSnapshot.containsKey(key) + || (!this.previousSnapshot.get(key).equals(currentSnapshot.get(key)))) { if (logger.isDebugEnabled()) { - logger.debug("Adding new or modified file '" + fileName + "' to backlog."); + logger.debug("Adding new or modified item '" + key + "' to backlog."); } - this.backlog.put(fileName, currentSnapshot.get(fileName)); + this.backlog.put(key, currentSnapshot.get(key)); } } - this.previousSnapshot = new HashMap(currentSnapshot); + this.previousSnapshot = new HashMap(currentSnapshot); } - public synchronized void fileProcessing(String... fileNames) { - for (String fileName : fileNames) { - if (fileName != null) { + public synchronized void itemProcessing(String... keys) { + for (String key : keys) { + if (key != null) { if (logger.isDebugEnabled()) { - logger.debug("Moving file '" + fileName + logger.debug("Moving item '" + key + "' from the backlog to thread local backlog. It is being processed."); } - processingBuffer.get().put(fileName, this.backlog.remove(fileName)); + processingBuffer.get().put(key, this.backlog.remove(key)); } } } public synchronized void processingFailed() { if (logger.isDebugEnabled()) { - logger.debug("Moving all files from processing buffer to backlog. Processing has failed"); + logger.debug("Moving all items from processing buffer to backlog. Processing has failed"); } - Map processing = this.processingBuffer.get(); + Map processing = this.processingBuffer.get(); this.backlog.putAll(processing); processing.clear(); } - public synchronized void fileProcessed(String... fileNames) { - for (String fileName : fileNames) { - if (fileName != null) { + public synchronized void fileProcessed(String... keys) { + for (String key : keys) { + if (key != null) { if (logger.isDebugEnabled()) { - logger.debug("Removing file '" + fileName + "' from the undo buffer. It has been processed."); + logger.debug("Removing item '" + key + "' from the undo buffer. It has been processed."); } /* * It's not relevant if clients use the thread safe approach or * not at this point, so we act on both. */ - this.processingBuffer.get().remove(fileName); - this.backlog.remove(fileName); + this.processingBuffer.get().remove(key); + this.backlog.remove(key); } } } - public Map getBacklog() { + public Map getBacklog() { return Collections.unmodifiableMap(this.backlog); } - public Map getProcessingBuffer() { + public Map getProcessingBuffer() { return Collections.unmodifiableMap(this.processingBuffer.get()); } diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FtpSource.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FtpSource.java index 231a356068..4c24f4c827 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FtpSource.java +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FtpSource.java @@ -33,7 +33,7 @@ import org.apache.commons.net.ftp.FTPFile; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.annotation.Required; import org.springframework.integration.adapter.file.AbstractDirectorySource; -import org.springframework.integration.adapter.file.DirectoryContentManager; +import org.springframework.integration.adapter.file.Backlog; import org.springframework.integration.adapter.file.FileInfo; import org.springframework.integration.message.Message; import org.springframework.integration.message.MessageCreator; @@ -117,14 +117,14 @@ public class FtpSource extends AbstractDirectorySource> implements Di } @Override - protected void refreshSnapshotAndMarkProcessing(DirectoryContentManager directoryContentManager) throws IOException { + protected void refreshSnapshotAndMarkProcessing(Backlog directoryContentManager) throws IOException { Map snapshot = new HashMap(); synchronized (directoryContentManager) { populateSnapshot(snapshot); directoryContentManager.processSnapshot(snapshot); ArrayList backlog = new ArrayList(directoryContentManager.getBacklog().keySet()); int toIndex = maxFilesPerPayload == -1 ? backlog.size() : Math.min(maxFilesPerPayload, backlog.size()); - directoryContentManager.fileProcessing(backlog.subList(0, toIndex).toArray(new String[] {})); + directoryContentManager.itemProcessing(backlog.subList(0, toIndex).toArray(new String[] {})); } } @@ -220,5 +220,4 @@ public class FtpSource extends AbstractDirectorySource> implements Di fileProcessed(file.getName()); } } - } diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/BacklogTests.java b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/BacklogTests.java new file mode 100644 index 0000000000..59b5634bde --- /dev/null +++ b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/BacklogTests.java @@ -0,0 +1,180 @@ +/* + * Copyright 2002-2008 the original author or authors. + * + * Licensed 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.springframework.integration.adapter.ftp; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.springframework.integration.adapter.file.Backlog; +import org.springframework.integration.adapter.file.FileInfo; + +/** + * @author Marius Bogoevici + * @author Iwein Fuld + */ +public class BacklogTests { + + private Backlog backlog; + + + @Before + public void setUp() { + backlog = new Backlog(); + } + + + @Test + public void testInitialization() { + Assert.assertTrue(backlog.getBacklog().isEmpty()); + Map remoteSnapshot = generateInitialSnapshot(); + backlog.processSnapshot(remoteSnapshot); + Assert.assertEquals(3, backlog.getBacklog().size()); + Assert.assertTrue(backlog.getBacklog().containsKey("a.txt")); + Assert.assertTrue(backlog.getBacklog().containsKey("b.txt")); + Assert.assertTrue(backlog.getBacklog().containsKey("c.txt")); + } + + @Test + public void testFullProcessingInOneStep() { + Assert.assertTrue(backlog.getBacklog().isEmpty()); + Map remoteSnapshot = generateInitialSnapshot(); + backlog.processSnapshot(remoteSnapshot); + backlog.fileProcessed("a.txt"); + backlog.fileProcessed("b.txt"); + backlog.fileProcessed("c.txt"); + Assert.assertTrue(backlog.getBacklog().isEmpty()); + backlog.processSnapshot(remoteSnapshot); + Assert.assertTrue(backlog.getBacklog().isEmpty()); + } + + @Test + public void testFullProcessingInTwoSteps() { + Assert.assertTrue(backlog.getBacklog().isEmpty()); + Map remoteSnapshot = generateInitialSnapshot(); + backlog.processSnapshot(remoteSnapshot); + backlog.fileProcessed("a.txt"); + backlog.fileProcessed("b.txt"); + Assert.assertEquals(1, backlog.getBacklog().size()); + Assert.assertTrue(backlog.getBacklog().containsKey("c.txt")); + backlog.processSnapshot(remoteSnapshot); + Assert.assertEquals(1, backlog.getBacklog().size()); + Assert.assertTrue(backlog.getBacklog().containsKey("c.txt")); + backlog.fileProcessed("c.txt"); + Assert.assertTrue(backlog.getBacklog().isEmpty()); + backlog.processSnapshot(remoteSnapshot); + Assert.assertTrue(backlog.getBacklog().isEmpty()); + } + + @Test + public void testOneFileChangedSize() { + Assert.assertTrue(backlog.getBacklog().isEmpty()); + Map remoteSnapshot = generateInitialSnapshot(); + backlog.processSnapshot(remoteSnapshot); + backlog.fileProcessed("a.txt"); + backlog.fileProcessed("b.txt"); + Assert.assertEquals(1, backlog.getBacklog().size()); + Assert.assertTrue(backlog.getBacklog().containsKey("c.txt")); + backlog.processSnapshot(remoteSnapshot); + Assert.assertEquals(1, backlog.getBacklog().size()); + Assert.assertTrue(backlog.getBacklog().containsKey("c.txt")); + backlog.fileProcessed("c.txt"); + Assert.assertTrue(backlog.getBacklog().isEmpty()); + backlog.processSnapshot(remoteSnapshot); + remoteSnapshot.put("c.txt", new FileInfo("c.txt", 1001, 112)); + backlog.processSnapshot(remoteSnapshot); + Assert.assertEquals(1, backlog.getBacklog().size()); + Assert.assertTrue(backlog.getBacklog().containsKey("c.txt")); + } + + @Test + public void testOneFileChangedDate() { + Assert.assertTrue(backlog.getBacklog().isEmpty()); + Map remoteSnapshot = generateInitialSnapshot(); + backlog.processSnapshot(remoteSnapshot); + backlog.fileProcessed("a.txt"); + backlog.fileProcessed("b.txt"); + Assert.assertEquals(1, backlog.getBacklog().size()); + Assert.assertTrue(backlog.getBacklog().containsKey("c.txt")); + backlog.processSnapshot(remoteSnapshot); + Assert.assertEquals(1, backlog.getBacklog().size()); + Assert.assertTrue(backlog.getBacklog().containsKey("c.txt")); + backlog.fileProcessed("c.txt"); + Assert.assertTrue(backlog.getBacklog().isEmpty()); + backlog.processSnapshot(remoteSnapshot); + remoteSnapshot.put("c.txt", new FileInfo("c.txt", 1011, 102)); + backlog.processSnapshot(remoteSnapshot); + Assert.assertEquals(1, backlog.getBacklog().size()); + Assert.assertTrue(backlog.getBacklog().containsKey("c.txt")); + } + + @Test + public void testOneFileAdded() { + Assert.assertTrue(backlog.getBacklog().isEmpty()); + Map remoteSnapshot = generateInitialSnapshot(); + backlog.processSnapshot(remoteSnapshot); + backlog.fileProcessed("a.txt"); + backlog.fileProcessed("b.txt"); + backlog.fileProcessed("c.txt"); + Assert.assertTrue(backlog.getBacklog().isEmpty()); + backlog.processSnapshot(remoteSnapshot); + remoteSnapshot.put("d.txt", new FileInfo("d.txt", 1003, 103)); + backlog.processSnapshot(remoteSnapshot); + Assert.assertEquals(1, backlog.getBacklog().size()); + Assert.assertTrue(backlog.getBacklog().containsKey("d.txt")); + } + + @Test + public void testOneFileRemoved() { + Assert.assertTrue(backlog.getBacklog().isEmpty()); + Map remoteSnapshot = generateInitialSnapshot(); + backlog.processSnapshot(remoteSnapshot); + backlog.fileProcessed("a.txt"); + backlog.fileProcessed("b.txt"); + backlog.fileProcessed("c.txt"); + Assert.assertTrue(backlog.getBacklog().isEmpty()); + backlog.processSnapshot(remoteSnapshot); + remoteSnapshot.remove("c.txt"); + backlog.processSnapshot(remoteSnapshot); + Assert.assertTrue(backlog.getBacklog().isEmpty()); + } + + @Test + public void testOneFileRemovedBeforeBeingProcessedInTheNextStep() { + Assert.assertTrue(backlog.getBacklog().isEmpty()); + Map remoteSnapshot = generateInitialSnapshot(); + backlog.processSnapshot(remoteSnapshot); + Assert.assertTrue(backlog.getBacklog().containsKey("c.txt")); + remoteSnapshot.remove("c.txt"); + backlog.processSnapshot(remoteSnapshot); + Assert.assertEquals(2, backlog.getBacklog().size()); + backlog.processSnapshot(remoteSnapshot); + Assert.assertEquals(2, backlog.getBacklog().size()); + } + + + private static Map generateInitialSnapshot() { + Map remoteSnapshot = new HashMap(); + remoteSnapshot.put("a.txt", new FileInfo("a.txt", 1000, 100)); + remoteSnapshot.put("b.txt", new FileInfo("b.txt", 1001, 101)); + remoteSnapshot.put("c.txt", new FileInfo("c.txt", 1002, 102)); + return remoteSnapshot; + } + +} diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/DirectoryContentManagerTests.java b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/DirectoryContentManagerTests.java deleted file mode 100644 index 4f05ddd350..0000000000 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/DirectoryContentManagerTests.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright 2002-2008 the original author or authors. - * - * Licensed 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.springframework.integration.adapter.ftp; - -import java.util.HashMap; -import java.util.Map; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.springframework.integration.adapter.file.DirectoryContentManager; -import org.springframework.integration.adapter.file.FileInfo; - -/** - * @author Marius Bogoevici - */ -public class DirectoryContentManagerTests { - - private DirectoryContentManager directoryContentManager; - - - @Before - public void setUp() { - directoryContentManager = new DirectoryContentManager(); - } - - - @Test - public void testInitialization() { - Assert.assertTrue(directoryContentManager.getBacklog().isEmpty()); - Map remoteSnapshot = generateInitialSnapshot(); - directoryContentManager.processSnapshot(remoteSnapshot); - Assert.assertEquals(3, directoryContentManager.getBacklog().size()); - Assert.assertTrue(directoryContentManager.getBacklog().containsKey("a.txt")); - Assert.assertTrue(directoryContentManager.getBacklog().containsKey("b.txt")); - Assert.assertTrue(directoryContentManager.getBacklog().containsKey("c.txt")); - } - - @Test - public void testFullProcessingInOneStep() { - Assert.assertTrue(directoryContentManager.getBacklog().isEmpty()); - Map remoteSnapshot = generateInitialSnapshot(); - directoryContentManager.processSnapshot(remoteSnapshot); - directoryContentManager.fileProcessed("a.txt"); - directoryContentManager.fileProcessed("b.txt"); - directoryContentManager.fileProcessed("c.txt"); - Assert.assertTrue(directoryContentManager.getBacklog().isEmpty()); - directoryContentManager.processSnapshot(remoteSnapshot); - Assert.assertTrue(directoryContentManager.getBacklog().isEmpty()); - } - - @Test - public void testFullProcessingInTwoSteps() { - Assert.assertTrue(directoryContentManager.getBacklog().isEmpty()); - Map remoteSnapshot = generateInitialSnapshot(); - directoryContentManager.processSnapshot(remoteSnapshot); - directoryContentManager.fileProcessed("a.txt"); - directoryContentManager.fileProcessed("b.txt"); - Assert.assertEquals(1, directoryContentManager.getBacklog().size()); - Assert.assertTrue(directoryContentManager.getBacklog().containsKey("c.txt")); - directoryContentManager.processSnapshot(remoteSnapshot); - Assert.assertEquals(1, directoryContentManager.getBacklog().size()); - Assert.assertTrue(directoryContentManager.getBacklog().containsKey("c.txt")); - directoryContentManager.fileProcessed("c.txt"); - Assert.assertTrue(directoryContentManager.getBacklog().isEmpty()); - directoryContentManager.processSnapshot(remoteSnapshot); - Assert.assertTrue(directoryContentManager.getBacklog().isEmpty()); - } - - @Test - public void testOneFileChangedSize() { - Assert.assertTrue(directoryContentManager.getBacklog().isEmpty()); - Map remoteSnapshot = generateInitialSnapshot(); - directoryContentManager.processSnapshot(remoteSnapshot); - directoryContentManager.fileProcessed("a.txt"); - directoryContentManager.fileProcessed("b.txt"); - Assert.assertEquals(1, directoryContentManager.getBacklog().size()); - Assert.assertTrue(directoryContentManager.getBacklog().containsKey("c.txt")); - directoryContentManager.processSnapshot(remoteSnapshot); - Assert.assertEquals(1, directoryContentManager.getBacklog().size()); - Assert.assertTrue(directoryContentManager.getBacklog().containsKey("c.txt")); - directoryContentManager.fileProcessed("c.txt"); - Assert.assertTrue(directoryContentManager.getBacklog().isEmpty()); - directoryContentManager.processSnapshot(remoteSnapshot); - remoteSnapshot.put("c.txt", new FileInfo("c.txt", 1001, 112)); - directoryContentManager.processSnapshot(remoteSnapshot); - Assert.assertEquals(1, directoryContentManager.getBacklog().size()); - Assert.assertTrue(directoryContentManager.getBacklog().containsKey("c.txt")); - } - - @Test - public void testOneFileChangedDate() { - Assert.assertTrue(directoryContentManager.getBacklog().isEmpty()); - Map remoteSnapshot = generateInitialSnapshot(); - directoryContentManager.processSnapshot(remoteSnapshot); - directoryContentManager.fileProcessed("a.txt"); - directoryContentManager.fileProcessed("b.txt"); - Assert.assertEquals(1, directoryContentManager.getBacklog().size()); - Assert.assertTrue(directoryContentManager.getBacklog().containsKey("c.txt")); - directoryContentManager.processSnapshot(remoteSnapshot); - Assert.assertEquals(1, directoryContentManager.getBacklog().size()); - Assert.assertTrue(directoryContentManager.getBacklog().containsKey("c.txt")); - directoryContentManager.fileProcessed("c.txt"); - Assert.assertTrue(directoryContentManager.getBacklog().isEmpty()); - directoryContentManager.processSnapshot(remoteSnapshot); - remoteSnapshot.put("c.txt", new FileInfo("c.txt", 1011, 102)); - directoryContentManager.processSnapshot(remoteSnapshot); - Assert.assertEquals(1, directoryContentManager.getBacklog().size()); - Assert.assertTrue(directoryContentManager.getBacklog().containsKey("c.txt")); - } - - @Test - public void testOneFileAdded() { - Assert.assertTrue(directoryContentManager.getBacklog().isEmpty()); - Map remoteSnapshot = generateInitialSnapshot(); - directoryContentManager.processSnapshot(remoteSnapshot); - directoryContentManager.fileProcessed("a.txt"); - directoryContentManager.fileProcessed("b.txt"); - directoryContentManager.fileProcessed("c.txt"); - Assert.assertTrue(directoryContentManager.getBacklog().isEmpty()); - directoryContentManager.processSnapshot(remoteSnapshot); - remoteSnapshot.put("d.txt", new FileInfo("d.txt", 1003, 103)); - directoryContentManager.processSnapshot(remoteSnapshot); - Assert.assertEquals(1, directoryContentManager.getBacklog().size()); - Assert.assertTrue(directoryContentManager.getBacklog().containsKey("d.txt")); - } - - @Test - public void testOneFileRemoved() { - Assert.assertTrue(directoryContentManager.getBacklog().isEmpty()); - Map remoteSnapshot = generateInitialSnapshot(); - directoryContentManager.processSnapshot(remoteSnapshot); - directoryContentManager.fileProcessed("a.txt"); - directoryContentManager.fileProcessed("b.txt"); - directoryContentManager.fileProcessed("c.txt"); - Assert.assertTrue(directoryContentManager.getBacklog().isEmpty()); - directoryContentManager.processSnapshot(remoteSnapshot); - remoteSnapshot.remove("c.txt"); - directoryContentManager.processSnapshot(remoteSnapshot); - Assert.assertTrue(directoryContentManager.getBacklog().isEmpty()); - } - - @Test - public void testOneFileRemovedBeforeBeingProcessedInTheNextStep() { - Assert.assertTrue(directoryContentManager.getBacklog().isEmpty()); - Map remoteSnapshot = generateInitialSnapshot(); - directoryContentManager.processSnapshot(remoteSnapshot); - Assert.assertTrue(directoryContentManager.getBacklog().containsKey("c.txt")); - remoteSnapshot.remove("c.txt"); - directoryContentManager.processSnapshot(remoteSnapshot); - Assert.assertEquals(2, directoryContentManager.getBacklog().size()); - directoryContentManager.processSnapshot(remoteSnapshot); - Assert.assertEquals(2, directoryContentManager.getBacklog().size()); - } - - - private static Map generateInitialSnapshot() { - Map remoteSnapshot = new HashMap(); - remoteSnapshot.put("a.txt", new FileInfo("a.txt", 1000, 100)); - remoteSnapshot.put("b.txt", new FileInfo("b.txt", 1001, 101)); - remoteSnapshot.put("c.txt", new FileInfo("c.txt", 1002, 102)); - return remoteSnapshot; - } - -} diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/FtpTargetIntegrationTest.java b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/FtpTargetIntegrationTest.java new file mode 100644 index 0000000000..129bee4dd0 --- /dev/null +++ b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/FtpTargetIntegrationTest.java @@ -0,0 +1,70 @@ +/* + * Copyright 2002-2008 the original author or authors. + * + * Licensed 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.springframework.integration.adapter.ftp.config; + +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.FilenameFilter; + +import org.apache.oro.io.Perl5FilenameFilter; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.springframework.integration.adapter.ftp.FTPClientPool; +import org.springframework.integration.adapter.ftp.FtpTarget; +import org.springframework.integration.message.GenericMessage; +import org.springframework.integration.message.Message; +import org.springframework.integration.message.MessageMapper; + +/** + * @author Iwein Fuld + */ +@Ignore +public class FtpTargetIntegrationTest { + + private FtpTarget ftpTarget; + + @Before + public void initFtpTarget() { + ftpTarget = new FtpTarget(new MessageMapper() { + public File mapMessage(Message message) { + return message.getPayload(); + } + }); + FTPClientPool clientPool = new FTPClientPool(); + clientPool.setHost("localhost"); + clientPool.setUser("ftp-user"); + clientPool.setPass("kaas"); + ftpTarget.setFtpClientPool(clientPool); + } + + @Test + public void send() throws Exception { + File file = File.createTempFile("test", ""); + assertTrue(ftpTarget.send(new GenericMessage(file))); + } + + @AfterClass + public static void deleteTestFiles() { + File tmpDir = new File(System.getProperty("java.io.tmpdir")); + File[] files = tmpDir.listFiles((FilenameFilter) new Perl5FilenameFilter("test\\d")); + for (File file : files) { + file.delete(); + } + } +}