activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject activemq git commit: https://issues.apache.org/jira/browse/AMQ-5604
Date Fri, 20 Feb 2015 16:42:07 GMT
Repository: activemq
Updated Branches:
  refs/heads/master 2c92c3413 -> a2b78fdeb


https://issues.apache.org/jira/browse/AMQ-5604

Clean up test start / stop to streamline things and make the tests run
at a bit more reasonable speed. 

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

Branch: refs/heads/master
Commit: a2b78fdeb0c55f9bf039557861cb0b4400411462
Parents: 2c92c34
Author: Timothy Bish <tabish121@gmail.com>
Authored: Fri Feb 20 11:41:23 2015 -0500
Committer: Timothy Bish <tabish121@gmail.com>
Committed: Fri Feb 20 11:42:03 2015 -0500

----------------------------------------------------------------------
 .../transport/amqp/AmqpTestSupport.java         | 82 ++------------------
 .../transport/amqp/JMSClientTestSupport.java    | 16 +++-
 2 files changed, 17 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/a2b78fde/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/AmqpTestSupport.java
----------------------------------------------------------------------
diff --git a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/AmqpTestSupport.java
b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/AmqpTestSupport.java
index 7c6b052..fa608ab 100644
--- a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/AmqpTestSupport.java
+++ b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/AmqpTestSupport.java
@@ -20,12 +20,8 @@ import java.io.File;
 import java.security.SecureRandom;
 import java.util.Set;
 import java.util.Vector;
-import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
 
 import javax.jms.Connection;
 import javax.jms.Destination;
@@ -59,6 +55,9 @@ public class AmqpTestSupport {
     @Rule public TestName name = new TestName();
 
     protected static final Logger LOG = LoggerFactory.getLogger(AmqpTestSupport.class);
+
+    protected ExecutorService testService = Executors.newSingleThreadExecutor();
+
     protected BrokerService brokerService;
     protected Vector<Throwable> exceptions = new Vector<Throwable>();
     protected int numberOfMessages;
@@ -82,19 +81,8 @@ public class AmqpTestSupport {
     public void setUp() throws Exception {
         LOG.info("========== start " + getTestName() + " ==========");
         exceptions.clear();
-        if (killHungThreads("setUp")) {
-            LOG.warn("HUNG THREADS in setUp");
-        }
 
-        ExecutorService executor = Executors.newSingleThreadExecutor();
-        Future<Boolean> future = executor.submit(new SetUpTask());
-        try {
-            LOG.debug("SetUpTask started.");
-            future.get(60, TimeUnit.SECONDS);
-        } catch (TimeoutException e) {
-            throw new Exception("startBroker timed out");
-        }
-        executor.shutdownNow();
+        startBroker();
 
         this.numberOfMessages = 2000;
     }
@@ -218,42 +206,8 @@ public class AmqpTestSupport {
 
     @After
     public void tearDown() throws Exception {
+        stopBroker();
         LOG.info("========== tearDown " + getTestName() + " ==========");
-        ExecutorService executor = Executors.newSingleThreadExecutor();
-        Future<Boolean> future = executor.submit(new TearDownTask());
-        try {
-            LOG.debug("tearDown started.");
-            future.get(60, TimeUnit.SECONDS);
-        } catch (TimeoutException e) {
-            throw new Exception("stopBroker timed out");
-        } finally {
-            executor.shutdownNow();
-
-            if (killHungThreads("tearDown")) {
-                LOG.warn("HUNG THREADS in tearDown");
-            }
-        }
-    }
-
-    private boolean killHungThreads(String stage) throws Exception{
-        Thread.sleep(500);
-        if (Thread.activeCount() == 1) {
-            return false;
-        }
-        LOG.warn("Hung Thread(s) on {} entry threadCount {} ", stage, Thread.activeCount());
-
-        Thread[] threads = new Thread[Thread.activeCount()];
-        Thread.enumerate(threads);
-        for (int i=0; i < threads.length; i++) {
-            Thread t = threads[i];
-            if (!t.getName().equals("main")) {
-                LOG.warn("KillHungThreads: Interrupting thread {}", t.getName());
-                t.interrupt();
-            }
-        }
-
-        LOG.warn("Hung Thread on {} exit threadCount {} ", stage, Thread.activeCount());
-        return true;
     }
 
     public void sendMessages(Connection connection, Destination destination, int count) throws
Exception {
@@ -310,30 +264,4 @@ public class AmqpTestSupport {
                 .newProxyInstance(queueViewMBeanName, QueueViewMBean.class, true);
         return proxy;
     }
-
-    public class SetUpTask implements Callable<Boolean> {
-        @SuppressWarnings("unused")
-        private String testName;
-
-        @Override
-        public Boolean call() throws Exception {
-            LOG.debug("in SetUpTask.call, calling startBroker");
-            startBroker();
-
-            return Boolean.TRUE;
-        }
-    }
-
-    public class TearDownTask implements Callable<Boolean> {
-        @SuppressWarnings("unused")
-        private String testName;
-
-        @Override
-        public Boolean call() throws Exception {
-            LOG.debug("in TearDownTask.call(), calling stopBroker");
-            stopBroker();
-
-            return Boolean.TRUE;
-        }
-    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/activemq/blob/a2b78fde/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/JMSClientTestSupport.java
----------------------------------------------------------------------
diff --git a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/JMSClientTestSupport.java
b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/JMSClientTestSupport.java
index f53eee3..c7d81a5 100644
--- a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/JMSClientTestSupport.java
+++ b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/JMSClientTestSupport.java
@@ -17,7 +17,6 @@
 package org.apache.activemq.transport.amqp;
 
 import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
@@ -35,18 +34,26 @@ public class JMSClientTestSupport extends AmqpTestSupport {
 
     protected Connection connection;
 
+    private Thread connectionCloseThread;
+
     @Override
     @After
     public void tearDown() throws Exception {
-        ExecutorService executor = Executors.newSingleThreadExecutor();
-        Future<Boolean> future = executor.submit(new CloseConnectionTask());
+        Future<Boolean> future = testService.submit(new CloseConnectionTask());
         try {
             LOG.debug("tearDown started.");
             future.get(60, TimeUnit.SECONDS);
         } catch (TimeoutException e) {
+            if (connectionCloseThread != null) {
+                connectionCloseThread.interrupt();;
+            }
+
+            testService.shutdownNow();
+            testService = Executors.newSingleThreadExecutor();
             throw new Exception("CloseConnection timed out");
         } finally {
-            executor.shutdownNow();
+            connectionCloseThread = null;
+            connection = null;
             super.tearDown();
         }
     }
@@ -55,6 +62,7 @@ public class JMSClientTestSupport extends AmqpTestSupport {
         @Override
         public Boolean call() throws Exception {
             if (connection != null) {
+                connectionCloseThread = Thread.currentThread();
                 LOG.debug("in CloseConnectionTask.call(), calling connection.close()");
                 connection.close();
             }


Mime
View raw message