Search in sources :

Example 21 with NIOSequentialFileFactory

use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory in project activemq-artemis by apache.

the class HangConsumerTest method testDuplicateDestinationsOnTopic.

/**
 * This will simulate what would happen with topic creationg where a single record is supposed to be created on the journal
 *
 * @throws Exception
 */
@Test
public void testDuplicateDestinationsOnTopic() throws Exception {
    try {
        for (int i = 0; i < 5; i++) {
            if (server.locateQueue(SimpleString.toSimpleString("tt")) == null) {
                server.createQueue(SimpleString.toSimpleString("tt"), RoutingType.ANYCAST, SimpleString.toSimpleString("tt"), SimpleString.toSimpleString(Filter.GENERIC_IGNORED_FILTER), true, false);
            }
            server.stop();
            SequentialFileFactory messagesFF = new NIOSequentialFileFactory(server.getConfiguration().getBindingsLocation(), null, 1);
            JournalImpl messagesJournal = new JournalImpl(1024 * 1024, 2, 2, 0, 0, messagesFF, "activemq-bindings", "bindings", 1);
            messagesJournal.start();
            LinkedList<RecordInfo> infos = new LinkedList<>();
            messagesJournal.load(infos, null, null);
            int bindings = 0;
            for (RecordInfo info : infos) {
                System.out.println("info: " + info);
                if (info.getUserRecordType() == JournalRecordIds.QUEUE_BINDING_RECORD) {
                    bindings++;
                }
            }
            assertEquals(1, bindings);
            System.out.println("Bindings: " + bindings);
            messagesJournal.stop();
            if (i < 4)
                server.start();
        }
    } finally {
        try {
            server.stop();
        } catch (Throwable ignored) {
        }
    }
}
Also used : RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) LinkedList(java.util.LinkedList) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Test(org.junit.Test)

Example 22 with NIOSequentialFileFactory

use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory 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 23 with NIOSequentialFileFactory

use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory in project activemq-artemis by apache.

the class PageTest method testDamagedDataWithNIO.

@Test
public void testDamagedDataWithNIO() throws Exception {
    recreateDirectory(getTestDir());
    testDamagedPage(new NIOSequentialFileFactory(getTestDirfile(), 1), 1000);
}
Also used : NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) Test(org.junit.Test)

Example 24 with NIOSequentialFileFactory

use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory in project activemq-artemis by apache.

the class PageTest method testPageWithNIO.

@Test
public void testPageWithNIO() throws Exception {
    recreateDirectory(getTestDir());
    testAdd(new NIOSequentialFileFactory(getTestDirfile(), 1), 1000);
}
Also used : NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) Test(org.junit.Test)

Example 25 with NIOSequentialFileFactory

use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory in project activemq-artemis by apache.

the class CompactJournal method compactJournal.

private void compactJournal(final File directory, final String journalPrefix, final String journalSuffix, final int minFiles, final int fileSize, final IOCriticalErrorListener listener) throws Exception {
    NIOSequentialFileFactory nio = new NIOSequentialFileFactory(directory, listener, 1);
    JournalImpl journal = new JournalImpl(fileSize, minFiles, minFiles, 0, 0, nio, journalPrefix, journalSuffix, 1);
    journal.start();
    journal.loadInternalOnly();
    journal.compact();
    journal.stop();
}
Also used : NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl)

Aggregations

NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)33 JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)19 File (java.io.File)18 SequentialFileFactory (org.apache.activemq.artemis.core.io.SequentialFileFactory)15 Test (org.junit.Test)11 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)7 SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)6 AIOSequentialFileFactory (org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 LinkedList (java.util.LinkedList)4 MappedSequentialFileFactory (org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory)4 JournalFile (org.apache.activemq.artemis.core.journal.impl.JournalFile)4 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)3 EncodingSupport (org.apache.activemq.artemis.core.journal.EncodingSupport)3 Journal (org.apache.activemq.artemis.core.journal.Journal)3 FakeSequentialFileFactory (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory)3 ByteBuffer (java.nio.ByteBuffer)2