Search in sources :

Example 31 with PreparedTransactionInfo

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

the class MessageJournalTest method testStoreAMQP.

@Test
public void testStoreAMQP() throws Throwable {
    ActiveMQServer server = createServer(true);
    server.start();
    ProtonProtocolManagerFactory factory = (ProtonProtocolManagerFactory) server.getRemotingService().getProtocolFactoryMap().get("AMQP");
    Message protonJMessage = Message.Factory.create();
    AMQPMessage message = new AMQPMessage(protonJMessage);
    message.setMessageID(333);
    Assert.assertNotNull(factory);
    server.getStorageManager().storeMessage(message);
    server.getStorageManager().stop();
    JournalStorageManager journalStorageManager = (JournalStorageManager) server.getStorageManager();
    List<RecordInfo> committedRecords = new LinkedList<>();
    List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
    TransactionFailureCallback transactionFailure = new TransactionFailureCallback() {

        @Override
        public void failedTransaction(long transactionID, List<RecordInfo> records, List<RecordInfo> recordsToDelete) {
        }
    };
    try {
        journalStorageManager.getMessageJournal().start();
        journalStorageManager.getMessageJournal().load(committedRecords, preparedTransactions, transactionFailure);
        Assert.assertEquals(1, committedRecords.size());
    } finally {
        journalStorageManager.getMessageJournal().stop();
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) Message(org.apache.qpid.proton.message.Message) ProtonProtocolManagerFactory(org.apache.activemq.artemis.protocol.amqp.broker.ProtonProtocolManagerFactory) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) List(java.util.List) LinkedList(java.util.LinkedList) TransactionFailureCallback(org.apache.activemq.artemis.core.journal.TransactionFailureCallback) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) LinkedList(java.util.LinkedList) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) Test(org.junit.Test)

Example 32 with PreparedTransactionInfo

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

the class MessageJournalTest method testStoreCore.

@Test
public void testStoreCore() throws Throwable {
    ActiveMQServer server = createServer(true);
    server.start();
    CoreMessage message = new CoreMessage().initBuffer(10 * 1024).setDurable(true);
    message.setMessageID(333);
    CoreProtocolManagerFactory factory = (CoreProtocolManagerFactory) server.getRemotingService().getProtocolFactoryMap().get("CORE");
    Assert.assertNotNull(factory);
    message.getBodyBuffer().writeByte((byte) 'Z');
    server.getStorageManager().storeMessage(message);
    server.getStorageManager().stop();
    JournalStorageManager journalStorageManager = (JournalStorageManager) server.getStorageManager();
    List<RecordInfo> committedRecords = new LinkedList<>();
    List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
    TransactionFailureCallback transactionFailure = new TransactionFailureCallback() {

        @Override
        public void failedTransaction(long transactionID, List<RecordInfo> records, List<RecordInfo> recordsToDelete) {
        }
    };
    try {
        journalStorageManager.getMessageJournal().start();
        journalStorageManager.getMessageJournal().load(committedRecords, preparedTransactions, transactionFailure);
        Assert.assertEquals(1, committedRecords.size());
    } finally {
        journalStorageManager.getMessageJournal().stop();
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) CoreProtocolManagerFactory(org.apache.activemq.artemis.core.protocol.core.impl.CoreProtocolManagerFactory) List(java.util.List) LinkedList(java.util.LinkedList) TransactionFailureCallback(org.apache.activemq.artemis.core.journal.TransactionFailureCallback) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) LinkedList(java.util.LinkedList) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) Test(org.junit.Test)

Example 33 with PreparedTransactionInfo

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

the class NIOJournalCompactTest method testCompactFirstFileReclaimed.

@Test
public void testCompactFirstFileReclaimed() throws Exception {
    setup(2, 60 * 1024, false);
    final byte recordType = (byte) 0;
    journal = new JournalImpl(fileSize, minFiles, minFiles, 0, 0, fileFactory, filePrefix, fileExtension, maxAIO);
    journal.start();
    journal.loadInternalOnly();
    journal.appendAddRecord(1, recordType, "test".getBytes(), true);
    journal.forceMoveNextFile();
    journal.appendUpdateRecord(1, recordType, "update".getBytes(), true);
    journal.appendDeleteRecord(1, true);
    journal.appendAddRecord(2, recordType, "finalRecord".getBytes(), true);
    for (int i = 10; i < 100; i++) {
        journal.appendAddRecord(i, recordType, ("tst" + i).getBytes(), true);
        journal.forceMoveNextFile();
        journal.appendUpdateRecord(i, recordType, ("uptst" + i).getBytes(), true);
        journal.appendDeleteRecord(i, true);
    }
    journal.testCompact();
    journal.stop();
    List<RecordInfo> records1 = new ArrayList<>();
    List<PreparedTransactionInfo> preparedRecords = new ArrayList<>();
    journal.start();
    journal.load(records1, preparedRecords, null);
    assertEquals(1, records1.size());
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) ArrayList(java.util.ArrayList) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Test(org.junit.Test)

Example 34 with PreparedTransactionInfo

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

the class ActiveMQTestBase method loadMessageJournal.

/**
 * Reads a journal system and returns a Map<Integer,AtomicInteger> of recordTypes and the number of records per type,
 * independent of being deleted or not
 *
 * @param config
 * @return
 * @throws Exception
 */
protected Pair<List<RecordInfo>, List<PreparedTransactionInfo>> loadMessageJournal(Configuration config) throws Exception {
    JournalImpl messagesJournal = null;
    try {
        SequentialFileFactory messagesFF = new NIOSequentialFileFactory(new File(getJournalDir()), null, 1);
        messagesJournal = new JournalImpl(config.getJournalFileSize(), config.getJournalMinFiles(), config.getJournalPoolFiles(), 0, 0, messagesFF, "activemq-data", "amq", 1);
        final List<RecordInfo> committedRecords = new LinkedList<>();
        final List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
        messagesJournal.start();
        messagesJournal.load(committedRecords, preparedTransactions, null, false);
        return new Pair<>(committedRecords, preparedTransactions);
    } finally {
        try {
            if (messagesJournal != null) {
                messagesJournal.stop();
            }
        } catch (Throwable ignored) {
        }
    }
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) File(java.io.File) JournalFile(org.apache.activemq.artemis.core.journal.impl.JournalFile) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) LinkedList(java.util.LinkedList) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) Pair(org.apache.activemq.artemis.api.core.Pair)

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