Search in sources :

Example 6 with LargeServerMessageImpl

use of org.apache.activemq.artemis.core.persistence.impl.journal.LargeServerMessageImpl in project activemq-artemis by apache.

the class XmlImportExportTest method testPagedLargeMessage.

@Test
public void testPagedLargeMessage() throws Exception {
    final String MY_ADDRESS = "myAddress";
    final String MY_QUEUE = "myQueue";
    server = createServer(true);
    AddressSettings defaultSetting = new AddressSettings().setPageSizeBytes(10 * 1024).setMaxSizeBytes(20 * 1024);
    server.getAddressSettingsRepository().addMatch("#", defaultSetting);
    server.start();
    ServerLocator locator = createInVMNonHALocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
    ClientSessionFactory factory = locator.createSessionFactory();
    ClientSession session = factory.createSession(false, true, true);
    session.createQueue(MY_ADDRESS, RoutingType.MULTICAST, MY_QUEUE, true);
    ClientProducer producer = session.createProducer(MY_ADDRESS);
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeBytes(new byte[1024]);
    for (int i = 0; i < 200; i++) {
        producer.send(message);
    }
    LargeServerMessageImpl fileMessage = new LargeServerMessageImpl((JournalStorageManager) server.getStorageManager());
    fileMessage.setMessageID(1005);
    fileMessage.setDurable(true);
    for (int i = 0; i < 2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE; i++) {
        fileMessage.addBytes(new byte[] { getSamplebyte(i) });
    }
    fileMessage.putLongProperty(Message.HDR_LARGE_BODY_SIZE, 2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
    fileMessage.releaseResources();
    producer.send(fileMessage);
    fileMessage.deleteFile();
    session.close();
    locator.close();
    server.stop();
    ByteArrayOutputStream xmlOutputStream = new ByteArrayOutputStream();
    XmlDataExporter xmlDataExporter = new XmlDataExporter();
    xmlDataExporter.process(xmlOutputStream, server.getConfiguration().getBindingsDirectory(), server.getConfiguration().getJournalDirectory(), server.getConfiguration().getPagingDirectory(), server.getConfiguration().getLargeMessagesDirectory());
    // System.out.print(new String(xmlOutputStream.toByteArray()));
    clearDataRecreateServerDirs();
    server.start();
    checkForLongs();
    locator = createInVMNonHALocator();
    factory = locator.createSessionFactory();
    session = factory.createSession(false, true, true);
    ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(xmlOutputStream.toByteArray());
    XmlDataImporter xmlDataImporter = new XmlDataImporter();
    xmlDataImporter.validate(xmlInputStream);
    xmlInputStream.reset();
    xmlDataImporter.process(xmlInputStream, session);
    ClientConsumer consumer = session.createConsumer(MY_QUEUE);
    session.start();
    for (int i = 0; i < 200; i++) {
        message = consumer.receive(CONSUMER_TIMEOUT);
        assertNotNull(message);
    }
    ClientMessage msg = consumer.receive(CONSUMER_TIMEOUT);
    assertNotNull(msg);
    assertEquals(2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, msg.getBodySize());
    for (int i = 0; i < 2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE; i++) {
        assertEquals(getSamplebyte(i), msg.getBodyBuffer().readByte());
    }
    session.close();
    locator.close();
    server.stop();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) LargeServerMessageImpl(org.apache.activemq.artemis.core.persistence.impl.journal.LargeServerMessageImpl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XmlDataImporter(org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataImporter) ByteArrayInputStream(java.io.ByteArrayInputStream) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) XmlDataExporter(org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataExporter) Test(org.junit.Test)

Example 7 with LargeServerMessageImpl

use of org.apache.activemq.artemis.core.persistence.impl.journal.LargeServerMessageImpl in project activemq-artemis by apache.

the class ServerLargeMessageTest method testSendServerMessage.

// Constructors --------------------------------------------------
// Public --------------------------------------------------------
// The ClientConsumer should be able to also send ServerLargeMessages as that's done by the CoreBridge
@Test
public void testSendServerMessage() throws Exception {
    ActiveMQServer server = createServer(true);
    server.start();
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, false);
    try {
        LargeServerMessageImpl fileMessage = new LargeServerMessageImpl((JournalStorageManager) server.getStorageManager());
        fileMessage.setMessageID(1005);
        for (int i = 0; i < 2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE; i++) {
            fileMessage.addBytes(new byte[] { ActiveMQTestBase.getSamplebyte(i) });
        }
        // The server would be doing this
        fileMessage.putLongProperty(Message.HDR_LARGE_BODY_SIZE, 2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
        fileMessage.releaseResources();
        session.createQueue("A", RoutingType.ANYCAST, "A");
        ClientProducer prod = session.createProducer("A");
        prod.send(fileMessage);
        fileMessage.deleteFile();
        session.commit();
        session.start();
        ClientConsumer cons = session.createConsumer("A");
        ClientMessage msg = cons.receive(5000);
        Assert.assertNotNull(msg);
        Assert.assertEquals(msg.getBodySize(), 2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
        for (int i = 0; i < 2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE; i++) {
            Assert.assertEquals(ActiveMQTestBase.getSamplebyte(i), msg.getBodyBuffer().readByte());
        }
        msg.acknowledge();
        session.commit();
    } finally {
        sf.close();
        locator.close();
        server.stop();
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) LargeServerMessageImpl(org.apache.activemq.artemis.core.persistence.impl.journal.LargeServerMessageImpl) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test) SecurityTest(org.apache.activemq.artemis.tests.integration.security.SecurityTest)

Aggregations

LargeServerMessageImpl (org.apache.activemq.artemis.core.persistence.impl.journal.LargeServerMessageImpl)7 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)6 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)6 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)6 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)5 Test (org.junit.Test)5 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)3 XmlDataExporter (org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataExporter)3 XmlDataImporter (org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataImporter)3 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)2 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)2 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)2 File (java.io.File)1 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)1 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)1 Message (org.apache.activemq.artemis.api.core.Message)1 LocalQueueBinding (org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding)1