Search in sources :

Example 6 with FileBackedMessageFactory

use of com.adaptris.core.lms.FileBackedMessageFactory in project interlok by adaptris.

the class SerializableMessageTranslatorTest method testSerialize_FileBackedMessage_TooLarge.

@Test
public void testSerialize_FileBackedMessage_TooLarge() throws Exception {
    FileBackedMessage adaptrisMessage = (FileBackedMessage) new FileBackedMessageFactory().newMessage();
    File sourceFile = TempFileUtils.createTrackedFile(this);
    RandomAccessFile rf = new RandomAccessFile(sourceFile, "rw");
    // 7Mb should be bigger than the default size.
    rf.setLength(1024L * 7 * 1024L);
    rf.close();
    adaptrisMessage.initialiseFrom(sourceFile);
    adaptrisMessage.addMetadata("MetaKey1", "MetaValue1");
    adaptrisMessage.addMetadata("MetaKey2", "MetaValue2");
    SerializableMessage serialisableAdaptrisMessage = new DefaultSerializableMessageTranslator().translate(adaptrisMessage);
    assertEquals("MetaValue1", serialisableAdaptrisMessage.getMessageHeaders().get("MetaKey1"));
    assertEquals("MetaValue2", serialisableAdaptrisMessage.getMessageHeaders().get("MetaKey2"));
    assertEquals(adaptrisMessage.getUniqueId(), serialisableAdaptrisMessage.getUniqueId());
    assertTrue(serialisableAdaptrisMessage.getContent().contains("Size=7 MB"));
}
Also used : FileBackedMessageFactory(com.adaptris.core.lms.FileBackedMessageFactory) RandomAccessFile(java.io.RandomAccessFile) SerializableMessage(com.adaptris.interlok.types.SerializableMessage) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) FileBackedMessage(com.adaptris.core.lms.FileBackedMessage) Test(org.junit.Test)

Example 7 with FileBackedMessageFactory

use of com.adaptris.core.lms.FileBackedMessageFactory in project interlok by adaptris.

the class RequestReplyProducerBaseTest method testMergeReply_IgnoreReplyMetadata.

@Test
public void testMergeReply_IgnoreReplyMetadata() throws Exception {
    AdaptrisMessage reply = new FileBackedMessageFactory().newMessage("hello world");
    AdaptrisMessage original = new FileBackedMessageFactory().newMessage();
    reply.addMessageHeader("hello", "world");
    reply.addObjectHeader("goodbye", "cruel world");
    setIgnoreReplyMetadata(true);
    AdaptrisMessage msg = mergeReply(reply, original);
    assertSame(original, msg);
    assertEquals("hello world", msg.getContent());
    assertNull(msg.getContentEncoding());
    assertFalse(msg.headersContainsKey("hello"));
    assertFalse(msg.getObjectHeaders().containsKey("goodbye"));
    // The reply should be "in-scope" for GC avoidance.
    assertTrue(msg.getObjectHeaders().containsKey(reply.getUniqueId()));
}
Also used : FileBackedMessageFactory(com.adaptris.core.lms.FileBackedMessageFactory) Test(org.junit.Test)

Example 8 with FileBackedMessageFactory

use of com.adaptris.core.lms.FileBackedMessageFactory in project interlok by adaptris.

the class RelaxedFtpConsumerTest method testSingleFileConsume_FilebackedMessageFactory.

@Test
public void testSingleFileConsume_FilebackedMessageFactory() throws Exception {
    setFilesToConsume(new String[] { "/MySingleFile.txt" }, new String[] { "My file payload" }, new long[] { calendarOneYearAgo.getTimeInMillis() });
    consumer.setMessageFactory(new FileBackedMessageFactory());
    LifecycleHelper.init(consumer);
    LifecycleHelper.start(consumer);
    waitForConsumer(1, 3000);
    assertEquals(1, messageListener.getMessages().size());
}
Also used : FileBackedMessageFactory(com.adaptris.core.lms.FileBackedMessageFactory) Test(org.junit.Test)

Example 9 with FileBackedMessageFactory

use of com.adaptris.core.lms.FileBackedMessageFactory in project interlok by adaptris.

the class BasicActiveMqProducerTest method testBlobProduceAndConsumeWithFileMessageFactory.

@Test
public void testBlobProduceAndConsumeWithFileMessageFactory() throws Exception {
    if (!ExternalResourcesHelper.isExternalServerAvailable()) {
        log.debug("Blob Server not available; skipping test");
        return;
    }
    PtpConsumer consumer = new PtpConsumer().withQueue(getName());
    consumer.setAcknowledgeMode("AUTO_ACKNOWLEDGE");
    consumer.setMessageTranslator(new BlobMessageTranslator());
    StandaloneConsumer standaloneConsumer = new StandaloneConsumer(activeMqBroker.getJmsConnection(createVendorImpl()), consumer);
    MockMessageListener jms = new MockMessageListener();
    standaloneConsumer.registerAdaptrisMessageListener(jms);
    PtpProducer producer = new PtpProducer().withQueue((getName()));
    producer.setMessageTranslator(new BlobMessageTranslator("blobUrl"));
    StandaloneProducer standaloneProducer = new StandaloneProducer(activeMqBroker.getJmsConnection(createVendorImpl()), producer);
    execute(standaloneConsumer, standaloneProducer, addBlobUrlRef(EmbeddedActiveMq.createMessage(new FileBackedMessageFactory()), "blobUrl"), jms);
    assertMessages(jms, 1, false);
}
Also used : PtpConsumer(com.adaptris.core.jms.PtpConsumer) FileBackedMessageFactory(com.adaptris.core.lms.FileBackedMessageFactory) PtpProducer(com.adaptris.core.jms.PtpProducer) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 10 with FileBackedMessageFactory

use of com.adaptris.core.lms.FileBackedMessageFactory in project interlok by adaptris.

the class FtpConsumerTest method testBasicConsume_WithFileBackedMessage.

@Test
public void testBasicConsume_WithFileBackedMessage() throws Exception {
    int count = 1;
    EmbeddedFtpServer helper = new EmbeddedFtpServer();
    MockMessageListener listener = new MockMessageListener();
    FakeFtpServer server = helper.createAndStart(helper.createFilesystem(count));
    StandaloneConsumer sc = null;
    try {
        FtpConsumer ftpConsumer = createForTests(listener);
        ftpConsumer.setMessageFactory(new FileBackedMessageFactory());
        FtpConnection consumeConnection = create(server);
        sc = new StandaloneConsumer(consumeConnection, ftpConsumer);
        start(sc);
        waitForMessages(listener, count);
        helper.assertMessages(listener.getMessages(), count);
    } catch (Exception e) {
        throw e;
    } finally {
        stop(sc);
        server.stop();
    }
}
Also used : FileBackedMessageFactory(com.adaptris.core.lms.FileBackedMessageFactory) FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) Test(org.junit.Test)

Aggregations

FileBackedMessageFactory (com.adaptris.core.lms.FileBackedMessageFactory)16 Test (org.junit.Test)16 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)4 StandaloneConsumer (com.adaptris.core.StandaloneConsumer)4 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)4 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)2 StandaloneProducer (com.adaptris.core.StandaloneProducer)2 PtpConsumer (com.adaptris.core.jms.PtpConsumer)2 PtpProducer (com.adaptris.core.jms.PtpProducer)2 FileBackedMessage (com.adaptris.core.lms.FileBackedMessage)2 SerializableMessage (com.adaptris.interlok.types.SerializableMessage)2 File (java.io.File)2 FakeFtpServer (org.mockftpserver.fake.FakeFtpServer)2 FileFilter (java.io.FileFilter)1 RandomAccessFile (java.io.RandomAccessFile)1 DirectoryFileFilter (org.apache.commons.io.filefilter.DirectoryFileFilter)1