Search in sources :

Example 6 with PagingStoreImpl

use of org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl in project activemq-artemis by apache.

the class PagingStoreImplTest method testDoubleStart.

@Test
public void testDoubleStart() throws Exception {
    SequentialFileFactory factory = new FakeSequentialFileFactory();
    PagingStore storeImpl = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, new FakeStoreFactory(factory), PagingStoreImplTest.destinationTestName, new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE), getExecutorFactory().getExecutor(), true);
    storeImpl.start();
    // this is not supposed to throw an exception.
    // As you could have start being called twice as Stores are dynamically
    // created, on a multi-thread environment
    storeImpl.start();
    storeImpl.stop();
}
Also used : FakeSequentialFileFactory(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) PagingStoreImpl(org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) FakeSequentialFileFactory(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) Test(org.junit.Test)

Example 7 with PagingStoreImpl

use of org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl in project activemq-artemis by apache.

the class PagingStoreImplTest method testDepageMultiplePages.

@Test
public void testDepageMultiplePages() throws Exception {
    SequentialFileFactory factory = new FakeSequentialFileFactory();
    SimpleString destination = new SimpleString("test");
    PagingStoreFactory storeFactory = new FakeStoreFactory(factory);
    PagingStoreImpl store = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, PagingStoreImplTest.destinationTestName, new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE), getExecutorFactory().getExecutor(), true);
    store.start();
    Assert.assertEquals(0, store.getNumberOfPages());
    store.startPaging();
    Assert.assertEquals(1, store.getNumberOfPages());
    List<ActiveMQBuffer> buffers = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        ActiveMQBuffer buffer = createRandomBuffer(i + 1L, 10);
        buffers.add(buffer);
        if (i == 5) {
            store.forceAnotherPage();
        }
        Message msg = createMessage(i, store, destination, buffer);
        final RoutingContextImpl ctx = new RoutingContextImpl(null);
        Assert.assertTrue(store.page(msg, ctx.getTransaction(), ctx.getContextListing(store.getStoreName()), lock));
    }
    Assert.assertEquals(2, store.getNumberOfPages());
    store.sync();
    int sequence = 0;
    for (int pageNr = 0; pageNr < 2; pageNr++) {
        Page page = store.depage();
        System.out.println("numberOfPages = " + store.getNumberOfPages());
        page.open();
        List<PagedMessage> msg = page.read(new NullStorageManager());
        page.close();
        Assert.assertEquals(5, msg.size());
        for (int i = 0; i < 5; i++) {
            Assert.assertEquals(sequence++, msg.get(i).getMessage().getMessageID());
            ActiveMQTestBase.assertEqualsBuffers(18, buffers.get(pageNr * 5 + i), msg.get(i).getMessage().toCore().getBodyBuffer());
        }
    }
    Assert.assertEquals(1, store.getNumberOfPages());
    Assert.assertTrue(store.isPaging());
    Message msg = createMessage(1, store, destination, buffers.get(0));
    final RoutingContextImpl ctx = new RoutingContextImpl(null);
    Assert.assertTrue(store.page(msg, ctx.getTransaction(), ctx.getContextListing(store.getStoreName()), lock));
    Page newPage = store.depage();
    newPage.open();
    Assert.assertEquals(1, newPage.read(new NullStorageManager()).size());
    newPage.delete(null);
    Assert.assertEquals(1, store.getNumberOfPages());
    Assert.assertTrue(store.isPaging());
    Assert.assertNull(store.depage());
    Assert.assertFalse(store.isPaging());
    {
        final RoutingContextImpl ctx2 = new RoutingContextImpl(null);
        Assert.assertFalse(store.page(msg, ctx2.getTransaction(), ctx2.getContextListing(store.getStoreName()), lock));
    }
    store.startPaging();
    {
        final RoutingContextImpl ctx2 = new RoutingContextImpl(null);
        Assert.assertTrue(store.page(msg, ctx2.getTransaction(), ctx2.getContextListing(store.getStoreName()), lock));
    }
    Page page = store.depage();
    page.open();
    List<PagedMessage> msgs = page.read(new NullStorageManager());
    Assert.assertEquals(1, msgs.size());
    Assert.assertEquals(1L, msgs.get(0).getMessage().getMessageID());
    ActiveMQTestBase.assertEqualsBuffers(18, buffers.get(0), msgs.get(0).getMessage().toCore().getBodyBuffer());
    Assert.assertEquals(1, store.getNumberOfPages());
    Assert.assertTrue(store.isPaging());
    Assert.assertNull(store.depage());
    Assert.assertEquals(0, store.getNumberOfPages());
    page.open();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) Message(org.apache.activemq.artemis.api.core.Message) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Page(org.apache.activemq.artemis.core.paging.impl.Page) FakeSequentialFileFactory(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) RoutingContextImpl(org.apache.activemq.artemis.core.server.impl.RoutingContextImpl) FakeSequentialFileFactory(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory) PagingStoreImpl(org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) PagingStoreFactory(org.apache.activemq.artemis.core.paging.PagingStoreFactory) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 8 with PagingStoreImpl

use of org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl in project activemq-artemis by apache.

the class PagingStoreImplTest method testStore.

@Test
public void testStore() throws Exception {
    SequentialFileFactory factory = new FakeSequentialFileFactory();
    PagingStoreFactory storeFactory = new FakeStoreFactory(factory);
    AddressSettings addressSettings = new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
    PagingStore storeImpl = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, PagingStoreImplTest.destinationTestName, addressSettings, getExecutorFactory().getExecutor(), true);
    storeImpl.start();
    Assert.assertEquals(0, storeImpl.getNumberOfPages());
    storeImpl.startPaging();
    Assert.assertEquals(1, storeImpl.getNumberOfPages());
    List<ActiveMQBuffer> buffers = new ArrayList<>();
    ActiveMQBuffer buffer = createRandomBuffer(0, 10);
    buffers.add(buffer);
    SimpleString destination = new SimpleString("test");
    Message msg = createMessage(1, storeImpl, destination, buffer);
    Assert.assertTrue(storeImpl.isPaging());
    final RoutingContextImpl ctx = new RoutingContextImpl(null);
    Assert.assertTrue(storeImpl.page(msg, ctx.getTransaction(), ctx.getContextListing(storeImpl.getStoreName()), lock));
    Assert.assertEquals(1, storeImpl.getNumberOfPages());
    storeImpl.sync();
    storeImpl = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, PagingStoreImplTest.destinationTestName, addressSettings, getExecutorFactory().getExecutor(), true);
    storeImpl.start();
    Assert.assertEquals(1, storeImpl.getNumberOfPages());
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) Message(org.apache.activemq.artemis.api.core.Message) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) FakeSequentialFileFactory(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) RoutingContextImpl(org.apache.activemq.artemis.core.server.impl.RoutingContextImpl) FakeSequentialFileFactory(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory) PagingStoreImpl(org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl) PagingStoreFactory(org.apache.activemq.artemis.core.paging.PagingStoreFactory) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 9 with PagingStoreImpl

use of org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl in project activemq-artemis by apache.

the class PagingStoreImplTest method testOrderOnPaging.

@Test
public void testOrderOnPaging() throws Throwable {
    clearDataRecreateServerDirs();
    SequentialFileFactory factory = new NIOSequentialFileFactory(new File(getPageDir()), 1);
    PagingStoreFactory storeFactory = new FakeStoreFactory(factory);
    final int MAX_SIZE = 1024 * 10;
    AddressSettings settings = new AddressSettings().setPageSizeBytes(MAX_SIZE).setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
    final PagingStore store = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, new SimpleString("test"), settings, getExecutorFactory().getExecutor(), false);
    store.start();
    Assert.assertEquals(0, store.getNumberOfPages());
    // Marked the store to be paged
    store.startPaging();
    final CountDownLatch producedLatch = new CountDownLatch(1);
    Assert.assertEquals(1, store.getNumberOfPages());
    final SimpleString destination = new SimpleString("test");
    final long NUMBER_OF_MESSAGES = 100000;
    final List<Throwable> errors = new ArrayList<>();
    class WriterThread extends Thread {

        WriterThread() {
            super("PageWriter");
        }

        @Override
        public void run() {
            try {
                for (long i = 0; i < NUMBER_OF_MESSAGES; i++) {
                    // Each thread will Keep paging until all the messages are depaged.
                    // This is possible because the depage thread is not actually reading the pages.
                    // Just using the internal API to remove it from the page file system
                    Message msg = createMessage(i, store, destination, createRandomBuffer(i, 1024));
                    msg.putLongProperty("count", i);
                    final RoutingContextImpl ctx2 = new RoutingContextImpl(null);
                    while (!store.page(msg, ctx2.getTransaction(), ctx2.getContextListing(store.getStoreName()), lock)) {
                        store.startPaging();
                    }
                    if (i == 0) {
                        producedLatch.countDown();
                    }
                }
            } catch (Throwable e) {
                e.printStackTrace();
                errors.add(e);
            }
        }
    }
    class ReaderThread extends Thread {

        ReaderThread() {
            super("PageReader");
        }

        @Override
        public void run() {
            try {
                long msgsRead = 0;
                while (msgsRead < NUMBER_OF_MESSAGES) {
                    Page page = store.depage();
                    if (page != null) {
                        page.open();
                        List<PagedMessage> messages = page.read(new NullStorageManager());
                        for (PagedMessage pgmsg : messages) {
                            Message msg = pgmsg.getMessage();
                            Assert.assertEquals(msgsRead++, msg.getMessageID());
                            Assert.assertEquals(msg.getMessageID(), msg.getLongProperty("count").longValue());
                        }
                        page.close();
                        page.delete(null);
                    } else {
                        System.out.println("Depaged!!!! numerOfMessages = " + msgsRead + " of " + NUMBER_OF_MESSAGES);
                        Thread.sleep(500);
                    }
                }
            } catch (Throwable e) {
                e.printStackTrace();
                errors.add(e);
            }
        }
    }
    WriterThread producerThread = new WriterThread();
    producerThread.start();
    ReaderThread consumer = new ReaderThread();
    consumer.start();
    producerThread.join();
    consumer.join();
    store.stop();
    for (Throwable e : errors) {
        throw e;
    }
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) Message(org.apache.activemq.artemis.api.core.Message) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Page(org.apache.activemq.artemis.core.paging.impl.Page) CountDownLatch(java.util.concurrent.CountDownLatch) FakeSequentialFileFactory(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) RoutingContextImpl(org.apache.activemq.artemis.core.server.impl.RoutingContextImpl) PagingStoreImpl(org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) PagingStoreFactory(org.apache.activemq.artemis.core.paging.PagingStoreFactory) SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) File(java.io.File) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) Test(org.junit.Test)

Example 10 with PagingStoreImpl

use of org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl 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)

Aggregations

PagingStoreImpl (org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl)11 Test (org.junit.Test)9 Message (org.apache.activemq.artemis.api.core.Message)8 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)8 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)7 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)6 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)6 SequentialFileFactory (org.apache.activemq.artemis.core.io.SequentialFileFactory)6 NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)6 PagingStoreFactory (org.apache.activemq.artemis.core.paging.PagingStoreFactory)6 RoutingContextImpl (org.apache.activemq.artemis.core.server.impl.RoutingContextImpl)6 FakeSequentialFileFactory (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory)6 ArrayList (java.util.ArrayList)5 PagedMessage (org.apache.activemq.artemis.core.paging.PagedMessage)5 PagingStore (org.apache.activemq.artemis.core.paging.PagingStore)5 Page (org.apache.activemq.artemis.core.paging.impl.Page)4 NullStorageManager (org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager)4 SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)3 PageCursorProvider (org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider)3 PageSubscription (org.apache.activemq.artemis.core.paging.cursor.PageSubscription)3