Search in sources :

Example 16 with NIOSequentialFileFactory

use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory in project activemq-artemis by apache.

the class RedeliveryConsumerTest method internaltestInfiniteDedeliveryMessageOnPersistent.

private void internaltestInfiniteDedeliveryMessageOnPersistent(final boolean strict) throws Exception {
    setUp(strict);
    ClientSession session = factory.createSession(false, false, false);
    RedeliveryConsumerTest.log.info("created");
    ClientProducer prod = session.createProducer(ADDRESS);
    prod.send(createTextMessage(session, "Hello"));
    session.commit();
    session.close();
    int expectedCount = 1;
    for (int i = 0; i < 700; i++) {
        session = factory.createSession(false, false, false);
        session.start();
        ClientConsumer consumer = session.createConsumer(ADDRESS);
        ClientMessage msg = consumer.receive(5000);
        assertNotNull(msg);
        assertEquals(expectedCount, msg.getDeliveryCount());
        if (i % 100 == 0) {
            expectedCount++;
            msg.acknowledge();
            session.rollback();
        }
        session.close();
    }
    factory.close();
    server.stop();
    setUp(false);
    for (int i = 0; i < 700; i++) {
        session = factory.createSession(false, false, false);
        session.start();
        ClientConsumer consumer = session.createConsumer(ADDRESS);
        ClientMessage msg = consumer.receive(5000);
        assertNotNull(msg);
        assertEquals(expectedCount, msg.getDeliveryCount());
        session.close();
    }
    server.stop();
    JournalImpl journal = new JournalImpl(server.getConfiguration().getJournalFileSize(), 2, 2, 0, 0, new NIOSequentialFileFactory(server.getConfiguration().getJournalLocation(), 1), "activemq-data", "amq", 1);
    final AtomicInteger updates = new AtomicInteger();
    journal.start();
    journal.load(new LoaderCallback() {

        @Override
        public void failedTransaction(long transactionID, List<RecordInfo> records, List<RecordInfo> recordsToDelete) {
        }

        @Override
        public void updateRecord(RecordInfo info) {
            if (info.userRecordType == JournalRecordIds.UPDATE_DELIVERY_COUNT) {
                updates.incrementAndGet();
            }
        }

        @Override
        public void deleteRecord(long id) {
        }

        @Override
        public void addRecord(RecordInfo info) {
        }

        @Override
        public void addPreparedTransaction(PreparedTransactionInfo preparedTransaction) {
        }
    });
    journal.stop();
    assertEquals(7, updates.get());
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) LoaderCallback(org.apache.activemq.artemis.core.journal.LoaderCallback) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)

Example 17 with NIOSequentialFileFactory

use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory in project activemq-artemis by apache.

the class RealJournalImplNIOTest method getFileFactory.

@Override
protected SequentialFileFactory getFileFactory() throws Exception {
    File file = new File(getTestDir());
    RealJournalImplNIOTest.log.debug("deleting directory " + getTestDir());
    deleteDirectory(file);
    file.mkdir();
    return new NIOSequentialFileFactory(getTestDirfile(), 1);
}
Also used : File(java.io.File) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)

Example 18 with NIOSequentialFileFactory

use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory in project activemq-artemis by apache.

the class ActiveMQTestBase method internalCountJournalLivingRecords.

/**
 * This method will load a journal and count the living records
 *
 * @param config
 * @param messageJournal if true -> MessageJournal, false -> BindingsJournal
 * @return
 * @throws Exception
 */
protected HashMap<Integer, AtomicInteger> internalCountJournalLivingRecords(Configuration config, boolean messageJournal) throws Exception {
    final HashMap<Integer, AtomicInteger> recordsType = new HashMap<>();
    SequentialFileFactory ff;
    JournalImpl journal;
    if (messageJournal) {
        ff = new NIOSequentialFileFactory(config.getJournalLocation(), null, 1);
        journal = new JournalImpl(config.getJournalFileSize(), config.getJournalMinFiles(), config.getJournalPoolFiles(), 0, 0, ff, "activemq-data", "amq", 1);
    } else {
        ff = new NIOSequentialFileFactory(config.getBindingsLocation(), null, 1);
        journal = new JournalImpl(1024 * 1024, 2, config.getJournalCompactMinFiles(), config.getJournalPoolFiles(), config.getJournalCompactPercentage(), ff, "activemq-bindings", "bindings", 1);
    }
    journal.start();
    final List<RecordInfo> committedRecords = new LinkedList<>();
    final List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
    journal.load(committedRecords, preparedTransactions, null, false);
    for (RecordInfo info : committedRecords) {
        Integer ikey = new Integer(info.getUserRecordType());
        AtomicInteger value = recordsType.get(ikey);
        if (value == null) {
            value = new AtomicInteger();
            recordsType.put(ikey, value);
        }
        value.incrementAndGet();
    }
    journal.stop();
    return recordsType;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) 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)

Example 19 with NIOSequentialFileFactory

use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory in project activemq-artemis by apache.

the class ActiveMQTestBase method countBindingJournal.

protected HashMap<Integer, AtomicInteger> countBindingJournal(Configuration config) throws Exception {
    final HashMap<Integer, AtomicInteger> recordsType = new HashMap<>();
    SequentialFileFactory messagesFF = new NIOSequentialFileFactory(config.getBindingsLocation(), null, 1);
    JournalImpl messagesJournal = new JournalImpl(config.getJournalFileSize(), config.getJournalMinFiles(), config.getJournalPoolFiles(), 0, 0, messagesFF, "activemq-bindings", "bindings", 1);
    List<JournalFile> filesToRead = messagesJournal.orderFiles();
    for (JournalFile file : filesToRead) {
        JournalImpl.readJournalFile(messagesFF, file, new RecordTypeCounter(recordsType));
    }
    return recordsType;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JournalFile(org.apache.activemq.artemis.core.journal.impl.JournalFile) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl)

Example 20 with NIOSequentialFileFactory

use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory in project activemq-artemis by apache.

the class JournalCrashTest method printJournal.

/**
 * @throws Exception
 */
private void printJournal() throws Exception {
    NIOSequentialFileFactory factory = new NIOSequentialFileFactory(new File(getJournalDir()), 100);
    JournalImpl journal = new JournalImpl(ActiveMQDefaultConfiguration.getDefaultJournalFileSize(), 2, 2, 0, 0, factory, "activemq-data", "amq", 100);
    ArrayList<RecordInfo> records = new ArrayList<>();
    ArrayList<PreparedTransactionInfo> transactions = new ArrayList<>();
    journal.start();
    journal.load(records, transactions, null);
    // System.out.println("===============================================");
    // System.out.println("Journal records at the end:");
    // 
    // for (RecordInfo record : records)
    // {
    // System.out.println(record.id + ", update = " + record.isUpdate);
    // }
    journal.stop();
}
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)

Aggregations

NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)33 JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)19 File (java.io.File)18 SequentialFileFactory (org.apache.activemq.artemis.core.io.SequentialFileFactory)15 Test (org.junit.Test)11 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)7 SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)6 AIOSequentialFileFactory (org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 LinkedList (java.util.LinkedList)4 MappedSequentialFileFactory (org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory)4 JournalFile (org.apache.activemq.artemis.core.journal.impl.JournalFile)4 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)3 EncodingSupport (org.apache.activemq.artemis.core.journal.EncodingSupport)3 Journal (org.apache.activemq.artemis.core.journal.Journal)3 FakeSequentialFileFactory (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory)3 ByteBuffer (java.nio.ByteBuffer)2