Search in sources :

Example 1 with IOCompletion

use of org.apache.activemq.artemis.core.journal.IOCompletion in project activemq-artemis by apache.

the class JournalImpl method runDirectJournalBlast.

@Override
public void runDirectJournalBlast() throws Exception {
    final int numIts = 100000000;
    ActiveMQJournalLogger.LOGGER.runningJournalBlast(numIts);
    final CountDownLatch latch = new CountDownLatch(numIts * 2);
    class MyAIOCallback implements IOCompletion {

        @Override
        public void done() {
            latch.countDown();
        }

        @Override
        public void onError(final int errorCode, final String errorMessage) {
        }

        @Override
        public void storeLineUp() {
        }
    }
    final MyAIOCallback task = new MyAIOCallback();
    final int recordSize = 1024;
    final byte[] bytes = new byte[recordSize];
    class MyRecord implements EncodingSupport {

        @Override
        public void decode(final ActiveMQBuffer buffer) {
        }

        @Override
        public void encode(final ActiveMQBuffer buffer) {
            buffer.writeBytes(bytes);
        }

        @Override
        public int getEncodeSize() {
            return recordSize;
        }
    }
    MyRecord record = new MyRecord();
    for (int i = 0; i < numIts; i++) {
        appendAddRecord(i, (byte) 1, record, true, task);
        appendDeleteRecord(i, true, task);
    }
    latch.await();
}
Also used : IOCompletion(org.apache.activemq.artemis.core.journal.IOCompletion) CountDownLatch(java.util.concurrent.CountDownLatch) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) EncodingSupport(org.apache.activemq.artemis.core.journal.EncodingSupport)

Example 2 with IOCompletion

use of org.apache.activemq.artemis.core.journal.IOCompletion in project activemq-artemis by apache.

the class JDBCJournalTest method testCallbacks.

@Test
public void testCallbacks() throws Exception {
    final int noRecords = 10;
    final CountDownLatch done = new CountDownLatch(noRecords);
    IOCompletion completion = new IOCompletion() {

        @Override
        public void storeLineUp() {
        }

        @Override
        public void done() {
            done.countDown();
        }

        @Override
        public void onError(int errorCode, String errorMessage) {
        }
    };
    for (int i = 0; i < noRecords; i++) {
        journal.appendAddRecord(1, (byte) 1, new FakeEncodingSupportImpl(new byte[0]), true, completion);
    }
    journal.sync();
    done.await(5, TimeUnit.SECONDS);
    assertEquals(done.getCount(), 0);
}
Also used : IOCompletion(org.apache.activemq.artemis.core.journal.IOCompletion) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)2 IOCompletion (org.apache.activemq.artemis.core.journal.IOCompletion)2 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)1 EncodingSupport (org.apache.activemq.artemis.core.journal.EncodingSupport)1 Test (org.junit.Test)1