Search in sources :

Example 1 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 testSyncNonTransaction.

@Test
public void testSyncNonTransaction() throws Exception {
    final int JOURNAL_SIZE = 20000;
    setupJournal(JOURNAL_SIZE, 100, 5);
    factory.setGenerateErrors(true);
    try {
        journalImpl.appendAddRecord(1L, (byte) 0, new SimpleEncoding(1, (byte) 0), true);
        Assert.fail("Exception expected");
    } catch (Exception ignored) {
    }
}
Also used : SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) Test(org.junit.Test)

Example 2 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 testPreviousError.

// If a callback error already arrived, we should just throw the exception right away
@Test
public void testPreviousError() throws Exception {
    final int JOURNAL_SIZE = 20000;
    setupJournal(JOURNAL_SIZE, 100, 5);
    factory.setHoldCallbacks(true, null);
    factory.setGenerateErrors(true);
    journalImpl.appendAddRecordTransactional(1L, 1, (byte) 1, new SimpleEncoding(1, (byte) 0));
    journalImpl.debugWait();
    factory.flushAllCallbacks();
    factory.setGenerateErrors(false);
    factory.setHoldCallbacks(false, null);
    try {
        journalImpl.appendAddRecordTransactional(1L, 2, (byte) 1, new SimpleEncoding(1, (byte) 0));
        journalImpl.appendCommitRecord(1L, true);
        Assert.fail("Exception expected");
    // An exception already happened in one of the elements on this transaction.
    // We can't accept any more elements on the transaction
    } catch (Exception ignored) {
    }
}
Also used : SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) Test(org.junit.Test)

Example 3 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 testXASimplePrepared.

@Test
public void testXASimplePrepared() 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);
    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 4 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 testXAChangesNotVisibleRollback.

@Test
public void testXAChangesNotVisibleRollback() 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);
    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)

Example 5 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 testPrepareReclaim.

@Test
public void testPrepareReclaim() throws Exception {
    setup(2, 100 * 1024, 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);
    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());
    // Make sure we move on to the next file
    journal.forceMoveNextFile();
    journal.debugWait();
    // in file 1
    addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD, 2);
    List<String> files2 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(3, files2.size());
    Assert.assertEquals(1, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getIDMapSize());
    EncodingSupport xid = new SimpleEncoding(10, (byte) 0);
    // in file 1
    prepare(1, xid);
    List<String> files3 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(3, files3.size());
    Assert.assertEquals(1, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(1, journal.getIDMapSize());
    // in file 1
    delete(2);
    List<String> files4 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(3, files4.size());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(1, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(0, journal.getIDMapSize());
    // Move on to another file
    journal.forceMoveNextFile();
    // in file 2
    addWithSize(1024 - JournalImpl.SIZE_ADD_RECORD, 3);
    checkAndReclaimFiles();
    List<String> files5 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(4, files5.size());
    Assert.assertEquals(2, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getIDMapSize());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    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.getIDMapSize());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    journal.forceMoveNextFile();
    // in file 3
    addWithSize(1024 - JournalImpl.SIZE_ADD_RECORD, 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 3
    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(3, journal.getIDMapSize());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    // in file 3
    delete(1);
    List<String> files9 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(5, files9.size());
    Assert.assertEquals(3, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(2, journal.getIDMapSize());
    checkAndReclaimFiles();
    List<String> files10 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(journal.getAlignment() == 1 ? 5 : 5, files10.size());
    Assert.assertEquals(journal.getAlignment() == 1 ? 3 : 3, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(2, journal.getIDMapSize());
    journal.forceMoveNextFile();
    // in file 4
    addWithSize(1024 - JournalImpl.SIZE_ADD_RECORD, 5);
    List<String> files11 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(6, files11.size());
    Assert.assertEquals(4, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(3, journal.getIDMapSize());
    checkAndReclaimFiles();
    List<String> files12 = fileFactory.listFiles(fileExtension);
    // File 0, and File 1 should be deleted
    Assert.assertEquals(4, files12.size());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(2, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(3, journal.getIDMapSize());
    // Restart
    stopJournal();
    createJournal();
    startJournal();
    loadAndCheck();
    delete(4);
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(2, journal.getIDMapSize());
    addWithSize(1024 - JournalImpl.SIZE_ADD_RECORD, 6);
    UnitTestLogger.LOGGER.debug("Debug journal on testPrepareReclaim ->\n" + debugJournal());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(3, journal.getIDMapSize());
    checkAndReclaimFiles();
    // file 3 should now be deleted
    List<String> files15 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(4, files15.size());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(2, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(3, journal.getIDMapSize());
    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