IN PROGRESS - issue INT-546: FileListFilters throw an IllegalArgumentException when the polled directory is empty
http://jira.springframework.org/browse/INT-546
This commit is contained in:
@@ -23,23 +23,25 @@ import java.util.List;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A convenience base class for any {@link FileListFilter} whose criteria can
|
||||
* be evaluated against each File in isolation. If the entire List of files is
|
||||
* A convenience base class for any {@link FileListFilter} whose criteria can be
|
||||
* evaluated against each File in isolation. If the entire List of files is
|
||||
* required for evaluation, implement the FileListFilter interface directly.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Iwein Fuld
|
||||
*/
|
||||
public abstract class AbstractFileListFilter implements FileListFilter {
|
||||
|
||||
/**
|
||||
* Returns the list of files that are accepted by this filter.
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public final List<File> filterFiles(File[] files) {
|
||||
Assert.notNull(files,"'files' should not be null.");
|
||||
List<File> accepted = new ArrayList<File>();
|
||||
for (File file : files) {
|
||||
if (this.accept(file)) {
|
||||
accepted.add(file);
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
if (this.accept(file)) {
|
||||
accepted.add(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
return accepted;
|
||||
|
||||
@@ -27,7 +27,8 @@ import java.util.List;
|
||||
public interface FileListFilter {
|
||||
|
||||
/**
|
||||
* Filters out files and returns the files that are left in a list.
|
||||
* Filters out files and returns the files that are left in a list, or an
|
||||
* empty list when a null is passed in.
|
||||
*/
|
||||
List<File> filterFiles(File[] files);
|
||||
|
||||
|
||||
@@ -110,6 +110,14 @@ public class FileReadingMessageSourceIntegrationTests {
|
||||
assertNotSame(received1 + " == " + received3, received1, received3);
|
||||
assertNotSame(received2 + " == " + received3, received2, received3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputDirExhausted() throws Exception {
|
||||
assertNotNull(pollableFileSource.receive());
|
||||
assertNotNull(pollableFileSource.receive());
|
||||
assertNotNull(pollableFileSource.receive());
|
||||
assertNull(pollableFileSource.receive());
|
||||
}
|
||||
|
||||
@Test(timeout = 6000)
|
||||
@Repeat(10)
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns:file="http://www.springframework.org/schema/integration/file"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
|
||||
http://www.springframework.org/schema/integration/file
|
||||
http://www.springframework.org/schema/integration/file/spring-integration-file-1.0.xsd">
|
||||
|
||||
<!-- under test -->
|
||||
<file:inbound-channel-adapter
|
||||
directory="file:${java.io.tmpdir}/FileToChannelIntegrationTests"
|
||||
channel="fileMessages" filter="compositeFilter" />
|
||||
|
||||
<si:channel id="fileMessages">
|
||||
<si:queue capacity="10" />
|
||||
</si:channel>
|
||||
|
||||
<!-- customized filter -->
|
||||
<bean id="compositeFilter"
|
||||
class="org.springframework.integration.file.CompositeFileListFilter">
|
||||
<constructor-arg>
|
||||
<list>
|
||||
<bean
|
||||
class="org.springframework.integration.file.AcceptOnceFileListFilter" />
|
||||
<bean class="org.springframework.integration.file.TestFileListFilter" />
|
||||
<bean
|
||||
class="org.springframework.integration.file.PatternMatchingFileListFilter">
|
||||
<constructor-arg value="^test.*$" />
|
||||
</bean>
|
||||
</list>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<si:poller default="true">
|
||||
<si:interval-trigger interval="10" />
|
||||
</si:poller>
|
||||
|
||||
<bean
|
||||
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,75 @@
|
||||
package org.springframework.integration.file;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class FileToChannelIntegrationTests {
|
||||
private static File inputDir;
|
||||
|
||||
@Autowired
|
||||
PollableChannel fileMessages;
|
||||
|
||||
@BeforeClass
|
||||
public static void setupInputDir() {
|
||||
inputDir = new File(System.getProperty("java.io.tmpdir") + "/"
|
||||
+ FileToChannelIntegrationTests.class.getSimpleName());
|
||||
inputDir.mkdir();
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanoutInputDir() throws Exception {
|
||||
File[] listFiles = inputDir.listFiles();
|
||||
for (int i = 0; i < listFiles.length; i++) {
|
||||
listFiles[i].delete();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void removeInputDir() throws Exception {
|
||||
inputDir.delete();
|
||||
}
|
||||
|
||||
@Test(timeout = 2000)
|
||||
public void fileMessageToChannel() throws Exception {
|
||||
File.createTempFile("test", null, inputDir).setLastModified(System.currentTimeMillis() - 1000);
|
||||
Message<File> received = receiveFileMessage();
|
||||
while (received == null) {
|
||||
Thread.sleep(50);
|
||||
received = receiveFileMessage();
|
||||
}
|
||||
assertNotNull(received.getPayload());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Message<File> receiveFileMessage() {
|
||||
return (Message<File>) fileMessages.receive();
|
||||
}
|
||||
|
||||
@Test(timeout = 2000)
|
||||
public void directoryExhaustion() throws Exception {
|
||||
File.createTempFile("test", null, inputDir).setLastModified(System.currentTimeMillis() - 1000);
|
||||
Message<File> received = receiveFileMessage();
|
||||
while (received == null) {
|
||||
Thread.sleep(5);
|
||||
received = receiveFileMessage();
|
||||
}
|
||||
assertNotNull(received.getPayload());
|
||||
assertNull(fileMessages.receive(200));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user