use of org.apache.activemq.artemis.core.journal.impl.JournalFile in project activemq-artemis by apache.
the class NIOJournalCompactTest method testLiveSizeTransactional.
@Test
public void testLiveSizeTransactional() throws Exception {
setup(2, 60 * 1024, true);
createJournal();
startJournal();
loadAndCheck();
ArrayList<Long> listToDelete = new ArrayList<>();
ArrayList<Integer> expectedSizes = new ArrayList<>();
for (int i = 0; i < 10; i++) {
long tx = idGenerator.generateID();
long id = idGenerator.generateID();
listToDelete.add(id);
// Append Record Transaction will make the recordSize as exactly recordLength (discounting SIZE_ADD_RECORD_TX)
addTx(tx, id);
expectedSizes.add(recordLength);
journal.forceMoveNextFile();
updateTx(tx, id);
// uPDATE Record Transaction will make the recordSize as exactly recordLength (discounting SIZE_ADD_RECORD_TX)
expectedSizes.add(recordLength);
journal.forceMoveNextFile();
expectedSizes.add(0);
commit(tx);
journal.forceMoveNextFile();
}
JournalFile[] files = journal.getDataFiles();
stopJournal();
createJournal();
startJournal();
loadAndCheck();
journal.forceMoveNextFile();
JournalFile[] files2 = journal.getDataFiles();
Assert.assertEquals(files.length, files2.length);
for (int i = 0; i < files.length; i++) {
Assert.assertEquals(expectedSizes.get(i).intValue(), files[i].getLiveSize());
Assert.assertEquals(expectedSizes.get(i).intValue(), files2[i].getLiveSize());
}
long tx = idGenerator.generateID();
for (long id : listToDelete) {
deleteTx(tx, id);
}
commit(tx);
journal.forceMoveNextFile();
JournalFile[] files3 = journal.getDataFiles();
for (JournalFile file : files3) {
Assert.assertEquals(0, file.getLiveSize());
}
stopJournal();
createJournal();
startJournal();
loadAndCheck();
files3 = journal.getDataFiles();
for (JournalFile file : files3) {
Assert.assertEquals(0, file.getLiveSize());
}
}
use of org.apache.activemq.artemis.core.journal.impl.JournalFile 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;
}
Aggregations