Search in sources :

Example 6 with InVMNamingContext

use of org.apache.activemq.artemis.tests.unit.util.InVMNamingContext in project activemq-artemis by apache.

the class StartStopDeadlockTest method testDeadlock.

/*
   * simple test to make sure connect still works with some network latency  built into netty
   * */
@Test
@BMRules(rules = { @BMRule(name = "Server.start wait-init", targetClass = "org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl", targetMethod = "initialisePart2", targetLocation = "ENTRY", condition = "incrementCounter(\"server-Init\") == 2", action = "System.out.println(\"server backup init\"), waitFor(\"start-init\")"), @BMRule(name = "JMSServer.stop wait-init", targetClass = "org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl", targetMethod = "stop", targetLocation = "ENTRY", action = "signalWake(\"start-init\", true)"), @BMRule(name = "StartStopDeadlockTest tearDown", targetClass = "org.apache.activemq.artemis.tests.extras.byteman.StartStopDeadlockTest", targetMethod = "tearDown", targetLocation = "ENTRY", action = "deleteCounter(\"server-Init\")") })
public void testDeadlock() throws Exception {
    // A live server that will always be crashed
    Configuration confLive = createDefaultNettyConfig().setHAPolicyConfiguration(new SharedStoreMasterPolicyConfiguration());
    final ActiveMQServer serverLive = addServer(ActiveMQServers.newActiveMQServer(confLive));
    serverLive.start();
    // A backup that will be waiting to be activated
    Configuration config = createDefaultNettyConfig().setHAPolicyConfiguration(new SharedStoreSlavePolicyConfiguration());
    final ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(config, true));
    final JMSServerManagerImpl jmsServer = new JMSServerManagerImpl(server);
    final InVMNamingContext context = new InVMNamingContext();
    jmsServer.setRegistry(new JndiBindingRegistry(context));
    jmsServer.start();
    final AtomicInteger errors = new AtomicInteger(0);
    final CountDownLatch align = new CountDownLatch(2);
    final CountDownLatch startLatch = new CountDownLatch(1);
    Thread tCrasher = new Thread("tStart") {

        @Override
        public void run() {
            try {
                align.countDown();
                startLatch.await();
                System.out.println("Crashing....");
                serverLive.fail(true);
            } catch (Exception e) {
                errors.incrementAndGet();
                e.printStackTrace();
            }
        }
    };
    Thread tStop = new Thread("tStop") {

        @Override
        public void run() {
            try {
                align.countDown();
                startLatch.await();
                jmsServer.stop();
            } catch (Exception e) {
                errors.incrementAndGet();
                e.printStackTrace();
            }
        }
    };
    tCrasher.start();
    tStop.start();
    align.await();
    startLatch.countDown();
    tCrasher.join();
    tStop.join();
    assertEquals(0, errors.get());
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Configuration(org.apache.activemq.artemis.core.config.Configuration) SharedStoreMasterPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration) SharedStoreSlavePolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreSlavePolicyConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SharedStoreSlavePolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreSlavePolicyConfiguration) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) SharedStoreMasterPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration) JndiBindingRegistry(org.apache.activemq.artemis.core.registry.JndiBindingRegistry) CountDownLatch(java.util.concurrent.CountDownLatch) InVMNamingContext(org.apache.activemq.artemis.tests.unit.util.InVMNamingContext) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Example 7 with InVMNamingContext

use of org.apache.activemq.artemis.tests.unit.util.InVMNamingContext in project activemq-artemis by apache.

the class BridgeTestBase method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    // Start the servers
    Configuration conf0 = createBasicConfig().setJournalDirectory(getJournalDir(0, false)).setBindingsDirectory(getBindingsDir(0, false)).addAcceptorConfiguration(new TransportConfiguration(INVM_ACCEPTOR_FACTORY));
    server0 = addServer(ActiveMQServers.newActiveMQServer(conf0, false));
    context0 = new InVMNamingContext();
    jmsServer0 = new JMSServerManagerImpl(server0);
    jmsServer0.setRegistry(new JndiBindingRegistry(context0));
    jmsServer0.start();
    params1 = new HashMap<>();
    params1.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
    Configuration conf1 = createBasicConfig().setJournalDirectory(getJournalDir(1, false)).setBindingsDirectory(getBindingsDir(1, false)).addAcceptorConfiguration(new TransportConfiguration(INVM_ACCEPTOR_FACTORY, params1));
    server1 = addServer(ActiveMQServers.newActiveMQServer(conf1, false));
    context1 = new InVMNamingContext();
    jmsServer1 = new JMSServerManagerImpl(server1);
    jmsServer1.setRegistry(new JndiBindingRegistry(context1));
    jmsServer1.start();
    createQueue("sourceQueue", 0);
    jmsServer0.createTopic(false, "sourceTopic", "/topic/sourceTopic");
    createQueue("localTargetQueue", 0);
    createQueue("targetQueue", 1);
    setUpAdministeredObjects();
    TxControl.enable();
// We need a local transaction and recovery manager
// We must start this after the remote servers have been created or it won't
// have deleted the database and the recovery manager may attempt to recover transactions
}
Also used : Configuration(org.apache.activemq.artemis.core.config.Configuration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) JndiBindingRegistry(org.apache.activemq.artemis.core.registry.JndiBindingRegistry) InVMNamingContext(org.apache.activemq.artemis.tests.unit.util.InVMNamingContext) Before(org.junit.Before)

Example 8 with InVMNamingContext

use of org.apache.activemq.artemis.tests.unit.util.InVMNamingContext in project activemq-artemis by apache.

the class JMSClusteredTestBase method setupServer2.

/**
 * @throws Exception
 */
private void setupServer2() throws Exception {
    Configuration configuration = createConfigServer(2, 1);
    JMSConfigurationImpl jmsconfig = new JMSConfigurationImpl();
    mBeanServer2 = MBeanServerFactory.createMBeanServer();
    server2 = addServer(ActiveMQServers.newActiveMQServer(configuration, mBeanServer2, enablePersistence()));
    jmsServer2 = new JMSServerManagerImpl(server2, jmsconfig);
    context2 = new InVMNamingContext();
    jmsServer2.setRegistry(new JndiBindingRegistry(context2));
}
Also used : Configuration(org.apache.activemq.artemis.core.config.Configuration) ClusterConnectionConfiguration(org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) JMSConfigurationImpl(org.apache.activemq.artemis.jms.server.config.impl.JMSConfigurationImpl) JndiBindingRegistry(org.apache.activemq.artemis.core.registry.JndiBindingRegistry) InVMNamingContext(org.apache.activemq.artemis.tests.unit.util.InVMNamingContext)

Example 9 with InVMNamingContext

use of org.apache.activemq.artemis.tests.unit.util.InVMNamingContext in project activemq-artemis by apache.

the class JMSTestBase method restartServer.

protected void restartServer() throws Exception {
    namingContext = new InVMNamingContext();
    jmsServer.setRegistry(new JndiBindingRegistry(namingContext));
    jmsServer.start();
    jmsServer.activated();
    registerConnectionFactory();
}
Also used : JndiBindingRegistry(org.apache.activemq.artemis.core.registry.JndiBindingRegistry) InVMNamingContext(org.apache.activemq.artemis.tests.unit.util.InVMNamingContext)

Example 10 with InVMNamingContext

use of org.apache.activemq.artemis.tests.unit.util.InVMNamingContext in project activemq-artemis by apache.

the class JMSTestBase method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    mbeanServer = MBeanServerFactory.createMBeanServer();
    Configuration config = createDefaultConfig(true).setSecurityEnabled(useSecurity()).addConnectorConfiguration("invm", new TransportConfiguration(INVM_CONNECTOR_FACTORY)).setTransactionTimeoutScanPeriod(100);
    config.getConnectorConfigurations().put("netty", new TransportConfiguration(NETTY_CONNECTOR_FACTORY));
    server = addServer(ActiveMQServers.newActiveMQServer(config, mbeanServer, usePersistence()));
    jmsServer = new JMSServerManagerImpl(server);
    namingContext = new InVMNamingContext();
    jmsServer.setRegistry(new JndiBindingRegistry(namingContext));
    jmsServer.start();
    registerConnectionFactory();
}
Also used : Configuration(org.apache.activemq.artemis.core.config.Configuration) ConnectionFactoryConfiguration(org.apache.activemq.artemis.jms.server.config.ConnectionFactoryConfiguration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) JndiBindingRegistry(org.apache.activemq.artemis.core.registry.JndiBindingRegistry) InVMNamingContext(org.apache.activemq.artemis.tests.unit.util.InVMNamingContext) Before(org.junit.Before)

Aggregations

JndiBindingRegistry (org.apache.activemq.artemis.core.registry.JndiBindingRegistry)18 InVMNamingContext (org.apache.activemq.artemis.tests.unit.util.InVMNamingContext)18 JMSServerManagerImpl (org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl)17 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)14 Configuration (org.apache.activemq.artemis.core.config.Configuration)12 Before (org.junit.Before)9 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)7 JMSConfigurationImpl (org.apache.activemq.artemis.jms.server.config.impl.JMSConfigurationImpl)6 ConnectionFactoryConfiguration (org.apache.activemq.artemis.jms.server.config.ConnectionFactoryConfiguration)4 JMSConfiguration (org.apache.activemq.artemis.jms.server.config.JMSConfiguration)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)3 JMSQueueConfigurationImpl (org.apache.activemq.artemis.jms.server.config.impl.JMSQueueConfigurationImpl)3 ActiveMQJAASSecurityManager (org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager)3 ArrayList (java.util.ArrayList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Connection (javax.jms.Connection)2 MessageProducer (javax.jms.MessageProducer)2