use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding in project activemq-artemis by apache.
the class AlignedJournalImplTest method testEmptyPrepare.
@Test
public void testEmptyPrepare() throws Exception {
final int JOURNAL_SIZE = 512 * 4;
setupAndLoadJournal(JOURNAL_SIZE, 1);
journalImpl.appendPrepareRecord(2L, new SimpleEncoding(10, (byte) 'j'), false);
journalImpl.forceMoveNextFile();
journalImpl.appendAddRecord(1L, (byte) 0, new SimpleEncoding(10, (byte) 'k'), false);
setupAndLoadJournal(JOURNAL_SIZE, 1);
Assert.assertEquals(1, journalImpl.getDataFilesCount());
Assert.assertEquals(1, transactions.size());
journalImpl.forceMoveNextFile();
setupAndLoadJournal(JOURNAL_SIZE, 1);
Assert.assertEquals(1, journalImpl.getDataFilesCount());
Assert.assertEquals(1, transactions.size());
journalImpl.appendCommitRecord(2L, false);
journalImpl.appendDeleteRecord(1L, false);
journalImpl.forceMoveNextFile();
setupAndLoadJournal(JOURNAL_SIZE, 0);
journalImpl.forceMoveNextFile();
journalImpl.debugWait();
journalImpl.checkReclaimStatus();
Assert.assertEquals(0, transactions.size());
Assert.assertEquals(0, journalImpl.getDataFilesCount());
}
use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding in project activemq-artemis by apache.
the class AlignedJournalImplTest method testReduceFreeFiles.
@Test
public void testReduceFreeFiles() throws Exception {
final int JOURNAL_SIZE = 2000;
setupAndLoadJournal(JOURNAL_SIZE, 100, 10);
Assert.assertEquals(10, factory.listFiles("tt").size());
setupAndLoadJournal(JOURNAL_SIZE, 100, 2);
Assert.assertEquals(10, factory.listFiles("tt").size());
for (int i = 0; i < 10; i++) {
journalImpl.appendAddRecord(i, (byte) 0, new SimpleEncoding(1, (byte) 0), false);
journalImpl.forceMoveNextFile();
}
setupAndLoadJournal(JOURNAL_SIZE, 100, 2);
Assert.assertEquals(10, records.size());
Assert.assertEquals(12, factory.listFiles("tt").size());
for (int i = 0; i < 10; i++) {
journalImpl.appendDeleteRecord(i, false);
}
journalImpl.forceMoveNextFile();
journalImpl.checkReclaimStatus();
setupAndLoadJournal(JOURNAL_SIZE, 100, 2);
Assert.assertEquals(0, records.size());
Assert.assertEquals(2, factory.listFiles("tt").size());
}
use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding in project activemq-artemis by apache.
the class AlignedJournalImplTest method testReloadWithCompletedTransaction.
@Test
public void testReloadWithCompletedTransaction() throws Exception {
final int JOURNAL_SIZE = 2000;
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(1, (byte) 1));
journalImpl.forceMoveNextFile();
}
journalImpl.appendCommitRecord(1L, false);
journalImpl.debugWait();
Assert.assertEquals(12, factory.listFiles("tt").size());
setupAndLoadJournal(JOURNAL_SIZE, 100);
Assert.assertEquals(10, records.size());
Assert.assertEquals(0, transactions.size());
journalImpl.checkReclaimStatus();
Assert.assertEquals(10, journalImpl.getDataFilesCount());
Assert.assertEquals(12, factory.listFiles("tt").size());
for (int i = 0; i < 10; i++) {
journalImpl.appendDeleteRecordTransactional(2L, i);
journalImpl.forceMoveNextFile();
}
journalImpl.appendCommitRecord(2L, false);
journalImpl.appendAddRecord(100, (byte) 1, new SimpleEncoding(5, (byte) 1), false);
journalImpl.forceMoveNextFile();
journalImpl.appendAddRecord(101, (byte) 1, new SimpleEncoding(5, (byte) 1), false);
journalImpl.checkReclaimStatus();
Assert.assertEquals(1, journalImpl.getDataFilesCount());
setupAndLoadJournal(JOURNAL_SIZE, 100);
Assert.assertEquals(1, journalImpl.getDataFilesCount());
Assert.assertEquals(3, factory.listFiles("tt").size());
}
use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding in project activemq-artemis by apache.
the class AlignedJournalImplTest method testReclaimingAfterConcurrentAddsAndDeletes.
public void testReclaimingAfterConcurrentAddsAndDeletes(final boolean transactional) throws Exception {
final int JOURNAL_SIZE = 10 * 1024;
setupAndLoadJournal(JOURNAL_SIZE, 1);
Assert.assertEquals(0, records.size());
Assert.assertEquals(0, transactions.size());
final CountDownLatch latchReady = new CountDownLatch(2);
final CountDownLatch latchStart = new CountDownLatch(1);
final AtomicInteger finishedOK = new AtomicInteger(0);
final BlockingQueue<Integer> queueDelete = new LinkedBlockingQueue<>();
final int NUMBER_OF_ELEMENTS = 500;
Thread t1 = new Thread() {
@Override
public void run() {
try {
latchReady.countDown();
ActiveMQTestBase.waitForLatch(latchStart);
for (int i = 0; i < NUMBER_OF_ELEMENTS; i++) {
if (transactional) {
journalImpl.appendAddRecordTransactional(i, i, (byte) 1, new SimpleEncoding(50, (byte) 1));
journalImpl.appendCommitRecord(i, false);
} else {
journalImpl.appendAddRecord(i, (byte) 1, new SimpleEncoding(50, (byte) 1), false);
}
queueDelete.offer(i);
}
finishedOK.incrementAndGet();
} catch (Exception e) {
e.printStackTrace();
}
}
};
Thread t2 = new Thread() {
@Override
public void run() {
try {
latchReady.countDown();
ActiveMQTestBase.waitForLatch(latchStart);
for (int i = 0; i < NUMBER_OF_ELEMENTS; i++) {
Integer toDelete = queueDelete.poll(10, TimeUnit.SECONDS);
if (toDelete == null) {
break;
}
if (transactional) {
journalImpl.appendDeleteRecordTransactional(toDelete, toDelete, new SimpleEncoding(50, (byte) 1));
journalImpl.appendCommitRecord(i, false);
} else {
journalImpl.appendDeleteRecord(toDelete, false);
}
}
finishedOK.incrementAndGet();
} catch (Exception e) {
e.printStackTrace();
}
}
};
t1.start();
t2.start();
ActiveMQTestBase.waitForLatch(latchReady);
latchStart.countDown();
t1.join();
t2.join();
Assert.assertEquals(2, finishedOK.intValue());
journalImpl.debugWait();
journalImpl.forceMoveNextFile();
journalImpl.debugWait();
journalImpl.checkReclaimStatus();
Assert.assertEquals(0, journalImpl.getDataFilesCount());
Assert.assertEquals(2, factory.listFiles("tt").size());
}
use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding in project activemq-artemis by apache.
the class AlignedJournalImplTest method testReloadWithPreparedTransaction.
@Test
public void testReloadWithPreparedTransaction() throws Exception {
final int JOURNAL_SIZE = 3 * 1024;
setupAndLoadJournal(JOURNAL_SIZE, 1);
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.forceMoveNextFile();
}
journalImpl.debugWait();
SimpleEncoding xid1 = new SimpleEncoding(10, (byte) 1);
journalImpl.appendPrepareRecord(1L, xid1, false);
Assert.assertEquals(12, factory.listFiles("tt").size());
setupAndLoadJournal(JOURNAL_SIZE, 1024);
Assert.assertEquals(0, records.size());
Assert.assertEquals(1, transactions.size());
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.checkReclaimStatus();
Assert.assertEquals(10, journalImpl.getDataFilesCount());
Assert.assertEquals(12, factory.listFiles("tt").size());
journalImpl.appendCommitRecord(1L, false);
setupAndLoadJournal(JOURNAL_SIZE, 1024);
Assert.assertEquals(10, records.size());
journalImpl.checkReclaimStatus();
for (int i = 0; i < 10; i++) {
journalImpl.appendDeleteRecordTransactional(2L, i);
}
SimpleEncoding xid2 = new SimpleEncoding(15, (byte) 2);
journalImpl.appendPrepareRecord(2L, xid2, false);
setupAndLoadJournal(JOURNAL_SIZE, 1);
Assert.assertEquals(1, transactions.size());
Assert.assertEquals(15, transactions.get(0).getExtraData().length);
for (byte element : transactions.get(0).getExtraData()) {
Assert.assertEquals(2, element);
}
Assert.assertEquals(10, journalImpl.getDataFilesCount());
Assert.assertEquals(12, factory.listFiles("tt").size());
journalImpl.appendCommitRecord(2L, false);
setupAndLoadJournal(JOURNAL_SIZE, 1);
Assert.assertEquals(0, records.size());
Assert.assertEquals(0, transactions.size());
journalImpl.forceMoveNextFile();
// Reclaiming should still be able to reclaim a file if a transaction was ignored
journalImpl.checkReclaimStatus();
journalImpl.flush();
}
Aggregations