use of com.adaptris.util.GuidGenerator in project interlok by adaptris.
the class FsMessageConsumerTest method testConsumeWithFilter.
@Test
public void testConsumeWithFilter() throws Exception {
String subDir = new GuidGenerator().safeUUID();
MockMessageListener stub = new MockMessageListener(10);
FsConsumer fs = createConsumer(subDir);
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.util.GuidGenerator in project interlok by adaptris.
the class FsMessageConsumerTest 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));
String subDir = parentDir.getCanonicalPath() + "/" + consumeDir + "/" + new GuidGenerator().safeUUID();
File subDirectory = new File(subDir);
subDirectory.mkdirs();
FsConsumer fs = createConsumer(consumeDir);
fs.setReacquireLockBetweenMessages(true);
AtomicBoolean pollFired = new AtomicBoolean(false);
fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)).withPollerCallback(e -> {
pollFired.set(true);
}));
File wipDirectory = new File(subDir + fs.getWipSuffix());
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());
assertEquals(false, wipDirectory.exists());
} finally {
stop(sc);
FileUtils.deleteQuietly(new File(PROPERTIES.getProperty(BASE_KEY), consumeDir));
}
}
use of com.adaptris.util.GuidGenerator in project interlok by adaptris.
the class FsMessageConsumerTest method testConsumeFailInitialRename.
@Test
public void testConsumeFailInitialRename() throws Exception {
String subDir = new GuidGenerator().safeUUID();
MockMessageListener stub = new MockMessageListener(10);
FsConsumer fs = createConsumer(subDir);
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);
List<File> createdFiles = createFiles(baseDir, ".xml", count);
for (File file : createdFiles) {
File wip = new File(file.getAbsolutePath() + ".wip");
wip.createNewFile();
}
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 FsMessageConsumerTest method testConsume.
@Test
public void testConsume() throws Exception {
String subDir = new GuidGenerator().safeUUID();
MockMessageListener stub = new MockMessageListener(10);
FsConsumer fs = createConsumer(subDir);
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);
// INTERLOK-3329 For coverage so the prepare() warning is executed 2x
LifecycleHelper.prepare(sc);
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 FsMessageProducerTest method testProduceFileAlreadyExists_AppendingFsWorker.
@Test
public void testProduceFileAlreadyExists_AppendingFsWorker() throws Exception {
String subdir = new GuidGenerator().safeUUID();
FsProducer fs = createProducer(subdir);
fs.setCreateDirs(true);
fs.setFsWorker(new AppendingFsWorker());
fs.setFilenameCreator(new MetadataFileNameCreator("targetFilename"));
FsWorker fsWorker = new StandardWorker();
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());
dir.mkdirs();
File targetFile = new File(dir, msg.getMetadataValue("targetFilename"));
fsWorker.put(TEXT.getBytes(), targetFile);
fs.produce(msg);
assertEquals(1, dir.listFiles().length);
assertEquals(AppendingFsWorker.class, fs.getFsWorker().getClass());
assertEquals(TEXT + TEXT, new String(fsWorker.get(targetFile)));
} finally {
FileUtils.deleteQuietly(new File(parentDir, subdir));
stop(fs);
}
}
Aggregations