use of org.apache.activemq.artemis.core.journal.RecordInfo in project activemq-artemis by apache.
the class NIOMultiThreadCompactorStressTest method testMultiThreadCompact.
@Test
public void testMultiThreadCompact() throws Throwable {
setupServer(getJournalType());
for (int i = 0; i < getNumberOfIterations(); i++) {
System.out.println("######################################");
System.out.println("test # " + i);
internalTestProduceAndConsume();
stopServer();
NIOSequentialFileFactory factory = new NIOSequentialFileFactory(new File(getJournalDir()), 1);
JournalImpl journal = new JournalImpl(ActiveMQDefaultConfiguration.getDefaultJournalFileSize(), 2, 2, 0, 0, factory, "activemq-data", "amq", 100);
List<RecordInfo> committedRecords = new ArrayList<>();
List<PreparedTransactionInfo> preparedTransactions = new ArrayList<>();
journal.start();
journal.load(committedRecords, preparedTransactions, null);
Assert.assertEquals(0, committedRecords.size());
Assert.assertEquals(0, preparedTransactions.size());
System.out.println("DataFiles = " + journal.getDataFilesCount());
if (i % 2 == 0 && i > 0) {
System.out.println("DataFiles = " + journal.getDataFilesCount());
journal.forceMoveNextFile();
journal.debugWait();
journal.checkReclaimStatus();
if (journal.getDataFilesCount() != 0) {
System.out.println("DebugJournal:" + journal.debug());
}
Assert.assertEquals(0, journal.getDataFilesCount());
}
journal.stop();
journal = null;
setupServer(getJournalType());
}
}
use of org.apache.activemq.artemis.core.journal.RecordInfo in project activemq-artemis by apache.
the class JournalImplTestUnit method testMultipleAddUpdateDeleteDifferentRecordLengths.
@Test
public void testMultipleAddUpdateDeleteDifferentRecordLengths() throws Exception {
setup(10, 20480, true);
createJournal();
startJournal();
load();
for (int i = 0; i < 100; i++) {
byte[] record = generateRecord(RandomUtil.randomInterval(1500, 10000));
journal.appendAddRecord(i, (byte) 0, record, false);
records.add(new RecordInfo(i, (byte) 0, record, false, (short) 0));
}
for (int i = 0; i < 100; i++) {
byte[] record = generateRecord(10 + RandomUtil.randomInterval(1500, 10000));
journal.appendUpdateRecord(i, (byte) 0, record, false);
records.add(new RecordInfo(i, (byte) 0, record, true, (short) 0));
}
for (int i = 0; i < 100; i++) {
journal.appendDeleteRecord(i, false);
removeRecordsForID(i);
}
stopJournal();
createJournal();
startJournal();
loadAndCheck();
stopJournal();
}
use of org.apache.activemq.artemis.core.journal.RecordInfo 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.core.journal.RecordInfo in project activemq-artemis by apache.
the class AlignedJournalImplTest method testAlignmentOverReload.
@Test
public void testAlignmentOverReload() throws Exception {
factory = new FakeSequentialFileFactory(512, false);
journalImpl = new JournalImpl(512 + 512 * 3, 20, 20, 0, 0, factory, "amq", "amq", 1000);
journalImpl.start();
journalImpl.load(AlignedJournalImplTest.dummyLoader);
journalImpl.appendAddRecord(1L, (byte) 0, new SimpleEncoding(100, (byte) 'a'), false);
journalImpl.appendAddRecord(2L, (byte) 0, new SimpleEncoding(100, (byte) 'b'), false);
journalImpl.appendAddRecord(3L, (byte) 0, new SimpleEncoding(100, (byte) 'b'), false);
journalImpl.appendAddRecord(4L, (byte) 0, new SimpleEncoding(100, (byte) 'b'), false);
journalImpl.stop();
journalImpl = new JournalImpl(512 + 1024 + 512, 20, 20, 0, 0, factory, "amq", "amq", 1000);
addActiveMQComponent(journalImpl);
journalImpl.start();
journalImpl.load(AlignedJournalImplTest.dummyLoader);
// It looks silly, but this forceMoveNextFile is in place to replicate one
// specific bug caught during development
journalImpl.forceMoveNextFile();
journalImpl.appendDeleteRecord(1L, false);
journalImpl.appendDeleteRecord(2L, false);
journalImpl.appendDeleteRecord(3L, false);
journalImpl.appendDeleteRecord(4L, false);
journalImpl.stop();
journalImpl = new JournalImpl(512 + 1024 + 512, 20, 20, 0, 0, factory, "amq", "amq", 1000);
addActiveMQComponent(journalImpl);
journalImpl.start();
ArrayList<RecordInfo> info = new ArrayList<>();
ArrayList<PreparedTransactionInfo> trans = new ArrayList<>();
journalImpl.load(info, trans, null);
Assert.assertEquals(0, info.size());
Assert.assertEquals(0, trans.size());
}
use of org.apache.activemq.artemis.core.journal.RecordInfo 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();
}
Aggregations