Search in sources :

Example 11 with ClusterConnection

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

the class ClusterTestBase method stopClusterConnections.

protected void stopClusterConnections(final int... nodes) throws Exception {
    for (int node : nodes) {
        if (servers[node].isStarted()) {
            for (ClusterConnection cc : servers[node].getClusterManager().getClusterConnections()) {
                cc.stop();
                cc.flushExecutor();
            }
        }
    }
}
Also used : ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection)

Example 12 with ClusterConnection

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

the class OneWayChainClusterTest method testChainClusterConnections.

@Test
public void testChainClusterConnections() throws Exception {
    setupClusterConnection("cluster0-1", 0, 1, "queues", MessageLoadBalancingType.ON_DEMAND, 4, isNetty(), true);
    setupClusterConnection("cluster1-2", 1, 2, "queues", MessageLoadBalancingType.ON_DEMAND, 4, isNetty(), true);
    setupClusterConnection("cluster2-3", 2, 3, "queues", MessageLoadBalancingType.ON_DEMAND, 4, isNetty(), true);
    setupClusterConnection("cluster3-4", 3, 4, "queues", MessageLoadBalancingType.ON_DEMAND, 4, isNetty(), true);
    setupClusterConnection("cluster4-X", 4, -1, "queues", MessageLoadBalancingType.ON_DEMAND, 4, isNetty(), true);
    startServers(0, 1, 2, 3, 4);
    Set<ClusterConnection> connectionSet = getServer(0).getClusterManager().getClusterConnections();
    assertNotNull(connectionSet);
    assertEquals(1, connectionSet.size());
    ClusterConnectionImpl ccon = (ClusterConnectionImpl) connectionSet.iterator().next();
    long timeout = System.currentTimeMillis() + 5000;
    Map<String, MessageFlowRecord> records = null;
    while (timeout > System.currentTimeMillis()) {
        records = ccon.getRecords();
        if (records != null && records.size() == 1) {
            break;
        }
    }
    assertNotNull(records);
    assertEquals(records.size(), 1);
    getServer(1).getClusterManager().getClusterConnections();
    assertNotNull(connectionSet);
    assertEquals(1, connectionSet.size());
    ccon = (ClusterConnectionImpl) connectionSet.iterator().next();
    records = ccon.getRecords();
    assertNotNull(records);
    assertEquals(records.size(), 1);
    getServer(2).getClusterManager().getClusterConnections();
    assertNotNull(connectionSet);
    assertEquals(1, connectionSet.size());
    ccon = (ClusterConnectionImpl) connectionSet.iterator().next();
    records = ccon.getRecords();
    assertNotNull(records);
    assertEquals(records.size(), 1);
    getServer(3).getClusterManager().getClusterConnections();
    assertNotNull(connectionSet);
    assertEquals(1, connectionSet.size());
    ccon = (ClusterConnectionImpl) connectionSet.iterator().next();
    records = ccon.getRecords();
    assertNotNull(records);
    assertEquals(records.size(), 1);
    getServer(4).getClusterManager().getClusterConnections();
    assertNotNull(connectionSet);
    assertEquals(1, connectionSet.size());
    ccon = (ClusterConnectionImpl) connectionSet.iterator().next();
    records = ccon.getRecords();
    assertNotNull(records);
    assertEquals(records.size(), 1);
}
Also used : MessageFlowRecord(org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord) ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) ClusterConnectionImpl(org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl) Test(org.junit.Test)

Example 13 with ClusterConnection

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

the class SharedNothingLiveActivation method getActivationChannelHandler.

@Override
public ChannelHandler getActivationChannelHandler(final Channel channel, final Acceptor acceptorUsed) {
    return new ChannelHandler() {

        @Override
        public void handlePacket(Packet packet) {
            if (packet.getType() == PacketImpl.BACKUP_REGISTRATION) {
                BackupRegistrationMessage msg = (BackupRegistrationMessage) packet;
                ClusterConnection clusterConnection = acceptorUsed.getClusterConnection();
                try {
                    startReplication(channel.getConnection(), clusterConnection, getPair(msg.getConnector(), true), msg.isFailBackRequest());
                } catch (ActiveMQAlreadyReplicatingException are) {
                    channel.send(new BackupReplicationStartFailedMessage(BackupReplicationStartFailedMessage.BackupRegistrationProblem.ALREADY_REPLICATING));
                } catch (ActiveMQException e) {
                    logger.debug("Failed to process backup registration packet", e);
                    channel.send(new BackupReplicationStartFailedMessage(BackupReplicationStartFailedMessage.BackupRegistrationProblem.EXCEPTION));
                }
            }
        }
    };
}
Also used : BackupRegistrationMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.BackupRegistrationMessage) Packet(org.apache.activemq.artemis.core.protocol.core.Packet) ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) BackupReplicationStartFailedMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.BackupReplicationStartFailedMessage) ActiveMQAlreadyReplicatingException(org.apache.activemq.artemis.api.core.ActiveMQAlreadyReplicatingException) ChannelHandler(org.apache.activemq.artemis.core.protocol.core.ChannelHandler)

Example 14 with ClusterConnection

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

the class JMSUtil method waitForFailoverTopology.

public static void waitForFailoverTopology(final int timeToWait, final ActiveMQServer backupServer, final ActiveMQServer... liveServers) throws Exception {
    long start = System.currentTimeMillis();
    final int waitMillis = 2000;
    final int sleepTime = 50;
    int nWaits = 0;
    while ((backupServer.getClusterManager() == null || backupServer.getClusterManager().getClusterConnections().size() != 1) && nWaits++ < waitMillis / sleepTime) {
        Thread.sleep(sleepTime);
    }
    Set<ClusterConnection> ccs = backupServer.getClusterManager().getClusterConnections();
    if (ccs.size() != 1) {
        throw new IllegalStateException("You need a single cluster connection on this version of waitForTopology on ServiceTestBase");
    }
    boolean exists = false;
    for (ActiveMQServer liveServer : liveServers) {
        ClusterConnectionImpl clusterConnection = (ClusterConnectionImpl) ccs.iterator().next();
        Topology topology = clusterConnection.getTopology();
        TransportConfiguration nodeConnector = liveServer.getClusterManager().getClusterConnections().iterator().next().getConnector();
        do {
            Collection<TopologyMemberImpl> members = topology.getMembers();
            for (TopologyMemberImpl member : members) {
                if (member.getConnector().getA() != null && member.getConnector().getA().equals(nodeConnector)) {
                    exists = true;
                    break;
                }
            }
            if (exists) {
                break;
            }
            Thread.sleep(10);
        } while (System.currentTimeMillis() - start < timeToWait);
        if (!exists) {
            String msg = "Timed out waiting for cluster topology of " + backupServer + " (received " + topology.getMembers().size() + ") topology = " + topology + ")";
            throw new Exception(msg);
        }
    }
}
Also used : TopologyMemberImpl(org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) Topology(org.apache.activemq.artemis.core.client.impl.Topology) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) JMSException(javax.jms.JMSException) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) ClusterConnectionImpl(org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl)

Example 15 with ClusterConnection

use of org.apache.activemq.artemis.core.server.cluster.ClusterConnection 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)

Aggregations

ClusterConnection (org.apache.activemq.artemis.core.server.cluster.ClusterConnection)16 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)7 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)6 TopologyMemberImpl (org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl)6 Topology (org.apache.activemq.artemis.core.client.impl.Topology)5 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)5 ClusterManager (org.apache.activemq.artemis.core.server.cluster.ClusterManager)5 ClusterConnectionImpl (org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl)4 IOException (java.io.IOException)3 SQLException (java.sql.SQLException)3 XAException (javax.transaction.xa.XAException)3 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)3 MessageFlowRecord (org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord)2 Test (org.junit.Test)2 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 JMSException (javax.jms.JMSException)1