Search in sources :

Example 51 with SequentialFile

use of org.apache.activemq.artemis.core.io.SequentialFile in project activemq-artemis by apache.

the class CrashOnCompactTest method createJournal.

private static JournalImpl createJournal(File folder, boolean crash) throws Exception {
    NIOSequentialFileFactory factory = new NIOSequentialFileFactory(folder, 10);
    JournalImpl journal = new JournalImpl(100 * 1024, 2, 2, 0, 0, factory, "jrntest", "jrn", 512) {

        @Override
        protected SequentialFile writeControlFile(final SequentialFileFactory fileFactory, final List<JournalFile> files, final List<JournalFile> newFiles, final List<Pair<String, String>> renames) throws Exception {
            if (crash) {
                SequentialFile controlFile = fileFactory.createSequentialFile(AbstractJournalUpdateTask.FILE_COMPACT_CONTROL);
                controlFile.open();
                controlFile.close();
                System.err.println("crashing after creation of control file");
                System.exit(OK);
            }
            return JournalCompactor.writeControlFile(fileFactory, files, newFiles, renames);
        }
    };
    journal.setAutoReclaim(false);
    journal.start();
    return journal;
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) ArrayList(java.util.ArrayList) List(java.util.List) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl)

Example 52 with SequentialFile

use of org.apache.activemq.artemis.core.io.SequentialFile in project activemq-artemis by apache.

the class MappedSequentialFileFactoryTest 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 MappedSequentialFileFactory factory = new MappedSequentialFileFactory(new File(getTestDir()), fakeEncoding.getEncodeSize(), false, 0, 0, (code, message, file) -> {
        new Exception("shutdown").printStackTrace();
        calls.incrementAndGet();
    });
    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(fakeEncoding.getEncodeSize());
                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) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MappedSequentialFileFactory(org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory) SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) File(java.io.File) ByteBuffer(java.nio.ByteBuffer) EncodingSupport(org.apache.activemq.artemis.core.journal.EncodingSupport) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 53 with SequentialFile

use of org.apache.activemq.artemis.core.io.SequentialFile in project activemq-artemis by apache.

the class JDBCJournalTest method setup.

@Before
public void setup() throws Exception {
    scheduledExecutorService = new ScheduledThreadPoolExecutor(5);
    executorService = Executors.newSingleThreadExecutor();
    jdbcUrl = "jdbc:derby:target/data;create=true";
    SQLProvider.Factory factory = new PropertySQLProvider.Factory(DERBY);
    journal = new JDBCJournalImpl(jdbcUrl, DRIVER_CLASS, factory.create(JOURNAL_TABLE_NAME, SQLProvider.DatabaseStoreType.MESSAGE_JOURNAL), scheduledExecutorService, executorService, new IOCriticalErrorListener() {

        @Override
        public void onIOException(Throwable code, String message, SequentialFile file) {
        }
    }, 5);
    journal.start();
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) IOCriticalErrorListener(org.apache.activemq.artemis.core.io.IOCriticalErrorListener) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) JDBCJournalImpl(org.apache.activemq.artemis.jdbc.store.journal.JDBCJournalImpl) SQLProvider(org.apache.activemq.artemis.jdbc.store.sql.SQLProvider) PropertySQLProvider(org.apache.activemq.artemis.jdbc.store.sql.PropertySQLProvider) Before(org.junit.Before)

Aggregations

SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)53 Test (org.junit.Test)21 ByteBuffer (java.nio.ByteBuffer)15 ArrayList (java.util.ArrayList)10 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)9 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)7 Pair (org.apache.activemq.artemis.api.core.Pair)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 SequentialFileFactory (org.apache.activemq.artemis.core.io.SequentialFileFactory)4 NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)4 Page (org.apache.activemq.artemis.core.paging.impl.Page)4 JDBCSequentialFile (org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFile)4 SimpleEncoding (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding)4 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)3 IOCriticalErrorListener (org.apache.activemq.artemis.core.io.IOCriticalErrorListener)3 PagedMessage (org.apache.activemq.artemis.core.paging.PagedMessage)3 File (java.io.File)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 CountDownLatch (java.util.concurrent.CountDownLatch)2