Search in sources :

Example 16 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 testCommitWithMultipleFiles.

@Test
public void testCommitWithMultipleFiles() throws Exception {
    final int JOURNAL_SIZE = 20000;
    setupAndLoadJournal(JOURNAL_SIZE, 100);
    Assert.assertEquals(0, records.size());
    Assert.assertEquals(0, transactions.size());
    for (int i = 0; i < 50; i++) {
        if (i == 10) {
            journalImpl.forceMoveNextFile();
        }
        journalImpl.appendAddRecordTransactional(1L, i, (byte) 0, new SimpleEncoding(1, (byte) 15));
    }
    journalImpl.appendCommitRecord(1L, false);
    for (int i = 0; i < 10; i++) {
        if (i == 5) {
            journalImpl.forceMoveNextFile();
        }
        journalImpl.appendDeleteRecordTransactional(2L, i);
    }
    journalImpl.appendCommitRecord(2L, false);
    journalImpl.forceMoveNextFile();
    journalImpl.checkReclaimStatus();
    setupAndLoadJournal(JOURNAL_SIZE, 100);
    Assert.assertEquals(40, records.size());
}
Also used : SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) Test(org.junit.Test)

Example 17 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 testReloadInvalidPrepared.

@Test
public void testReloadInvalidPrepared() throws Exception {
    final int JOURNAL_SIZE = 3000;
    setupAndLoadJournal(JOURNAL_SIZE, 100);
    Assert.assertEquals(0, records.size());
    Assert.assertEquals(0, transactions.size());
    for (int i = 0; i < 10; i++) {
        journalImpl.appendAddRecordTransactional(1, i, (byte) 1, new SimpleEncoding(50, (byte) 1));
    }
    journalImpl.appendPrepareRecord(1L, new SimpleEncoding(13, (byte) 0), false);
    setupAndLoadJournal(JOURNAL_SIZE, 100);
    Assert.assertEquals(0, records.size());
    Assert.assertEquals(1, transactions.size());
    SequentialFile file = factory.createSequentialFile("tt-1.tt");
    file.open();
    ByteBuffer buffer = ByteBuffer.allocate(100);
    // Messing up with the first record (removing the position)
    file.position(100);
    file.read(buffer);
    buffer.position(1);
    buffer.putInt(-1);
    buffer.rewind();
    // Messing up with the first record (changing the fileID, so Journal
    // reload will think the record came from a different journal usage)
    file.position(100);
    file.writeDirect(buffer, true);
    file.close();
    setupAndLoadJournal(JOURNAL_SIZE, 100);
    Assert.assertEquals(0, records.size());
    Assert.assertEquals(0, transactions.size());
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 18 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 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)

Example 19 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 testTotalSize.

@Test
public void testTotalSize() throws Exception {
    final int JOURNAL_SIZE = 2000;
    setupAndLoadJournal(JOURNAL_SIZE, 100);
    Assert.assertEquals(0, records.size());
    Assert.assertEquals(0, transactions.size());
    journalImpl.appendAddRecordTransactional(1L, 2L, (byte) 3, new SimpleEncoding(1900 - JournalImpl.SIZE_ADD_RECORD_TX - 1, (byte) 4));
    journalImpl.appendCommitRecord(1L, false);
    journalImpl.debugWait();
    setupAndLoadJournal(JOURNAL_SIZE, 100);
    Assert.assertEquals(1, records.size());
}
Also used : SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) Test(org.junit.Test)

Example 20 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 testDecreaseAlignment.

// It should be ok to write records on AIO, and later read then on NIO
@Test
public void testDecreaseAlignment() throws Exception {
    final int JOURNAL_SIZE = 512 * 4;
    setupAndLoadJournal(JOURNAL_SIZE, 512);
    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, 1);
    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