use of com.adaptris.util.GuidGenerator in project interlok by adaptris.
the class FsMessageProducerTest method testProduceWithMetadataFilenameCreator.
@Test
public void testProduceWithMetadataFilenameCreator() throws Exception {
String subdir = new GuidGenerator().safeUUID();
FsProducer fs = createProducer(subdir);
fs.setCreateDirs(true);
fs.setFilenameCreator(new MetadataFileNameCreator("targetFilename"));
File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
try {
File dir = new File(parentDir, subdir);
start(fs);
AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
msg.addMetadata("targetFilename", new GuidGenerator().safeUUID());
fs.produce(msg);
assertEquals(1, dir.listFiles().length);
} finally {
FileUtils.deleteQuietly(new File(parentDir, subdir));
stop(fs);
}
}
use of com.adaptris.util.GuidGenerator in project interlok by adaptris.
the class NonDeletingFsConsumerTest method testConsumeNotReprocessed.
@Test
public void testConsumeNotReprocessed() throws Exception {
String subDir = new GuidGenerator().safeUUID();
MockMessageListener stub = new MockMessageListener(10);
NonDeletingFsConsumer fs = createConsumer(subDir, "testConsume");
AtomicBoolean pollFired = new AtomicBoolean(false);
fs.setPoller(new FixedIntervalPoller(new TimeInterval(500L, TimeUnit.MILLISECONDS)).withPollerCallback(e -> {
if (e == 0) {
pollFired.set(true);
}
}));
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);
// The next call back should be on the next poll, when messages == 0;
waitForPollCallback(pollFired);
// that we don't reprocess them.
assertMessages(stub.getMessages(), count, baseDir.listFiles((FilenameFilter) new Perl5FilenameFilter(".*\\.xml")));
} catch (Exception e) {
log.warn(e.getMessage(), 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 testConsume.
@Test
public void testConsume() throws Exception {
String subDir = new GuidGenerator().safeUUID();
MockMessageListener stub = new MockMessageListener(10);
NonDeletingFsConsumer fs = createConsumer(subDir, "testConsume");
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.warn(e.getMessage(), 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 testBug2100_OriginalNameContainsWip.
@Test
public void testBug2100_OriginalNameContainsWip() throws Exception {
String subDir = new GuidGenerator().safeUUID();
MockMessageListener stub = new MockMessageListener(10);
NonDeletingFsConsumer fs = createConsumer(subDir, "testBug2100_OriginalNameContainsWip");
fs.setReacquireLockBetweenMessages(true);
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")));
for (AdaptrisMessage msg : stub.getMessages()) {
assertFalse("original name should not contain '.wip'", msg.getMetadataValue(CoreConstants.ORIGINAL_NAME_KEY).endsWith(".wip"));
}
} 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_Size.
@Test
public void testHasChanged_Size() 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(), f.lastModified(), 0);
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