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());
}
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);
}
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;
}
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;
}
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();
}
Aggregations