Search in sources :

Example 11 with EncodingSupport

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

the class NIOSequentialFileFactoryTest method testInterrupts.

@Test
public void testInterrupts() throws Throwable {
    final EncodingSupport fakeEncoding = new EncodingSupport() {

        @Override
        public int getEncodeSize() {
            return 10;
        }

        @Override
        public void encode(ActiveMQBuffer buffer) {
            buffer.writeBytes(new byte[10]);
        }

        @Override
        public void decode(ActiveMQBuffer buffer) {
        }
    };
    final AtomicInteger calls = new AtomicInteger(0);
    final NIOSequentialFileFactory factory = new NIOSequentialFileFactory(new File(getTestDir()), new IOCriticalErrorListener() {

        @Override
        public void onIOException(Throwable code, String message, SequentialFile file) {
            new Exception("shutdown").printStackTrace();
            calls.incrementAndGet();
        }
    }, 1);
    Thread threadOpen = new Thread() {

        @Override
        public void run() {
            try {
                Thread.currentThread().interrupt();
                SequentialFile file = factory.createSequentialFile("file.txt");
                file.open();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    threadOpen.start();
    threadOpen.join();
    Thread threadClose = new Thread() {

        @Override
        public void run() {
            try {
                SequentialFile file = factory.createSequentialFile("file.txt");
                file.open();
                file.write(fakeEncoding, true);
                Thread.currentThread().interrupt();
                file.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    threadClose.start();
    threadClose.join();
    Thread threadWrite = new Thread() {

        @Override
        public void run() {
            try {
                SequentialFile file = factory.createSequentialFile("file.txt");
                file.open();
                Thread.currentThread().interrupt();
                file.write(fakeEncoding, true);
                file.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    threadWrite.start();
    threadWrite.join();
    Thread threadFill = new Thread() {

        @Override
        public void run() {
            try {
                SequentialFile file = factory.createSequentialFile("file.txt");
                file.open();
                Thread.currentThread().interrupt();
                file.fill(1024);
                file.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    threadFill.start();
    threadFill.join();
    Thread threadWriteDirect = new Thread() {

        @Override
        public void run() {
            try {
                SequentialFile file = factory.createSequentialFile("file.txt");
                file.open();
                ByteBuffer buffer = ByteBuffer.allocate(10);
                buffer.put(new byte[10]);
                Thread.currentThread().interrupt();
                file.writeDirect(buffer, true);
                file.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    threadWriteDirect.start();
    threadWriteDirect.join();
    Thread threadRead = new Thread() {

        @Override
        public void run() {
            try {
                SequentialFile file = factory.createSequentialFile("file.txt");
                file.open();
                file.write(fakeEncoding, true);
                file.position(0);
                ByteBuffer readBytes = ByteBuffer.allocate(fakeEncoding.getEncodeSize());
                Thread.currentThread().interrupt();
                file.read(readBytes);
                file.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    threadRead.start();
    threadRead.join();
    // An interrupt exception shouldn't issue a shutdown
    Assert.assertEquals(0, calls.get());
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) IOCriticalErrorListener(org.apache.activemq.artemis.core.io.IOCriticalErrorListener) ByteBuffer(java.nio.ByteBuffer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) File(java.io.File) EncodingSupport(org.apache.activemq.artemis.core.journal.EncodingSupport) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) Test(org.junit.Test)

Example 12 with EncodingSupport

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

the class JournalImplTestUnit method testXASimpleCommit.

@Test
public void testXASimpleCommit() throws Exception {
    setup(10, 10 * 1024, true);
    createJournal();
    startJournal();
    load();
    addTx(1, 1, 2, 3, 4, 5, 6, 7, 8, 9);
    updateTx(1, 1, 2, 3, 4, 7, 8);
    deleteTx(1, 1, 2, 3, 4, 5);
    EncodingSupport xid = new SimpleEncoding(10, (byte) 0);
    prepare(1, xid);
    commit(1);
    stopJournal();
    createJournal();
    startJournal();
    loadAndCheck();
}
Also used : SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) EncodingSupport(org.apache.activemq.artemis.core.journal.EncodingSupport) Test(org.junit.Test)

Example 13 with EncodingSupport

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

the class JournalImplTestUnit method testSimpleAddTXXAReload.

@Test
public void testSimpleAddTXXAReload() throws Exception {
    setup(2, 10 * 1024, true);
    createJournal();
    startJournal();
    load();
    addTx(1, 1);
    EncodingSupport xid = new SimpleEncoding(10, (byte) 'p');
    prepare(1, xid);
    stopJournal();
    createJournal();
    startJournal();
    loadAndCheck();
}
Also used : SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) EncodingSupport(org.apache.activemq.artemis.core.journal.EncodingSupport) Test(org.junit.Test)

Example 14 with EncodingSupport

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

the class JournalImplTestUnit method testXASimpleRollback.

@Test
public void testXASimpleRollback() throws Exception {
    setup(10, 10 * 1024, true);
    createJournal();
    startJournal();
    load();
    addTx(1, 1, 2, 3, 4, 5, 6, 7, 8, 9);
    updateTx(1, 1, 2, 3, 4, 7, 8);
    deleteTx(1, 1, 2, 3, 4, 5);
    EncodingSupport xid = new SimpleEncoding(10, (byte) 0);
    prepare(1, xid);
    rollback(1);
    stopJournal();
    createJournal();
    startJournal();
    loadAndCheck();
}
Also used : SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) EncodingSupport(org.apache.activemq.artemis.core.journal.EncodingSupport) Test(org.junit.Test)

Example 15 with EncodingSupport

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

the class JournalImplTestUnit method testXAMultiple.

@Test
public void testXAMultiple() throws Exception {
    setup(10, 10 * 1024, true);
    createJournal();
    startJournal();
    load();
    add(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    addTx(1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20);
    addTx(2, 21, 22, 23, 24, 25, 26, 27);
    updateTx(1, 1, 3, 6, 11, 14, 17);
    addTx(3, 28, 29, 30, 31, 32, 33, 34, 35);
    updateTx(3, 7, 8, 9, 10);
    deleteTx(2, 4, 5, 6, 23, 25, 27);
    EncodingSupport xid = new SimpleEncoding(10, (byte) 0);
    prepare(2, xid);
    deleteTx(1, 1, 2, 11, 14, 15);
    prepare(1, xid);
    deleteTx(3, 28, 31, 32, 9);
    prepare(3, xid);
    commit(1);
    rollback(2);
    commit(3);
}
Also used : SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) EncodingSupport(org.apache.activemq.artemis.core.journal.EncodingSupport) Test(org.junit.Test)

Aggregations

EncodingSupport (org.apache.activemq.artemis.core.journal.EncodingSupport)19 Test (org.junit.Test)15 SimpleEncoding (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding)13 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)6 File (java.io.File)4 MappedSequentialFileFactory (org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory)3 NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)3 ByteBuffer (java.nio.ByteBuffer)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)2 AIOSequentialFileFactory (org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory)2 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)2 MpscArrayQueue (io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueue)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 ActiveMQExceptionType (org.apache.activemq.artemis.api.core.ActiveMQExceptionType)1 Message (org.apache.activemq.artemis.api.core.Message)1 IOCriticalErrorListener (org.apache.activemq.artemis.core.io.IOCriticalErrorListener)1 IOCompletion (org.apache.activemq.artemis.core.journal.IOCompletion)1