Improving openwire tests on the integration-testsuite

In one situation I have seen a failrue on ProducerFlowControl to break everything else from here
This change will both avoid the failure and change the report of leaked threads so we can find them easily on the system.out when it happens (for future debugging)
This commit is contained in:
Clebert Suconic 2015-09-03 19:16:17 -04:00
parent dbd8bdbd8f
commit 90d05bb17d
3 changed files with 35 additions and 13 deletions

View File

@ -292,6 +292,8 @@ public abstract class ActiveMQTestBase extends Assert {
boolean failed = true;
boolean failedOnce = false;
long timeout = System.currentTimeMillis() + 60000;
while (failed && timeout > System.currentTimeMillis()) {
buffer = new StringBuffer();
@ -299,6 +301,7 @@ public abstract class ActiveMQTestBase extends Assert {
failed = checkThread(buffer);
if (failed) {
failedOnce = true;
forceGC();
Thread.sleep(500);
log.info("There are still threads running, trying again");
@ -309,10 +312,15 @@ public abstract class ActiveMQTestBase extends Assert {
if (failed) {
logAndSystemOut("Thread leaked on test " + this.getClass().getName() + "::" + this.getName() + "\n" +
buffer);
logAndSystemOut("Thread leakage");
logAndSystemOut("Thread leakage! Failure!!!");
fail("Thread leaked");
}
else if (failedOnce) {
System.out.println("******************** Threads cleared after retries ********************");
System.out.println();
}
}
else {
@ -598,12 +606,12 @@ public abstract class ActiveMQTestBase extends Assert {
* Sends the message to both logger and System.out (for unit report)
*/
public void logAndSystemOut(String message, Exception e) {
ActiveMQServerLogger log0 = ActiveMQServerLogger.LOGGER;
log0.info(message, e);
System.out.println(message);
if (e != null) {
e.printStackTrace(System.out);
}
ActiveMQServerLogger log0 = ActiveMQServerLogger.LOGGER;
log0.debug(message, e);
}
/**

View File

@ -16,10 +16,6 @@
*/
package org.apache.activemq.artemis.tests.integration.openwire;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
@ -27,11 +23,15 @@ import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException;
import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.command.ActiveMQDestination;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@ -91,8 +91,15 @@ public class BasicOpenWireTest extends OpenWireTestBase {
Iterator<SimpleString> iterQueues = testQueues.values().iterator();
while (iterQueues.hasNext()) {
SimpleString coreQ = iterQueues.next();
if (server.locateQueue(coreQ) != null) {
this.server.destroyQueue(coreQ);
try {
this.server.destroyQueue(coreQ, null, false, true);
}
catch (ActiveMQNonExistentQueueException idontcare) {
// i don't care if this failed. it means it didn't find the queue
}
catch (Throwable e) {
// just print, what else can we do?
e.printStackTrace();
}
System.out.println("Destroyed queue: " + coreQ);
}

View File

@ -29,11 +29,11 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.artemis.core.config.Configuration;
import org.apache.activemq.artemis.core.settings.impl.AddressFullMessagePolicy;
import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
import org.apache.activemq.artemis.tests.integration.openwire.BasicOpenWireTest;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.transport.tcp.TcpTransport;
import org.junit.After;
import org.junit.Before;
@ -340,9 +340,16 @@ public class ProducerFlowControlTest extends BasicOpenWireTest {
try {
if (flowControlConnection != null) {
TcpTransport t = (TcpTransport) flowControlConnection.getTransport().narrow(TcpTransport.class);
try {
flowControlConnection.getTransport().stop();
flowControlConnection.close();
}
catch (Throwable ignored) {
// sometimes the disposed up can make the test to fail
// even worse I have seen this breaking every single test after this
// if not caught here
}
t.getTransportListener().onException(new IOException("Disposed."));
flowControlConnection.getTransport().stop();
flowControlConnection.close();
}
if (asyncThread != null) {
asyncThread.join();