Search in sources :

Example 6 with NodeManager

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

the class MultiServerTestBase method setupLiveServer.

protected Pair<ActiveMQServer, NodeManager> setupLiveServer(final int node, final boolean realFiles, final boolean sharedStorage) throws Exception {
    NodeManager nodeManager = null;
    TransportConfiguration serverConfigAcceptor = createTransportConfiguration(useNetty(), true, generateParams(node, useNetty()));
    TransportConfiguration thisConnector = createTransportConfiguration(useNetty(), false, generateParams(node, useNetty()));
    if (sharedStorage) {
        nodeManager = new InVMNodeManager(false);
    }
    Configuration configuration = createBasicConfig(node).setJournalMaxIO_AIO(1000).setThreadPoolMaxSize(10).clearAcceptorConfigurations().addAcceptorConfiguration(serverConfigAcceptor).addConnectorConfiguration("thisConnector", thisConnector).setHAPolicyConfiguration(sharedStorage ? new SharedStoreMasterPolicyConfiguration() : new ReplicatedPolicyConfiguration());
    List<String> targetServersOnConnection = new ArrayList<>();
    for (int targetNode = 0; targetNode < getNumberOfServers(); targetNode++) {
        if (targetNode == node) {
            continue;
        }
        String targetConnectorName = "target-" + targetNode;
        TransportConfiguration targetServer = createTransportConfiguration(useNetty(), false, generateParams(targetNode, useNetty()));
        configuration.getConnectorConfigurations().put(targetConnectorName, targetServer);
        targetServersOnConnection.add(targetConnectorName);
        // The connector towards a backup.. just to have a reference so bridges can connect to backups on their configs
        String backupConnectorName = "backup-" + targetNode;
        TransportConfiguration backupConnector = createTransportConfiguration(useNetty(), false, generateParams(targetNode + getNumberOfServers(), useNetty()));
        configuration.getConnectorConfigurations().put(backupConnectorName, backupConnector);
    }
    ClusterConnectionConfiguration clusterConf = new ClusterConnectionConfiguration().setName("localCluster" + node).setAddress("cluster-queues").setConnectorName("thisConnector").setRetryInterval(100).setConfirmationWindowSize(1024).setMessageLoadBalancingType(MessageLoadBalancingType.ON_DEMAND).setStaticConnectors(targetServersOnConnection);
    configuration.getClusterConfigurations().add(clusterConf);
    ActiveMQServer server;
    if (sharedStorage) {
        server = createInVMFailoverServer(realFiles, configuration, nodeManager, node);
    } else {
        server = createServer(realFiles, configuration);
    }
    server.setIdentity(this.getClass().getSimpleName() + "/Live(" + node + ")");
    addServer(server);
    return new Pair<>(server, nodeManager);
}
Also used : ClusterConnectionConfiguration(org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration) InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) Configuration(org.apache.activemq.artemis.core.config.Configuration) ReplicaPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.ReplicaPolicyConfiguration) SharedStoreMasterPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration) SharedStoreSlavePolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreSlavePolicyConfiguration) ClusterConnectionConfiguration(org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) ReplicatedPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.ReplicatedPolicyConfiguration) ArrayList(java.util.ArrayList) SharedStoreMasterPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) NodeManager(org.apache.activemq.artemis.core.server.NodeManager) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ReplicatedPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.ReplicatedPolicyConfiguration) Pair(org.apache.activemq.artemis.api.core.Pair)

Example 7 with NodeManager

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

the class MultipleLivesMultipleBackupsFailoverTest method testMultipleFailovers2LiveServers.

@Test
public void testMultipleFailovers2LiveServers() throws Exception {
    NodeManager nodeManager1 = new InVMNodeManager(!sharedStore);
    NodeManager nodeManager2 = new InVMNodeManager(!sharedStore);
    createLiveConfig(nodeManager1, 0, 3, 4, 5);
    createBackupConfig(nodeManager1, 0, 1, true, new int[] { 0, 2 }, 3, 4, 5);
    createBackupConfig(nodeManager1, 0, 2, true, new int[] { 0, 1 }, 3, 4, 5);
    createLiveConfig(nodeManager2, 3, 0);
    createBackupConfig(nodeManager2, 3, 4, true, new int[] { 3, 5 }, 0, 1, 2);
    createBackupConfig(nodeManager2, 3, 5, true, new int[] { 3, 4 }, 0, 1, 2);
    servers.get(0).start();
    waitForServerToStart(servers.get(0).getServer());
    servers.get(3).start();
    waitForServerToStart(servers.get(3).getServer());
    servers.get(1).start();
    waitForServerToStart(servers.get(1).getServer());
    servers.get(2).start();
    servers.get(4).start();
    waitForServerToStart(servers.get(4).getServer());
    servers.get(5).start();
    waitForServerToStart(servers.get(4).getServer());
    locator = getServerLocator(0).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setReconnectAttempts(15);
    ClientSessionFactoryInternal sf = createSessionFactoryAndWaitForTopology(locator, 4, servers.get(0).getServer());
    ClientSession session = sendAndConsume(sf, true);
    System.out.println(((ServerLocatorInternal) locator).getTopology().describe());
    Thread.sleep(500);
    servers.get(0).crash(session);
    int liveAfter0 = waitForNewLive(10000, true, servers, 1, 2);
    locator2 = getServerLocator(3).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setReconnectAttempts(15);
    ClientSessionFactoryInternal sf2 = createSessionFactoryAndWaitForTopology(locator2, 4);
    ClientSession session2 = sendAndConsume(sf2, true);
    System.setProperty("foo", "bar");
    servers.get(3).crash(session2);
    int liveAfter3 = waitForNewLive(10000, true, servers, 4, 5);
    locator.close();
    locator2.close();
    if (liveAfter0 == 2) {
        Thread.sleep(500);
        servers.get(1).stop();
        Thread.sleep(500);
        servers.get(2).stop();
    } else {
        Thread.sleep(500);
        servers.get(2).stop();
        Thread.sleep(500);
        servers.get(1).stop();
    }
    if (liveAfter3 == 4) {
        Thread.sleep(500);
        servers.get(5).stop();
        Thread.sleep(500);
        servers.get(4).stop();
    } else {
        Thread.sleep(500);
        servers.get(4).stop();
        Thread.sleep(500);
        servers.get(5).stop();
    }
}
Also used : InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) NodeManager(org.apache.activemq.artemis.core.server.NodeManager) 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) ServerLocatorInternal(org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal) Test(org.junit.Test)

Example 8 with NodeManager

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

the class NettyFailoverTest method createNodeManager.

@Override
protected NodeManager createNodeManager() throws Exception {
    switch(nodeManagerType) {
        case InVM:
            return new InVMNodeManager(false);
        case Jdbc:
            final ThreadFactory daemonThreadFactory = t -> {
                final Thread th = new Thread(t);
                th.setDaemon(true);
                return th;
            };
            final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(daemonThreadFactory);
            scheduledExecutorServices.add(scheduledExecutorService);
            final ExecutorService executor = Executors.newFixedThreadPool(2, daemonThreadFactory);
            executors.add(executor);
            final DatabaseStorageConfiguration dbConf = createDefaultDatabaseStorageConfiguration();
            final ExecutorFactory executorFactory = new OrderedExecutorFactory(executor);
            return JdbcNodeManager.with(dbConf, scheduledExecutorService, executorFactory, (code, message, file) -> {
                code.printStackTrace();
                Assert.fail(message);
            });
        default:
            throw new AssertionError("enum type not supported!");
    }
}
Also used : Configuration(org.apache.activemq.artemis.core.config.Configuration) Arrays(java.util.Arrays) SameProcessActiveMQServer(org.apache.activemq.artemis.tests.integration.cluster.util.SameProcessActiveMQServer) OrderedExecutorFactory(org.apache.activemq.artemis.utils.actors.OrderedExecutorFactory) ClientSessionFactoryInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal) DatabaseStorageConfiguration(org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration) TransportConstants(org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ArrayList(java.util.ArrayList) ActiveMQClient(org.apache.activemq.artemis.api.core.client.ActiveMQClient) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Is(org.hamcrest.core.Is) TestableServer(org.apache.activemq.artemis.tests.integration.cluster.util.TestableServer) Map(java.util.Map) After(org.junit.After) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) Assume(org.junit.Assume) NodeManager(org.apache.activemq.artemis.core.server.NodeManager) ThreadFactory(java.util.concurrent.ThreadFactory) ExecutorService(java.util.concurrent.ExecutorService) Parameterized(org.junit.runners.Parameterized) ReplicaPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.ReplicaPolicyConfiguration) SharedStoreSlavePolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreSlavePolicyConfiguration) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test) ExecutorFactory(org.apache.activemq.artemis.utils.ExecutorFactory) Executors(java.util.concurrent.Executors) List(java.util.List) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) JdbcNodeManager(org.apache.activemq.artemis.core.server.impl.jdbc.JdbcNodeManager) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) ThreadLeakCheckRule(org.apache.activemq.artemis.utils.ThreadLeakCheckRule) Assert(org.junit.Assert) DatabaseStorageConfiguration(org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration) ThreadFactory(java.util.concurrent.ThreadFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) OrderedExecutorFactory(org.apache.activemq.artemis.utils.actors.OrderedExecutorFactory) InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) OrderedExecutorFactory(org.apache.activemq.artemis.utils.actors.OrderedExecutorFactory) ExecutorFactory(org.apache.activemq.artemis.utils.ExecutorFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService)

Example 9 with NodeManager

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

the class RealNodeManagerTest method testId.

@Test
public void testId() throws Exception {
    NodeManager nodeManager = new FileLockNodeManager(new File(getTemporaryDir()), false);
    nodeManager.start();
    UUID id1 = nodeManager.getUUID();
    nodeManager.stop();
    nodeManager.start();
    ActiveMQTestBase.assertEqualsByteArrays(id1.asBytes(), nodeManager.getUUID().asBytes());
    nodeManager.stop();
}
Also used : FileLockNodeManager(org.apache.activemq.artemis.core.server.impl.FileLockNodeManager) NodeManager(org.apache.activemq.artemis.core.server.NodeManager) FileLockNodeManager(org.apache.activemq.artemis.core.server.impl.FileLockNodeManager) UUID(org.apache.activemq.artemis.utils.UUID) File(java.io.File) Test(org.junit.Test)

Example 10 with NodeManager

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

the class BridgeReconnectTest method testFailoverAndReconnectImmediately.

// Fail bridge and reconnecting immediately
@Test
public void testFailoverAndReconnectImmediately() 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);
    reconnectAttempts = 1;
    BridgeConfiguration bridgeConfiguration = createBridgeConfig();
    List<BridgeConfiguration> bridgeConfigs = new ArrayList<>();
    bridgeConfigs.add(bridgeConfiguration);
    server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
    CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName);
    List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<>();
    queueConfigs0.add(queueConfig0);
    server0.getConfiguration().setQueueConfigurations(queueConfigs0);
    CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration().setAddress(forwardAddress).setName(queueName);
    List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<>();
    queueConfigs1.add(queueConfig1);
    server1.getConfiguration().setQueueConfigurations(queueConfigs1);
    server2.getConfiguration().setQueueConfigurations(queueConfigs1);
    startServers();
    BridgeReconnectTest.log.info("** failing connection");
    // Now we will simulate a failure of the bridge connection between server0 and server1
    server0.fail(true);
    waitForServerStart(server2);
    locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(server0tc, server2tc));
    ClientSessionFactory csf0 = addSessionFactory(locator.createSessionFactory(server2tc));
    session0 = csf0.createSession(false, true, true);
    ClientProducer prod0 = session0.createProducer(testAddress);
    ClientSessionFactory csf2 = addSessionFactory(locator.createSessionFactory(server2tc));
    session2 = csf2.createSession(false, true, true);
    ClientConsumer cons2 = session2.createConsumer(queueName);
    session2.start();
    final int numMessages = NUM_MESSAGES;
    SimpleString propKey = new SimpleString("propkey");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session0.createMessage(true);
        message.putIntProperty(propKey, i);
        prod0.send(message);
    }
    for (int i = 0; i < numMessages; i++) {
        ClientMessage r1 = cons2.receive(1500);
        assertNotNull(r1);
        assertEquals(i, r1.getObjectProperty(propKey));
    }
    closeServers();
    assertNoMoreConnections();
}
Also used : InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) BridgeConfiguration(org.apache.activemq.artemis.core.config.BridgeConfiguration) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) CoreQueueConfiguration(org.apache.activemq.artemis.core.config.CoreQueueConfiguration) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) NodeManager(org.apache.activemq.artemis.core.server.NodeManager) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Aggregations

NodeManager (org.apache.activemq.artemis.core.server.NodeManager)14 InVMNodeManager (org.apache.activemq.artemis.core.server.impl.InVMNodeManager)10 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 SharedStoreSlavePolicyConfiguration (org.apache.activemq.artemis.core.config.ha.SharedStoreSlavePolicyConfiguration)5 ReplicaPolicyConfiguration (org.apache.activemq.artemis.core.config.ha.ReplicaPolicyConfiguration)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)3 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)3 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)3 BridgeConfiguration (org.apache.activemq.artemis.core.config.BridgeConfiguration)3 CoreQueueConfiguration (org.apache.activemq.artemis.core.config.CoreQueueConfiguration)3 SharedStoreMasterPolicyConfiguration (org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration)3 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)2 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)2 ClientSessionFactoryInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal)2 Configuration (org.apache.activemq.artemis.core.config.Configuration)2 ReplicatedPolicyConfiguration (org.apache.activemq.artemis.core.config.ha.ReplicatedPolicyConfiguration)2 JndiBindingRegistry (org.apache.activemq.artemis.core.registry.JndiBindingRegistry)2