Search in sources :

Example 16 with StorageManager

use of org.apache.activemq.artemis.core.persistence.StorageManager in project activemq-artemis by apache.

the class ReplicationTest method testNoActions.

@Test
public void testNoActions() throws Exception {
    setupServer(true);
    StorageManager storage = getStorage();
    manager = liveServer.getReplicationManager();
    waitForComponent(manager);
    Journal replicatedJournal = new ReplicatedJournal((byte) 1, new FakeJournal(), manager);
    replicatedJournal.appendPrepareRecord(1, new FakeData(), false);
    final CountDownLatch latch = new CountDownLatch(1);
    storage.afterCompleteOperations(new IOCallback() {

        @Override
        public void onError(final int errorCode, final String errorMessage) {
        }

        @Override
        public void done() {
            latch.countDown();
        }
    });
    Assert.assertTrue(latch.await(1, TimeUnit.SECONDS));
    Assert.assertEquals("should be empty " + manager.getActiveTokens(), 0, manager.getActiveTokens().size());
}
Also used : JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) ReplicatedJournal(org.apache.activemq.artemis.core.replication.ReplicatedJournal) Journal(org.apache.activemq.artemis.core.journal.Journal) ReplicatedJournal(org.apache.activemq.artemis.core.replication.ReplicatedJournal) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CountDownLatch(java.util.concurrent.CountDownLatch) IOCallback(org.apache.activemq.artemis.core.io.IOCallback) Test(org.junit.Test)

Example 17 with StorageManager

use of org.apache.activemq.artemis.core.persistence.StorageManager in project activemq-artemis by apache.

the class ReplicationTest method testOrderOnNonPersistency.

@Test
public void testOrderOnNonPersistency() throws Exception {
    setupServer(true);
    final ArrayList<Integer> executions = new ArrayList<>();
    StorageManager storage = getStorage();
    manager = liveServer.getReplicationManager();
    Journal replicatedJournal = new ReplicatedJournal((byte) 1, new FakeJournal(), manager);
    int numberOfAdds = 200;
    final CountDownLatch latch = new CountDownLatch(numberOfAdds);
    OperationContext ctx = storage.getContext();
    for (int i = 0; i < numberOfAdds; i++) {
        final int nAdd = i;
        if (i % 2 == 0) {
            replicatedJournal.appendPrepareRecord(i, new FakeData(), false);
        }
        ctx.executeOnCompletion(new IOCallback() {

            @Override
            public void onError(final int errorCode, final String errorMessage) {
            }

            @Override
            public void done() {
                executions.add(nAdd);
                latch.countDown();
            }
        });
    }
    Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));
    for (int i = 0; i < numberOfAdds; i++) {
        Assert.assertEquals(i, executions.get(i).intValue());
    }
    Assert.assertEquals(0, manager.getActiveTokens().size());
}
Also used : OperationContext(org.apache.activemq.artemis.core.persistence.OperationContext) ArrayList(java.util.ArrayList) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) ReplicatedJournal(org.apache.activemq.artemis.core.replication.ReplicatedJournal) Journal(org.apache.activemq.artemis.core.journal.Journal) ReplicatedJournal(org.apache.activemq.artemis.core.replication.ReplicatedJournal) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CountDownLatch(java.util.concurrent.CountDownLatch) IOCallback(org.apache.activemq.artemis.core.io.IOCallback) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 18 with StorageManager

use of org.apache.activemq.artemis.core.persistence.StorageManager 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 StorageManager

use of org.apache.activemq.artemis.core.persistence.StorageManager in project activemq-artemis by apache.

the class PagingCounterTest method testCleanupCounter.

@Test
public void testCleanupCounter() 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);
        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(2100, counter.getValue());
        assertEquals(2100 * 1000, 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) Test(org.junit.Test)

Example 20 with StorageManager

use of org.apache.activemq.artemis.core.persistence.StorageManager 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)

Aggregations

StorageManager (org.apache.activemq.artemis.core.persistence.StorageManager)22 Test (org.junit.Test)17 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)15 Queue (org.apache.activemq.artemis.core.server.Queue)9 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)7 Transaction (org.apache.activemq.artemis.core.transaction.Transaction)7 PageSubscription (org.apache.activemq.artemis.core.paging.cursor.PageSubscription)6 PagingStoreFactoryNIO (org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO)6 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)6 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)6 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)5 Configuration (org.apache.activemq.artemis.core.config.Configuration)5 PagingManagerImpl (org.apache.activemq.artemis.core.paging.impl.PagingManagerImpl)5 NullStorageManager (org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager)5 HierarchicalObjectRepository (org.apache.activemq.artemis.core.settings.impl.HierarchicalObjectRepository)5 ExecutorService (java.util.concurrent.ExecutorService)4 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)4 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)4