use of org.apache.activemq.artemis.core.journal.PreparedTransactionInfo in project activemq-artemis by apache.
the class JDBCJournalLoaderCallbackTest method testAddDeleteRecord.
@Test
public void testAddDeleteRecord() throws Exception {
ArrayList<RecordInfo> committedRecords = new ArrayList<>();
ArrayList<PreparedTransactionInfo> preparedTransactions = new ArrayList<>();
TransactionFailureCallback failureCallback = null;
boolean fixBadTX = false;
JDBCJournalLoaderCallback cb = new JDBCJournalLoaderCallback(committedRecords, preparedTransactions, failureCallback, fixBadTX);
RecordInfo record = new RecordInfo(42, (byte) 0, null, false, (short) 0);
cb.addRecord(record);
assertEquals(1, committedRecords.size());
assertTrue(committedRecords.contains(record));
cb.deleteRecord(record.id);
assertTrue(committedRecords.isEmpty());
}
use of org.apache.activemq.artemis.core.journal.PreparedTransactionInfo 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.PreparedTransactionInfo 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.PreparedTransactionInfo in project activemq-artemis by apache.
the class BatchIDGeneratorUnitTest method testSequence.
@Test
public void testSequence() throws Exception {
NIOSequentialFileFactory factory = new NIOSequentialFileFactory(new File(getTestDir()), 1);
Journal journal = new JournalImpl(10 * 1024, 2, 2, 0, 0, factory, "activemq-bindings", "bindings", 1);
journal.start();
journal.load(new ArrayList<RecordInfo>(), new ArrayList<PreparedTransactionInfo>(), null);
BatchingIDGenerator batch = new BatchingIDGenerator(0, 1000, getJournalStorageManager(journal));
long id1 = batch.generateID();
long id2 = batch.generateID();
Assert.assertTrue(id2 > id1);
journal.stop();
batch = new BatchingIDGenerator(0, 1000, getJournalStorageManager(journal));
loadIDs(journal, batch);
long id3 = batch.generateID();
Assert.assertEquals(1001, id3);
long id4 = batch.generateID();
Assert.assertTrue(id4 > id3 && id4 < 2000);
batch.persistCurrentID();
journal.stop();
batch = new BatchingIDGenerator(0, 1000, getJournalStorageManager(journal));
loadIDs(journal, batch);
long id5 = batch.generateID();
Assert.assertTrue(id5 > id4 && id5 < 2000);
long lastId = id5;
boolean close = true;
for (int i = 0; i < 100000; i++) {
if (i % 1000 == 0) {
// interchanging closes and simulated crashes
if (close) {
batch.persistCurrentID();
}
close = !close;
journal.stop();
batch = new BatchingIDGenerator(0, 1000, getJournalStorageManager(journal));
loadIDs(journal, batch);
}
long id = batch.generateID();
Assert.assertTrue(id > lastId);
lastId = id;
}
batch.persistCurrentID();
journal.stop();
batch = new BatchingIDGenerator(0, 1000, getJournalStorageManager(journal));
loadIDs(journal, batch);
lastId = batch.getCurrentID();
journal.stop();
batch = new BatchingIDGenerator(0, 1000, getJournalStorageManager(journal));
loadIDs(journal, batch);
Assert.assertEquals("No Ids were generated, so the currentID was supposed to stay the same", lastId, batch.getCurrentID());
journal.stop();
}
use of org.apache.activemq.artemis.core.journal.PreparedTransactionInfo in project activemq-artemis by apache.
the class CrashOnCompactTest method checkJournalSize.
private void checkJournalSize() throws Exception {
JournalImpl journal = createJournal(getTestDirfile(), false);
ArrayList<RecordInfo> info = new ArrayList<>();
ArrayList<PreparedTransactionInfo> txInfo = new ArrayList<>();
journal.load(info, txInfo, new TransactionFailureCallback() {
@Override
public void failedTransaction(long transactionID, List<RecordInfo> records, List<RecordInfo> recordsToDelete) {
}
});
Assert.assertEquals(900, info.size());
}
Aggregations