Search in sources :

Example 11 with JournalFile

use of org.apache.activemq.artemis.core.journal.impl.JournalFile in project activemq-artemis by apache.

the class NIOJournalCompactTest method testLiveSizeTransactional.

@Test
public void testLiveSizeTransactional() throws Exception {
    setup(2, 60 * 1024, true);
    createJournal();
    startJournal();
    loadAndCheck();
    ArrayList<Long> listToDelete = new ArrayList<>();
    ArrayList<Integer> expectedSizes = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        long tx = idGenerator.generateID();
        long id = idGenerator.generateID();
        listToDelete.add(id);
        // Append Record Transaction will make the recordSize as exactly recordLength (discounting SIZE_ADD_RECORD_TX)
        addTx(tx, id);
        expectedSizes.add(recordLength);
        journal.forceMoveNextFile();
        updateTx(tx, id);
        // uPDATE Record Transaction will make the recordSize as exactly recordLength (discounting SIZE_ADD_RECORD_TX)
        expectedSizes.add(recordLength);
        journal.forceMoveNextFile();
        expectedSizes.add(0);
        commit(tx);
        journal.forceMoveNextFile();
    }
    JournalFile[] files = journal.getDataFiles();
    stopJournal();
    createJournal();
    startJournal();
    loadAndCheck();
    journal.forceMoveNextFile();
    JournalFile[] files2 = journal.getDataFiles();
    Assert.assertEquals(files.length, files2.length);
    for (int i = 0; i < files.length; i++) {
        Assert.assertEquals(expectedSizes.get(i).intValue(), files[i].getLiveSize());
        Assert.assertEquals(expectedSizes.get(i).intValue(), files2[i].getLiveSize());
    }
    long tx = idGenerator.generateID();
    for (long id : listToDelete) {
        deleteTx(tx, id);
    }
    commit(tx);
    journal.forceMoveNextFile();
    JournalFile[] files3 = journal.getDataFiles();
    for (JournalFile file : files3) {
        Assert.assertEquals(0, file.getLiveSize());
    }
    stopJournal();
    createJournal();
    startJournal();
    loadAndCheck();
    files3 = journal.getDataFiles();
    for (JournalFile file : files3) {
        Assert.assertEquals(0, file.getLiveSize());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JournalFile(org.apache.activemq.artemis.core.journal.impl.JournalFile) AtomicLong(java.util.concurrent.atomic.AtomicLong) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 12 with JournalFile

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

Aggregations

JournalFile (org.apache.activemq.artemis.core.journal.impl.JournalFile)12 JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)5 ArrayList (java.util.ArrayList)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Pair (org.apache.activemq.artemis.api.core.Pair)4 HashMap (java.util.HashMap)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)3 Test (org.junit.Test)3 SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)2 SequentialFileFactory (org.apache.activemq.artemis.core.io.SequentialFileFactory)2 File (java.io.File)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 ActiveMQIllegalStateException (org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)1 ActiveMQInternalErrorException (org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1