Search in sources :

Example 16 with RecordInfo

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

the class JournalImplTestBase method checkRecordsEquivalent.

protected void checkRecordsEquivalent(final List<RecordInfo> expected, final List<RecordInfo> actual) {
    if (expected.size() != actual.size()) {
        printJournalLists(expected, actual);
    }
    Assert.assertEquals("Lists not same length", expected.size(), actual.size());
    Iterator<RecordInfo> iterExpected = expected.iterator();
    Iterator<RecordInfo> iterActual = actual.iterator();
    while (iterExpected.hasNext()) {
        RecordInfo rexpected = iterExpected.next();
        RecordInfo ractual = iterActual.next();
        if (rexpected.id != ractual.id || rexpected.isUpdate != ractual.isUpdate) {
            printJournalLists(expected, actual);
        }
        Assert.assertEquals("ids not same", rexpected.id, ractual.id);
        Assert.assertEquals("type not same", rexpected.isUpdate, ractual.isUpdate);
        ActiveMQTestBase.assertEqualsByteArrays(rexpected.data, ractual.data);
    }
}
Also used : RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo)

Example 17 with RecordInfo

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

the class JournalImplTestBase method updateTx.

protected void updateTx(final long txID, final long... arguments) throws Exception {
    TransactionHolder tx = getTransaction(txID);
    for (long element : arguments) {
        byte[] updateRecord = generateRecord(recordLength - (JournalImpl.SIZE_ADD_RECORD_TX + 1));
        beforeJournalOperation();
        journal.appendUpdateRecordTransactional(txID, element, (byte) 0, updateRecord);
        tx.records.add(new RecordInfo(element, (byte) 0, updateRecord, true, (short) 0));
    }
    journal.debugWait();
}
Also used : RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo)

Example 18 with RecordInfo

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

the class JournalImplTestBase method deleteTx.

protected void deleteTx(final long txID, final long... arguments) throws Exception {
    TransactionHolder tx = getTransaction(txID);
    for (long element : arguments) {
        beforeJournalOperation();
        journal.appendDeleteRecordTransactional(txID, element);
        tx.deletes.add(new RecordInfo(element, (byte) 0, null, true, (short) 0));
    }
    journal.debugWait();
}
Also used : RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo)

Example 19 with RecordInfo

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

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

RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)65 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)33 ArrayList (java.util.ArrayList)22 JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)20 Test (org.junit.Test)20 LinkedList (java.util.LinkedList)15 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)15 HashMap (java.util.HashMap)10 NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)10 TransactionFailureCallback (org.apache.activemq.artemis.core.journal.TransactionFailureCallback)9 File (java.io.File)7 Journal (org.apache.activemq.artemis.core.journal.Journal)7 SimpleEncoding (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding)7 List (java.util.List)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 SequentialFileFactory (org.apache.activemq.artemis.core.io.SequentialFileFactory)6 PageCountRecordInc (org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageCountRecordInc)6 IOException (java.io.IOException)5 HashSet (java.util.HashSet)5 LinkedHashMap (java.util.LinkedHashMap)5