Search in sources :

Example 1 with IOCriticalErrorListener

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

the class ShutdownOnCriticalIOErrorMoveNextTest method createServer.

ActiveMQServer createServer(String folder) throws Exception {
    final AtomicBoolean blocked = new AtomicBoolean(false);
    Configuration conf = createConfig(folder);
    ActiveMQSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), new SecurityConfiguration());
    conf.setPersistenceEnabled(true);
    ActiveMQServer server = new ActiveMQServerImpl(conf, securityManager) {

        @Override
        protected StorageManager createStorageManager() {
            JournalStorageManager storageManager = new JournalStorageManager(conf, getCriticalAnalyzer(), executorFactory, scheduledPool, ioExecutorFactory, shutdownOnCriticalIO) {

                @Override
                protected Journal createMessageJournal(Configuration config, IOCriticalErrorListener criticalErrorListener, int fileSize) {
                    return new JournalImpl(ioExecutorFactory, fileSize, config.getJournalMinFiles(), config.getJournalPoolFiles(), config.getJournalCompactMinFiles(), config.getJournalCompactPercentage(), config.getJournalFileOpenTimeout(), journalFF, "activemq-data", "amq", journalFF.getMaxIO(), 0, criticalErrorListener) {

                        @Override
                        protected void moveNextFile(boolean scheduleReclaim) throws Exception {
                            super.moveNextFile(scheduleReclaim);
                            if (blocked.get()) {
                                throw new IllegalStateException("forcibly down");
                            }
                        }
                    };
                }

                @Override
                public void storeMessage(Message message) throws Exception {
                    super.storeMessage(message);
                    blocked.set(true);
                }
            };
            this.getCriticalAnalyzer().add(storageManager);
            return storageManager;
        }
    };
    return server;
}
Also used : IOCriticalErrorListener(org.apache.activemq.artemis.core.io.IOCriticalErrorListener) Configuration(org.apache.activemq.artemis.core.config.Configuration) SecurityConfiguration(org.apache.activemq.artemis.core.config.impl.SecurityConfiguration) Message(org.apache.activemq.artemis.api.core.Message) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) InVMLoginModule(org.apache.activemq.artemis.spi.core.security.jaas.InVMLoginModule) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) SecurityConfiguration(org.apache.activemq.artemis.core.config.impl.SecurityConfiguration) ActiveMQSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl)

Example 2 with IOCriticalErrorListener

use of org.apache.activemq.artemis.core.io.IOCriticalErrorListener 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 3 with IOCriticalErrorListener

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

the class JDBCSequentialFileFactoryTest method setup.

@Before
public void setup() throws Exception {
    executor = Executors.newSingleThreadExecutor(ActiveMQThreadFactory.defaultThreadFactory());
    String connectionUrl = "jdbc:derby:target/data;create=true";
    String tableName = "FILES";
    factory = new JDBCSequentialFileFactory(connectionUrl, className, JDBCUtils.getSQLProvider(className, tableName, SQLProvider.DatabaseStoreType.PAGE), executor, new IOCriticalErrorListener() {

        @Override
        public void onIOException(Throwable code, String message, SequentialFile file) {
        }
    });
    factory.start();
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) JDBCSequentialFile(org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFile) IOCriticalErrorListener(org.apache.activemq.artemis.core.io.IOCriticalErrorListener) JDBCSequentialFileFactory(org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFileFactory) Before(org.junit.Before)

Example 4 with IOCriticalErrorListener

use of org.apache.activemq.artemis.core.io.IOCriticalErrorListener 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

IOCriticalErrorListener (org.apache.activemq.artemis.core.io.IOCriticalErrorListener)4 SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)3 Before (org.junit.Before)2 File (java.io.File)1 ByteBuffer (java.nio.ByteBuffer)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)1 Message (org.apache.activemq.artemis.api.core.Message)1 Configuration (org.apache.activemq.artemis.core.config.Configuration)1 SecurityConfiguration (org.apache.activemq.artemis.core.config.impl.SecurityConfiguration)1 NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)1 EncodingSupport (org.apache.activemq.artemis.core.journal.EncodingSupport)1 JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)1 JournalStorageManager (org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager)1 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)1 ActiveMQServerImpl (org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl)1 JDBCSequentialFile (org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFile)1 JDBCSequentialFileFactory (org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFileFactory)1