Search in sources :

Example 6 with PreparedTransactionInfo

use of org.apache.activemq.artemis.core.journal.PreparedTransactionInfo in project activemq-artemis by apache.

the class JDBCJournalLoaderCallbackTest method testAddDeleteRecord.

@Test
public void testAddDeleteRecord() throws Exception {
    ArrayList<RecordInfo> committedRecords = new ArrayList<>();
    ArrayList<PreparedTransactionInfo> preparedTransactions = new ArrayList<>();
    TransactionFailureCallback failureCallback = null;
    boolean fixBadTX = false;
    JDBCJournalLoaderCallback cb = new JDBCJournalLoaderCallback(committedRecords, preparedTransactions, failureCallback, fixBadTX);
    RecordInfo record = new RecordInfo(42, (byte) 0, null, false, (short) 0);
    cb.addRecord(record);
    assertEquals(1, committedRecords.size());
    assertTrue(committedRecords.contains(record));
    cb.deleteRecord(record.id);
    assertTrue(committedRecords.isEmpty());
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) ArrayList(java.util.ArrayList) TransactionFailureCallback(org.apache.activemq.artemis.core.journal.TransactionFailureCallback) Test(org.junit.Test)

Example 7 with PreparedTransactionInfo

use of org.apache.activemq.artemis.core.journal.PreparedTransactionInfo in project activemq-artemis by apache.

the class NIOMultiThreadCompactorStressTest method testMultiThreadCompact.

@Test
public void testMultiThreadCompact() throws Throwable {
    setupServer(getJournalType());
    for (int i = 0; i < getNumberOfIterations(); i++) {
        System.out.println("######################################");
        System.out.println("test # " + i);
        internalTestProduceAndConsume();
        stopServer();
        NIOSequentialFileFactory factory = new NIOSequentialFileFactory(new File(getJournalDir()), 1);
        JournalImpl journal = new JournalImpl(ActiveMQDefaultConfiguration.getDefaultJournalFileSize(), 2, 2, 0, 0, factory, "activemq-data", "amq", 100);
        List<RecordInfo> committedRecords = new ArrayList<>();
        List<PreparedTransactionInfo> preparedTransactions = new ArrayList<>();
        journal.start();
        journal.load(committedRecords, preparedTransactions, null);
        Assert.assertEquals(0, committedRecords.size());
        Assert.assertEquals(0, preparedTransactions.size());
        System.out.println("DataFiles = " + journal.getDataFilesCount());
        if (i % 2 == 0 && i > 0) {
            System.out.println("DataFiles = " + journal.getDataFilesCount());
            journal.forceMoveNextFile();
            journal.debugWait();
            journal.checkReclaimStatus();
            if (journal.getDataFilesCount() != 0) {
                System.out.println("DebugJournal:" + journal.debug());
            }
            Assert.assertEquals(0, journal.getDataFilesCount());
        }
        journal.stop();
        journal = null;
        setupServer(getJournalType());
    }
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) ArrayList(java.util.ArrayList) File(java.io.File) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Test(org.junit.Test)

Example 8 with PreparedTransactionInfo

use of org.apache.activemq.artemis.core.journal.PreparedTransactionInfo 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 9 with PreparedTransactionInfo

use of org.apache.activemq.artemis.core.journal.PreparedTransactionInfo in project activemq-artemis by apache.

the class BatchIDGeneratorUnitTest method testSequence.

@Test
public void testSequence() throws Exception {
    NIOSequentialFileFactory factory = new NIOSequentialFileFactory(new File(getTestDir()), 1);
    Journal journal = new JournalImpl(10 * 1024, 2, 2, 0, 0, factory, "activemq-bindings", "bindings", 1);
    journal.start();
    journal.load(new ArrayList<RecordInfo>(), new ArrayList<PreparedTransactionInfo>(), null);
    BatchingIDGenerator batch = new BatchingIDGenerator(0, 1000, getJournalStorageManager(journal));
    long id1 = batch.generateID();
    long id2 = batch.generateID();
    Assert.assertTrue(id2 > id1);
    journal.stop();
    batch = new BatchingIDGenerator(0, 1000, getJournalStorageManager(journal));
    loadIDs(journal, batch);
    long id3 = batch.generateID();
    Assert.assertEquals(1001, id3);
    long id4 = batch.generateID();
    Assert.assertTrue(id4 > id3 && id4 < 2000);
    batch.persistCurrentID();
    journal.stop();
    batch = new BatchingIDGenerator(0, 1000, getJournalStorageManager(journal));
    loadIDs(journal, batch);
    long id5 = batch.generateID();
    Assert.assertTrue(id5 > id4 && id5 < 2000);
    long lastId = id5;
    boolean close = true;
    for (int i = 0; i < 100000; i++) {
        if (i % 1000 == 0) {
            // interchanging closes and simulated crashes
            if (close) {
                batch.persistCurrentID();
            }
            close = !close;
            journal.stop();
            batch = new BatchingIDGenerator(0, 1000, getJournalStorageManager(journal));
            loadIDs(journal, batch);
        }
        long id = batch.generateID();
        Assert.assertTrue(id > lastId);
        lastId = id;
    }
    batch.persistCurrentID();
    journal.stop();
    batch = new BatchingIDGenerator(0, 1000, getJournalStorageManager(journal));
    loadIDs(journal, batch);
    lastId = batch.getCurrentID();
    journal.stop();
    batch = new BatchingIDGenerator(0, 1000, getJournalStorageManager(journal));
    loadIDs(journal, batch);
    Assert.assertEquals("No Ids were generated, so the currentID was supposed to stay the same", lastId, batch.getCurrentID());
    journal.stop();
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) Journal(org.apache.activemq.artemis.core.journal.Journal) BatchingIDGenerator(org.apache.activemq.artemis.core.persistence.impl.journal.BatchingIDGenerator) File(java.io.File) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Test(org.junit.Test)

Example 10 with PreparedTransactionInfo

use of org.apache.activemq.artemis.core.journal.PreparedTransactionInfo in project activemq-artemis by apache.

the class CrashOnCompactTest method checkJournalSize.

private void checkJournalSize() throws Exception {
    JournalImpl journal = createJournal(getTestDirfile(), false);
    ArrayList<RecordInfo> info = new ArrayList<>();
    ArrayList<PreparedTransactionInfo> txInfo = new ArrayList<>();
    journal.load(info, txInfo, new TransactionFailureCallback() {

        @Override
        public void failedTransaction(long transactionID, List<RecordInfo> records, List<RecordInfo> recordsToDelete) {
        }
    });
    Assert.assertEquals(900, info.size());
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) ArrayList(java.util.ArrayList) TransactionFailureCallback(org.apache.activemq.artemis.core.journal.TransactionFailureCallback) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl)

Aggregations

PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)34 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)33 ArrayList (java.util.ArrayList)17 JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)13 Test (org.junit.Test)13 LinkedList (java.util.LinkedList)12 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)10 TransactionFailureCallback (org.apache.activemq.artemis.core.journal.TransactionFailureCallback)8 HashMap (java.util.HashMap)7 NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)7 LinkedHashMap (java.util.LinkedHashMap)5 List (java.util.List)5 JournalLoadInformation (org.apache.activemq.artemis.core.journal.JournalLoadInformation)5 JournalStorageManager (org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager)5 PageCountRecordInc (org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecordInc)5 File (java.io.File)4 SequentialFileFactory (org.apache.activemq.artemis.core.io.SequentialFileFactory)4 HashSet (java.util.HashSet)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3