Search in sources :

Example 6 with EncodingSupport

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

the class JournalImplTestUnit method testPrepareReclaim.

@Test
public void testPrepareReclaim() throws Exception {
    setup(2, 100 * 1024, true);
    createJournal();
    startJournal();
    load();
    List<String> files1 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(2, files1.size());
    Assert.assertEquals(0, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(0, journal.getIDMapSize());
    // in file 0
    addTx(1, 1);
    files1 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(2, files1.size());
    Assert.assertEquals(0, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(0, journal.getIDMapSize());
    // Make sure we move on to the next file
    journal.forceMoveNextFile();
    journal.debugWait();
    // in file 1
    addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD, 2);
    List<String> files2 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(3, files2.size());
    Assert.assertEquals(1, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getIDMapSize());
    EncodingSupport xid = new SimpleEncoding(10, (byte) 0);
    // in file 1
    prepare(1, xid);
    List<String> files3 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(3, files3.size());
    Assert.assertEquals(1, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(1, journal.getIDMapSize());
    // in file 1
    delete(2);
    List<String> files4 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(3, files4.size());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(1, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(0, journal.getIDMapSize());
    // Move on to another file
    journal.forceMoveNextFile();
    // in file 2
    addWithSize(1024 - JournalImpl.SIZE_ADD_RECORD, 3);
    checkAndReclaimFiles();
    List<String> files5 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(4, files5.size());
    Assert.assertEquals(2, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getIDMapSize());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    checkAndReclaimFiles();
    List<String> files6 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(4, files6.size());
    Assert.assertEquals(2, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getIDMapSize());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    journal.forceMoveNextFile();
    // in file 3
    addWithSize(1024 - JournalImpl.SIZE_ADD_RECORD, 4);
    List<String> files7 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(5, files7.size());
    Assert.assertEquals(3, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(2, journal.getIDMapSize());
    // in file 3
    commit(1);
    List<String> files8 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(5, files8.size());
    Assert.assertEquals(3, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(3, journal.getIDMapSize());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    // in file 3
    delete(1);
    List<String> files9 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(5, files9.size());
    Assert.assertEquals(3, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(2, journal.getIDMapSize());
    checkAndReclaimFiles();
    List<String> files10 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(journal.getAlignment() == 1 ? 5 : 5, files10.size());
    Assert.assertEquals(journal.getAlignment() == 1 ? 3 : 3, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(2, journal.getIDMapSize());
    journal.forceMoveNextFile();
    // in file 4
    addWithSize(1024 - JournalImpl.SIZE_ADD_RECORD, 5);
    List<String> files11 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(6, files11.size());
    Assert.assertEquals(4, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(3, journal.getIDMapSize());
    checkAndReclaimFiles();
    List<String> files12 = fileFactory.listFiles(fileExtension);
    // File 0, and File 1 should be deleted
    Assert.assertEquals(4, files12.size());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(2, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(3, journal.getIDMapSize());
    // Restart
    stopJournal();
    createJournal();
    startJournal();
    loadAndCheck();
    delete(4);
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(2, journal.getIDMapSize());
    addWithSize(1024 - JournalImpl.SIZE_ADD_RECORD, 6);
    UnitTestLogger.LOGGER.debug("Debug journal on testPrepareReclaim ->\n" + debugJournal());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(3, journal.getIDMapSize());
    checkAndReclaimFiles();
    // file 3 should now be deleted
    List<String> files15 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(4, files15.size());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(2, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(3, journal.getIDMapSize());
    stopJournal();
    createJournal();
    startJournal();
    loadAndCheck();
}
Also used : SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) EncodingSupport(org.apache.activemq.artemis.core.journal.EncodingSupport) Test(org.junit.Test)

Example 7 with EncodingSupport

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

the class JournalImplTestUnit method testEmptyPrepare.

@Test
public void testEmptyPrepare() throws Exception {
    setup(2, calculateRecordSize(JournalImpl.SIZE_HEADER, getAlignment()) + calculateRecordSize(recordLength, getAlignment()) + 512, true);
    createJournal();
    startJournal();
    load();
    EncodingSupport xid = new SimpleEncoding(10, (byte) 0);
    prepare(1, xid);
    stopJournal();
    createJournal();
    startJournal();
    loadAndCheck();
    commit(1);
    xid = new SimpleEncoding(10, (byte) 1);
    prepare(2, xid);
    stopJournal();
    createJournal();
    startJournal();
    loadAndCheck();
    rollback(2);
    stopJournal();
    createJournal();
    startJournal();
    loadAndCheck();
}
Also used : SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) EncodingSupport(org.apache.activemq.artemis.core.journal.EncodingSupport) Test(org.junit.Test)

Example 8 with EncodingSupport

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

the class JournalImplTestUnit method testXAChangesisibleCommit.

@Test
public void testXAChangesisibleCommit() throws Exception {
    setup(10, 10 * 1024, true);
    createJournal();
    startJournal();
    load();
    add(1, 2, 3, 4, 5, 6);
    addTx(1, 7, 8, 9, 10);
    updateTx(1, 1, 2, 3, 7, 8, 9);
    deleteTx(1, 1, 2, 3, 4, 5);
    EncodingSupport xid = new SimpleEncoding(10, (byte) 0);
    prepare(1, xid);
    commit(1);
    stopJournal();
    createJournal();
    startJournal();
    loadAndCheck();
}
Also used : SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) EncodingSupport(org.apache.activemq.artemis.core.journal.EncodingSupport) Test(org.junit.Test)

Example 9 with EncodingSupport

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

the class JournalImplTestUnit method testPrepareNoReclaim.

@Test
public void testPrepareNoReclaim() throws Exception {
    setup(2, calculateRecordSize(JournalImpl.SIZE_HEADER, getAlignment()) + calculateRecordSize(recordLength, getAlignment()) + 512, true);
    createJournal();
    startJournal();
    load();
    List<String> files1 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(2, files1.size());
    Assert.assertEquals(0, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(0, journal.getIDMapSize());
    // in file 0
    addTx(1, 1);
    // Make sure we move on to the next file
    // in file 1
    addWithSize(1024 - JournalImpl.SIZE_ADD_RECORD, 2);
    List<String> files2 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(3, files2.size());
    Assert.assertEquals(calculateNumberOfFiles(journal, fileSize, journal.getAlignment(), 2, recordLength), journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(1, journal.getIDMapSize());
    EncodingSupport xid = new SimpleEncoding(10, (byte) 0);
    // in file 1
    prepare(1, xid);
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getIDMapSize());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    // in file 1
    delete(2);
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(0, journal.getIDMapSize());
    // Move on to another file
    // in file 2
    addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD - 1, 3);
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getIDMapSize());
    checkAndReclaimFiles();
    List<String> files6 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(4, files6.size());
    Assert.assertEquals(2, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(1, journal.getIDMapSize());
    // in file 3
    addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD - 1, 4);
    List<String> files7 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(5, files7.size());
    Assert.assertEquals(3, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(2, journal.getIDMapSize());
    // in file 4
    commit(1);
    List<String> files8 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(5, files8.size());
    Assert.assertEquals(3, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(3, journal.getIDMapSize());
    // Restart
    stopJournal();
    createJournal();
    startJournal();
    loadAndCheck();
}
Also used : SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) EncodingSupport(org.apache.activemq.artemis.core.journal.EncodingSupport) Test(org.junit.Test)

Example 10 with EncodingSupport

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

the class AlignedJournalImplTest method testAppendAndUpdateRecords.

@Test
public void testAppendAndUpdateRecords() throws Exception {
    final int JOURNAL_SIZE = 1060;
    setupAndLoadJournal(JOURNAL_SIZE, 10);
    Assert.assertEquals(0, records.size());
    Assert.assertEquals(0, transactions.size());
    for (int i = 0; i < 25; i++) {
        byte[] bytes = new byte[5];
        for (int j = 0; j < bytes.length; j++) {
            bytes[j] = (byte) i;
        }
        journalImpl.appendAddRecord(i * 100L, (byte) i, bytes, false);
    }
    for (int i = 25; i < 50; i++) {
        EncodingSupport support = new SimpleEncoding(5, (byte) i);
        journalImpl.appendAddRecord(i * 100L, (byte) i, support, false);
    }
    setupAndLoadJournal(JOURNAL_SIZE, 1024);
    Assert.assertEquals(50, records.size());
    int i = 0;
    for (RecordInfo recordItem : records) {
        Assert.assertEquals(i * 100L, recordItem.id);
        Assert.assertEquals(i, recordItem.getUserRecordType());
        Assert.assertEquals(5, recordItem.data.length);
        for (int j = 0; j < 5; j++) {
            Assert.assertEquals((byte) i, recordItem.data[j]);
        }
        i++;
    }
    for (i = 40; i < 50; i++) {
        byte[] bytes = new byte[10];
        for (int j = 0; j < 10; j++) {
            bytes[j] = (byte) 'x';
        }
        journalImpl.appendUpdateRecord(i * 100L, (byte) i, bytes, false);
    }
    setupAndLoadJournal(JOURNAL_SIZE, 1024);
    i = 0;
    for (RecordInfo recordItem : records) {
        if (i < 50) {
            Assert.assertEquals(i * 100L, recordItem.id);
            Assert.assertEquals(i, recordItem.getUserRecordType());
            Assert.assertEquals(5, recordItem.data.length);
            for (int j = 0; j < 5; j++) {
                Assert.assertEquals((byte) i, recordItem.data[j]);
            }
        } else {
            Assert.assertEquals((i - 10) * 100L, recordItem.id);
            Assert.assertEquals(i - 10, recordItem.getUserRecordType());
            Assert.assertTrue(recordItem.isUpdate);
            Assert.assertEquals(10, recordItem.data.length);
            for (int j = 0; j < 10; j++) {
                Assert.assertEquals((byte) 'x', recordItem.data[j]);
            }
        }
        i++;
    }
    journalImpl.stop();
}
Also used : RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) EncodingSupport(org.apache.activemq.artemis.core.journal.EncodingSupport) Test(org.junit.Test)

Aggregations

EncodingSupport (org.apache.activemq.artemis.core.journal.EncodingSupport)19 Test (org.junit.Test)15 SimpleEncoding (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding)13 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)6 File (java.io.File)4 MappedSequentialFileFactory (org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory)3 NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)3 ByteBuffer (java.nio.ByteBuffer)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)2 AIOSequentialFileFactory (org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory)2 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)2 MpscArrayQueue (io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueue)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 ActiveMQExceptionType (org.apache.activemq.artemis.api.core.ActiveMQExceptionType)1 Message (org.apache.activemq.artemis.api.core.Message)1 IOCriticalErrorListener (org.apache.activemq.artemis.core.io.IOCriticalErrorListener)1 IOCompletion (org.apache.activemq.artemis.core.journal.IOCompletion)1