Search in sources :

Example 41 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 testXAMultiple.

@Test
public void testXAMultiple() throws Exception {
    setup(10, 10 * 1024, true);
    createJournal();
    startJournal();
    load();
    add(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    addTx(1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20);
    addTx(2, 21, 22, 23, 24, 25, 26, 27);
    updateTx(1, 1, 3, 6, 11, 14, 17);
    addTx(3, 28, 29, 30, 31, 32, 33, 34, 35);
    updateTx(3, 7, 8, 9, 10);
    deleteTx(2, 4, 5, 6, 23, 25, 27);
    EncodingSupport xid = new SimpleEncoding(10, (byte) 0);
    prepare(2, xid);
    deleteTx(1, 1, 2, 11, 14, 15);
    prepare(1, xid);
    deleteTx(3, 28, 31, 32, 9);
    prepare(3, xid);
    commit(1);
    rollback(2);
    commit(3);
}
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 42 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 testRestartJournal.

@Test
public void testRestartJournal() throws Exception {
    setup(10, 10 * 1024, true);
    createJournal();
    startJournal();
    load();
    stopJournal();
    startJournal();
    load();
    byte[] record = new byte[1000];
    for (int i = 0; i < record.length; i++) {
        record[i] = (byte) 'a';
    }
    // exceptions)
    for (int i = 0; i < 100; i++) {
        journal.appendAddRecord(1, (byte) 1, new SimpleEncoding(2, (byte) 'a'), false);
    }
    stopJournal();
}
Also used : SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) Test(org.junit.Test)

Example 43 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 testXAChangesNotVisiblePrepared.

@Test
public void testXAChangesNotVisiblePrepared() 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);
    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 44 with SimpleEncoding

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

the class AddAndRemoveStressTest method testInsertAndLoad.

// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testInsertAndLoad() throws Exception {
    SequentialFileFactory factory = new AIOSequentialFileFactory(getTestDirfile(), 1000);
    JournalImpl impl = new JournalImpl(10 * 1024 * 1024, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, 0, 0, factory, "amq", "amq", 1000);
    impl.start();
    impl.load(AddAndRemoveStressTest.dummyLoader);
    for (long i = 1; i <= AddAndRemoveStressTest.NUMBER_OF_MESSAGES; i++) {
        if (i % 10000 == 0) {
            System.out.println("Append " + i);
        }
        impl.appendAddRecord(i, (byte) 0, new SimpleEncoding(1024, (byte) 'f'), false);
    }
    impl.stop();
    factory = new AIOSequentialFileFactory(getTestDirfile(), 1000);
    impl = new JournalImpl(10 * 1024 * 1024, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, 0, 0, factory, "amq", "amq", 1000);
    impl.start();
    impl.load(AddAndRemoveStressTest.dummyLoader);
    for (long i = 1; i <= AddAndRemoveStressTest.NUMBER_OF_MESSAGES; i++) {
        if (i % 10000 == 0) {
            System.out.println("Delete " + i);
        }
        impl.appendDeleteRecord(i, false);
    }
    impl.stop();
    factory = new AIOSequentialFileFactory(getTestDirfile(), 1000);
    impl = new JournalImpl(10 * 1024 * 1024, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, 0, 0, factory, "amq", "amq", 1000);
    impl.start();
    ArrayList<RecordInfo> info = new ArrayList<>();
    ArrayList<PreparedTransactionInfo> trans = new ArrayList<>();
    impl.load(info, trans, null);
    impl.forceMoveNextFile();
    if (info.size() > 0) {
        System.out.println("Info ID: " + info.get(0).id);
    }
    impl.stop();
    Assert.assertEquals(0, info.size());
    Assert.assertEquals(0, trans.size());
    Assert.assertEquals(0, impl.getDataFilesCount());
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) ArrayList(java.util.ArrayList) SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Test(org.junit.Test)

Example 45 with SimpleEncoding

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

the class AddAndRemoveStressTest method testInsertUpdateAndLoad.

@Test
public void testInsertUpdateAndLoad() throws Exception {
    SequentialFileFactory factory = new AIOSequentialFileFactory(getTestDirfile(), 1000);
    JournalImpl impl = new JournalImpl(10 * 1024 * 1024, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, 0, 0, factory, "amq", "amq", 1000);
    impl.start();
    impl.load(AddAndRemoveStressTest.dummyLoader);
    for (long i = 1; i <= AddAndRemoveStressTest.NUMBER_OF_MESSAGES; i++) {
        if (i % 10000 == 0) {
            System.out.println("Append " + i);
        }
        impl.appendAddRecord(i, (byte) 21, new SimpleEncoding(40, (byte) 'f'), false);
        impl.appendUpdateRecord(i, (byte) 22, new SimpleEncoding(40, (byte) 'g'), false);
    }
    impl.stop();
    factory = new AIOSequentialFileFactory(getTestDirfile(), 1000);
    impl = new JournalImpl(10 * 1024 * 1024, 10, 10, 0, 0, factory, "amq", "amq", 1000);
    impl.start();
    impl.load(AddAndRemoveStressTest.dummyLoader);
    for (long i = 1; i <= AddAndRemoveStressTest.NUMBER_OF_MESSAGES; i++) {
        if (i % 10000 == 0) {
            System.out.println("Delete " + i);
        }
        impl.appendDeleteRecord(i, false);
    }
    impl.stop();
    factory = new AIOSequentialFileFactory(getTestDirfile(), 1000);
    impl = new JournalImpl(10 * 1024 * 1024, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, 0, 0, factory, "amq", "amq", 1000);
    impl.start();
    ArrayList<RecordInfo> info = new ArrayList<>();
    ArrayList<PreparedTransactionInfo> trans = new ArrayList<>();
    impl.load(info, trans, null);
    if (info.size() > 0) {
        System.out.println("Info ID: " + info.get(0).id);
    }
    impl.forceMoveNextFile();
    impl.checkReclaimStatus();
    impl.stop();
    Assert.assertEquals(0, info.size());
    Assert.assertEquals(0, trans.size());
    Assert.assertEquals(0, impl.getDataFilesCount());
    System.out.println("Size = " + impl.getDataFilesCount());
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) ArrayList(java.util.ArrayList) SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) 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