Search in sources :

Example 6 with ClusterManager

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

the class JMSUtil method crash.

public static void crash(ActiveMQServer server, ClientSession... sessions) throws Exception {
    final CountDownLatch latch = new CountDownLatch(sessions.length);
    class MyListener implements SessionFailureListener {

        @Override
        public void connectionFailed(final ActiveMQException me, boolean failedOver) {
            latch.countDown();
        }

        @Override
        public void connectionFailed(final ActiveMQException me, boolean failedOver, String scaleDownTargetNodeID) {
            connectionFailed(me, failedOver);
        }

        @Override
        public void beforeReconnect(ActiveMQException exception) {
            System.out.println("MyListener.beforeReconnect");
        }
    }
    for (ClientSession session : sessions) {
        session.addFailureListener(new MyListener());
    }
    ClusterManager clusterManager = server.getClusterManager();
    clusterManager.clear();
    server.fail(true);
    // Wait to be informed of failure
    boolean ok = latch.await(10000, TimeUnit.MILLISECONDS);
    Assert.assertTrue(ok);
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) CountDownLatch(java.util.concurrent.CountDownLatch) SessionFailureListener(org.apache.activemq.artemis.api.core.client.SessionFailureListener) ClusterManager(org.apache.activemq.artemis.core.server.cluster.ClusterManager)

Example 7 with ClusterManager

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

the class ClusterTestBase method clusterDescription.

protected String clusterDescription(ActiveMQServer server) {
    String br = "-------------------------\n";
    String out = br;
    out += "ActiveMQ Artemis server " + server + "\n";
    ClusterManager clusterManager = server.getClusterManager();
    if (clusterManager == null) {
        out += "N/A";
    } else {
        for (ClusterConnection cc : clusterManager.getClusterConnections()) {
            out += cc.describe() + "\n";
            out += cc.getTopology().describe();
        }
    }
    out += "\n\nfull topology:";
    return out + br;
}
Also used : ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClusterManager(org.apache.activemq.artemis.core.server.cluster.ClusterManager)

Example 8 with ClusterManager

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

the class ActiveMQTestBase method tearDown.

@After
public void tearDown() throws Exception {
    closeAllSessionFactories();
    closeAllServerLocatorsFactories();
    try {
        assertAllClientConsumersAreClosed();
        assertAllClientProducersAreClosed();
        assertAllClientSessionsAreClosed();
    } finally {
        synchronized (servers) {
            for (ActiveMQServer server : servers) {
                if (server == null) {
                    continue;
                }
                try {
                    final ClusterManager clusterManager = server.getClusterManager();
                    if (clusterManager != null) {
                        for (ClusterConnection cc : clusterManager.getClusterConnections()) {
                            stopComponent(cc);
                        }
                    }
                } catch (Exception e) {
                // no-op
                }
                stopComponentOutputExceptions(server);
            }
            servers.clear();
        }
        closeAllOtherComponents();
        ArrayList<Exception> exceptions;
        try {
            exceptions = checkCsfStopped();
        } finally {
            cleanupPools();
        }
        for (ExecutorService s : executorSet) {
            s.shutdown();
        }
        InVMConnector.resetThreadPool();
        assertAllExecutorsFinished();
        // clean up pools before failing
        if (!exceptions.isEmpty()) {
            for (Exception exception : exceptions) {
                exception.printStackTrace(System.out);
            }
            fail("Client Session Factories still trying to reconnect, see above to see where created");
        }
        Map<Thread, StackTraceElement[]> threadMap = Thread.getAllStackTraces();
        for (Map.Entry<Thread, StackTraceElement[]> entry : threadMap.entrySet()) {
            Thread thread = entry.getKey();
            StackTraceElement[] stack = entry.getValue();
            for (StackTraceElement stackTraceElement : stack) {
                if (stackTraceElement.getMethodName().contains("getConnectionWithRetry") && !alreadyFailedThread.contains(thread)) {
                    alreadyFailedThread.add(thread);
                    System.out.println(threadDump(this.getName() + " has left threads running. Look at thread " + thread.getName() + " id = " + thread.getId() + " has running locators on test " + this.getName() + " on this following dump"));
                    fail("test '" + getName() + "' left serverlocator running, this could effect other tests");
                } else if (stackTraceElement.getMethodName().contains("BroadcastGroupImpl.run") && !alreadyFailedThread.contains(thread)) {
                    alreadyFailedThread.add(thread);
                    System.out.println(threadDump(this.getName() + " has left threads running. Look at thread " + thread.getName() + " id = " + thread.getId() + " is still broadcasting " + this.getName() + " on this following dump"));
                    fail("test left broadcastgroupimpl running, this could effect other tests");
                }
            }
        }
        if (Thread.currentThread().getContextClassLoader() == null) {
            Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
            fail("Thread Context ClassLoader was set to null at some point before this test. We will set to this.getClass().getClassLoader(), but you are supposed to fix your tests");
        }
        checkFilesUsage();
    }
    if (InVMRegistry.instance.size() > 0) {
        fail("InVMREgistry size > 0");
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) ExecutorService(java.util.concurrent.ExecutorService) ClusterManager(org.apache.activemq.artemis.core.server.cluster.ClusterManager) Map(java.util.Map) HashMap(java.util.HashMap) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) XAException(javax.transaction.xa.XAException) SQLException(java.sql.SQLException) IOException(java.io.IOException) After(org.junit.After)

Example 9 with ClusterManager

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

the class ActiveMQTestBase method crashAndWaitForFailure.

public static void crashAndWaitForFailure(ActiveMQServer server, ClientSession... sessions) throws Exception {
    CountDownLatch latch = new CountDownLatch(sessions.length);
    for (ClientSession session : sessions) {
        CountDownSessionFailureListener listener = new CountDownSessionFailureListener(latch, session);
        session.addFailureListener(listener);
    }
    ClusterManager clusterManager = server.getClusterManager();
    clusterManager.flushExecutor();
    clusterManager.clear();
    Assert.assertTrue("server should be running!", server.isStarted());
    server.fail(true);
    if (sessions.length > 0) {
        // Wait to be informed of failure
        boolean ok = latch.await(10000, TimeUnit.MILLISECONDS);
        Assert.assertTrue("Failed to stop the server! Latch count is " + latch.getCount() + " out of " + sessions.length, ok);
    }
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterManager(org.apache.activemq.artemis.core.server.cluster.ClusterManager)

Example 10 with ClusterManager

use of org.apache.activemq.artemis.core.server.cluster.ClusterManager in project wildfly by wildfly.

the class HTTPUpgradeService method selectServer.

private static ActiveMQServer selectServer(HttpServerExchange exchange, ActiveMQServer rootServer) {
    String activemqServerName = exchange.getRequestHeaders().getFirst(TransportConstants.ACTIVEMQ_SERVER_NAME);
    if (activemqServerName == null) {
        return rootServer;
    }
    ClusterManager clusterManager = rootServer.getClusterManager();
    if (clusterManager != null) {
        HAManager haManager = clusterManager.getHAManager();
        if (haManager != null) {
            for (Map.Entry<String, ActiveMQServer> entry : haManager.getBackupServers().entrySet()) {
                if (entry.getKey().equals(activemqServerName)) {
                    return entry.getValue();
                }
            }
        }
    }
    if (activemqServerName.equals(rootServer.getConfiguration().getName())) {
        return rootServer;
    } else {
        return null;
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) HAManager(org.apache.activemq.artemis.core.server.cluster.ha.HAManager) HttpString(io.undertow.util.HttpString) ClusterManager(org.apache.activemq.artemis.core.server.cluster.ClusterManager) Map(java.util.Map)

Aggregations

ClusterManager (org.apache.activemq.artemis.core.server.cluster.ClusterManager)10 ClusterConnection (org.apache.activemq.artemis.core.server.cluster.ClusterConnection)5 CountDownLatch (java.util.concurrent.CountDownLatch)3 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)3 Map (java.util.Map)2 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)2 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)2 TopologyMemberImpl (org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl)2 HttpString (io.undertow.util.HttpString)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 JsonArrayBuilder (javax.json.JsonArrayBuilder)1 JsonObjectBuilder (javax.json.JsonObjectBuilder)1 XAException (javax.transaction.xa.XAException)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)1 SessionFailureListener (org.apache.activemq.artemis.api.core.client.SessionFailureListener)1 Topology (org.apache.activemq.artemis.core.client.impl.Topology)1