org.apache.activemq.artemis.core.transaction.impl.TransactionImpl

Here are the examples of the java api class org.apache.activemq.artemis.core.transaction.impl.TransactionImpl taken from open source projects.

1. DuplicateCacheTest#testDuplicateNonPersistent()

Project: activemq-artemis
File: DuplicateCacheTest.java
@Test
public void testDuplicateNonPersistent() throws Exception {
    createStorage();
    DuplicateIDCache cache = new DuplicateIDCacheImpl(new SimpleString("test"), 2000, journal, false);
    TransactionImpl tx = new TransactionImpl(journal);
    for (int i = 0; i < 5000; i++) {
        byte[] bytes = RandomUtil.randomBytes();
        cache.addToCache(bytes, tx);
    }
    tx.commit();
    for (int i = 0; i < 5000; i++) {
        byte[] bytes = RandomUtil.randomBytes();
        cache.addToCache(bytes, null);
    }
}

2. PageCursorStressTest#pgMessages()

Project: activemq-artemis
File: PageCursorStressTest.java
/**
    * @param storage
    * @param pageStore
    * @param pgParameter
    * @param start
    * @param NUM_MESSAGES
    * @param messageSize
    * @throws Exception
    */
private Transaction pgMessages(StorageManager storage, PagingStoreImpl pageStore, long pgParameter, int start, final int NUM_MESSAGES, final int messageSize) throws Exception {
    TransactionImpl txImpl = new TransactionImpl(pgParameter, null, storage);
    RoutingContext ctx = generateCTX(txImpl);
    for (int i = start; i < start + NUM_MESSAGES; i++) {
        ActiveMQBuffer buffer = RandomUtil.randomBuffer(messageSize, i + 1L);
        ServerMessage msg = new ServerMessageImpl(storage.generateID(), buffer.writerIndex());
        msg.getBodyBuffer().writeBytes(buffer, 0, buffer.writerIndex());
        msg.putIntProperty("key", i);
        pageStore.page(msg, ctx.getTransaction(), ctx.getContextListing(ADDRESS), lock);
    }
    return txImpl;
}

3. DuplicateCacheTest#testDuplicate()

Project: activemq-artemis
File: DuplicateCacheTest.java
@Test
public void testDuplicate() throws Exception {
    createStorage();
    DuplicateIDCache cache = new DuplicateIDCacheImpl(new SimpleString("test"), 2000, journal, true);
    TransactionImpl tx = new TransactionImpl(journal);
    for (int i = 0; i < 5000; i++) {
        byte[] bytes = RandomUtil.randomBytes();
        cache.addToCache(bytes, tx);
    }
    tx.commit();
    tx = new TransactionImpl(journal);
    for (int i = 0; i < 5000; i++) {
        byte[] bytes = RandomUtil.randomBytes();
        cache.addToCache(bytes, tx);
    }
    tx.commit();
    byte[] id = RandomUtil.randomBytes();
    Assert.assertFalse(cache.contains(id));
    cache.addToCache(id, null);
    Assert.assertTrue(cache.contains(id));
    cache.deleteFromCache(id);
    final CountDownLatch latch = new CountDownLatch(1);
    OperationContextImpl.getContext().executeOnCompletion(new IOCallback() {

        @Override
        public void done() {
            latch.countDown();
        }

        @Override
        public void onError(int errorCode, String errorMessage) {
        }
    }, true);
    Assert.assertTrue(latch.await(1, TimeUnit.MINUTES));
    Assert.assertFalse(cache.contains(id));
}

4. PageCursorStressTest#testRestartWithHoleOnAckAndTransaction()

Project: activemq-artemis
File: PageCursorStressTest.java
@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());
}