Search in sources :

Example 11 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 testAlignmentOverReload.

@Test
public void testAlignmentOverReload() throws Exception {
    factory = new FakeSequentialFileFactory(512, false);
    journalImpl = new JournalImpl(512 + 512 * 3, 20, 20, 0, 0, factory, "amq", "amq", 1000);
    journalImpl.start();
    journalImpl.load(AlignedJournalImplTest.dummyLoader);
    journalImpl.appendAddRecord(1L, (byte) 0, new SimpleEncoding(100, (byte) 'a'), false);
    journalImpl.appendAddRecord(2L, (byte) 0, new SimpleEncoding(100, (byte) 'b'), false);
    journalImpl.appendAddRecord(3L, (byte) 0, new SimpleEncoding(100, (byte) 'b'), false);
    journalImpl.appendAddRecord(4L, (byte) 0, new SimpleEncoding(100, (byte) 'b'), false);
    journalImpl.stop();
    journalImpl = new JournalImpl(512 + 1024 + 512, 20, 20, 0, 0, factory, "amq", "amq", 1000);
    addActiveMQComponent(journalImpl);
    journalImpl.start();
    journalImpl.load(AlignedJournalImplTest.dummyLoader);
    // It looks silly, but this forceMoveNextFile is in place to replicate one
    // specific bug caught during development
    journalImpl.forceMoveNextFile();
    journalImpl.appendDeleteRecord(1L, false);
    journalImpl.appendDeleteRecord(2L, false);
    journalImpl.appendDeleteRecord(3L, false);
    journalImpl.appendDeleteRecord(4L, false);
    journalImpl.stop();
    journalImpl = new JournalImpl(512 + 1024 + 512, 20, 20, 0, 0, factory, "amq", "amq", 1000);
    addActiveMQComponent(journalImpl);
    journalImpl.start();
    ArrayList<RecordInfo> info = new ArrayList<>();
    ArrayList<PreparedTransactionInfo> trans = new ArrayList<>();
    journalImpl.load(info, trans, null);
    Assert.assertEquals(0, info.size());
    Assert.assertEquals(0, trans.size());
}
Also used : FakeSequentialFileFactory(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory) PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) ArrayList(java.util.ArrayList) SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Test(org.junit.Test)

Example 12 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 testReloadIncompleteTransaction.

@Test
public void testReloadIncompleteTransaction() throws Exception {
    final int JOURNAL_SIZE = 2000;
    setupAndLoadJournal(JOURNAL_SIZE, 1);
    Assert.assertEquals(2, factory.listFiles("tt").size());
    Assert.assertEquals(0, records.size());
    Assert.assertEquals(0, transactions.size());
    for (int i = 0; i < 10; i++) {
        journalImpl.appendAddRecordTransactional(1L, i, (byte) 0, new SimpleEncoding(1, (byte) 15));
    }
    for (int i = 10; i < 20; i++) {
        journalImpl.appendAddRecordTransactional(1L, i, (byte) 0, new SimpleEncoding(1, (byte) 15));
    }
    journalImpl.appendCommitRecord(1L, false);
    journalImpl.debugWait();
    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);
    buffer.rewind();
    file.writeDirect(buffer, true);
    file.close();
    setupAndLoadJournal(JOURNAL_SIZE, 100);
    Assert.assertEquals(0, records.size());
    journalImpl.checkReclaimStatus();
    Assert.assertEquals(0, journalImpl.getDataFilesCount());
    Assert.assertEquals(2, factory.listFiles("tt").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 13 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 testPrepareAloneOnSeparatedFile.

@Test
public void testPrepareAloneOnSeparatedFile() 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 < 10; i++) {
        journalImpl.appendAddRecordTransactional(1L, i, (byte) 0, new SimpleEncoding(1, (byte) 15));
    }
    journalImpl.forceMoveNextFile();
    SimpleEncoding xidEncoding = new SimpleEncoding(10, (byte) 'a');
    journalImpl.appendPrepareRecord(1L, xidEncoding, false);
    journalImpl.appendCommitRecord(1L, false);
    for (int i = 0; i < 10; i++) {
        journalImpl.appendDeleteRecordTransactional(2L, i);
    }
    journalImpl.appendCommitRecord(2L, false);
    // Add
    journalImpl.appendAddRecord(100L, (byte) 0, new SimpleEncoding(1, (byte) 10), false);
    // anything
    // to
    // keep
    // holding
    // the
    // file
    journalImpl.forceMoveNextFile();
    journalImpl.checkReclaimStatus();
    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 14 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 testSimpleAdd.

@Test
public void testSimpleAdd() throws Exception {
    final int JOURNAL_SIZE = 1060;
    setupAndLoadJournal(JOURNAL_SIZE, 10);
    journalImpl.appendAddRecord(13, (byte) 14, new SimpleEncoding(1, (byte) 15), false);
    journalImpl.forceMoveNextFile();
    journalImpl.checkReclaimStatus();
    setupAndLoadJournal(JOURNAL_SIZE, 10);
    Assert.assertEquals(1, records.size());
    Assert.assertEquals(13, records.get(0).id);
    Assert.assertEquals(14, records.get(0).userRecordType);
    Assert.assertEquals(1, records.get(0).data.length);
    Assert.assertEquals(15, records.get(0).data[0]);
}
Also used : SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) Test(org.junit.Test)

Example 15 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 testPartiallyBrokenFile.

@Test
public void testPartiallyBrokenFile() throws Exception {
    final int JOURNAL_SIZE = 20000;
    setupAndLoadJournal(JOURNAL_SIZE, 100);
    Assert.assertEquals(2, factory.listFiles("tt").size());
    Assert.assertEquals(0, records.size());
    Assert.assertEquals(0, transactions.size());
    for (int i = 0; i < 20; i++) {
        journalImpl.appendAddRecordTransactional(1L, i, (byte) 0, new SimpleEncoding(1, (byte) 15));
        journalImpl.appendAddRecordTransactional(2L, i + 20L, (byte) 0, new SimpleEncoding(1, (byte) 15));
    }
    journalImpl.appendCommitRecord(1L, false);
    journalImpl.appendCommitRecord(2L, false);
    journalImpl.debugWait();
    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);
    // jumping RecordType, FileId, TransactionID, RecordID, VariableSize,
    // RecordType, RecordBody (that we know it is 1 )
    buffer.position(1 + 4 + 8 + 8 + 4 + 1 + 1 + 1);
    int posCheckSize = buffer.position();
    Assert.assertEquals(JournalImpl.SIZE_ADD_RECORD_TX + 2, buffer.getInt());
    buffer.position(posCheckSize);
    buffer.putInt(-1);
    buffer.rewind();
    // Changing the check bufferSize, so reload will ignore this record
    file.position(100);
    file.writeDirect(buffer, true);
    file.close();
    setupAndLoadJournal(JOURNAL_SIZE, 100);
    Assert.assertEquals(20, records.size());
    journalImpl.checkReclaimStatus();
}
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)

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