Search in sources :

Example 16 with PageSubscription

use of org.apache.activemq.artemis.core.paging.cursor.PageSubscription in project activemq-artemis by apache.

the class PageCursorProviderImpl method checkPageCompletion.

private boolean checkPageCompletion(ArrayList<PageSubscription> cursorList, long minPage) {
    logger.tracef("checkPageCompletion(%d)", minPage);
    boolean complete = true;
    for (PageSubscription cursor : cursorList) {
        if (!cursor.isComplete(minPage)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Cursor " + cursor + " was considered incomplete at pageNr=" + minPage);
            }
            complete = false;
            break;
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("Cursor " + cursor + " was considered **complete** at pageNr=" + minPage);
            }
        }
    }
    return complete;
}
Also used : PageSubscription(org.apache.activemq.artemis.core.paging.cursor.PageSubscription)

Example 17 with PageSubscription

use of org.apache.activemq.artemis.core.paging.cursor.PageSubscription in project activemq-artemis by apache.

the class PageCursorStressTest method testRestartWithHoleOnAck.

@Test
public void testRestartWithHoleOnAck() throws Exception {
    final int NUM_MESSAGES = 1000;
    int numberOfPages = addMessages(NUM_MESSAGES, 10 * 1024);
    System.out.println("Number of pages = " + numberOfPages);
    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);
    LinkedListIterator<PagedReference> iterator = cursor.iterator();
    for (int i = 0; i < 100; i++) {
        PagedReference msg = iterator.next();
        assertEquals(i, msg.getMessage().getIntProperty("key").intValue());
        if (i < 10 || i > 20) {
            cursor.ack(msg);
        }
    }
    server.getStorageManager().waitOnOperations();
    server.stop();
    OperationContextImpl.clearContext();
    server.start();
    cursor = this.server.getPagingManager().getPageStore(ADDRESS).getCursorProvider().getSubscription(queue.getID());
    iterator = cursor.iterator();
    for (int i = 10; i <= 20; i++) {
        PagedReference msg = iterator.next();
        assertEquals(i, msg.getMessage().getIntProperty("key").intValue());
        cursor.ack(msg);
    }
    for (int i = 100; i < NUM_MESSAGES; i++) {
        PagedReference msg = iterator.next();
        assertEquals(i, msg.getMessage().getIntProperty("key").intValue());
        cursor.ack(msg);
    }
    server.stop();
    createServer();
    waitCleanup();
    assertEquals(1, lookupPageStore(ADDRESS).getNumberOfPages());
}
Also used : PagedReference(org.apache.activemq.artemis.core.paging.cursor.PagedReference) PageSubscription(org.apache.activemq.artemis.core.paging.cursor.PageSubscription) PageCursorProvider(org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider) Test(org.junit.Test)

Example 18 with PageSubscription

use of org.apache.activemq.artemis.core.paging.cursor.PageSubscription 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 19 with PageSubscription

use of org.apache.activemq.artemis.core.paging.cursor.PageSubscription in project activemq-artemis by apache.

the class PageCursorStressTest method testRestartWithHoleOnAckAndTransaction.

@Test
public void testRestartWithHoleOnAckAndTransaction() throws Exception {
    final int NUM_MESSAGES = 1000;
    int numberOfPages = addMessages(NUM_MESSAGES, 10 * 1024);
    System.out.println("Number of pages = " + numberOfPages);
    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);
    Transaction tx = new TransactionImpl(server.getStorageManager(), 60 * 1000);
    LinkedListIterator<PagedReference> iterator = cursor.iterator();
    for (int i = 0; i < 100; i++) {
        PagedReference msg = iterator.next();
        assertEquals(i, msg.getMessage().getIntProperty("key").intValue());
        if (i < 10 || i > 20) {
            cursor.ackTx(tx, msg);
        }
    }
    tx.commit();
    server.stop();
    OperationContextImpl.clearContext();
    server.start();
    cursor = this.server.getPagingManager().getPageStore(ADDRESS).getCursorProvider().getSubscription(queue.getID());
    tx = new TransactionImpl(server.getStorageManager(), 60 * 1000);
    iterator = cursor.iterator();
    for (int i = 10; i <= 20; i++) {
        PagedReference msg = iterator.next();
        assertEquals(i, msg.getMessage().getIntProperty("key").intValue());
        cursor.ackTx(tx, msg);
    }
    for (int i = 100; i < NUM_MESSAGES; i++) {
        PagedReference msg = iterator.next();
        assertEquals(i, msg.getMessage().getIntProperty("key").intValue());
        cursor.ackTx(tx, msg);
    }
    tx.commit();
    server.stop();
    createServer();
    waitCleanup();
    assertEquals(1, lookupPageStore(ADDRESS).getNumberOfPages());
}
Also used : PagedReference(org.apache.activemq.artemis.core.paging.cursor.PagedReference) Transaction(org.apache.activemq.artemis.core.transaction.Transaction) PageSubscription(org.apache.activemq.artemis.core.paging.cursor.PageSubscription) TransactionImpl(org.apache.activemq.artemis.core.transaction.impl.TransactionImpl) PageCursorProvider(org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider) Test(org.junit.Test)

Example 20 with PageSubscription

use of org.apache.activemq.artemis.core.paging.cursor.PageSubscription in project activemq-artemis by apache.

the class PageCursorStressTest method testSimpleCursorWithFilter.

@Test
public void testSimpleCursorWithFilter() throws Exception {
    final int NUM_MESSAGES = 100;
    PageSubscription cursorEven = createNonPersistentCursor(new Filter() {

        @Override
        public boolean match(Message message) {
            Boolean property = message.getBooleanProperty("even");
            if (property == null) {
                return false;
            } else {
                return property.booleanValue();
            }
        }

        @Override
        public SimpleString getFilterString() {
            return new SimpleString("even=true");
        }
    });
    PageSubscription cursorOdd = createNonPersistentCursor(new Filter() {

        @Override
        public boolean match(Message message) {
            Boolean property = message.getBooleanProperty("even");
            if (property == null) {
                return false;
            } else {
                return !property.booleanValue();
            }
        }

        @Override
        public SimpleString getFilterString() {
            return new SimpleString("even=true");
        }
    });
    int numberOfPages = addMessages(NUM_MESSAGES, 1024 * 1024);
    System.out.println("NumberOfPages = " + numberOfPages);
    queue.getPageSubscription().destroy();
    PagedReference msg;
    LinkedListIterator<PagedReference> iteratorEven = cursorEven.iterator();
    LinkedListIterator<PagedReference> iteratorOdd = cursorOdd.iterator();
    int key = 0;
    while ((msg = iteratorEven.next()) != null) {
        System.out.println("Received" + msg);
        assertEquals(key, msg.getMessage().getIntProperty("key").intValue());
        assertTrue(msg.getMessage().getBooleanProperty("even").booleanValue());
        key += 2;
        cursorEven.confirmPosition(msg.getPosition());
    }
    assertEquals(NUM_MESSAGES, key);
    key = 1;
    while ((msg = iteratorOdd.next()) != null) {
        assertEquals(key, msg.getMessage().getIntProperty("key").intValue());
        assertFalse(msg.getMessage().getBooleanProperty("even").booleanValue());
        key += 2;
        cursorOdd.confirmPosition(msg.getPosition());
    }
    assertEquals(NUM_MESSAGES + 1, key);
    forceGC();
    // assertTrue(lookupCursorProvider().getCacheSize() < numberOfPages);
    server.stop();
    createServer();
    waitCleanup();
    assertEquals(1, lookupPageStore(ADDRESS).getNumberOfPages());
}
Also used : PagedReference(org.apache.activemq.artemis.core.paging.cursor.PagedReference) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Message(org.apache.activemq.artemis.api.core.Message) Filter(org.apache.activemq.artemis.core.filter.Filter) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) PageSubscription(org.apache.activemq.artemis.core.paging.cursor.PageSubscription) Test(org.junit.Test)

Aggregations

PageSubscription (org.apache.activemq.artemis.core.paging.cursor.PageSubscription)22 Test (org.junit.Test)10 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)8 PagedReference (org.apache.activemq.artemis.core.paging.cursor.PagedReference)8 Message (org.apache.activemq.artemis.api.core.Message)6 StorageManager (org.apache.activemq.artemis.core.persistence.StorageManager)6 ArrayList (java.util.ArrayList)5 Filter (org.apache.activemq.artemis.core.filter.Filter)5 Transaction (org.apache.activemq.artemis.core.transaction.Transaction)5 HashMap (java.util.HashMap)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)4 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)4 PageCursorProvider (org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider)4 PostOffice (org.apache.activemq.artemis.core.postoffice.PostOffice)4 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)4 LargeServerMessage (org.apache.activemq.artemis.core.server.LargeServerMessage)4 QueueConfig (org.apache.activemq.artemis.core.server.QueueConfig)4 HierarchicalRepository (org.apache.activemq.artemis.core.settings.HierarchicalRepository)4 ExecutorFactory (org.apache.activemq.artemis.utils.ExecutorFactory)4