Search in sources :

Example 1 with CriticalComponent

use of org.apache.activemq.artemis.utils.critical.CriticalComponent in project activemq-artemis by apache.

the class CriticalSimpleTest method testCriticalOff.

@Test
public void testCriticalOff() throws Exception {
    Configuration configuration = createDefaultConfig(false);
    configuration.setCriticalAnalyzerCheckPeriod(10).setCriticalAnalyzer(false);
    ActiveMQServer server = createServer(false, configuration, AddressSettings.DEFAULT_PAGE_SIZE, AddressSettings.DEFAULT_MAX_SIZE_BYTES);
    server.start();
    try {
        server.getCriticalAnalyzer().add(new CriticalComponent() {

            @Override
            public boolean isExpired(long timeout) {
                return true;
            }
        });
        Wait.waitFor(() -> !server.isStarted(), 500, 10);
        Assert.assertTrue(server.isStarted());
    } finally {
        server.stop();
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) CriticalComponent(org.apache.activemq.artemis.utils.critical.CriticalComponent) Configuration(org.apache.activemq.artemis.core.config.Configuration) Test(org.junit.Test)

Example 2 with CriticalComponent

use of org.apache.activemq.artemis.utils.critical.CriticalComponent in project activemq-artemis by apache.

the class CriticalSimpleTest method testSimpleShutdown.

@Test
public void testSimpleShutdown() throws Exception {
    Configuration configuration = createDefaultConfig(false);
    configuration.setCriticalAnalyzerCheckPeriod(10).setCriticalAnalyzerPolicy(CriticalAnalyzerPolicy.SHUTDOWN);
    ActiveMQServer server = createServer(false, configuration, AddressSettings.DEFAULT_PAGE_SIZE, AddressSettings.DEFAULT_MAX_SIZE_BYTES);
    server.start();
    try {
        CountDownLatch latch = new CountDownLatch(1);
        server.getConfiguration().registerBrokerPlugin(new ActiveMQServerPlugin() {

            @Override
            public void criticalFailure(CriticalComponent components) throws ActiveMQException {
                latch.countDown();
            }
        });
        server.getCriticalAnalyzer().add(new CriticalComponent() {

            @Override
            public boolean isExpired(long timeout) {
                return true;
            }
        });
        Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));
        Wait.waitFor(() -> !server.isStarted());
        Assert.assertFalse(server.isStarted());
    } finally {
        server.stop();
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) CriticalComponent(org.apache.activemq.artemis.utils.critical.CriticalComponent) Configuration(org.apache.activemq.artemis.core.config.Configuration) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQServerPlugin(org.apache.activemq.artemis.core.server.plugin.ActiveMQServerPlugin) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

Configuration (org.apache.activemq.artemis.core.config.Configuration)2 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)2 CriticalComponent (org.apache.activemq.artemis.utils.critical.CriticalComponent)2 Test (org.junit.Test)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 ActiveMQServerPlugin (org.apache.activemq.artemis.core.server.plugin.ActiveMQServerPlugin)1