use of com.adaptris.core.StandaloneConsumer 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.StandaloneConsumer 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.StandaloneConsumer 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.StandaloneConsumer in project interlok by adaptris.
the class NonDeletingFsConsumerTest method testHasChanged_LastModified.
@Test
public void testHasChanged_LastModified() throws Exception {
String subDir = new GuidGenerator().safeUUID();
NonDeletingFsConsumer fs = createConsumer(subDir, "testConsume");
File f = createFile(TempFileUtils.createTrackedFile(getName(), "", fs), PANGRAM_1);
ProcessedItem item = new ProcessedItem(f.getAbsolutePath(), 0, f.length());
ProcessedItemCache cache = new InlineItemCache();
fs.setPoller(new Never());
fs.setProcessedItemCache(cache);
StandaloneConsumer consumer = new StandaloneConsumer(fs);
try {
start(consumer);
cache.update(item);
ProcessedItem changed = new ProcessedItem(f.getAbsolutePath(), f.lastModified(), f.length());
assertTrue(fs.hasChanged(changed));
cache.update(changed);
assertFalse(fs.hasChanged(changed));
} finally {
stop(consumer);
}
}
use of com.adaptris.core.StandaloneConsumer 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