Search in sources :

Example 16 with CoreMessage

use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.

the class PageCursorStressTest method testConsumeLivePage.

@Test
public void testConsumeLivePage() throws Exception {
    PagingStoreImpl pageStore = lookupPageStore(ADDRESS);
    pageStore.startPaging();
    final int NUM_MESSAGES = 100;
    final int messageSize = 1024 * 1024;
    PageCursorProvider cursorProvider = this.server.getPagingManager().getPageStore(ADDRESS).getCursorProvider();
    System.out.println("cursorProvider = " + cursorProvider);
    PageSubscription cursor = this.server.getPagingManager().getPageStore(ADDRESS).getCursorProvider().getSubscription(queue.getID());
    System.out.println("Cursor: " + cursor);
    RoutingContextImpl ctx = generateCTX();
    LinkedListIterator<PagedReference> iterator = cursor.iterator();
    for (int i = 0; i < NUM_MESSAGES; i++) {
        // if (i % 100 == 0)
        System.out.println("read/written " + i);
        ActiveMQBuffer buffer = RandomUtil.randomBuffer(messageSize, i + 1L);
        Message msg = new CoreMessage(i, buffer.writerIndex());
        msg.putIntProperty("key", i);
        msg.getBodyBuffer().writeBytes(buffer, 0, buffer.writerIndex());
        Assert.assertTrue(pageStore.page(msg, ctx.getTransaction(), ctx.getContextListing(ADDRESS), lock));
        PagedReference readMessage = iterator.next();
        assertNotNull(readMessage);
        assertEquals(i, readMessage.getMessage().getIntProperty("key").intValue());
        assertNull(iterator.next());
    }
    OperationContextImpl.clearContext();
    ctx = generateCTX();
    pageStore = lookupPageStore(ADDRESS);
    cursor = this.server.getPagingManager().getPageStore(ADDRESS).getCursorProvider().getSubscription(queue.getID());
    iterator = cursor.iterator();
    for (int i = 0; i < NUM_MESSAGES * 2; i++) {
        if (i % 100 == 0)
            System.out.println("Paged " + i);
        if (i >= NUM_MESSAGES) {
            ActiveMQBuffer buffer = RandomUtil.randomBuffer(messageSize, i + 1L);
            Message msg = new CoreMessage(i, buffer.writerIndex());
            msg.putIntProperty("key", i);
            msg.getBodyBuffer().writeBytes(buffer, 0, buffer.writerIndex());
            Assert.assertTrue(pageStore.page(msg, ctx.getTransaction(), ctx.getContextListing(ADDRESS), lock));
        }
        PagedReference readMessage = iterator.next();
        assertNotNull(readMessage);
        assertEquals(i, readMessage.getMessage().getIntProperty("key").intValue());
    }
    OperationContextImpl.clearContext();
    pageStore = lookupPageStore(ADDRESS);
    cursor = this.server.getPagingManager().getPageStore(ADDRESS).getCursorProvider().getSubscription(queue.getID());
    iterator = cursor.iterator();
    for (int i = 0; i < NUM_MESSAGES * 3; i++) {
        if (i % 100 == 0)
            System.out.println("Paged " + i);
        if (i >= NUM_MESSAGES * 2 - 1) {
            ActiveMQBuffer buffer = RandomUtil.randomBuffer(messageSize, i + 1L);
            Message msg = new CoreMessage(i, buffer.writerIndex());
            msg.putIntProperty("key", i + 1);
            msg.getBodyBuffer().writeBytes(buffer, 0, buffer.writerIndex());
            Assert.assertTrue(pageStore.page(msg, ctx.getTransaction(), ctx.getContextListing(ADDRESS), lock));
        }
        PagedReference readMessage = iterator.next();
        assertNotNull(readMessage);
        cursor.ack(readMessage);
        assertEquals(i, readMessage.getMessage().getIntProperty("key").intValue());
    }
    PagedReference readMessage = iterator.next();
    assertEquals(NUM_MESSAGES * 3, readMessage.getMessage().getIntProperty("key").intValue());
    cursor.ack(readMessage);
    server.getStorageManager().waitOnOperations();
    pageStore.flushExecutors();
    assertFalse(pageStore.isPaging());
    server.stop();
    createServer();
    assertFalse(pageStore.isPaging());
    waitCleanup();
    assertFalse(lookupPageStore(ADDRESS).isPaging());
}
Also used : RoutingContextImpl(org.apache.activemq.artemis.core.server.impl.RoutingContextImpl) PagedReference(org.apache.activemq.artemis.core.paging.cursor.PagedReference) PagingStoreImpl(org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Message(org.apache.activemq.artemis.api.core.Message) PageSubscription(org.apache.activemq.artemis.core.paging.cursor.PageSubscription) PageCursorProvider(org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 17 with CoreMessage

use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.

the class PageTest method addPageElements.

/**
 * @param simpleDestination
 * @param page
 * @param numberOfElements
 * @return
 * @throws Exception
 */
protected void addPageElements(final SimpleString simpleDestination, final Page page, final int numberOfElements) throws Exception {
    int initialNumberOfMessages = page.getNumberOfMessages();
    for (int i = 0; i < numberOfElements; i++) {
        ICoreMessage msg = new CoreMessage().initBuffer(100);
        for (int j = 0; j < 10; j++) {
            msg.getBodyBuffer().writeByte((byte) 'b');
        }
        msg.setAddress(simpleDestination);
        page.write(new PagedMessageImpl(msg, new long[0]));
        Assert.assertEquals(initialNumberOfMessages + i + 1, page.getNumberOfMessages());
    }
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) PagedMessageImpl(org.apache.activemq.artemis.core.paging.impl.PagedMessageImpl) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage)

Example 18 with CoreMessage

use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.

the class PagingManagerImplTest method createMessage.

protected ICoreMessage createMessage(final long messageId, final SimpleString destination, final ByteBuffer buffer) {
    ICoreMessage msg = new CoreMessage(messageId, 200);
    msg.setAddress(destination);
    msg.getBodyBuffer().writeBytes(buffer);
    return msg;
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage)

Example 19 with CoreMessage

use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.

the class ManagementServiceImplTest method testHandleManagementMessageWithOperationWhichFails.

@Test
public void testHandleManagementMessageWithOperationWhichFails() throws Exception {
    Configuration config = createBasicConfig().setJMXManagementEnabled(false);
    ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(config, false));
    server.start();
    // invoke attribute and operation on the server
    CoreMessage message = new CoreMessage(1, 100);
    ManagementHelper.putOperationInvocation(message, ResourceNames.BROKER, "thereIsNoSuchOperation");
    ICoreMessage reply = server.getManagementService().handleMessage(message);
    Assert.assertFalse(ManagementHelper.hasOperationSucceeded(reply));
    Assert.assertNotNull(ManagementHelper.getResult(reply));
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) Configuration(org.apache.activemq.artemis.core.config.Configuration) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) Test(org.junit.Test)

Example 20 with CoreMessage

use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.

the class ManagementServiceImplTest method testHandleManagementMessageWithKnownAttribute.

@Test
public void testHandleManagementMessageWithKnownAttribute() throws Exception {
    Configuration config = createBasicConfig().setJMXManagementEnabled(false);
    ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(config, false));
    server.start();
    // invoke attribute and operation on the server
    ICoreMessage message = new CoreMessage(1, 100);
    ManagementHelper.putAttribute(message, ResourceNames.BROKER, "attribute.Does.Not.Exist");
    ICoreMessage reply = server.getManagementService().handleMessage(message);
    Assert.assertFalse(ManagementHelper.hasOperationSucceeded(reply));
    Assert.assertNotNull(ManagementHelper.getResult(reply));
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) Configuration(org.apache.activemq.artemis.core.config.Configuration) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) Test(org.junit.Test)

Aggregations

CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)48 Test (org.junit.Test)20 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)17 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)16 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)11 Message (org.apache.activemq.artemis.api.core.Message)11 Configuration (org.apache.activemq.artemis.core.config.Configuration)6 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)6 ByteBuf (io.netty.buffer.ByteBuf)5 LinkedList (java.util.LinkedList)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)3 PagingStoreImpl (org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl)3 JournalStorageManager (org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager)3 RoutingContext (org.apache.activemq.artemis.core.server.RoutingContext)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 InstanceNotFoundException (javax.management.InstanceNotFoundException)2 MBeanRegistrationException (javax.management.MBeanRegistrationException)2 PageCursorProvider (org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider)2 PageSubscription (org.apache.activemq.artemis.core.paging.cursor.PageSubscription)2