Search in sources :

Example 76 with Message

use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.

the class LargeMessageCompressTest method testLargeMessageCompression2.

@Test
public void testLargeMessageCompression2() throws Exception {
    final int messageSize = (int) (3.5 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
    ActiveMQServer server = createServer(true, isNetty());
    server.start();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = addClientSession(sf.createSession(false, false, false));
    session.createTemporaryQueue(ADDRESS, ADDRESS);
    ClientProducer producer = session.createProducer(ADDRESS);
    Message clientFile = createLargeClientMessageStreaming(session, messageSize, true);
    producer.send(clientFile);
    session.commit();
    session.start();
    ClientConsumer consumer = session.createConsumer(ADDRESS);
    ClientMessage msg1 = consumer.receive(1000);
    Assert.assertNotNull(msg1);
    String testDir = getTestDir();
    File testFile = new File(testDir, "async_large_message");
    FileOutputStream output = new FileOutputStream(testFile);
    msg1.setOutputStream(output);
    msg1.waitOutputStreamCompletion(0);
    msg1.acknowledge();
    output.close();
    session.commit();
    consumer.close();
    session.close();
    // verify
    FileInputStream input = new FileInputStream(testFile);
    for (int i = 0; i < messageSize; i++) {
        byte b = (byte) input.read();
        assertEquals("position = " + i, getSamplebyte(i), b);
    }
    input.close();
    testFile.delete();
    validateNoFilesOnLargeDir();
}
Also used : ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) FileInputStream(java.io.FileInputStream) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) FileOutputStream(java.io.FileOutputStream) 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) File(java.io.File) Test(org.junit.Test)

Example 77 with Message

use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.

the class LargeMessageCompressTest method testLargeMessageCompressionRestartAndCheckSize.

@Test
public void testLargeMessageCompressionRestartAndCheckSize() throws Exception {
    final int messageSize = 1024 * 1024;
    ActiveMQServer server = createServer(true, isNetty());
    server.start();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = addClientSession(sf.createSession(false, false, false));
    session.createQueue(ADDRESS, ADDRESS, true);
    ClientProducer producer = session.createProducer(ADDRESS);
    byte[] msgs = new byte[1024 * 1024];
    for (int i = 0; i < msgs.length; i++) {
        msgs[i] = RandomUtil.randomByte();
    }
    Message clientFile = createLargeClientMessage(session, msgs, true);
    producer.send(clientFile);
    session.commit();
    session.close();
    sf.close();
    locator.close();
    server.stop();
    server = createServer(true, isNetty());
    server.start();
    locator = createFactory(isNetty());
    sf = createSessionFactory(locator);
    session = sf.createSession();
    session.start();
    ClientConsumer consumer = session.createConsumer(ADDRESS);
    ClientMessage msg1 = consumer.receive(1000);
    Assert.assertNotNull(msg1);
    assertEquals(messageSize, msg1.getBodySize());
    String testDir = getTestDir();
    File testFile = new File(testDir, "async_large_message");
    FileOutputStream output = new FileOutputStream(testFile);
    msg1.saveToOutputStream(output);
    msg1.acknowledge();
    session.commit();
    consumer.close();
    session.close();
    // verify
    FileInputStream input = new FileInputStream(testFile);
    for (int i = 0; i < messageSize; i++) {
        byte b = (byte) input.read();
        assertEquals("position = " + i, msgs[i], b);
    }
    input.close();
    testFile.delete();
    validateNoFilesOnLargeDir();
}
Also used : ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) FileInputStream(java.io.FileInputStream) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) FileOutputStream(java.io.FileOutputStream) 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) File(java.io.File) Test(org.junit.Test)

Example 78 with Message

use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.

the class SendAckFailTest method testSend.

@Test
public void testSend() throws Exception {
    Process process = SpawnedVMSupport.spawnVM(SendAckFailTest.class.getName());
    ActiveMQServer server = null;
    try {
        HashSet<Integer> listSent = new HashSet<>();
        Thread t = null;
        {
            ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
            ServerLocator locator = factory.getServerLocator();
            locator.setConfirmationWindowSize(0).setInitialConnectAttempts(100).setRetryInterval(100).setBlockOnDurableSend(false).setReconnectAttempts(0);
            ClientSessionFactory sf = locator.createSessionFactory();
            ClientSession session = sf.createSession();
            session.createAddress(SimpleString.toSimpleString("T1"), RoutingType.ANYCAST, true);
            session.createQueue(SimpleString.toSimpleString("T1"), RoutingType.ANYCAST, SimpleString.toSimpleString("T1"), true);
            ClientProducer producer = session.createProducer("T1");
            session.setSendAcknowledgementHandler(new SendAcknowledgementHandler() {

                @Override
                public void sendAcknowledged(Message message) {
                    listSent.add(message.getIntProperty("myid"));
                }
            });
            t = new Thread() {

                @Override
                public void run() {
                    for (int i = 0; i < 5000; i++) {
                        try {
                            producer.send(session.createMessage(true).putIntProperty("myid", i));
                        } catch (Exception e) {
                            e.printStackTrace();
                            break;
                        }
                    }
                }
            };
            t.start();
        }
        Wait.waitFor(() -> listSent.size() > 100, 5000, 10);
        Assert.assertTrue(process.waitFor(1, TimeUnit.MINUTES));
        server = startServer(false);
        {
            ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
            ServerLocator locator = factory.getServerLocator();
            ClientSessionFactory sf = locator.createSessionFactory();
            ClientSession session = sf.createSession();
            ClientConsumer consumer = session.createConsumer("T1");
            session.start();
            for (int i = 0; i < listSent.size(); i++) {
                ClientMessage message = consumer.receive(1000);
                if (message == null) {
                    for (Integer msgi : listSent) {
                        System.out.println("Message " + msgi + " was lost");
                    }
                    fail("missed messages!");
                }
                message.acknowledge();
                if (!listSent.remove(message.getIntProperty("myid"))) {
                    System.out.println("Message " + message + " with id " + message.getIntProperty("myid") + " received in duplicate");
                    fail("Message " + message + " with id " + message.getIntProperty("myid") + " received in duplicate");
                }
            }
        }
    } finally {
        if (process != null) {
            process.destroy();
        }
        if (server != null) {
            server.stop();
        }
    }
}
Also used : LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage) PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) SendAcknowledgementHandler(org.apache.activemq.artemis.api.core.client.SendAcknowledgementHandler) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) 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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 79 with Message

use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.

the class QueueImplTest method testGetFilter.

@Test
public void testGetFilter() {
    QueueImpl queue = getTemporaryQueue();
    Assert.assertNull(queue.getFilter());
    Filter filter = new Filter() {

        @Override
        public boolean match(final Message message) {
            return false;
        }

        @Override
        public SimpleString getFilterString() {
            return null;
        }
    };
    queue = getFilteredQueue(filter);
    Assert.assertEquals(filter, queue.getFilter());
}
Also used : ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) Filter(org.apache.activemq.artemis.core.filter.Filter) FakeFilter(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeFilter) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Test(org.junit.Test)

Example 80 with Message

use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.

the class PagingStoreImplTest method testDepageOnCurrentPage.

@Test
public void testDepageOnCurrentPage() throws Exception {
    SequentialFileFactory factory = new FakeSequentialFileFactory();
    SimpleString destination = new SimpleString("test");
    PagingStoreFactory storeFactory = new FakeStoreFactory(factory);
    PagingStoreImpl storeImpl = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, PagingStoreImplTest.destinationTestName, new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE), getExecutorFactory().getExecutor(), true);
    storeImpl.start();
    Assert.assertEquals(0, storeImpl.getNumberOfPages());
    storeImpl.startPaging();
    List<ActiveMQBuffer> buffers = new ArrayList<>();
    int numMessages = 10;
    for (int i = 0; i < numMessages; i++) {
        ActiveMQBuffer buffer = createRandomBuffer(i + 1L, 10);
        buffers.add(buffer);
        Message msg = createMessage(i, storeImpl, destination, buffer);
        final RoutingContextImpl ctx = new RoutingContextImpl(null);
        Assert.assertTrue(storeImpl.page(msg, ctx.getTransaction(), ctx.getContextListing(storeImpl.getStoreName()), lock));
    }
    Assert.assertEquals(1, storeImpl.getNumberOfPages());
    storeImpl.sync();
    Page page = storeImpl.depage();
    page.open();
    List<PagedMessage> msg = page.read(new NullStorageManager());
    Assert.assertEquals(numMessages, msg.size());
    Assert.assertEquals(1, storeImpl.getNumberOfPages());
    page = storeImpl.depage();
    Assert.assertNull(page);
    Assert.assertEquals(0, storeImpl.getNumberOfPages());
    for (int i = 0; i < numMessages; i++) {
        ActiveMQBuffer horn1 = buffers.get(i);
        ActiveMQBuffer horn2 = msg.get(i).getMessage().toCore().getBodyBuffer();
        horn1.resetReaderIndex();
        horn2.resetReaderIndex();
        for (int j = 0; j < horn1.writerIndex(); j++) {
            Assert.assertEquals(horn1.readByte(), horn2.readByte());
        }
    }
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) Message(org.apache.activemq.artemis.api.core.Message) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Page(org.apache.activemq.artemis.core.paging.impl.Page) FakeSequentialFileFactory(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) RoutingContextImpl(org.apache.activemq.artemis.core.server.impl.RoutingContextImpl) FakeSequentialFileFactory(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory) PagingStoreImpl(org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) PagingStoreFactory(org.apache.activemq.artemis.core.paging.PagingStoreFactory) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Aggregations

Message (org.apache.activemq.artemis.api.core.Message)114 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)56 Test (org.junit.Test)52 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)51 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)48 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)46 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)41 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)35 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)34 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)28 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)18 LargeServerMessage (org.apache.activemq.artemis.core.server.LargeServerMessage)16 ArrayList (java.util.ArrayList)15 MessageReference (org.apache.activemq.artemis.core.server.MessageReference)12 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)11 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)11 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)10 Transaction (org.apache.activemq.artemis.core.transaction.Transaction)10 HashMap (java.util.HashMap)9 TransactionImpl (org.apache.activemq.artemis.core.transaction.impl.TransactionImpl)8