Search in sources :

Example 1 with InVMNodeManager

use of org.apache.activemq.artemis.core.server.impl.InVMNodeManager in project activemq-artemis by apache.

the class SecurityFailoverTest method createConfigs.

/**
 * @throws Exception
 */
@Override
protected void createConfigs() throws Exception {
    nodeManager = new InVMNodeManager(false);
    TransportConfiguration liveConnector = getConnectorTransportConfiguration(true);
    TransportConfiguration backupConnector = getConnectorTransportConfiguration(false);
    backupConfig = super.createDefaultInVMConfig().clearAcceptorConfigurations().addAcceptorConfiguration(getAcceptorTransportConfiguration(false)).setSecurityEnabled(true).setHAPolicyConfiguration(new SharedStoreSlavePolicyConfiguration()).addConnectorConfiguration(liveConnector.getName(), liveConnector).addConnectorConfiguration(backupConnector.getName(), backupConnector).addClusterConfiguration(basicClusterConnectionConfig(backupConnector.getName(), liveConnector.getName()));
    backupServer = createTestableServer(backupConfig);
    ActiveMQJAASSecurityManager securityManager = installSecurity(backupServer);
    securityManager.getConfiguration().setDefaultUser(null);
    liveConfig = super.createDefaultInVMConfig().clearAcceptorConfigurations().addAcceptorConfiguration(getAcceptorTransportConfiguration(true)).setSecurityEnabled(true).setHAPolicyConfiguration(new SharedStoreMasterPolicyConfiguration()).addClusterConfiguration(basicClusterConnectionConfig(liveConnector.getName())).addConnectorConfiguration(liveConnector.getName(), liveConnector);
    liveServer = createTestableServer(liveConfig);
    installSecurity(liveServer);
}
Also used : InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) SharedStoreSlavePolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreSlavePolicyConfiguration) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) SharedStoreMasterPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration)

Example 2 with InVMNodeManager

use of org.apache.activemq.artemis.core.server.impl.InVMNodeManager in project activemq-artemis by apache.

the class SingleLiveMultipleBackupsFailoverTest method testMultipleFailovers.

@Test
public void testMultipleFailovers() throws Exception {
    nodeManager = new InVMNodeManager(!sharedStore);
    createLiveConfig(0);
    createBackupConfig(0, 1, 0, 2, 3, 4, 5);
    createBackupConfig(0, 2, 0, 1, 3, 4, 5);
    createBackupConfig(0, 3, 0, 1, 2, 4, 5);
    createBackupConfig(0, 4, 0, 1, 2, 3, 5);
    createBackupConfig(0, 5, 0, 1, 2, 3, 4);
    servers.get(0).start();
    waitForServerToStart(servers.get(0).getServer());
    servers.get(1).start();
    waitForServerToStart(servers.get(1).getServer());
    servers.get(2).start();
    servers.get(3).start();
    servers.get(4).start();
    servers.get(5).start();
    locator = (ServerLocatorImpl) getServerLocator(0);
    Topology topology = locator.getTopology();
    // for logging and debugging
    topology.setOwner("testMultipleFailovers");
    locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setReconnectAttempts(15);
    ClientSessionFactoryInternal sf = createSessionFactoryAndWaitForTopology(locator, 2);
    int backupNode;
    ClientSession session = sendAndConsume(sf, true);
    log.info("failing node 0");
    servers.get(0).crash(session);
    session.close();
    backupNode = waitForNewLive(5, true, servers, 1, 2, 3, 4, 5);
    session = sendAndConsume(sf, false);
    log.info("failing node " + backupNode);
    servers.get(backupNode).crash(session);
    session.close();
    backupNode = waitForNewLive(5, true, servers, 1, 2, 3, 4, 5);
    session = sendAndConsume(sf, false);
    log.info("failing node " + backupNode);
    servers.get(backupNode).crash(session);
    session.close();
    backupNode = waitForNewLive(5, true, servers, 1, 2, 3, 4, 5);
    session = sendAndConsume(sf, false);
    log.info("failing node " + backupNode);
    servers.get(backupNode).crash(session);
    session.close();
    backupNode = waitForNewLive(5, true, servers, 1, 2, 3, 4, 5);
    session = sendAndConsume(sf, false);
    log.info("failing node " + backupNode);
    servers.get(backupNode).crash(session);
    session.close();
    backupNode = waitForNewLive(5, false, servers, 1, 2, 3, 4, 5);
    session = sendAndConsume(sf, false);
    session.close();
    servers.get(backupNode).stop();
    locator.close();
}
Also used : ClientSessionFactoryInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal) InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Topology(org.apache.activemq.artemis.core.client.impl.Topology) Test(org.junit.Test)

Example 3 with InVMNodeManager

use of org.apache.activemq.artemis.core.server.impl.InVMNodeManager in project activemq-artemis by apache.

the class JMSFailoverTest method startServers.

/**
 * @throws Exception
 */
protected void startServers() throws Exception {
    final boolean sharedStore = true;
    NodeManager nodeManager = new InVMNodeManager(!sharedStore);
    backuptc = new TransportConfiguration(INVM_CONNECTOR_FACTORY, backupParams);
    livetc = new TransportConfiguration(INVM_CONNECTOR_FACTORY);
    liveAcceptortc = new TransportConfiguration(INVM_ACCEPTOR_FACTORY);
    backupAcceptortc = new TransportConfiguration(INVM_ACCEPTOR_FACTORY, backupParams);
    backupParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
    backupConf = createBasicConfig().addAcceptorConfiguration(backupAcceptortc).addConnectorConfiguration(livetc.getName(), livetc).addConnectorConfiguration(backuptc.getName(), backuptc).setSecurityEnabled(false).setJournalType(getDefaultJournalType()).addAcceptorConfiguration(new TransportConfiguration(INVM_ACCEPTOR_FACTORY, backupParams)).setBindingsDirectory(getBindingsDir()).setJournalMinFiles(2).setJournalDirectory(getJournalDir()).setPagingDirectory(getPageDir()).setLargeMessagesDirectory(getLargeMessagesDir()).setPersistenceEnabled(true).setHAPolicyConfiguration(sharedStore ? new SharedStoreSlavePolicyConfiguration() : new ReplicaPolicyConfiguration()).addClusterConfiguration(basicClusterConnectionConfig(backuptc.getName(), livetc.getName()));
    backupServer = addServer(new InVMNodeManagerServer(backupConf, nodeManager));
    backupJMSServer = new JMSServerManagerImpl(backupServer);
    backupJMSServer.setRegistry(new JndiBindingRegistry(ctx2));
    backupJMSServer.getActiveMQServer().setIdentity("JMSBackup");
    log.info("Starting backup");
    backupJMSServer.start();
    liveConf = createBasicConfig().setJournalDirectory(getJournalDir()).setBindingsDirectory(getBindingsDir()).setSecurityEnabled(false).addAcceptorConfiguration(liveAcceptortc).setJournalType(getDefaultJournalType()).setBindingsDirectory(getBindingsDir()).setJournalMinFiles(2).setJournalDirectory(getJournalDir()).setPagingDirectory(getPageDir()).setLargeMessagesDirectory(getLargeMessagesDir()).addConnectorConfiguration(livetc.getName(), livetc).setPersistenceEnabled(true).setHAPolicyConfiguration(sharedStore ? new SharedStoreMasterPolicyConfiguration() : new ReplicatedPolicyConfiguration()).addClusterConfiguration(basicClusterConnectionConfig(livetc.getName()));
    liveServer = addServer(new InVMNodeManagerServer(liveConf, nodeManager));
    liveJMSServer = new JMSServerManagerImpl(liveServer);
    liveJMSServer.setRegistry(new JndiBindingRegistry(ctx1));
    liveJMSServer.getActiveMQServer().setIdentity("JMSLive");
    log.info("Starting life");
    liveJMSServer.start();
    JMSUtil.waitForServer(backupServer);
}
Also used : InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) NodeManager(org.apache.activemq.artemis.core.server.NodeManager) InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) SharedStoreSlavePolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreSlavePolicyConfiguration) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) ReplicatedPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.ReplicatedPolicyConfiguration) InVMNodeManagerServer(org.apache.activemq.artemis.tests.util.InVMNodeManagerServer) SharedStoreMasterPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) JndiBindingRegistry(org.apache.activemq.artemis.core.registry.JndiBindingRegistry) ReplicaPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.ReplicaPolicyConfiguration)

Example 4 with InVMNodeManager

use of org.apache.activemq.artemis.core.server.impl.InVMNodeManager in project activemq-artemis by apache.

the class BridgeReconnectTest method testFailoverDeploysBridge.

/**
 * Backups must successfully deploy its bridges on fail-over.
 *
 * @see https://bugzilla.redhat.com/show_bug.cgi?id=900764
 */
@Test
public void testFailoverDeploysBridge() throws Exception {
    NodeManager nodeManager = new InVMNodeManager(false);
    server0 = createActiveMQServer(0, server0Params, isNetty(), nodeManager);
    server2 = createBackupActiveMQServer(2, server2Params, isNetty(), 0, nodeManager);
    TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params, "server0tc");
    TransportConfiguration server2tc = new TransportConfiguration(getConnector(), server2Params, "server2tc");
    connectors.put(server2tc.getName(), server2tc);
    server0.getConfiguration().setConnectorConfigurations(connectors);
    server1.getConfiguration().setConnectorConfigurations(connectors);
    server2.getConfiguration().setConnectorConfigurations(connectors);
    reconnectAttempts = -1;
    BridgeConfiguration bridgeConfiguration = createBridgeConfig();
    bridgeConfiguration.setQueueName(queueName);
    List<BridgeConfiguration> bridgeConfigs = new ArrayList<>();
    bridgeConfigs.add(bridgeConfiguration);
    server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
    server2.getConfiguration().setBridgeConfigurations(bridgeConfigs);
    CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName);
    List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<>();
    queueConfigs0.add(queueConfig0);
    server1.getConfiguration().setQueueConfigurations(queueConfigs0);
    CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration().setAddress(forwardAddress).setName(queueName);
    List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<>();
    queueConfigs1.add(queueConfig1);
    server0.getConfiguration().setQueueConfigurations(queueConfigs1);
    server2.getConfiguration().setQueueConfigurations(queueConfigs1);
    startServers();
    waitForServerStart(server0);
    server0.fail(true);
    waitForServerStart(server2);
    locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(server0tc, server2tc));
    ClientSessionFactory csf0 = addSessionFactory(locator.createSessionFactory(server2tc));
    session0 = csf0.createSession(false, true, true);
    Map<String, Bridge> bridges = server2.getClusterManager().getBridges();
    assertTrue("backup must deploy bridge on failover", !bridges.isEmpty());
}
Also used : InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) NodeManager(org.apache.activemq.artemis.core.server.NodeManager) InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) BridgeConfiguration(org.apache.activemq.artemis.core.config.BridgeConfiguration) ArrayList(java.util.ArrayList) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) CoreQueueConfiguration(org.apache.activemq.artemis.core.config.CoreQueueConfiguration) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Bridge(org.apache.activemq.artemis.core.server.cluster.Bridge) Test(org.junit.Test)

Example 5 with InVMNodeManager

use of org.apache.activemq.artemis.core.server.impl.InVMNodeManager in project activemq-artemis by apache.

the class NodeManagerTest method performWork.

public void performWork(NodeManagerAction... actions) throws Exception {
    NodeManager nodeManager = new InVMNodeManager(false);
    List<NodeRunner> nodeRunners = new ArrayList<>();
    Thread[] threads = new Thread[actions.length];
    for (NodeManagerAction action : actions) {
        NodeRunner nodeRunner = new NodeRunner(nodeManager, action);
        nodeRunners.add(nodeRunner);
    }
    for (int i = 0, nodeRunnersSize = nodeRunners.size(); i < nodeRunnersSize; i++) {
        NodeRunner nodeRunner = nodeRunners.get(i);
        threads[i] = new Thread(nodeRunner);
        threads[i].start();
    }
    for (Thread thread : threads) {
        try {
            thread.join(5000);
        } catch (InterruptedException e) {
        // 
        }
        if (thread.isAlive()) {
            thread.interrupt();
            fail("thread still running");
        }
    }
    for (NodeRunner nodeRunner : nodeRunners) {
        if (nodeRunner.e != null) {
            nodeRunner.e.printStackTrace();
            fail(nodeRunner.e.getMessage());
        }
    }
}
Also used : InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) NodeManager(org.apache.activemq.artemis.core.server.NodeManager) InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) ArrayList(java.util.ArrayList)

Aggregations

InVMNodeManager (org.apache.activemq.artemis.core.server.impl.InVMNodeManager)24 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)14 Test (org.junit.Test)13 SharedStoreSlavePolicyConfiguration (org.apache.activemq.artemis.core.config.ha.SharedStoreSlavePolicyConfiguration)10 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)9 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)9 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)9 ClientSessionFactoryInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal)9 SharedStoreMasterPolicyConfiguration (org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration)9 NodeManager (org.apache.activemq.artemis.core.server.NodeManager)9 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)8 ArrayList (java.util.ArrayList)6 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 XAException (javax.transaction.xa.XAException)5 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)5 ActiveMQDuplicateIdException (org.apache.activemq.artemis.api.core.ActiveMQDuplicateIdException)4 ActiveMQObjectClosedException (org.apache.activemq.artemis.api.core.ActiveMQObjectClosedException)4 ActiveMQTransactionOutcomeUnknownException (org.apache.activemq.artemis.api.core.ActiveMQTransactionOutcomeUnknownException)4 ActiveMQTransactionRolledBackException (org.apache.activemq.artemis.api.core.ActiveMQTransactionRolledBackException)4