Search in sources :

Example 16 with JournalStorageManager

use of org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager in project activemq-artemis by apache.

the class RestartSMTest method testRestartStorageManager.

@Test
public void testRestartStorageManager() throws Exception {
    File testdir = new File(getTestDir());
    deleteDirectory(testdir);
    PostOffice postOffice = new FakePostOffice();
    final JournalStorageManager journal = new JournalStorageManager(createDefaultInVMConfig(), EmptyCriticalAnalyzer.getInstance(), execFactory, execFactory);
    try {
        journal.start();
        List<QueueBindingInfo> queueBindingInfos = new ArrayList<>();
        journal.loadBindingJournal(queueBindingInfos, new ArrayList<GroupingInfo>(), new ArrayList<AddressBindingInfo>());
        journal.loadMessageJournal(postOffice, null, null, null, null, null, null, new FakeJournalLoader());
        journal.stop();
        deleteDirectory(testdir);
        journal.start();
        journal.loadMessageJournal(postOffice, null, null, null, null, null, null, new FakeJournalLoader());
        queueBindingInfos = new ArrayList<>();
        journal.loadBindingJournal(queueBindingInfos, new ArrayList<GroupingInfo>(), new ArrayList<AddressBindingInfo>());
        journal.start();
    } finally {
        try {
            journal.stop();
        } catch (Exception ex) {
            RestartSMTest.log.warn(ex.getMessage(), ex);
        }
    }
}
Also used : GroupingInfo(org.apache.activemq.artemis.core.persistence.GroupingInfo) ArrayList(java.util.ArrayList) FakePostOffice(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakePostOffice) PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice) QueueBindingInfo(org.apache.activemq.artemis.core.persistence.QueueBindingInfo) FakePostOffice(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakePostOffice) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) FakeJournalLoader(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeJournalLoader) AddressBindingInfo(org.apache.activemq.artemis.core.persistence.AddressBindingInfo) File(java.io.File) Test(org.junit.Test)

Example 17 with JournalStorageManager

use of org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager in project activemq-artemis by apache.

the class MessageJournalTest method testStoreAMQP.

@Test
public void testStoreAMQP() throws Throwable {
    ActiveMQServer server = createServer(true);
    server.start();
    ProtonProtocolManagerFactory factory = (ProtonProtocolManagerFactory) server.getRemotingService().getProtocolFactoryMap().get("AMQP");
    Message protonJMessage = Message.Factory.create();
    AMQPMessage message = new AMQPMessage(protonJMessage);
    message.setMessageID(333);
    Assert.assertNotNull(factory);
    server.getStorageManager().storeMessage(message);
    server.getStorageManager().stop();
    JournalStorageManager journalStorageManager = (JournalStorageManager) server.getStorageManager();
    List<RecordInfo> committedRecords = new LinkedList<>();
    List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
    TransactionFailureCallback transactionFailure = new TransactionFailureCallback() {

        @Override
        public void failedTransaction(long transactionID, List<RecordInfo> records, List<RecordInfo> recordsToDelete) {
        }
    };
    try {
        journalStorageManager.getMessageJournal().start();
        journalStorageManager.getMessageJournal().load(committedRecords, preparedTransactions, transactionFailure);
        Assert.assertEquals(1, committedRecords.size());
    } finally {
        journalStorageManager.getMessageJournal().stop();
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) Message(org.apache.qpid.proton.message.Message) ProtonProtocolManagerFactory(org.apache.activemq.artemis.protocol.amqp.broker.ProtonProtocolManagerFactory) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) List(java.util.List) LinkedList(java.util.LinkedList) TransactionFailureCallback(org.apache.activemq.artemis.core.journal.TransactionFailureCallback) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) LinkedList(java.util.LinkedList) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) Test(org.junit.Test)

Example 18 with JournalStorageManager

use of org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager in project activemq-artemis by apache.

the class MessageJournalTest method testStoreCore.

@Test
public void testStoreCore() throws Throwable {
    ActiveMQServer server = createServer(true);
    server.start();
    CoreMessage message = new CoreMessage().initBuffer(10 * 1024).setDurable(true);
    message.setMessageID(333);
    CoreProtocolManagerFactory factory = (CoreProtocolManagerFactory) server.getRemotingService().getProtocolFactoryMap().get("CORE");
    Assert.assertNotNull(factory);
    message.getBodyBuffer().writeByte((byte) 'Z');
    server.getStorageManager().storeMessage(message);
    server.getStorageManager().stop();
    JournalStorageManager journalStorageManager = (JournalStorageManager) server.getStorageManager();
    List<RecordInfo> committedRecords = new LinkedList<>();
    List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
    TransactionFailureCallback transactionFailure = new TransactionFailureCallback() {

        @Override
        public void failedTransaction(long transactionID, List<RecordInfo> records, List<RecordInfo> recordsToDelete) {
        }
    };
    try {
        journalStorageManager.getMessageJournal().start();
        journalStorageManager.getMessageJournal().load(committedRecords, preparedTransactions, transactionFailure);
        Assert.assertEquals(1, committedRecords.size());
    } finally {
        journalStorageManager.getMessageJournal().stop();
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) CoreProtocolManagerFactory(org.apache.activemq.artemis.core.protocol.core.impl.CoreProtocolManagerFactory) List(java.util.List) LinkedList(java.util.LinkedList) TransactionFailureCallback(org.apache.activemq.artemis.core.journal.TransactionFailureCallback) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) LinkedList(java.util.LinkedList) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) Test(org.junit.Test)

Example 19 with JournalStorageManager

use of org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager in project activemq-artemis by apache.

the class NIOJournalCompactTest method testStressDeletesNoSync.

@Test
public void testStressDeletesNoSync() throws Throwable {
    Configuration config = createBasicConfig().setJournalFileSize(100 * 1024).setJournalSyncNonTransactional(false).setJournalSyncTransactional(false).setJournalCompactMinFiles(0).setJournalCompactPercentage(0);
    final AtomicInteger errors = new AtomicInteger(0);
    final AtomicBoolean running = new AtomicBoolean(true);
    final AtomicLong seqGenerator = new AtomicLong(1);
    final ExecutorService executor = Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory());
    final ExecutorService ioexecutor = Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory());
    OrderedExecutorFactory factory = new OrderedExecutorFactory(executor);
    OrderedExecutorFactory iofactory = new OrderedExecutorFactory(ioexecutor);
    final ExecutorService deleteExecutor = Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory());
    final JournalStorageManager storage = new JournalStorageManager(config, EmptyCriticalAnalyzer.getInstance(), factory, iofactory);
    storage.start();
    try {
        storage.loadInternalOnly();
        ((JournalImpl) storage.getMessageJournal()).setAutoReclaim(false);
        final LinkedList<Long> survivingMsgs = new LinkedList<>();
        Runnable producerRunnable = new Runnable() {

            @Override
            public void run() {
                try {
                    while (running.get()) {
                        final long[] values = new long[100];
                        long tx = seqGenerator.incrementAndGet();
                        OperationContextImpl ctx = new OperationContextImpl(executor);
                        storage.setContext(ctx);
                        for (int i = 0; i < 100; i++) {
                            long id = seqGenerator.incrementAndGet();
                            values[i] = id;
                            CoreMessage message = new CoreMessage(id, 100);
                            message.getBodyBuffer().writeBytes(new byte[1024]);
                            storage.storeMessageTransactional(tx, message);
                        }
                        CoreMessage message = new CoreMessage(seqGenerator.incrementAndGet(), 100);
                        survivingMsgs.add(message.getMessageID());
                        logger.info("Going to store " + message);
                        // This one will stay here forever
                        storage.storeMessage(message);
                        logger.info("message storeed " + message);
                        logger.info("Going to commit " + tx);
                        storage.commit(tx);
                        logger.info("Committed " + tx);
                        ctx.executeOnCompletion(new IOCallback() {

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

                            @Override
                            public void done() {
                                deleteExecutor.execute(new Runnable() {

                                    @Override
                                    public void run() {
                                        try {
                                            for (long messageID : values) {
                                                storage.deleteMessage(messageID);
                                            }
                                        } catch (Throwable e) {
                                            e.printStackTrace();
                                            errors.incrementAndGet();
                                        }
                                    }
                                });
                            }
                        });
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                    errors.incrementAndGet();
                }
            }
        };
        Runnable compressRunnable = new Runnable() {

            @Override
            public void run() {
                try {
                    while (running.get()) {
                        Thread.sleep(500);
                        System.out.println("Compacting");
                        ((JournalImpl) storage.getMessageJournal()).testCompact();
                        ((JournalImpl) storage.getMessageJournal()).checkReclaimStatus();
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                    errors.incrementAndGet();
                }
            }
        };
        Thread producerThread = new Thread(producerRunnable);
        producerThread.start();
        Thread compactorThread = new Thread(compressRunnable);
        compactorThread.start();
        Thread.sleep(1000);
        running.set(false);
        producerThread.join();
        compactorThread.join();
        deleteExecutor.shutdown();
        assertTrue("delete executor failted to terminate", deleteExecutor.awaitTermination(30, TimeUnit.SECONDS));
        storage.stop();
        executor.shutdown();
        assertTrue("executor failed to terminate", executor.awaitTermination(30, TimeUnit.SECONDS));
        ioexecutor.shutdown();
        assertTrue("ioexecutor failed to terminate", ioexecutor.awaitTermination(30, TimeUnit.SECONDS));
        Assert.assertEquals(0, errors.get());
    } catch (Throwable e) {
        e.printStackTrace();
        throw e;
    } finally {
        try {
            storage.stop();
        } catch (Exception e) {
            e.printStackTrace();
        }
        executor.shutdownNow();
        deleteExecutor.shutdownNow();
        ioexecutor.shutdownNow();
    }
}
Also used : OrderedExecutorFactory(org.apache.activemq.artemis.utils.actors.OrderedExecutorFactory) Configuration(org.apache.activemq.artemis.core.config.Configuration) OperationContextImpl(org.apache.activemq.artemis.core.persistence.impl.journal.OperationContextImpl) IOCallback(org.apache.activemq.artemis.core.io.IOCallback) LinkedList(java.util.LinkedList) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) AtomicLong(java.util.concurrent.atomic.AtomicLong) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Test(org.junit.Test)

Aggregations

JournalStorageManager (org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager)19 Test (org.junit.Test)13 LinkedList (java.util.LinkedList)6 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)5 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)5 OrderedExecutorFactory (org.apache.activemq.artemis.utils.actors.OrderedExecutorFactory)5 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)4 Configuration (org.apache.activemq.artemis.core.config.Configuration)4 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)4 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)4 List (java.util.List)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 ConfigurationImpl (org.apache.activemq.artemis.core.config.impl.ConfigurationImpl)3 JDBCJournalStorageManager (org.apache.activemq.artemis.core.persistence.impl.journal.JDBCJournalStorageManager)3 ArrayList (java.util.ArrayList)2 Message (org.apache.activemq.artemis.api.core.Message)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 SecurityConfiguration (org.apache.activemq.artemis.core.config.impl.SecurityConfiguration)2 TransactionFailureCallback (org.apache.activemq.artemis.core.journal.TransactionFailureCallback)2 JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)2