Search in sources :

Example 56 with StandaloneConsumer

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

the class FtpCase method testConsume_WithEncoder.

@Test
public void testConsume_WithEncoder() throws Exception {
    Assume.assumeTrue(areTestsEnabled());
    MockMessageListener listener = new MockMessageListener();
    FtpConsumer ftpConsumer = new FtpConsumer();
    ftpConsumer.setFtpEndpoint(getDestinationString());
    ftpConsumer.registerAdaptrisMessageListener(listener);
    ftpConsumer.setQuietInterval(new TimeInterval(300l, TimeUnit.MILLISECONDS));
    ftpConsumer.setPoller(new QuartzCronPoller("*/1 * * * * ?"));
    ftpConsumer.setEncoder(new MimeEncoder());
    FileTransferConnection consumeConnection = createConnection();
    consumeConnection.setCacheConnection(true);
    StandaloneConsumer sc = new StandaloneConsumer(consumeConnection, ftpConsumer);
    start(sc);
    int count = 10;
    try {
        FileTransferConnection produceConnection = createConnection();
        produceConnection.setCacheConnection(true);
        FtpProducer producer = createFtpProducer();
        producer.setEncoder(new MimeEncoder());
        produce(new StandaloneProducer(produceConnection, producer), count);
        waitForMessages(listener, count);
        assertMessages(listener.getMessages(), count);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw e;
    } finally {
        stop(sc);
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) QuartzCronPoller(com.adaptris.core.QuartzCronPoller) MimeEncoder(com.adaptris.core.MimeEncoder) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) StandaloneProducer(com.adaptris.core.StandaloneProducer) CoreException(com.adaptris.core.CoreException) Test(org.junit.Test)

Example 57 with StandaloneConsumer

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

the class FtpCase method testConsume_CachedConnection.

@Test
public void testConsume_CachedConnection() throws Exception {
    Assume.assumeTrue(areTestsEnabled());
    MockMessageListener listener = new MockMessageListener();
    FtpConsumer ftpConsumer = new FtpConsumer();
    ftpConsumer.setFtpEndpoint(getDestinationString());
    ftpConsumer.registerAdaptrisMessageListener(listener);
    ftpConsumer.setQuietInterval(new TimeInterval(300l, TimeUnit.MILLISECONDS));
    ftpConsumer.setPoller(new QuartzCronPoller("*/1 * * * * ?"));
    FileTransferConnection consumeConnection = createConnection();
    consumeConnection.setCacheConnection(true);
    StandaloneConsumer sc = new StandaloneConsumer(consumeConnection, ftpConsumer);
    start(sc);
    int count = 10;
    try {
        FileTransferConnection produceConnection = createConnection();
        produceConnection.setCacheConnection(true);
        produce(new StandaloneProducer(produceConnection, createFtpProducer()), count);
        waitForMessages(listener, count);
        assertMessages(listener.getMessages(), count);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw e;
    } finally {
        stop(sc);
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) QuartzCronPoller(com.adaptris.core.QuartzCronPoller) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) StandaloneProducer(com.adaptris.core.StandaloneProducer) CoreException(com.adaptris.core.CoreException) Test(org.junit.Test)

Example 58 with StandaloneConsumer

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

the class FtpCase method testConsumeWithFilter.

@Test
public void testConsumeWithFilter() throws Exception {
    Assume.assumeTrue(areTestsEnabled());
    MockMessageListener listener = new MockMessageListener();
    FtpConsumer ftpConsumer = new FtpConsumer();
    ftpConsumer.setFtpEndpoint(getDestinationString());
    ftpConsumer.setWorkDirectory(DEFAULT_WORK_DIR);
    ftpConsumer.setFileFilterImp(GlobFilenameFilter.class.getCanonicalName());
    ftpConsumer.setFilterExpression(".txt");
    ftpConsumer.registerAdaptrisMessageListener(listener);
    ftpConsumer.setPoller(new QuartzCronPoller("*/1 * * * * ?"));
    StandaloneConsumer sc = new StandaloneConsumer(createConnection(), ftpConsumer);
    start(sc);
    int count = 1;
    try {
        FtpProducer ftpProducer = createFtpProducer();
        MetadataFileNameCreator mfc = new MetadataFileNameCreator();
        mfc.setDefaultName(new GuidGenerator().getUUID() + ".txt");
        mfc.setMetadataKey(new GuidGenerator().getUUID());
        ftpProducer.setFilenameCreator(mfc);
        produce(new StandaloneProducer(createConnection(), ftpProducer), count);
        Awaitility.await().atMost(Duration.ofSeconds(5)).with().pollInterval(Duration.ofMillis(100)).until(() -> listener.getMessages().size() >= count);
        assertMessages(listener.getMessages(), count);
    } finally {
        stop(sc);
    }
}
Also used : QuartzCronPoller(com.adaptris.core.QuartzCronPoller) GlobFilenameFilter(org.apache.oro.io.GlobFilenameFilter) GuidGenerator(com.adaptris.util.GuidGenerator) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) MetadataFileNameCreator(com.adaptris.core.MetadataFileNameCreator) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 59 with StandaloneConsumer

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

the class NonDeletingFsConsumerTest method testConsumeWithFilter.

@Test
public void testConsumeWithFilter() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    NonDeletingFsConsumer fs = createConsumer(subDir, "testConsumeWithFilter");
    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));
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) TimeInterval(com.adaptris.util.TimeInterval) GuidGenerator(com.adaptris.util.GuidGenerator) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Example 60 with StandaloneConsumer

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

the class NonDeletingFsConsumerTest method testHasChanged_NotInCache.

@Test
public void testHasChanged_NotInCache() 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(), 0, f.length());
    ProcessedItemCache cache = new InlineItemCache();
    fs.setPoller(new Never());
    fs.setProcessedItemCache(cache);
    StandaloneConsumer consumer = new StandaloneConsumer(fs);
    try {
        start(consumer);
        assertTrue(fs.hasChanged(item));
    } finally {
        stop(consumer);
    }
}
Also used : GuidGenerator(com.adaptris.util.GuidGenerator) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) Test(org.junit.Test)

Aggregations

StandaloneConsumer (com.adaptris.core.StandaloneConsumer)188 Test (org.junit.Test)164 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)160 StandaloneProducer (com.adaptris.core.StandaloneProducer)91 TimeInterval (com.adaptris.util.TimeInterval)49 FixedIntervalPoller (com.adaptris.core.FixedIntervalPoller)37 File (java.io.File)31 GuidGenerator (com.adaptris.util.GuidGenerator)30 FakeFtpServer (org.mockftpserver.fake.FakeFtpServer)30 PtpConsumer (com.adaptris.core.jms.PtpConsumer)24 FilenameFilter (java.io.FilenameFilter)24 RandomAccessFile (java.io.RandomAccessFile)24 Perl5FilenameFilter (org.apache.oro.io.Perl5FilenameFilter)24 PtpProducer (com.adaptris.core.jms.PtpProducer)23 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)22 QuartzCronPoller (com.adaptris.core.QuartzCronPoller)17 CoreException (com.adaptris.core.CoreException)16 PasProducer (com.adaptris.core.jms.PasProducer)15 LargeFsConsumer (com.adaptris.core.lms.LargeFsConsumer)15 PasConsumer (com.adaptris.core.jms.PasConsumer)14