use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding in project activemq-artemis by apache.
the class JournalImplTestUnit method internaltestSpeedNonTransactional.
private void internaltestSpeedNonTransactional() throws Exception {
final long numMessages = 10000;
int numFiles = (int) ((numMessages * 1024 + 512) / (10 * 1024 * 1024) * 1.3);
if (numFiles < 2) {
numFiles = 2;
}
JournalImplTestUnit.log.debug("num Files=" + numFiles);
Journal journal = new JournalImpl(10 * 1024 * 1024, numFiles, numFiles, 0, 0, getFileFactory(), "activemq-data", "amq", 5000);
journal.start();
journal.load(new ArrayList<RecordInfo>(), null, null);
JournalImplTestUnit.log.debug("Adding data");
SimpleEncoding data = new SimpleEncoding(700, (byte) 'j');
long start = System.currentTimeMillis();
for (int i = 0; i < numMessages; i++) {
journal.appendAddRecord(i, (byte) 0, data, true);
}
long end = System.currentTimeMillis();
double rate = 1000 * (double) numMessages / (end - start);
JournalImplTestUnit.log.info("Rate " + rate + " records/sec");
journal.stop();
journal = new JournalImpl(10 * 1024 * 1024, numFiles, numFiles, 0, 0, getFileFactory(), "activemq-data", "amq", 5000);
journal.start();
journal.load(new ArrayList<RecordInfo>(), null, null);
journal.stop();
}
use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding in project activemq-artemis by apache.
the class JournalImplTestUnit method testSpeedTransactional.
@Test
public void testSpeedTransactional() throws Exception {
Journal journal = new JournalImpl(10 * 1024 * 1024, 10, 10, 0, 0, getFileFactory(), "activemq-data", "amq", 5000);
journal.start();
journal.load(new ArrayList<RecordInfo>(), null, null);
try {
final int numMessages = 50050;
SimpleEncoding data = new SimpleEncoding(1024, (byte) 'j');
long start = System.currentTimeMillis();
int count = 0;
double[] rates = new double[50];
for (int i = 0; i < 50; i++) {
long startTrans = System.currentTimeMillis();
for (int j = 0; j < 1000; j++) {
journal.appendAddRecordTransactional(i, count++, (byte) 0, data);
}
journal.appendCommitRecord(i, true);
long endTrans = System.currentTimeMillis();
rates[i] = 1000 * (double) 1000 / (endTrans - startTrans);
}
long end = System.currentTimeMillis();
for (double rate : rates) {
JournalImplTestUnit.log.info("Transaction Rate = " + rate + " records/sec");
}
double rate = 1000 * (double) numMessages / (end - start);
JournalImplTestUnit.log.info("Rate " + rate + " records/sec");
} finally {
journal.stop();
}
}
use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding in project activemq-artemis by apache.
the class AlignedJournalImplTest method testReloadWithTransaction.
@Test
public void testReloadWithTransaction() throws Exception {
final int JOURNAL_SIZE = 2000;
setupAndLoadJournal(JOURNAL_SIZE, 100);
Assert.assertEquals(0, records.size());
Assert.assertEquals(0, transactions.size());
journalImpl.appendAddRecordTransactional(1, 1, (byte) 1, new SimpleEncoding(1, (byte) 1));
setupAndLoadJournal(JOURNAL_SIZE, 100);
Assert.assertEquals(0, records.size());
Assert.assertEquals(0, transactions.size());
try {
journalImpl.appendCommitRecord(1L, true);
// This was supposed to throw an exception, as the transaction was
// forgotten (interrupted by a reload).
Assert.fail("Supposed to throw exception");
} catch (Exception e) {
UnitTestLogger.LOGGER.warn(e);
}
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 testReloadWithInterruptedTransaction.
@Test
public void testReloadWithInterruptedTransaction() throws Exception {
final int JOURNAL_SIZE = 1100;
setupAndLoadJournal(JOURNAL_SIZE, 100);
journalImpl.setAutoReclaim(false);
Assert.assertEquals(0, records.size());
Assert.assertEquals(0, transactions.size());
for (int i = 0; i < 10; i++) {
journalImpl.appendAddRecordTransactional(77L, 1, (byte) 1, new SimpleEncoding(1, (byte) 1));
journalImpl.forceMoveNextFile();
}
journalImpl.debugWait();
Assert.assertEquals(12, factory.listFiles("tt").size());
journalImpl.appendAddRecordTransactional(78L, 1, (byte) 1, new SimpleEncoding(1, (byte) 1));
Assert.assertEquals(12, factory.listFiles("tt").size());
setupAndLoadJournal(JOURNAL_SIZE, 100);
Assert.assertEquals(0, records.size());
Assert.assertEquals(0, transactions.size());
Assert.assertEquals(2, incompleteTransactions.size());
Assert.assertEquals((Long) 77L, incompleteTransactions.get(0));
Assert.assertEquals((Long) 78L, incompleteTransactions.get(1));
try {
journalImpl.appendCommitRecord(77L, true);
// This was supposed to throw an exception, as the transaction was
// forgotten (interrupted by a reload).
Assert.fail("Supposed to throw exception");
} catch (Exception e) {
UnitTestLogger.LOGGER.debug("Expected exception " + e, e);
}
setupAndLoadJournal(JOURNAL_SIZE, 100);
journalImpl.forceMoveNextFile();
journalImpl.checkReclaimStatus();
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 testAddAndDeleteReclaimWithoutTransactions.
@Test
public void testAddAndDeleteReclaimWithoutTransactions() throws Exception {
final int JOURNAL_SIZE = 10000;
setupAndLoadJournal(JOURNAL_SIZE, 1);
journalImpl.setAutoReclaim(false);
journalImpl.checkReclaimStatus();
journalImpl.debugWait();
Assert.assertEquals(2, factory.listFiles("tt").size());
UnitTestLogger.LOGGER.debug("Initial:--> " + journalImpl.debug());
UnitTestLogger.LOGGER.debug("_______________________________");
for (int i = 0; i < 50; i++) {
journalImpl.appendAddRecord(i, (byte) 1, new SimpleEncoding(1, (byte) 'x'), false);
}
// as the request to a new file is asynchronous, we need to make sure the
// async requests are done
journalImpl.debugWait();
Assert.assertEquals(2, factory.listFiles("tt").size());
for (int i = 0; i < 50; i++) {
journalImpl.appendDeleteRecord(i, false);
}
journalImpl.forceMoveNextFile();
journalImpl.appendAddRecord(1000, (byte) 1, new SimpleEncoding(1, (byte) 'x'), false);
journalImpl.debugWait();
Assert.assertEquals(3, factory.listFiles("tt").size());
setupAndLoadJournal(JOURNAL_SIZE, 1);
Assert.assertEquals(1, records.size());
Assert.assertEquals(1000, records.get(0).id);
journalImpl.checkReclaimStatus();
UnitTestLogger.LOGGER.debug(journalImpl.debug());
journalImpl.debugWait();
UnitTestLogger.LOGGER.debug("Final:--> " + journalImpl.debug());
UnitTestLogger.LOGGER.debug("_______________________________");
UnitTestLogger.LOGGER.debug("Files bufferSize:" + factory.listFiles("tt").size());
Assert.assertEquals(2, factory.listFiles("tt").size());
}
Aggregations