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();
}
}
}
}
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);
}
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));
}
}
}
};
}
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);
}
}
}
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");
}
}
Aggregations