use of com.adaptris.core.FixedIntervalPoller 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.core.FixedIntervalPoller in project interlok by adaptris.
the class FtpConsumerTest method testConsumeWithNonMatchingFilter.
@Test
public void testConsumeWithNonMatchingFilter() throws Exception {
int count = 1;
EmbeddedFtpServer helper = new EmbeddedFtpServer();
MockMessageListener listener = new MockMessageListener();
FileSystem filesystem = helper.createFilesystem_DirsOnly();
for (int i = 0; i < count; i++) {
filesystem.add(new FileEntry(DEFAULT_WORK_DIR_CANONICAL + SLASH + DEFAULT_FILENAME + i + ".txt", PAYLOAD));
}
FakeFtpServer server = helper.createAndStart(filesystem);
StandaloneConsumer sc = null;
try {
AtomicBoolean pollFired = new AtomicBoolean(false);
FixedIntervalPoller poller = new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)).withPollerCallback(e -> {
log.trace("Poll Fired {}", getName());
if (e == 0) {
pollFired.set(true);
}
});
FtpConsumer ftpConsumer = createForTests(listener, SERVER_ADDRESS, poller);
ftpConsumer.setFilterExpression("^*.xml$");
ftpConsumer.setFileFilterImp(RegexFileFilter.class.getCanonicalName());
FtpConnection consumeConnection = create(server);
sc = new StandaloneConsumer(consumeConnection, ftpConsumer);
start(sc);
long waitTime = waitForPollCallback(pollFired);
log.trace("Waited for {}ms for == 0 poll", waitTime);
helper.assertMessages(listener.getMessages(), 0);
assertEquals(count, filesystem.listFiles(DEFAULT_WORK_DIR_CANONICAL).size());
} catch (Exception e) {
throw e;
} finally {
stop(sc);
server.stop();
}
}
use of com.adaptris.core.FixedIntervalPoller in project interlok by adaptris.
the class FtpConsumerTest method testConsumeWithQuietPeriodAndTimezone.
@Test
public void testConsumeWithQuietPeriodAndTimezone() throws Exception {
int count = 1;
EmbeddedFtpServer helper = new EmbeddedFtpServer();
MockMessageListener listener = new MockMessageListener(100);
FileSystem filesystem = helper.createFilesystem_DirsOnly();
for (int i = 0; i < count; i++) {
filesystem.add(new FileEntry(DEFAULT_WORK_DIR_CANONICAL + SLASH + DEFAULT_FILENAME + i + ".txt", PAYLOAD));
}
FakeFtpServer server = helper.createAndStart(filesystem);
StandaloneConsumer sc = null;
try {
AtomicBoolean pollFired = new AtomicBoolean(false);
PollerImp poller = new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)).withPollerCallback(e -> {
log.trace("Poll Fired {}", getName());
if (e == 0) {
pollFired.set(true);
}
});
FtpConsumer ftpConsumer = createForTests(listener, "testConsumeWithQuietPeriodAndTimezone", poller);
ftpConsumer.setQuietInterval(new TimeInterval(3L, TimeUnit.SECONDS));
FtpConnection consumeConnection = create(server);
consumeConnection.setAdditionalDebug(true);
consumeConnection.setServerTimezone("America/Los_Angeles");
sc = new StandaloneConsumer(consumeConnection, ftpConsumer);
start(sc);
long waitTime = waitForPollCallback(pollFired);
log.trace("Waited for {}ms for == 0 poll", waitTime);
helper.assertMessages(listener.getMessages(), 0);
assertEquals(count, filesystem.listFiles(DEFAULT_WORK_DIR_CANONICAL).size());
} catch (Exception e) {
throw e;
} finally {
stop(sc);
server.stop();
}
}
use of com.adaptris.core.FixedIntervalPoller 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.core.FixedIntervalPoller 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));
}
}
Aggregations