Search in sources :

Example 36 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 testReloadInvalidCheckSizeOnTransaction.

@Test
public void testReloadInvalidCheckSizeOnTransaction() throws Exception {
    final int JOURNAL_SIZE = 2000;
    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 < 2; i++) {
        journalImpl.appendAddRecordTransactional(1L, i, (byte) 0, new SimpleEncoding(1, (byte) 15));
    }
    journalImpl.appendCommitRecord(1L, false);
    journalImpl.debugWait();
    System.out.println("Files = " + factory.listFiles("tt"));
    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(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 37 with SimpleEncoding

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

the class JournalAsyncTest method doAsynchronousTest.

public void doAsynchronousTest(final boolean isCommit) throws Exception {
    final int JOURNAL_SIZE = 20000;
    setupJournal(JOURNAL_SIZE, 100, 5);
    factory.setHoldCallbacks(true, null);
    final CountDownLatch latch = new CountDownLatch(1);
    class LocalThread extends Thread {

        Exception e;

        @Override
        public void run() {
            try {
                for (int i = 0; i < 10; i++) {
                    journalImpl.appendAddRecordTransactional(1L, i, (byte) 1, new SimpleEncoding(1, (byte) 0));
                }
                journalImpl.debugWait();
                latch.countDown();
                factory.setHoldCallbacks(false, null);
                if (isCommit) {
                    journalImpl.appendCommitRecord(1L, true);
                } else {
                    journalImpl.appendRollbackRecord(1L, true);
                }
            } catch (Exception e) {
                e.printStackTrace();
                this.e = e;
            }
        }
    }
    LocalThread t = new LocalThread();
    t.start();
    Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
    Thread.yield();
    Thread.sleep(100);
    Assert.assertTrue(t.isAlive());
    factory.flushAllCallbacks();
    t.join();
    if (t.e != null) {
        throw t.e;
    }
}
Also used : SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 38 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 testXASimpleCommit.

@Test
public void testXASimpleCommit() throws Exception {
    setup(10, 10 * 1024, true);
    createJournal();
    startJournal();
    load();
    addTx(1, 1, 2, 3, 4, 5, 6, 7, 8, 9);
    updateTx(1, 1, 2, 3, 4, 7, 8);
    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 39 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 testSimpleAddTXXAReload.

@Test
public void testSimpleAddTXXAReload() throws Exception {
    setup(2, 10 * 1024, true);
    createJournal();
    startJournal();
    load();
    addTx(1, 1);
    EncodingSupport xid = new SimpleEncoding(10, (byte) 'p');
    prepare(1, xid);
    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 40 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 testXASimpleRollback.

@Test
public void testXASimpleRollback() throws Exception {
    setup(10, 10 * 1024, true);
    createJournal();
    startJournal();
    load();
    addTx(1, 1, 2, 3, 4, 5, 6, 7, 8, 9);
    updateTx(1, 1, 2, 3, 4, 7, 8);
    deleteTx(1, 1, 2, 3, 4, 5);
    EncodingSupport xid = new SimpleEncoding(10, (byte) 0);
    prepare(1, xid);
    rollback(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)

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