Search in sources :

Example 6 with PageSubscriptionCounter

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

the class PagingCounterTest method testRestartCounter.

@Test
public void testRestartCounter() throws Exception {
    server.addAddressInfo(new AddressInfo(new SimpleString("A1"), RoutingType.ANYCAST));
    Queue queue = server.createQueue(new SimpleString("A1"), RoutingType.ANYCAST, new SimpleString("A1"), null, true, false);
    PageSubscriptionCounter counter = locateCounter(queue);
    StorageManager storage = server.getStorageManager();
    Transaction tx = new TransactionImpl(server.getStorageManager());
    counter.increment(tx, 1, 1000);
    assertEquals(0, counter.getValue());
    assertEquals(0, counter.getPersistentSize());
    tx.commit();
    storage.waitOnOperations();
    assertEquals(1, counter.getValue());
    assertEquals(1000, counter.getPersistentSize());
    sl.close();
    server.stop();
    server = newActiveMQServer();
    server.start();
    queue = server.locateQueue(new SimpleString("A1"));
    assertNotNull(queue);
    counter = locateCounter(queue);
    assertEquals(1, counter.getValue());
    assertEquals(1000, counter.getPersistentSize());
}
Also used : Transaction(org.apache.activemq.artemis.core.transaction.Transaction) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) PageSubscriptionCounter(org.apache.activemq.artemis.core.paging.cursor.PageSubscriptionCounter) TransactionImpl(org.apache.activemq.artemis.core.transaction.impl.TransactionImpl) Queue(org.apache.activemq.artemis.core.server.Queue) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 7 with PageSubscriptionCounter

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

the class PagingCounterTest method testCleanupCounterNonPersistent.

@Test
public void testCleanupCounterNonPersistent() throws Exception {
    ClientSessionFactory sf = createSessionFactory(sl);
    ClientSession session = sf.createSession();
    try {
        server.addAddressInfo(new AddressInfo(new SimpleString("A1"), RoutingType.ANYCAST));
        Queue queue = server.createQueue(new SimpleString("A1"), RoutingType.ANYCAST, new SimpleString("A1"), null, true, false);
        PageSubscriptionCounter counter = locateCounter(queue);
        ((PageSubscriptionCounterImpl) counter).setPersistent(false);
        StorageManager storage = server.getStorageManager();
        Transaction tx = new TransactionImpl(server.getStorageManager());
        for (int i = 0; i < 2100; i++) {
            counter.increment(tx, 1, 1000);
            if (i % 200 == 0) {
                tx.commit();
                storage.waitOnOperations();
                assertEquals(i + 1, counter.getValue());
                assertEquals((i + 1) * 1000, counter.getPersistentSize());
                tx = new TransactionImpl(server.getStorageManager());
            }
        }
        tx.commit();
        storage.waitOnOperations();
        assertEquals(2100, counter.getValue());
        assertEquals(2100 * 1000, counter.getPersistentSize());
        server.stop();
        server = newActiveMQServer();
        server.start();
        queue = server.locateQueue(new SimpleString("A1"));
        assertNotNull(queue);
        counter = locateCounter(queue);
        assertEquals(0, counter.getValue());
        assertEquals(0, counter.getPersistentSize());
    } finally {
        sf.close();
        session.close();
    }
}
Also used : Transaction(org.apache.activemq.artemis.core.transaction.Transaction) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) PageSubscriptionCounter(org.apache.activemq.artemis.core.paging.cursor.PageSubscriptionCounter) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) TransactionImpl(org.apache.activemq.artemis.core.transaction.impl.TransactionImpl) Queue(org.apache.activemq.artemis.core.server.Queue) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) PageSubscriptionCounterImpl(org.apache.activemq.artemis.core.paging.cursor.impl.PageSubscriptionCounterImpl) Test(org.junit.Test)

Example 8 with PageSubscriptionCounter

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

the class PagingCounterTest method locateCounter.

/**
 * @param queue
 * @return
 * @throws Exception
 */
private PageSubscriptionCounter locateCounter(Queue queue) throws Exception {
    PageSubscription subscription = server.getPagingManager().getPageStore(new SimpleString("A1")).getCursorProvider().getSubscription(queue.getID());
    PageSubscriptionCounter counter = subscription.getCounter();
    return counter;
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) PageSubscriptionCounter(org.apache.activemq.artemis.core.paging.cursor.PageSubscriptionCounter) PageSubscription(org.apache.activemq.artemis.core.paging.cursor.PageSubscription)

Aggregations

PageSubscriptionCounter (org.apache.activemq.artemis.core.paging.cursor.PageSubscriptionCounter)8 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)7 Transaction (org.apache.activemq.artemis.core.transaction.Transaction)6 TransactionImpl (org.apache.activemq.artemis.core.transaction.impl.TransactionImpl)6 StorageManager (org.apache.activemq.artemis.core.persistence.StorageManager)5 Queue (org.apache.activemq.artemis.core.server.Queue)5 Test (org.junit.Test)5 AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)4 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)3 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)3 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Xid (javax.transaction.xa.Xid)1 PagedMessage (org.apache.activemq.artemis.core.paging.PagedMessage)1 PagingStore (org.apache.activemq.artemis.core.paging.PagingStore)1 PageSubscription (org.apache.activemq.artemis.core.paging.cursor.PageSubscription)1