use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding in project activemq-artemis by apache.
the class AlignedJournalImplTest method testCommitWithMultipleFiles.
@Test
public void testCommitWithMultipleFiles() throws Exception {
final int JOURNAL_SIZE = 20000;
setupAndLoadJournal(JOURNAL_SIZE, 100);
Assert.assertEquals(0, records.size());
Assert.assertEquals(0, transactions.size());
for (int i = 0; i < 50; i++) {
if (i == 10) {
journalImpl.forceMoveNextFile();
}
journalImpl.appendAddRecordTransactional(1L, i, (byte) 0, new SimpleEncoding(1, (byte) 15));
}
journalImpl.appendCommitRecord(1L, false);
for (int i = 0; i < 10; i++) {
if (i == 5) {
journalImpl.forceMoveNextFile();
}
journalImpl.appendDeleteRecordTransactional(2L, i);
}
journalImpl.appendCommitRecord(2L, false);
journalImpl.forceMoveNextFile();
journalImpl.checkReclaimStatus();
setupAndLoadJournal(JOURNAL_SIZE, 100);
Assert.assertEquals(40, 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 testReloadInvalidPrepared.
@Test
public void testReloadInvalidPrepared() throws Exception {
final int JOURNAL_SIZE = 3000;
setupAndLoadJournal(JOURNAL_SIZE, 100);
Assert.assertEquals(0, records.size());
Assert.assertEquals(0, transactions.size());
for (int i = 0; i < 10; i++) {
journalImpl.appendAddRecordTransactional(1, i, (byte) 1, new SimpleEncoding(50, (byte) 1));
}
journalImpl.appendPrepareRecord(1L, new SimpleEncoding(13, (byte) 0), false);
setupAndLoadJournal(JOURNAL_SIZE, 100);
Assert.assertEquals(0, records.size());
Assert.assertEquals(1, transactions.size());
SequentialFile file = factory.createSequentialFile("tt-1.tt");
file.open();
ByteBuffer buffer = ByteBuffer.allocate(100);
// Messing up with the first record (removing the position)
file.position(100);
file.read(buffer);
buffer.position(1);
buffer.putInt(-1);
buffer.rewind();
// Messing up with the first record (changing the fileID, so Journal
// reload will think the record came from a different journal usage)
file.position(100);
file.writeDirect(buffer, true);
file.close();
setupAndLoadJournal(JOURNAL_SIZE, 100);
Assert.assertEquals(0, records.size());
Assert.assertEquals(0, transactions.size());
}
use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding in project activemq-artemis by apache.
the class AlignedJournalImplTest method testAppendAndUpdateRecords.
@Test
public void testAppendAndUpdateRecords() throws Exception {
final int JOURNAL_SIZE = 1060;
setupAndLoadJournal(JOURNAL_SIZE, 10);
Assert.assertEquals(0, records.size());
Assert.assertEquals(0, transactions.size());
for (int i = 0; i < 25; i++) {
byte[] bytes = new byte[5];
for (int j = 0; j < bytes.length; j++) {
bytes[j] = (byte) i;
}
journalImpl.appendAddRecord(i * 100L, (byte) i, bytes, false);
}
for (int i = 25; i < 50; i++) {
EncodingSupport support = new SimpleEncoding(5, (byte) i);
journalImpl.appendAddRecord(i * 100L, (byte) i, support, false);
}
setupAndLoadJournal(JOURNAL_SIZE, 1024);
Assert.assertEquals(50, records.size());
int i = 0;
for (RecordInfo recordItem : records) {
Assert.assertEquals(i * 100L, recordItem.id);
Assert.assertEquals(i, recordItem.getUserRecordType());
Assert.assertEquals(5, recordItem.data.length);
for (int j = 0; j < 5; j++) {
Assert.assertEquals((byte) i, recordItem.data[j]);
}
i++;
}
for (i = 40; i < 50; i++) {
byte[] bytes = new byte[10];
for (int j = 0; j < 10; j++) {
bytes[j] = (byte) 'x';
}
journalImpl.appendUpdateRecord(i * 100L, (byte) i, bytes, false);
}
setupAndLoadJournal(JOURNAL_SIZE, 1024);
i = 0;
for (RecordInfo recordItem : records) {
if (i < 50) {
Assert.assertEquals(i * 100L, recordItem.id);
Assert.assertEquals(i, recordItem.getUserRecordType());
Assert.assertEquals(5, recordItem.data.length);
for (int j = 0; j < 5; j++) {
Assert.assertEquals((byte) i, recordItem.data[j]);
}
} else {
Assert.assertEquals((i - 10) * 100L, recordItem.id);
Assert.assertEquals(i - 10, recordItem.getUserRecordType());
Assert.assertTrue(recordItem.isUpdate);
Assert.assertEquals(10, recordItem.data.length);
for (int j = 0; j < 10; j++) {
Assert.assertEquals((byte) 'x', recordItem.data[j]);
}
}
i++;
}
journalImpl.stop();
}
use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding in project activemq-artemis by apache.
the class AlignedJournalImplTest method testTotalSize.
@Test
public void testTotalSize() throws Exception {
final int JOURNAL_SIZE = 2000;
setupAndLoadJournal(JOURNAL_SIZE, 100);
Assert.assertEquals(0, records.size());
Assert.assertEquals(0, transactions.size());
journalImpl.appendAddRecordTransactional(1L, 2L, (byte) 3, new SimpleEncoding(1900 - JournalImpl.SIZE_ADD_RECORD_TX - 1, (byte) 4));
journalImpl.appendCommitRecord(1L, false);
journalImpl.debugWait();
setupAndLoadJournal(JOURNAL_SIZE, 100);
Assert.assertEquals(1, 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 testDecreaseAlignment.
// It should be ok to write records on AIO, and later read then on NIO
@Test
public void testDecreaseAlignment() throws Exception {
final int JOURNAL_SIZE = 512 * 4;
setupAndLoadJournal(JOURNAL_SIZE, 512);
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, 1);
Assert.assertEquals(10, records.size());
}
Aggregations