use of com.adaptris.util.GuidGenerator in project interlok by adaptris.
the class FsMessageConsumerTest method testBug2100_OriginalNameContainsWip.
@Test
public void testBug2100_OriginalNameContainsWip() 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);
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 FsMessageConsumerTest method testConsumeIgnoresWip.
@Test
public void testConsumeIgnoresWip() throws Exception {
String subDir = new GuidGenerator().safeUUID();
MockMessageListener stub = new MockMessageListener();
FsConsumer fs = createConsumer(subDir);
fs.setResetWipFiles(false);
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);
baseDir.mkdirs();
createFiles(baseDir, ".xml", count);
createFiles(baseDir, ".xml.wip", count);
start(sc);
waitForMessages(stub, count);
Perl5FilenameFilter wip = new Perl5FilenameFilter(".*\\.wip");
assertEquals(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 FsMessageProducerTest method testSetFsWorker.
@Test
public void testSetFsWorker() throws Exception {
String subdir = new GuidGenerator().safeUUID();
FsProducer producer = createProducer(subdir);
assertEquals(NioWorker.class, producer.getFsWorker().getClass());
OverwriteIfExistsWorker worker = new OverwriteIfExistsWorker();
producer.setFsWorker(worker);
assertEquals(OverwriteIfExistsWorker.class, producer.getFsWorker().getClass());
assertEquals(worker, producer.getFsWorker());
try {
producer.setFsWorker(null);
fail();
} catch (IllegalArgumentException | NullPointerException expected) {
}
assertEquals(OverwriteIfExistsWorker.class, producer.getFsWorker().getClass());
assertEquals(worker, producer.getFsWorker());
}
use of com.adaptris.util.GuidGenerator in project interlok by adaptris.
the class FsMessageProducerTest method testCreateName.
@Test
public void testCreateName() throws Exception {
String subdir = new GuidGenerator().safeUUID();
FsProducer producer = createProducer(subdir);
assertEquals(producer.getClass().getCanonicalName(), producer.createName());
}
use of com.adaptris.util.GuidGenerator in project interlok by adaptris.
the class FsMessageProducerTest method testProduceWithTempDir.
@Test
public void testProduceWithTempDir() throws Exception {
String subdir = new GuidGenerator().safeUUID();
String tmpDir = new GuidGenerator().safeUUID();
String tempDir = PROPERTIES.getProperty(BASE_TEMP_DIR) + "/" + tmpDir;
FsProducer producer = createProducer(subdir);
File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
File tmpParentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_TEMP_DIR), true));
try {
producer.setTempDirectory(tempDir);
StandaloneProducer sp = new StandaloneProducer(producer);
ServiceCase.execute(sp, new DefaultMessageFactory().newMessage(TEXT));
File f = new File(tmpParentDir, tmpDir);
assertTrue(f.exists());
assertTrue(f.isDirectory());
assertEquals(1, new File(parentDir, subdir).listFiles().length);
assertEquals(0, new File(tmpParentDir, tmpDir).listFiles().length);
} finally {
FileUtils.deleteQuietly(new File(parentDir, subdir));
FileUtils.deleteQuietly(new File(tmpParentDir, tmpDir));
}
}
Aggregations