Search in sources :

Example 36 with FixedIntervalPoller

use of com.adaptris.core.FixedIntervalPoller in project interlok by adaptris.

the class PasPollingConsumerTest method retrieveObjectForSampleConfig.

@Override
protected Object retrieveObjectForSampleConfig() {
    PasPollingConsumer consumer = createConsumer();
    consumer.setPoller(new FixedIntervalPoller(new TimeInterval(1L, TimeUnit.MINUTES)));
    consumer.setUserName("user-name");
    consumer.setPassword("password");
    consumer.setClientId("client-id");
    consumer.setSubscriptionId("subscription-id");
    consumer.setPoller(new FixedIntervalPoller(new TimeInterval(1L, TimeUnit.MINUTES)));
    consumer.setReacquireLockBetweenMessages(true);
    consumer.setTopic("MyTopic");
    StandaloneConsumer result = new StandaloneConsumer();
    result.setConsumer(consumer);
    return result;
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) StandaloneConsumer(com.adaptris.core.StandaloneConsumer)

Example 37 with FixedIntervalPoller

use of com.adaptris.core.FixedIntervalPoller in project interlok by adaptris.

the class FtpRecursiveConsumerTest 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);
            }
        });
        FtpRecursiveConsumer 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();
    }
}
Also used : FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) TimeInterval(com.adaptris.util.TimeInterval) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PollerImp(com.adaptris.core.PollerImp) FileSystem(org.mockftpserver.fake.filesystem.FileSystem) FileEntry(org.mockftpserver.fake.filesystem.FileEntry) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) Test(org.junit.Test)

Example 38 with FixedIntervalPoller

use of com.adaptris.core.FixedIntervalPoller in project interlok by adaptris.

the class FtpRecursiveConsumerTest 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);
            }
        });
        FtpRecursiveConsumer 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();
    }
}
Also used : FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) TimeInterval(com.adaptris.util.TimeInterval) RegexFileFilter(org.apache.commons.io.filefilter.RegexFileFilter) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FileSystem(org.mockftpserver.fake.filesystem.FileSystem) FileEntry(org.mockftpserver.fake.filesystem.FileEntry) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) Test(org.junit.Test)

Aggregations

FixedIntervalPoller (com.adaptris.core.FixedIntervalPoller)38 TimeInterval (com.adaptris.util.TimeInterval)38 StandaloneConsumer (com.adaptris.core.StandaloneConsumer)36 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)32 Test (org.junit.Test)31 File (java.io.File)26 GuidGenerator (com.adaptris.util.GuidGenerator)24 FilenameFilter (java.io.FilenameFilter)23 Perl5FilenameFilter (org.apache.oro.io.Perl5FilenameFilter)23 RandomAccessFile (java.io.RandomAccessFile)20 LargeFsConsumer (com.adaptris.core.lms.LargeFsConsumer)14 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)8 IOException (java.io.IOException)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 CoreConstants (com.adaptris.core.CoreConstants)4 CoreException (com.adaptris.core.CoreException)4 PollerImp (com.adaptris.core.PollerImp)4 LifecycleHelper (com.adaptris.core.util.LifecycleHelper)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4