use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding in project activemq-artemis by apache.
the class JournalImplTestUnit method testEmptyPrepare.
@Test
public void testEmptyPrepare() throws Exception {
setup(2, calculateRecordSize(JournalImpl.SIZE_HEADER, getAlignment()) + calculateRecordSize(recordLength, getAlignment()) + 512, true);
createJournal();
startJournal();
load();
EncodingSupport xid = new SimpleEncoding(10, (byte) 0);
prepare(1, xid);
stopJournal();
createJournal();
startJournal();
loadAndCheck();
commit(1);
xid = new SimpleEncoding(10, (byte) 1);
prepare(2, xid);
stopJournal();
createJournal();
startJournal();
loadAndCheck();
rollback(2);
stopJournal();
createJournal();
startJournal();
loadAndCheck();
}
use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding in project activemq-artemis by apache.
the class JournalImplTestUnit method testXAChangesisibleCommit.
@Test
public void testXAChangesisibleCommit() throws Exception {
setup(10, 10 * 1024, true);
createJournal();
startJournal();
load();
add(1, 2, 3, 4, 5, 6);
addTx(1, 7, 8, 9, 10);
updateTx(1, 1, 2, 3, 7, 8, 9);
deleteTx(1, 1, 2, 3, 4, 5);
EncodingSupport xid = new SimpleEncoding(10, (byte) 0);
prepare(1, xid);
commit(1);
stopJournal();
createJournal();
startJournal();
loadAndCheck();
}
use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding in project activemq-artemis by apache.
the class JournalImplTestUnit method testPrepareNoReclaim.
@Test
public void testPrepareNoReclaim() throws Exception {
setup(2, calculateRecordSize(JournalImpl.SIZE_HEADER, getAlignment()) + calculateRecordSize(recordLength, getAlignment()) + 512, true);
createJournal();
startJournal();
load();
List<String> files1 = fileFactory.listFiles(fileExtension);
Assert.assertEquals(2, files1.size());
Assert.assertEquals(0, journal.getDataFilesCount());
Assert.assertEquals(0, journal.getFreeFilesCount());
Assert.assertEquals(1, journal.getOpenedFilesCount());
Assert.assertEquals(0, journal.getIDMapSize());
// in file 0
addTx(1, 1);
// Make sure we move on to the next file
// in file 1
addWithSize(1024 - JournalImpl.SIZE_ADD_RECORD, 2);
List<String> files2 = fileFactory.listFiles(fileExtension);
Assert.assertEquals(3, files2.size());
Assert.assertEquals(calculateNumberOfFiles(journal, fileSize, journal.getAlignment(), 2, recordLength), journal.getDataFilesCount());
Assert.assertEquals(0, journal.getFreeFilesCount());
Assert.assertEquals(1, journal.getOpenedFilesCount());
Assert.assertEquals(1, journal.getIDMapSize());
EncodingSupport xid = new SimpleEncoding(10, (byte) 0);
// in file 1
prepare(1, xid);
Assert.assertEquals(0, journal.getFreeFilesCount());
Assert.assertEquals(1, journal.getIDMapSize());
Assert.assertEquals(1, journal.getOpenedFilesCount());
// in file 1
delete(2);
Assert.assertEquals(1, journal.getOpenedFilesCount());
Assert.assertEquals(0, journal.getFreeFilesCount());
Assert.assertEquals(0, journal.getIDMapSize());
// Move on to another file
// in file 2
addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD - 1, 3);
Assert.assertEquals(1, journal.getOpenedFilesCount());
Assert.assertEquals(0, journal.getFreeFilesCount());
Assert.assertEquals(1, journal.getIDMapSize());
checkAndReclaimFiles();
List<String> files6 = fileFactory.listFiles(fileExtension);
Assert.assertEquals(4, files6.size());
Assert.assertEquals(2, journal.getDataFilesCount());
Assert.assertEquals(0, journal.getFreeFilesCount());
Assert.assertEquals(1, journal.getOpenedFilesCount());
Assert.assertEquals(1, journal.getIDMapSize());
// in file 3
addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD - 1, 4);
List<String> files7 = fileFactory.listFiles(fileExtension);
Assert.assertEquals(5, files7.size());
Assert.assertEquals(3, journal.getDataFilesCount());
Assert.assertEquals(0, journal.getFreeFilesCount());
Assert.assertEquals(1, journal.getOpenedFilesCount());
Assert.assertEquals(2, journal.getIDMapSize());
// in file 4
commit(1);
List<String> files8 = fileFactory.listFiles(fileExtension);
Assert.assertEquals(5, files8.size());
Assert.assertEquals(3, journal.getDataFilesCount());
Assert.assertEquals(0, journal.getFreeFilesCount());
Assert.assertEquals(1, journal.getOpenedFilesCount());
Assert.assertEquals(3, journal.getIDMapSize());
// Restart
stopJournal();
createJournal();
startJournal();
loadAndCheck();
}
use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding in project activemq-artemis by apache.
the class AlignedJournalImplTest method testSimplePrepare.
@Test
public void testSimplePrepare() throws Exception {
final int JOURNAL_SIZE = 3 * 1024;
setupAndLoadJournal(JOURNAL_SIZE, 1);
Assert.assertEquals(0, records.size());
Assert.assertEquals(0, transactions.size());
SimpleEncoding xid = new SimpleEncoding(10, (byte) 1);
journalImpl.appendAddRecord(10L, (byte) 0, new SimpleEncoding(10, (byte) 0), false);
journalImpl.appendDeleteRecordTransactional(1L, 10L, new SimpleEncoding(100, (byte) 'j'));
journalImpl.appendPrepareRecord(1, xid, false);
journalImpl.debugWait();
setupAndLoadJournal(JOURNAL_SIZE, 1);
Assert.assertEquals(1, transactions.size());
Assert.assertEquals(1, transactions.get(0).getRecordsToDelete().size());
Assert.assertEquals(1, records.size());
for (RecordInfo record : transactions.get(0).getRecordsToDelete()) {
byte[] data = record.data;
Assert.assertEquals(100, data.length);
for (byte element : data) {
Assert.assertEquals((byte) 'j', element);
}
}
Assert.assertEquals(10, transactions.get(0).getExtraData().length);
for (int i = 0; i < 10; i++) {
Assert.assertEquals((byte) 1, transactions.get(0).getExtraData()[i]);
}
journalImpl.appendCommitRecord(1L, false);
journalImpl.debugWait();
setupAndLoadJournal(JOURNAL_SIZE, 1);
Assert.assertEquals(0, transactions.size());
Assert.assertEquals(0, records.size());
}
use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding in project activemq-artemis by apache.
the class AlignedJournalImplTest method testIncreaseAlignment.
// It should be ok to write records on NIO, and later read then on AIO
@Test
public void testIncreaseAlignment() throws Exception {
final int JOURNAL_SIZE = 512 * 4;
setupAndLoadJournal(JOURNAL_SIZE, 1);
for (int i = 0; i < 10; i++) {
journalImpl.appendAddRecordTransactional(1L, i, (byte) 0, new SimpleEncoding(1, (byte) 0));
}
journalImpl.appendCommitRecord(1L, false);
setupAndLoadJournal(JOURNAL_SIZE, 100);
Assert.assertEquals(10, records.size());
setupAndLoadJournal(JOURNAL_SIZE, 512);
Assert.assertEquals(10, records.size());
}
Aggregations