Search in sources :

Example 1 with TestableServer

use of org.apache.activemq.artemis.tests.integration.cluster.util.TestableServer in project activemq-artemis by apache.

the class ClusterWithBackupFailoverTestBase method failNode.

/**
 * @param node             The node which we should fail
 * @param originalLiveNode The number of the original node, to locate session to fail
 * @throws Exception
 */
protected void failNode(final int node, final int originalLiveNode) throws Exception {
    ClusterWithBackupFailoverTestBase.log.info("*** failing node " + node);
    ActiveMQServer server = getServer(node);
    TestableServer tstServer = new SameProcessActiveMQServer(server);
    ClientSession[] sessionsArray = exploreSessions(originalLiveNode);
    tstServer.crash(sessionsArray);
}
Also used : SameProcessActiveMQServer(org.apache.activemq.artemis.tests.integration.cluster.util.SameProcessActiveMQServer) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) SameProcessActiveMQServer(org.apache.activemq.artemis.tests.integration.cluster.util.SameProcessActiveMQServer) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) TestableServer(org.apache.activemq.artemis.tests.integration.cluster.util.TestableServer)

Example 2 with TestableServer

use of org.apache.activemq.artemis.tests.integration.cluster.util.TestableServer in project activemq-artemis by apache.

the class MultipleBackupsFailoverTestBase method waitForNewLive.

protected int waitForNewLive(long seconds, boolean waitForNewBackup, Map<Integer, TestableServer> servers, int... nodes) {
    long time = System.currentTimeMillis();
    long toWait = seconds * 1000;
    int newLive = -1;
    while (true) {
        for (int node : nodes) {
            TestableServer backupServer = servers.get(node);
            if (newLive == -1 && backupServer.isActive()) {
                newLive = node;
            } else if (newLive != -1) {
                if (waitForNewBackup) {
                    if (node != newLive && servers.get(node).isStarted()) {
                        return newLive;
                    }
                } else {
                    return newLive;
                }
            }
        }
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
        // ignore
        }
        if (System.currentTimeMillis() > (time + toWait)) {
            Assert.fail("backup server never started");
        }
    }
}
Also used : TestableServer(org.apache.activemq.artemis.tests.integration.cluster.util.TestableServer)

Example 3 with TestableServer

use of org.apache.activemq.artemis.tests.integration.cluster.util.TestableServer in project activemq-artemis by apache.

the class ReplicatedMultipleServerFailoverExtraBackupsTest method sendCrashBackupReceive.

protected void sendCrashBackupReceive() throws Exception {
    ServerLocator locator0 = getBackupServerLocator(0);
    ServerLocator locator1 = getBackupServerLocator(1);
    ClientSessionFactory factory0 = createSessionFactory(locator0);
    ClientSessionFactory factory1 = createSessionFactory(locator1);
    ClientSession session0 = factory0.createSession(false, true, true);
    ClientSession session1 = factory1.createSession(false, true, true);
    ClientProducer producer = session0.createProducer(ADDRESS);
    for (int i = 0; i < 200; i++) {
        ClientMessage message = session0.createMessage(true);
        setBody(i, message);
        message.putIntProperty("counter", i);
        producer.send(message);
    }
    producer.close();
    waitForDistribution(ADDRESS, backupServers.get(0).getServer(), 100);
    waitForDistribution(ADDRESS, backupServers.get(1).getServer(), 100);
    List<TestableServer> toCrash = new ArrayList<>();
    for (TestableServer backupServer : backupServers) {
        if (!backupServer.getServer().getHAPolicy().isBackup()) {
            toCrash.add(backupServer);
        }
    }
    for (TestableServer testableServer : toCrash) {
        testableServer.crash();
    }
    ClientConsumer consumer0 = session0.createConsumer(ADDRESS);
    ClientConsumer consumer1 = session1.createConsumer(ADDRESS);
    session0.start();
    session1.start();
    for (int i = 0; i < 100; i++) {
        ClientMessage message = consumer0.receive(1000);
        assertNotNull("expecting durable msg " + i, message);
        message.acknowledge();
        consumer1.receive(1000);
        assertNotNull("expecting durable msg " + i, message);
        message.acknowledge();
    }
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) TestableServer(org.apache.activemq.artemis.tests.integration.cluster.util.TestableServer) ArrayList(java.util.ArrayList) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator)

Example 4 with TestableServer

use of org.apache.activemq.artemis.tests.integration.cluster.util.TestableServer in project activemq-artemis by apache.

the class MultipleServerFailoverTestBase method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    liveServers = new ArrayList<>();
    backupServers = new ArrayList<>();
    backupConfigs = new ArrayList<>();
    liveConfigs = new ArrayList<>();
    for (int i = 0; i < getLiveServerCount(); i++) {
        HAPolicyConfiguration haPolicyConfiguration = null;
        if (isSharedStore()) {
            haPolicyConfiguration = new SharedStoreMasterPolicyConfiguration();
        } else {
            haPolicyConfiguration = new ReplicatedPolicyConfiguration();
            if (getNodeGroupName() != null) {
                ((ReplicatedPolicyConfiguration) haPolicyConfiguration).setGroupName(getNodeGroupName() + "-" + i);
            }
        }
        Configuration configuration = createDefaultConfig(isNetty()).clearAcceptorConfigurations().addAcceptorConfiguration(getAcceptorTransportConfiguration(true, i)).setHAPolicyConfiguration(haPolicyConfiguration);
        if (!isSharedStore()) {
            configuration.setBindingsDirectory(getBindingsDir(i, false));
            configuration.setJournalDirectory(getJournalDir(i, false));
            configuration.setPagingDirectory(getPageDir(i, false));
            configuration.setLargeMessagesDirectory(getLargeMessagesDir(i, false));
        } else {
        // todo
        }
        TransportConfiguration livetc = getConnectorTransportConfiguration(true, i);
        configuration.addConnectorConfiguration(livetc.getName(), livetc);
        List<String> connectors = new ArrayList<>();
        for (int j = 0; j < getLiveServerCount(); j++) {
            if (j != i) {
                TransportConfiguration staticTc = getConnectorTransportConfiguration(true, j);
                configuration.getConnectorConfigurations().put(staticTc.getName(), staticTc);
                connectors.add(staticTc.getName());
            }
        }
        String[] input = new String[connectors.size()];
        connectors.toArray(input);
        configuration.addClusterConfiguration(basicClusterConnectionConfig(livetc.getName(), input));
        liveConfigs.add(configuration);
        ActiveMQServer server = createServer(true, configuration);
        TestableServer activeMQServer = new SameProcessActiveMQServer(server);
        activeMQServer.setIdentity("Live-" + i);
        liveServers.add(activeMQServer);
    }
    for (int i = 0; i < getBackupServerCount(); i++) {
        HAPolicyConfiguration haPolicyConfiguration = null;
        if (isSharedStore()) {
            haPolicyConfiguration = new SharedStoreSlavePolicyConfiguration();
        } else {
            haPolicyConfiguration = new ReplicaPolicyConfiguration();
            if (getNodeGroupName() != null) {
                ((ReplicaPolicyConfiguration) haPolicyConfiguration).setGroupName(getNodeGroupName() + "-" + i);
            }
        }
        Configuration configuration = createDefaultConfig(isNetty()).clearAcceptorConfigurations().addAcceptorConfiguration(getAcceptorTransportConfiguration(false, i)).setHAPolicyConfiguration(haPolicyConfiguration);
        if (!isSharedStore()) {
            configuration.setBindingsDirectory(getBindingsDir(i, true));
            configuration.setJournalDirectory(getJournalDir(i, true));
            configuration.setPagingDirectory(getPageDir(i, true));
            configuration.setLargeMessagesDirectory(getLargeMessagesDir(i, true));
        } else {
        // todo
        }
        TransportConfiguration backuptc = getConnectorTransportConfiguration(false, i);
        configuration.addConnectorConfiguration(backuptc.getName(), backuptc);
        List<String> connectors = new ArrayList<>();
        for (int j = 0; j < getBackupServerCount(); j++) {
            TransportConfiguration staticTc = getConnectorTransportConfiguration(true, j);
            configuration.addConnectorConfiguration(staticTc.getName(), staticTc);
            connectors.add(staticTc.getName());
        }
        for (int j = 0; j < getBackupServerCount(); j++) {
            if (j != i) {
                TransportConfiguration staticTc = getConnectorTransportConfiguration(false, j);
                configuration.getConnectorConfigurations().put(staticTc.getName(), staticTc);
                connectors.add(staticTc.getName());
            }
        }
        String[] input = new String[connectors.size()];
        connectors.toArray(input);
        configuration.addClusterConfiguration(basicClusterConnectionConfig(backuptc.getName(), input));
        backupConfigs.add(configuration);
        ActiveMQServer server = createServer(true, configuration);
        TestableServer testableServer = new SameProcessActiveMQServer(server);
        testableServer.setIdentity("Backup-" + i);
        backupServers.add(testableServer);
    }
}
Also used : 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) HAPolicyConfiguration(org.apache.activemq.artemis.core.config.HAPolicyConfiguration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) ReplicatedPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.ReplicatedPolicyConfiguration) ArrayList(java.util.ArrayList) TestableServer(org.apache.activemq.artemis.tests.integration.cluster.util.TestableServer) SharedStoreMasterPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) HAPolicyConfiguration(org.apache.activemq.artemis.core.config.HAPolicyConfiguration) SameProcessActiveMQServer(org.apache.activemq.artemis.tests.integration.cluster.util.SameProcessActiveMQServer) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) SameProcessActiveMQServer(org.apache.activemq.artemis.tests.integration.cluster.util.SameProcessActiveMQServer) SharedStoreSlavePolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreSlavePolicyConfiguration) ReplicatedPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.ReplicatedPolicyConfiguration) ReplicaPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.ReplicaPolicyConfiguration) Before(org.junit.Before)

Example 5 with TestableServer

use of org.apache.activemq.artemis.tests.integration.cluster.util.TestableServer in project activemq-artemis by apache.

the class ReplicatedMultipleServerFailoverTest method testStartBackupFirst.

@Test
public void testStartBackupFirst() throws Exception {
    for (TestableServer backupServer : backupServers) {
        backupServer.start();
    }
    for (TestableServer liveServer : liveServers) {
        liveServer.start();
    }
    waitForTopology(liveServers.get(0).getServer(), liveServers.size(), liveServers.size());
    sendCrashReceive();
}
Also used : TestableServer(org.apache.activemq.artemis.tests.integration.cluster.util.TestableServer) Test(org.junit.Test)

Aggregations

TestableServer (org.apache.activemq.artemis.tests.integration.cluster.util.TestableServer)7 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)3 ArrayList (java.util.ArrayList)2 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)2 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)2 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)2 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)2 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)2 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)2 SameProcessActiveMQServer (org.apache.activemq.artemis.tests.integration.cluster.util.SameProcessActiveMQServer)2 Test (org.junit.Test)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)1 Configuration (org.apache.activemq.artemis.core.config.Configuration)1 HAPolicyConfiguration (org.apache.activemq.artemis.core.config.HAPolicyConfiguration)1 ReplicaPolicyConfiguration (org.apache.activemq.artemis.core.config.ha.ReplicaPolicyConfiguration)1 ReplicatedPolicyConfiguration (org.apache.activemq.artemis.core.config.ha.ReplicatedPolicyConfiguration)1 SharedStoreMasterPolicyConfiguration (org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration)1 SharedStoreSlavePolicyConfiguration (org.apache.activemq.artemis.core.config.ha.SharedStoreSlavePolicyConfiguration)1 Before (org.junit.Before)1