Search in sources :

Example 6 with SimpleEncoding

use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding 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 7 with SimpleEncoding

use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding 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 8 with SimpleEncoding

use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding 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 9 with SimpleEncoding

use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding in project activemq-artemis by apache.

the class AlignedJournalImplTest method testSimplePrepare.

@Test
public void testSimplePrepare() throws Exception {
    final int JOURNAL_SIZE = 3 * 1024;
    setupAndLoadJournal(JOURNAL_SIZE, 1);
    Assert.assertEquals(0, records.size());
    Assert.assertEquals(0, transactions.size());
    SimpleEncoding xid = new SimpleEncoding(10, (byte) 1);
    journalImpl.appendAddRecord(10L, (byte) 0, new SimpleEncoding(10, (byte) 0), false);
    journalImpl.appendDeleteRecordTransactional(1L, 10L, new SimpleEncoding(100, (byte) 'j'));
    journalImpl.appendPrepareRecord(1, xid, false);
    journalImpl.debugWait();
    setupAndLoadJournal(JOURNAL_SIZE, 1);
    Assert.assertEquals(1, transactions.size());
    Assert.assertEquals(1, transactions.get(0).getRecordsToDelete().size());
    Assert.assertEquals(1, records.size());
    for (RecordInfo record : transactions.get(0).getRecordsToDelete()) {
        byte[] data = record.data;
        Assert.assertEquals(100, data.length);
        for (byte element : data) {
            Assert.assertEquals((byte) 'j', element);
        }
    }
    Assert.assertEquals(10, transactions.get(0).getExtraData().length);
    for (int i = 0; i < 10; i++) {
        Assert.assertEquals((byte) 1, transactions.get(0).getExtraData()[i]);
    }
    journalImpl.appendCommitRecord(1L, false);
    journalImpl.debugWait();
    setupAndLoadJournal(JOURNAL_SIZE, 1);
    Assert.assertEquals(0, transactions.size());
    Assert.assertEquals(0, records.size());
}
Also used : RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) Test(org.junit.Test)

Example 10 with SimpleEncoding

use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding in project activemq-artemis by apache.

the class AlignedJournalImplTest method testIncreaseAlignment.

// It should be ok to write records on NIO, and later read then on AIO
@Test
public void testIncreaseAlignment() throws Exception {
    final int JOURNAL_SIZE = 512 * 4;
    setupAndLoadJournal(JOURNAL_SIZE, 1);
    for (int i = 0; i < 10; i++) {
        journalImpl.appendAddRecordTransactional(1L, i, (byte) 0, new SimpleEncoding(1, (byte) 0));
    }
    journalImpl.appendCommitRecord(1L, false);
    setupAndLoadJournal(JOURNAL_SIZE, 100);
    Assert.assertEquals(10, records.size());
    setupAndLoadJournal(JOURNAL_SIZE, 512);
    Assert.assertEquals(10, records.size());
}
Also used : SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) Test(org.junit.Test)

Aggregations

SimpleEncoding (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding)47 Test (org.junit.Test)43 EncodingSupport (org.apache.activemq.artemis.core.journal.EncodingSupport)13 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)7 JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)6 SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)5 ByteBuffer (java.nio.ByteBuffer)4 ArrayList (java.util.ArrayList)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)3 SequentialFileFactory (org.apache.activemq.artemis.core.io.SequentialFileFactory)2 AIOSequentialFileFactory (org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory)2 Journal (org.apache.activemq.artemis.core.journal.Journal)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Pair (org.apache.activemq.artemis.api.core.Pair)1 JournalFile (org.apache.activemq.artemis.core.journal.impl.JournalFile)1 FakeSequentialFileFactory (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory)1