Search in sources :

Example 6 with TestableServer

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

the class ReplicatedMultipleServerFailoverTest method sendCrashReceive.

protected void sendCrashReceive() throws Exception {
    ServerLocator[] locators = new ServerLocator[liveServers.size()];
    try {
        for (int i = 0; i < locators.length; i++) {
            locators[i] = getServerLocator(i);
        }
        ClientSessionFactory[] factories = new ClientSessionFactory[liveServers.size()];
        for (int i = 0; i < factories.length; i++) {
            factories[i] = createSessionFactory(locators[i]);
        }
        ClientSession[] sessions = new ClientSession[liveServers.size()];
        for (int i = 0; i < factories.length; i++) {
            sessions[i] = createSession(factories[i], true, true);
            sessions[i].createQueue(ADDRESS, RoutingType.MULTICAST, ADDRESS, null, true);
        }
        // make sure bindings are ready before sending messages
        for (int i = 0; i < liveServers.size(); i++) {
            this.waitForBindings(liveServers.get(i).getServer(), ADDRESS.toString(), true, 1, 0, 2000);
            this.waitForBindings(liveServers.get(i).getServer(), ADDRESS.toString(), false, 1, 0, 2000);
        }
        ClientProducer producer = sessions[0].createProducer(ADDRESS);
        for (int i = 0; i < liveServers.size() * 100; i++) {
            ClientMessage message = sessions[0].createMessage(true);
            setBody(i, message);
            message.putIntProperty("counter", i);
            producer.send(message);
        }
        producer.close();
        for (TestableServer liveServer : liveServers) {
            waitForDistribution(ADDRESS, liveServer.getServer(), 100);
        }
        for (TestableServer liveServer : liveServers) {
            liveServer.crash();
        }
        ClientConsumer[] consumers = new ClientConsumer[liveServers.size()];
        for (int i = 0; i < factories.length; i++) {
            consumers[i] = sessions[i].createConsumer(ADDRESS);
            sessions[i].start();
        }
        for (int i = 0; i < 100; i++) {
            for (ClientConsumer consumer : consumers) {
                ClientMessage message = consumer.receive(1000);
                assertNotNull("expecting durable msg " + i, message);
                message.acknowledge();
            }
        }
    } finally {
        for (ServerLocator locator : locators) {
            if (locator != null) {
                try {
                    locator.close();
                } catch (Exception e) {
                // ignore
                }
            }
        }
    }
}
Also used : TestableServer(org.apache.activemq.artemis.tests.integration.cluster.util.TestableServer) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) 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) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator)

Example 7 with TestableServer

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

the class ReplicatedMultipleServerFailoverTest method testStartLiveFirst.

@Test
public void testStartLiveFirst() throws Exception {
    for (TestableServer liveServer : liveServers) {
        liveServer.start();
    }
    for (TestableServer backupServer : backupServers) {
        backupServer.start();
    }
    waitForTopology(liveServers.get(0).getServer(), liveServers.size(), backupServers.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