use of com.adaptris.core.FixedIntervalPoller in project interlok by adaptris.
the class NonDeletingFsConsumerTest method testConsumeWithFilter.
@Test
public void testConsumeWithFilter() throws Exception {
String subDir = new GuidGenerator().safeUUID();
MockMessageListener stub = new MockMessageListener(10);
NonDeletingFsConsumer fs = createConsumer(subDir, "testConsumeWithFilter");
fs.setFilterExpression(".*\\.xml");
fs.setFileFilterImp(Perl5FilenameFilter.class.getName());
fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)));
StandaloneConsumer sc = new StandaloneConsumer(fs);
sc.registerAdaptrisMessageListener(stub);
int count = 10;
File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
try {
File baseDir = new File(parentDir, subDir);
LifecycleHelper.init(sc);
createFiles(baseDir, ".xml", count);
createFiles(baseDir, ".tmp", count);
LifecycleHelper.start(sc);
waitForMessages(stub, count);
Perl5FilenameFilter wip = new Perl5FilenameFilter(".*\\.tmp");
assertEquals("TMP Files remain", count, baseDir.listFiles((FilenameFilter) wip).length);
assertMessages(stub.getMessages(), count, baseDir.listFiles((FilenameFilter) new Perl5FilenameFilter(".*\\.xml")));
} finally {
stop(sc);
FileUtils.deleteQuietly(new File(parentDir, subDir));
}
}
use of com.adaptris.core.FixedIntervalPoller in project interlok by adaptris.
the class NonDeletingFsConsumerTest method testBug1675ConsumeWithSpacesInDir.
@Test
public void testBug1675ConsumeWithSpacesInDir() throws Exception {
String uniqueName = new GuidGenerator().safeUUID();
String subDir = uniqueName + "Directory WithSpaces";
String subDirEncoded = uniqueName + "Directory%20WithSpaces";
MockMessageListener stub = new MockMessageListener(10);
NonDeletingFsConsumer fs = createConsumer(subDirEncoded, "testBug1675ConsumeWithSpacesInDir");
fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)));
StandaloneConsumer sc = new StandaloneConsumer(fs);
sc.registerAdaptrisMessageListener(stub);
int count = 10;
File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
try {
File baseDir = new File(parentDir, subDir);
LifecycleHelper.init(sc);
createFiles(baseDir, ".xml", count);
LifecycleHelper.start(sc);
waitForMessages(stub, count);
assertMessages(stub.getMessages(), count, baseDir.listFiles((FilenameFilter) new Perl5FilenameFilter(".*\\.xml")));
} catch (Exception e) {
log.debug(e.getMessage(), e);
throw e;
} finally {
stop(sc);
FileUtils.deleteQuietly(new File(parentDir, subDir));
}
}
use of com.adaptris.core.FixedIntervalPoller in project interlok by adaptris.
the class NonDeletingFsConsumerTest method testRedmine481_SubDirInConsumeDirectory.
@Test
public void testRedmine481_SubDirInConsumeDirectory() throws Exception {
String consumeDir = new GuidGenerator().safeUUID();
File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
File subDirectory = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY) + "/" + consumeDir + "/" + new GuidGenerator().safeUUID(), true));
subDirectory.mkdirs();
NonDeletingFsConsumer fs = createConsumer(consumeDir, "testRedmine481_SubDirInConsumeDirectory");
fs.setReacquireLockBetweenMessages(true);
AtomicBoolean pollFired = new AtomicBoolean(false);
fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)).withPollerCallback(e -> {
pollFired.set(true);
}));
MockMessageListener stub = new MockMessageListener(0);
StandaloneConsumer sc = new StandaloneConsumer(fs);
sc.registerAdaptrisMessageListener(stub);
try {
start(sc);
waitForPollCallback(pollFired);
assertEquals(true, subDirectory.exists());
assertEquals(true, subDirectory.isDirectory());
} finally {
stop(sc);
FileUtils.deleteQuietly(new File(parentDir, consumeDir));
}
}
use of com.adaptris.core.FixedIntervalPoller in project interlok by adaptris.
the class NonDeletingFsConsumerTest method testConsumeWithQuietPeriod.
@Test
public void testConsumeWithQuietPeriod() throws Exception {
String subDir = new GuidGenerator().safeUUID();
MockMessageListener stub = new MockMessageListener(10);
NonDeletingFsConsumer fs = createConsumer(subDir, "testConsumeWithQuietPeriod");
fs.setQuietInterval(new TimeInterval(300L, TimeUnit.MILLISECONDS));
fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)));
StandaloneConsumer sc = new StandaloneConsumer(fs);
sc.registerAdaptrisMessageListener(stub);
int count = 10;
File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
try {
File baseDir = new File(parentDir, subDir);
LifecycleHelper.init(sc);
createFiles(baseDir, ".xml", count);
LifecycleHelper.start(sc);
waitForMessages(stub, count);
assertMessages(stub.getMessages(), count, baseDir.listFiles((FilenameFilter) new Perl5FilenameFilter(".*\\.xml")));
} finally {
stop(sc);
FileUtils.deleteQuietly(new File(parentDir, subDir));
}
}
use of com.adaptris.core.FixedIntervalPoller in project interlok by adaptris.
the class MovingDeletingFsConsumerTest method testConsume.
@Test
public void testConsume() throws Exception {
final File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
final String subDir = new GuidGenerator().safeUUID();
final File baseDir = new File(parentDir, subDir);
final File procDir = new File(parentDir, "proc");
final MockMessageListener stub = new MockMessageListener(10);
final MovingNonDeletingFsConsumer fs = createConsumer(subDir, "testConsume");
fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)));
fs.setProcessedPath(procDir.getAbsolutePath());
final StandaloneConsumer sc = new StandaloneConsumer(fs);
sc.registerAdaptrisMessageListener(stub);
final int count = 10;
List<File> files = null;
try {
LifecycleHelper.init(sc);
files = createFiles(baseDir, ".xml", count);
LifecycleHelper.start(sc);
waitForMessages(stub, count);
assertMessages(stub.getMessages(), count, baseDir.listFiles((FilenameFilter) new Perl5FilenameFilter(".*\\.xml")));
} catch (final Exception e) {
log.warn(e.getMessage(), e);
fail();
} finally {
stop(sc);
if (files != null) {
for (final File f : files) {
boolean found = false;
for (final String n : procDir.list()) {
if (f.getName().equals(n)) {
found = true;
}
}
if (!found) {
fail("Couldn't find file " + f.getName() + " in processed directory");
}
}
}
FileUtils.deleteQuietly(baseDir);
FileUtils.deleteQuietly(procDir);
}
}
Aggregations