You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2016/01/12 23:24:23 UTC

[2/3] activemq-artemis git commit: Improvements on Thread check

Improvements on Thread check


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/2d3061d9
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/2d3061d9
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/2d3061d9

Branch: refs/heads/master
Commit: 2d3061d9b69de61cb89ea9cc3e5898e32caf7198
Parents: 8b6d3a6
Author: Clebert Suconic <cl...@apache.org>
Authored: Tue Jan 12 15:10:48 2016 -0500
Committer: Clebert Suconic <cl...@apache.org>
Committed: Tue Jan 12 17:22:56 2016 -0500

----------------------------------------------------------------------
 .../artemis/tests/util/ThreadLeakCheckRule.java | 94 +++++++++-----------
 .../cluster/failover/FailoverTest.java          |  1 -
 .../failover/LiveToLiveFailoverTest.java        |  1 -
 3 files changed, 44 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/2d3061d9/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ThreadLeakCheckRule.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ThreadLeakCheckRule.java b/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ThreadLeakCheckRule.java
index 3f371a8..e3ef4c7 100644
--- a/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ThreadLeakCheckRule.java
+++ b/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ThreadLeakCheckRule.java
@@ -51,84 +51,78 @@ public class ThreadLeakCheckRule extends ExternalResource {
     * Override to tear down your specific external resource.
     */
    protected void after() {
-      if (enabled) {
-         StringBuffer buffer = null;
-
-         boolean failed = true;
-
-         boolean failedOnce = false;
-
-         long timeout = System.currentTimeMillis() + 60000;
-         while (failed && timeout > System.currentTimeMillis()) {
-            buffer = new StringBuffer();
-
-            failed = checkThread(buffer);
-
-            if (failed) {
-               failedOnce = true;
-               ActiveMQTestBase.forceGC();
-               try {
-                  Thread.sleep(500);
+      try {
+         if (enabled) {
+            boolean failed = true;
+
+            boolean failedOnce = false;
+
+            long timeout = System.currentTimeMillis() + 60000;
+            while (failed && timeout > System.currentTimeMillis()) {
+               failed = checkThread();
+
+               if (failed) {
+                  failedOnce = true;
+                  ActiveMQTestBase.forceGC();
+                  try {
+                     Thread.sleep(500);
+                  }
+                  catch (Throwable e) {
+                  }
                }
-               catch (Throwable e) {
-               }
-
-               System.out.println("There are still threads running, trying again");
-               System.out.println(buffer);
             }
-         }
 
-         if (failed) {
-            System.out.println("Thread leaked on test \n" +
-                               buffer);
-            System.out.println("Thread leakage! Failure!!!");
+            if (failed) {
+               Assert.fail("Thread leaked");
+            }
+            else if (failedOnce) {
+               System.out.println("******************** Threads cleared after retries ********************");
+               System.out.println();
+            }
 
-            Assert.fail("Thread leaked");
          }
-         else if (failedOnce) {
-            System.out.println("******************** Threads cleared after retries ********************");
-            System.out.println();
+         else {
+            enabled = true;
          }
-
-
       }
-      else {
-         enabled = true;
+      finally {
+         // clearing just to help GC
+         previousThreads = null;
       }
 
    }
 
 
-
-   /**
-    * @param buffer
-    * @return
-    */
-   private boolean checkThread(StringBuffer buffer) {
+   private boolean checkThread() {
       boolean failedThread = false;
 
       Map<Thread, StackTraceElement[]> postThreads = Thread.getAllStackTraces();
 
       if (postThreads != null && previousThreads != null && postThreads.size() > previousThreads.size()) {
 
-         buffer.append("*********************************************************************************\n");
-         buffer.append("LEAKING THREADS\n");
 
          for (Thread aliveThread : postThreads.keySet()) {
-            if (!isExpectedThread(aliveThread) && !previousThreads.containsKey(aliveThread)) {
+            if (aliveThread.isAlive() && !isExpectedThread(aliveThread) && !previousThreads.containsKey(aliveThread)) {
+               if (!failedThread) {
+                  System.out.println("*********************************************************************************");
+                  System.out.println("LEAKING THREADS");
+               }
                failedThread = true;
-               buffer.append("=============================================================================\n");
-               buffer.append("Thread " + aliveThread + " is still alive with the following stackTrace:\n");
+               System.out.println("=============================================================================");
+               System.out.println("Thread " + aliveThread + " is still alive with the following stackTrace:");
                StackTraceElement[] elements = postThreads.get(aliveThread);
                for (StackTraceElement el : elements) {
-                  buffer.append(el + "\n");
+                  System.out.println(el);
                }
             }
 
          }
-         buffer.append("*********************************************************************************\n");
-
+         if (failedThread) {
+            System.out.println("*********************************************************************************");
+         }
       }
+
+
       return failedThread;
    }
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/2d3061d9/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/FailoverTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/FailoverTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/FailoverTest.java
index 28012eb..8b78f3d 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/FailoverTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/FailoverTest.java
@@ -1393,7 +1393,6 @@ public class FailoverTest extends FailoverTestBase {
 
    @Test
    public void testCreateNewFactoryAfterFailover() throws Exception {
-      this.disableCheckThread();
       locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setFailoverOnInitialConnection(true);
       sf = createSessionFactoryAndWaitForTopology(locator, 2);
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/2d3061d9/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/LiveToLiveFailoverTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/LiveToLiveFailoverTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/LiveToLiveFailoverTest.java
index d0876b3..68f65a4 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/LiveToLiveFailoverTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/LiveToLiveFailoverTest.java
@@ -246,7 +246,6 @@ public class LiveToLiveFailoverTest extends FailoverTest {
    @Override
    @Test
    public void testCreateNewFactoryAfterFailover() throws Exception {
-      this.disableCheckThread();
       locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setFailoverOnInitialConnection(true);
       sf = createSessionFactoryAndWaitForTopology(locator, 2);