Search in sources :

Example 26 with SimpleEncoding

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();
}
Also used : RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) Journal(org.apache.activemq.artemis.core.journal.Journal) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl)

Example 27 with SimpleEncoding

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();
    }
}
Also used : RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) Journal(org.apache.activemq.artemis.core.journal.Journal) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Test(org.junit.Test)

Example 28 with SimpleEncoding

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());
}
Also used : SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) Test(org.junit.Test)

Example 29 with SimpleEncoding

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());
}
Also used : SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) Test(org.junit.Test)

Example 30 with SimpleEncoding

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());
}
Also used : SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) Test(org.junit.Test)

Aggregations

SimpleEncoding (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding)47 Test (org.junit.Test)43 EncodingSupport (org.apache.activemq.artemis.core.journal.EncodingSupport)13 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)7 JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)6 SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)5 ByteBuffer (java.nio.ByteBuffer)4 ArrayList (java.util.ArrayList)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)3 SequentialFileFactory (org.apache.activemq.artemis.core.io.SequentialFileFactory)2 AIOSequentialFileFactory (org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory)2 Journal (org.apache.activemq.artemis.core.journal.Journal)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Pair (org.apache.activemq.artemis.api.core.Pair)1 JournalFile (org.apache.activemq.artemis.core.journal.impl.JournalFile)1 FakeSequentialFileFactory (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory)1