Search in sources :

Example 41 with CoreMessage

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

the class PageCursorStressTest method testConsumeLivePageMultiThread.

@Test
public void testConsumeLivePageMultiThread() throws Exception {
    final PagingStoreImpl pageStore = lookupPageStore(ADDRESS);
    pageStore.startPaging();
    final int NUM_TX = 100;
    final int MSGS_TX = 100;
    final int TOTAL_MSG = NUM_TX * MSGS_TX;
    final int messageSize = 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);
    final StorageManager storage = this.server.getStorageManager();
    final AtomicInteger exceptions = new AtomicInteger(0);
    Thread t1 = new Thread() {

        @Override
        public void run() {
            try {
                int count = 0;
                for (int txCount = 0; txCount < NUM_TX; txCount++) {
                    Transaction tx = null;
                    if (txCount % 2 == 0) {
                        tx = new TransactionImpl(storage);
                    }
                    RoutingContext ctx = generateCTX(tx);
                    for (int i = 0; i < MSGS_TX; i++) {
                        // System.out.println("Sending " + count);
                        ActiveMQBuffer buffer = RandomUtil.randomBuffer(messageSize, count);
                        Message msg = new CoreMessage(i, buffer.writerIndex());
                        msg.putIntProperty("key", count++);
                        msg.getBodyBuffer().writeBytes(buffer, 0, buffer.writerIndex());
                        Assert.assertTrue(pageStore.page(msg, ctx.getTransaction(), ctx.getContextListing(ADDRESS), lock));
                    }
                    if (tx != null) {
                        tx.commit();
                    }
                }
            } catch (Throwable e) {
                e.printStackTrace();
                exceptions.incrementAndGet();
            }
        }
    };
    t1.start();
    LinkedListIterator<PagedReference> iterator = cursor.iterator();
    for (int i = 0; i < TOTAL_MSG; i++) {
        assertEquals(0, exceptions.get());
        PagedReference ref = null;
        for (int repeat = 0; repeat < 5; repeat++) {
            ref = iterator.next();
            if (ref == null) {
                Thread.sleep(1000);
            } else {
                break;
            }
        }
        assertNotNull(ref);
        ref.acknowledge();
        assertNotNull(ref);
        System.out.println("Consuming " + ref.getMessage().getIntProperty("key"));
    // assertEquals(i, ref.getMessage().getIntProperty("key").intValue());
    }
    assertEquals(0, exceptions.get());
}
Also used : CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Message(org.apache.activemq.artemis.api.core.Message) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) PageSubscription(org.apache.activemq.artemis.core.paging.cursor.PageSubscription) TransactionImpl(org.apache.activemq.artemis.core.transaction.impl.TransactionImpl) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) PagedReference(org.apache.activemq.artemis.core.paging.cursor.PagedReference) RoutingContext(org.apache.activemq.artemis.core.server.RoutingContext) PagingStoreImpl(org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl) Transaction(org.apache.activemq.artemis.core.transaction.Transaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PageCursorProvider(org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 42 with CoreMessage

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

the class PageCursorStressTest method addMessages.

private int addMessages(final int start, final int numMessages, final int messageSize) throws Exception {
    PagingStoreImpl pageStore = lookupPageStore(ADDRESS);
    pageStore.startPaging();
    RoutingContext ctx = generateCTX();
    for (int i = start; i < start + numMessages; i++) {
        if (i % 100 == 0)
            System.out.println("Paged " + i);
        ActiveMQBuffer buffer = RandomUtil.randomBuffer(messageSize, i + 1L);
        Message msg = new CoreMessage(i, buffer.writerIndex());
        msg.putIntProperty("key", i);
        // to be used on tests that are validating filters
        msg.putBooleanProperty("even", i % 2 == 0);
        msg.getBodyBuffer().writeBytes(buffer, 0, buffer.writerIndex());
        Assert.assertTrue(pageStore.page(msg, ctx.getTransaction(), ctx.getContextListing(ADDRESS), lock));
    }
    return pageStore.getNumberOfPages();
}
Also used : RoutingContext(org.apache.activemq.artemis.core.server.RoutingContext) 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) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 43 with CoreMessage

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

the class ManagementServiceImplTest method testHandleManagementMessageWithOperation.

@Test
public void testHandleManagementMessageWithOperation() throws Exception {
    String queue = RandomUtil.randomString();
    String address = RandomUtil.randomString();
    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, "createQueue", queue, address);
    Message reply = server.getManagementService().handleMessage(message);
    Assert.assertTrue(ManagementHelper.hasOperationSucceeded(reply));
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) 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) Message(org.apache.activemq.artemis.api.core.Message) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) Test(org.junit.Test)

Example 44 with CoreMessage

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

the class ManagementServiceImplTest method testHandleManagementMessageWithUnknownAttribute.

@Test
public void testHandleManagementMessageWithUnknownAttribute() 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, "started");
    ICoreMessage reply = server.getManagementService().handleMessage(message);
    Assert.assertTrue(ManagementHelper.hasOperationSucceeded(reply));
    Assert.assertTrue((Boolean) 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 45 with CoreMessage

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

the class MessageJournalTest method testStoreCore.

@Test
public void testStoreCore() throws Throwable {
    ActiveMQServer server = createServer(true);
    server.start();
    CoreMessage message = new CoreMessage().initBuffer(10 * 1024).setDurable(true);
    message.setMessageID(333);
    CoreProtocolManagerFactory factory = (CoreProtocolManagerFactory) server.getRemotingService().getProtocolFactoryMap().get("CORE");
    Assert.assertNotNull(factory);
    message.getBodyBuffer().writeByte((byte) 'Z');
    server.getStorageManager().storeMessage(message);
    server.getStorageManager().stop();
    JournalStorageManager journalStorageManager = (JournalStorageManager) server.getStorageManager();
    List<RecordInfo> committedRecords = new LinkedList<>();
    List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
    TransactionFailureCallback transactionFailure = new TransactionFailureCallback() {

        @Override
        public void failedTransaction(long transactionID, List<RecordInfo> records, List<RecordInfo> recordsToDelete) {
        }
    };
    try {
        journalStorageManager.getMessageJournal().start();
        journalStorageManager.getMessageJournal().load(committedRecords, preparedTransactions, transactionFailure);
        Assert.assertEquals(1, committedRecords.size());
    } finally {
        journalStorageManager.getMessageJournal().stop();
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) CoreProtocolManagerFactory(org.apache.activemq.artemis.core.protocol.core.impl.CoreProtocolManagerFactory) List(java.util.List) LinkedList(java.util.LinkedList) TransactionFailureCallback(org.apache.activemq.artemis.core.journal.TransactionFailureCallback) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) LinkedList(java.util.LinkedList) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) 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