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