use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory in project activemq-artemis by apache.
the class CrashOnCompactTest method createJournal.
private static JournalImpl createJournal(File folder, boolean crash) throws Exception {
NIOSequentialFileFactory factory = new NIOSequentialFileFactory(folder, 10);
JournalImpl journal = new JournalImpl(100 * 1024, 2, 2, 0, 0, factory, "jrntest", "jrn", 512) {
@Override
protected SequentialFile writeControlFile(final SequentialFileFactory fileFactory, final List<JournalFile> files, final List<JournalFile> newFiles, final List<Pair<String, String>> renames) throws Exception {
if (crash) {
SequentialFile controlFile = fileFactory.createSequentialFile(AbstractJournalUpdateTask.FILE_COMPACT_CONTROL);
controlFile.open();
controlFile.close();
System.err.println("crashing after creation of control file");
System.exit(OK);
}
return JournalCompactor.writeControlFile(fileFactory, files, newFiles, renames);
}
};
journal.setAutoReclaim(false);
journal.start();
return journal;
}
use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory in project activemq-artemis by apache.
the class ActiveMQTestBase method countJournal.
/**
* 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 HashMap<Integer, AtomicInteger> countJournal(Configuration config) throws Exception {
final HashMap<Integer, AtomicInteger> recordsType = new HashMap<>();
SequentialFileFactory messagesFF = new NIOSequentialFileFactory(config.getJournalLocation(), null, 1);
JournalImpl messagesJournal = new JournalImpl(config.getJournalFileSize(), config.getJournalMinFiles(), config.getJournalPoolFiles(), 0, 0, messagesFF, "activemq-data", "amq", 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 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) {
}
}
}
Aggregations