Search in sources :

Example 31 with PagingStore

use of org.apache.activemq.artemis.core.paging.PagingStore 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 32 with PagingStore

use of org.apache.activemq.artemis.core.paging.PagingStore 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 33 with PagingStore

use of org.apache.activemq.artemis.core.paging.PagingStore 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 34 with PagingStore

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

the class PagingManagerImplTest method testPagingManager.

@Test
public void testPagingManager() throws Exception {
    HierarchicalRepository<AddressSettings> addressSettings = new HierarchicalObjectRepository<>();
    addressSettings.setDefault(new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE));
    final StorageManager storageManager = new NullStorageManager();
    PagingStoreFactoryNIO storeFactory = new PagingStoreFactoryNIO(storageManager, getPageDirFile(), 100, null, getOrderedExecutor(), true, null);
    PagingManagerImpl managerImpl = new PagingManagerImpl(storeFactory, addressSettings);
    managerImpl.start();
    PagingStore store = managerImpl.getPageStore(new SimpleString("simple-test"));
    ICoreMessage msg = createMessage(1L, new SimpleString("simple-test"), createRandomBuffer(10));
    final RoutingContextImpl ctx = new RoutingContextImpl(null);
    Assert.assertFalse(store.page(msg, ctx.getTransaction(), ctx.getContextListing(store.getStoreName()), lock));
    store.startPaging();
    Assert.assertTrue(store.page(msg, ctx.getTransaction(), ctx.getContextListing(store.getStoreName()), lock));
    Page page = store.depage();
    page.open();
    List<PagedMessage> msgs = page.read(new NullStorageManager());
    page.close();
    Assert.assertEquals(1, msgs.size());
    ActiveMQTestBase.assertEqualsByteArrays(msg.getBodyBuffer().writerIndex(), msg.getBodyBuffer().toByteBuffer().array(), (msgs.get(0).getMessage()).toCore().getBodyBuffer().toByteBuffer().array());
    Assert.assertTrue(store.isPaging());
    Assert.assertNull(store.depage());
    final RoutingContextImpl ctx2 = new RoutingContextImpl(null);
    Assert.assertFalse(store.page(msg, ctx2.getTransaction(), ctx2.getContextListing(store.getStoreName()), lock));
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Page(org.apache.activemq.artemis.core.paging.impl.Page) HierarchicalObjectRepository(org.apache.activemq.artemis.core.settings.impl.HierarchicalObjectRepository) RoutingContextImpl(org.apache.activemq.artemis.core.server.impl.RoutingContextImpl) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) PagingStoreFactoryNIO(org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO) PagingManagerImpl(org.apache.activemq.artemis.core.paging.impl.PagingManagerImpl) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) Test(org.junit.Test)

Example 35 with PagingStore

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

the class BackupSyncJournalTest method testReserveFileIdValuesOnBackup.

@Test
public void testReserveFileIdValuesOnBackup() throws Exception {
    final int totalRounds = 5;
    createProducerSendSomeMessages();
    JournalImpl messageJournal = getMessageJournalFromServer(liveServer);
    for (int i = 0; i < totalRounds; i++) {
        messageJournal.forceMoveNextFile();
        sendMessages(session, producer, n_msgs);
    }
    Queue queue = liveServer.getServer().locateQueue(ADDRESS);
    PagingStore store = queue.getPageSubscription().getPagingStore();
    // what would make the verification on similar journal to fail after the recovery
    if (store.isPaging()) {
        store.forceAnotherPage();
    }
    backupServer.start();
    // Deliver messages with Backup in-sync
    waitForRemoteBackup(sessionFactory, BACKUP_WAIT_TIME, false, backupServer.getServer());
    final JournalImpl backupMsgJournal = getMessageJournalFromServer(backupServer);
    sendMessages(session, producer, n_msgs);
    // what would make the verification on similar journal to fail after the recovery
    if (store.isPaging()) {
        store.forceAnotherPage();
    }
    // Deliver messages with Backup up-to-date
    syncDelay.deliverUpToDateMsg();
    waitForRemoteBackup(sessionFactory, BACKUP_WAIT_TIME, true, backupServer.getServer());
    // SEND more messages, now with the backup replicating
    sendMessages(session, producer, n_msgs);
    // what would make the verification on similar journal to fail after the recovery
    if (store.isPaging()) {
        store.forceAnotherPage();
    }
    Set<Pair<Long, Integer>> liveIds = getFileIds(messageJournal);
    int size = messageJournal.getFileSize();
    PagingStore ps = liveServer.getServer().getPagingManager().getPageStore(ADDRESS);
    if (ps.getPageSizeBytes() == PAGE_SIZE) {
        assertTrue("isStarted", ps.isStarted());
        assertFalse("start paging should return false, because we expect paging to be running", ps.startPaging());
    }
    finishSyncAndFailover();
    assertEquals("file sizes must be the same", size, backupMsgJournal.getFileSize());
    Set<Pair<Long, Integer>> backupIds = getFileIds(backupMsgJournal);
    int total = 0;
    for (Pair<Long, Integer> pair : liveIds) {
        total += pair.getB();
    }
    int totalBackup = 0;
    for (Pair<Long, Integer> pair : backupIds) {
        totalBackup += pair.getB();
    }
    assertEquals("number of records must match ", total, totalBackup);
    // "+ 2": there two other calls that send N_MSGS.
    for (int i = 0; i < totalRounds + 3; i++) {
        receiveMsgsInRange(0, n_msgs);
    }
    assertNoMoreMessages();
}
Also used : Queue(org.apache.activemq.artemis.core.server.Queue) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Pair(org.apache.activemq.artemis.api.core.Pair) Test(org.junit.Test)

Aggregations

PagingStore (org.apache.activemq.artemis.core.paging.PagingStore)48 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)31 Test (org.junit.Test)24 Configuration (org.apache.activemq.artemis.core.config.Configuration)19 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)17 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)17 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)17 DatabaseStorageConfiguration (org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration)17 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)16 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)15 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)15 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)15 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)11 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)11 HashMap (java.util.HashMap)9 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)9 Queue (org.apache.activemq.artemis.core.server.Queue)9 PagedMessage (org.apache.activemq.artemis.core.paging.PagedMessage)8 ArrayList (java.util.ArrayList)7 Page (org.apache.activemq.artemis.core.paging.impl.Page)6