Search in sources :

Example 26 with SequentialFileFactory

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

the class AddAndRemoveStressTest method testInsertAndLoad.

// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testInsertAndLoad() throws Exception {
    SequentialFileFactory factory = new AIOSequentialFileFactory(getTestDirfile(), 1000);
    JournalImpl impl = new JournalImpl(10 * 1024 * 1024, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, 0, 0, factory, "amq", "amq", 1000);
    impl.start();
    impl.load(AddAndRemoveStressTest.dummyLoader);
    for (long i = 1; i <= AddAndRemoveStressTest.NUMBER_OF_MESSAGES; i++) {
        if (i % 10000 == 0) {
            System.out.println("Append " + i);
        }
        impl.appendAddRecord(i, (byte) 0, new SimpleEncoding(1024, (byte) 'f'), false);
    }
    impl.stop();
    factory = new AIOSequentialFileFactory(getTestDirfile(), 1000);
    impl = new JournalImpl(10 * 1024 * 1024, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, 0, 0, factory, "amq", "amq", 1000);
    impl.start();
    impl.load(AddAndRemoveStressTest.dummyLoader);
    for (long i = 1; i <= AddAndRemoveStressTest.NUMBER_OF_MESSAGES; i++) {
        if (i % 10000 == 0) {
            System.out.println("Delete " + i);
        }
        impl.appendDeleteRecord(i, false);
    }
    impl.stop();
    factory = new AIOSequentialFileFactory(getTestDirfile(), 1000);
    impl = new JournalImpl(10 * 1024 * 1024, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, 0, 0, factory, "amq", "amq", 1000);
    impl.start();
    ArrayList<RecordInfo> info = new ArrayList<>();
    ArrayList<PreparedTransactionInfo> trans = new ArrayList<>();
    impl.load(info, trans, null);
    impl.forceMoveNextFile();
    if (info.size() > 0) {
        System.out.println("Info ID: " + info.get(0).id);
    }
    impl.stop();
    Assert.assertEquals(0, info.size());
    Assert.assertEquals(0, trans.size());
    Assert.assertEquals(0, impl.getDataFilesCount());
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) ArrayList(java.util.ArrayList) SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Test(org.junit.Test)

Example 27 with SequentialFileFactory

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

the class AddAndRemoveStressTest method testInsertUpdateAndLoad.

@Test
public void testInsertUpdateAndLoad() throws Exception {
    SequentialFileFactory factory = new AIOSequentialFileFactory(getTestDirfile(), 1000);
    JournalImpl impl = new JournalImpl(10 * 1024 * 1024, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, 0, 0, factory, "amq", "amq", 1000);
    impl.start();
    impl.load(AddAndRemoveStressTest.dummyLoader);
    for (long i = 1; i <= AddAndRemoveStressTest.NUMBER_OF_MESSAGES; i++) {
        if (i % 10000 == 0) {
            System.out.println("Append " + i);
        }
        impl.appendAddRecord(i, (byte) 21, new SimpleEncoding(40, (byte) 'f'), false);
        impl.appendUpdateRecord(i, (byte) 22, new SimpleEncoding(40, (byte) 'g'), false);
    }
    impl.stop();
    factory = new AIOSequentialFileFactory(getTestDirfile(), 1000);
    impl = new JournalImpl(10 * 1024 * 1024, 10, 10, 0, 0, factory, "amq", "amq", 1000);
    impl.start();
    impl.load(AddAndRemoveStressTest.dummyLoader);
    for (long i = 1; i <= AddAndRemoveStressTest.NUMBER_OF_MESSAGES; i++) {
        if (i % 10000 == 0) {
            System.out.println("Delete " + i);
        }
        impl.appendDeleteRecord(i, false);
    }
    impl.stop();
    factory = new AIOSequentialFileFactory(getTestDirfile(), 1000);
    impl = new JournalImpl(10 * 1024 * 1024, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, 0, 0, factory, "amq", "amq", 1000);
    impl.start();
    ArrayList<RecordInfo> info = new ArrayList<>();
    ArrayList<PreparedTransactionInfo> trans = new ArrayList<>();
    impl.load(info, trans, null);
    if (info.size() > 0) {
        System.out.println("Info ID: " + info.get(0).id);
    }
    impl.forceMoveNextFile();
    impl.checkReclaimStatus();
    impl.stop();
    Assert.assertEquals(0, info.size());
    Assert.assertEquals(0, trans.size());
    Assert.assertEquals(0, impl.getDataFilesCount());
    System.out.println("Size = " + impl.getDataFilesCount());
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) ArrayList(java.util.ArrayList) SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Test(org.junit.Test)

Example 28 with SequentialFileFactory

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

the class CrashOnCompactTest method createJournal.

private static JournalImpl createJournal(File folder, boolean crash) throws Exception {
    NIOSequentialFileFactory factory = new NIOSequentialFileFactory(folder, 10);
    JournalImpl journal = new JournalImpl(100 * 1024, 2, 2, 0, 0, factory, "jrntest", "jrn", 512) {

        @Override
        protected SequentialFile writeControlFile(final SequentialFileFactory fileFactory, final List<JournalFile> files, final List<JournalFile> newFiles, final List<Pair<String, String>> renames) throws Exception {
            if (crash) {
                SequentialFile controlFile = fileFactory.createSequentialFile(AbstractJournalUpdateTask.FILE_COMPACT_CONTROL);
                controlFile.open();
                controlFile.close();
                System.err.println("crashing after creation of control file");
                System.exit(OK);
            }
            return JournalCompactor.writeControlFile(fileFactory, files, newFiles, renames);
        }
    };
    journal.setAutoReclaim(false);
    journal.start();
    return journal;
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) ArrayList(java.util.ArrayList) List(java.util.List) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl)

Example 29 with SequentialFileFactory

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

the class ActiveMQTestBase method countJournal.

/**
 * Reads a journal system and returns a Map<Integer,AtomicInteger> of recordTypes and the number of records per type,
 * independent of being deleted or not
 *
 * @param config
 * @return
 * @throws Exception
 */
protected HashMap<Integer, AtomicInteger> countJournal(Configuration config) throws Exception {
    final HashMap<Integer, AtomicInteger> recordsType = new HashMap<>();
    SequentialFileFactory messagesFF = new NIOSequentialFileFactory(config.getJournalLocation(), null, 1);
    JournalImpl messagesJournal = new JournalImpl(config.getJournalFileSize(), config.getJournalMinFiles(), config.getJournalPoolFiles(), 0, 0, messagesFF, "activemq-data", "amq", 1);
    List<JournalFile> filesToRead = messagesJournal.orderFiles();
    for (JournalFile file : filesToRead) {
        JournalImpl.readJournalFile(messagesFF, file, new RecordTypeCounter(recordsType));
    }
    return recordsType;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JournalFile(org.apache.activemq.artemis.core.journal.impl.JournalFile) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl)

Example 30 with SequentialFileFactory

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

the class ActiveMQTestBase method loadMessageJournal.

/**
 * Reads a journal system and returns a Map<Integer,AtomicInteger> of recordTypes and the number of records per type,
 * independent of being deleted or not
 *
 * @param config
 * @return
 * @throws Exception
 */
protected Pair<List<RecordInfo>, List<PreparedTransactionInfo>> loadMessageJournal(Configuration config) throws Exception {
    JournalImpl messagesJournal = null;
    try {
        SequentialFileFactory messagesFF = new NIOSequentialFileFactory(new File(getJournalDir()), null, 1);
        messagesJournal = new JournalImpl(config.getJournalFileSize(), config.getJournalMinFiles(), config.getJournalPoolFiles(), 0, 0, messagesFF, "activemq-data", "amq", 1);
        final List<RecordInfo> committedRecords = new LinkedList<>();
        final List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
        messagesJournal.start();
        messagesJournal.load(committedRecords, preparedTransactions, null, false);
        return new Pair<>(committedRecords, preparedTransactions);
    } finally {
        try {
            if (messagesJournal != null) {
                messagesJournal.stop();
            }
        } catch (Throwable ignored) {
        }
    }
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) File(java.io.File) JournalFile(org.apache.activemq.artemis.core.journal.impl.JournalFile) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) LinkedList(java.util.LinkedList) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) Pair(org.apache.activemq.artemis.api.core.Pair)

Aggregations

SequentialFileFactory (org.apache.activemq.artemis.core.io.SequentialFileFactory)30 NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)25 Test (org.junit.Test)16 JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)13 FakeSequentialFileFactory (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory)10 File (java.io.File)9 ArrayList (java.util.ArrayList)8 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)8 AIOSequentialFileFactory (org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory)8 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)7 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)7 SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)6 PagingStoreImpl (org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)5 PagingStore (org.apache.activemq.artemis.core.paging.PagingStore)5 PagingStoreFactory (org.apache.activemq.artemis.core.paging.PagingStoreFactory)5 HashMap (java.util.HashMap)4 LinkedList (java.util.LinkedList)4 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)4