use of org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl in project activemq-artemis by apache.
the class ClusterTestBase method logTopologyDiagram.
private void logTopologyDiagram() {
StringBuffer topologyDiagram = new StringBuffer();
for (ActiveMQServer activeMQServer : servers) {
if (activeMQServer != null) {
topologyDiagram.append("\n").append(activeMQServer.getIdentity()).append("\n");
if (activeMQServer.isStarted()) {
Set<ClusterConnection> ccs = activeMQServer.getClusterManager().getClusterConnections();
if (ccs.size() >= 1) {
ClusterConnectionImpl clusterConnection = (ClusterConnectionImpl) ccs.iterator().next();
Collection<TopologyMemberImpl> members = clusterConnection.getTopology().getMembers();
for (TopologyMemberImpl member : members) {
String nodeId = member.getNodeId();
String liveServer = null;
String backupServer = null;
for (ActiveMQServer server : servers) {
if (server != null && server.getNodeID() != null && server.isActive() && server.getNodeID().toString().equals(nodeId)) {
if (server.isActive()) {
liveServer = server.getIdentity();
if (member.getLive() != null) {
liveServer += "(notified)";
} else {
liveServer += "(not notified)";
}
} else {
backupServer = server.getIdentity();
if (member.getBackup() != null) {
liveServer += "(notified)";
} else {
liveServer += "(not notified)";
}
}
}
}
topologyDiagram.append("\t").append("|\n").append("\t->").append(liveServer).append("/").append(backupServer).append("\n");
}
} else {
topologyDiagram.append("-> no cluster connections\n");
}
} else {
topologyDiagram.append("-> stopped\n");
}
}
}
topologyDiagram.append("\n");
log.info(topologyDiagram.toString());
}
use of org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl 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);
}
use of org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl 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);
}
}
}
use of org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl in project activemq-artemis by apache.
the class BindingsClusterTest method crash.
private void crash() throws Exception {
/*
* Rather than just calling stop() on the server here we want to simulate an actual node crash or bridge failure
* so the bridge's failure listener needs to get something other than a DISCONNECTED message. In this case we
* simulate a NOT_CONNECTED exception.
*/
final CountDownLatch latch = new CountDownLatch(1);
ClusterConnectionImpl next = (ClusterConnectionImpl) server1.getClusterManager().getClusterConnections().iterator().next();
BridgeImpl bridge = (BridgeImpl) next.getRecords().values().iterator().next().getBridge();
RemotingConnection forwardingConnection = getForwardingConnection(bridge);
forwardingConnection.addFailureListener(new FailureListener() {
@Override
public void connectionFailed(ActiveMQException exception, boolean failedOver) {
latch.countDown();
}
@Override
public void connectionFailed(final ActiveMQException me, boolean failedOver, String scaleDownTargetNodeID) {
connectionFailed(me, failedOver);
}
});
forwardingConnection.fail(new ActiveMQNotConnectedException());
assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));
if (crash) {
jmsServer2.stop();
}
}
Aggregations