org.apache.activemq.artemis.core.paging.cursor.PageSubscriptionCounter

Here are the examples of the java api class org.apache.activemq.artemis.core.paging.cursor.PageSubscriptionCounter taken from open source projects.

1. PagingCounterTest#testRestartCounter()

View license
@Test
public void testRestartCounter() throws Exception {
    Queue queue = server.createQueue(new SimpleString("A1"), new SimpleString("A1"), null, true, false);
    PageSubscriptionCounter counter = locateCounter(queue);
    StorageManager storage = server.getStorageManager();
    Transaction tx = new TransactionImpl(server.getStorageManager());
    counter.increment(tx, 1);
    assertEquals(0, counter.getValue());
    tx.commit();
    storage.waitOnOperations();
    assertEquals(1, counter.getValue());
    sl.close();
    server.stop();
    server = newActiveMQServer();
    server.start();
    queue = server.locateQueue(new SimpleString("A1"));
    assertNotNull(queue);
    counter = locateCounter(queue);
    assertEquals(1, counter.getValue());
}

2. PagingCounterTest#locateCounter()

View license
/**
    * @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;
}

3. PagingCounterTest#testPrepareCounter()

View license
@Test
public void testPrepareCounter() throws Exception {
    Xid xid = newXID();
    Queue queue = server.createQueue(new SimpleString("A1"), new SimpleString("A1"), null, true, false);
    PageSubscriptionCounter counter = locateCounter(queue);
    StorageManager storage = server.getStorageManager();
    Transaction tx = new TransactionImpl(xid, server.getStorageManager(), 300);
    for (int i = 0; i < 2000; i++) {
        counter.increment(tx, 1);
    }
    assertEquals(0, counter.getValue());
    tx.prepare();
    storage.waitOnOperations();
    assertEquals(0, counter.getValue());
    server.stop();
    server = newActiveMQServer();
    server.start();
    storage = server.getStorageManager();
    queue = server.locateQueue(new SimpleString("A1"));
    assertNotNull(queue);
    counter = locateCounter(queue);
    tx = server.getResourceManager().removeTransaction(xid);
    assertNotNull(tx);
    assertEquals(0, counter.getValue());
    tx.commit(false);
    storage.waitOnOperations();
    assertEquals(2000, counter.getValue());
}