use of com.adaptris.util.GuidGenerator in project interlok by adaptris.
the class NonDeletingFsConsumerTest method testHasChanged_NotInCache.
@Test
public void testHasChanged_NotInCache() 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);
assertTrue(fs.hasChanged(item));
} finally {
stop(consumer);
}
}
use of com.adaptris.util.GuidGenerator 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.util.GuidGenerator 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.util.GuidGenerator 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.util.GuidGenerator 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);
}
}
Aggregations