activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [1/2] activemq-artemis git commit: added check to stop broker
Date Mon, 03 Aug 2015 12:23:32 GMT
Repository: activemq-artemis
Updated Branches:
  refs/heads/master 9e761ad8e -> 5e2a40555


added check to stop broker


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

Branch: refs/heads/master
Commit: 38147ddbe7493a06f66ffa88d390781334a6eda7
Parents: 9e761ad
Author: Andy Taylor <andy.tayls67@gmail.com>
Authored: Fri Jul 31 09:52:46 2015 +0100
Committer: Andy Taylor <andy.tayls67@gmail.com>
Committed: Mon Aug 3 08:53:39 2015 +0100

----------------------------------------------------------------------
 .../apache/activemq/broker/BrokerService.java   | 32 ++++++++++++++-
 .../ActiveMQXAConnectionFactoryTest.java        |  1 +
 .../apache/activemq/CombinationTestSupport.java | 42 ++++++++++++++++++++
 .../org/apache/activemq/JmsRedeliveredTest.java |  1 +
 .../apache/activemq/MessageEvictionTest.java    | 10 ++++-
 5 files changed, 83 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/38147ddb/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/BrokerService.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/BrokerService.java
b/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/BrokerService.java
index f2b5b30..8ce8fd9 100644
--- a/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/BrokerService.java
+++ b/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/BrokerService.java
@@ -27,6 +27,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.WeakHashMap;
 
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
@@ -96,6 +97,8 @@ public class BrokerService implements Service
    private PolicyMap destinationPolicy;
    private SystemUsage systemUsage;
 
+   public static WeakHashMap<Broker, Exception> map = new WeakHashMap<>();
+
    static
    {
       InputStream in;
@@ -135,7 +138,10 @@ public class BrokerService implements Service
    @Override
    public void start() throws Exception
    {
+      Exception e = new Exception();
+      e.fillInStackTrace();
       startBroker(startAsync);
+      map.put(broker, e);
    }
 
    private void startBroker(boolean async) throws Exception
@@ -605,7 +611,7 @@ public class BrokerService implements Service
 
    public boolean isStopped()
    {
-      return broker.isStopped();
+      return broker != null ? broker.isStopped() : true;
    }
 
    public void setBrokerId(String brokerId)
@@ -744,6 +750,30 @@ public class BrokerService implements Service
    {
       return "tcp://localhost:61616";
    }
+
+   public static boolean checkStopped()
+   {
+      boolean runningBrokers = false;
+      for (Map.Entry<Broker, Exception> brokerExceptionEntry : map.entrySet())
+      {
+         Broker b = brokerExceptionEntry.getKey();
+         if (!b.isStopped())
+         {
+            try
+            {
+               b.stop();
+            }
+            catch (Exception e)
+            {
+               e.printStackTrace();
+            }
+            brokerExceptionEntry.getValue().printStackTrace();
+            runningBrokers = true;
+         }
+      }
+      map.clear();
+      return runningBrokers;
+   }
 }
 
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/38147ddb/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java
b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java
index 4b89851..bafcaa6 100644
--- a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java
@@ -71,6 +71,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport
{
             broker.stop();
         } catch (Throwable ignore) {
         }
+        super.tearDown();
     }
 
     public void testCopy() throws URISyntaxException, JMSException {

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/38147ddb/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/CombinationTestSupport.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/CombinationTestSupport.java
b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/CombinationTestSupport.java
index a11505c..f26a975 100644
--- a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/CombinationTestSupport.java
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/CombinationTestSupport.java
@@ -21,6 +21,7 @@ import java.io.IOException;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.net.ServerSocket;
 import java.security.ProtectionDomain;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -35,6 +36,9 @@ import java.util.Map;
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import org.apache.activemq.artemiswrapper.ArtemisBrokerHelper;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.transport.tcp.TcpTransportFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -102,6 +106,44 @@ public abstract class CombinationTestSupport extends AutoFailTestSupport
{
     }
 
     @Override
+    protected void tearDown() throws Exception
+    {
+        super.tearDown();
+        checkStopped();
+    }
+
+    public static void checkStopped() throws Exception
+    {
+        ArtemisBrokerHelper.stopArtemisBroker();
+        boolean notStopped = BrokerService.checkStopped();
+        TcpTransportFactory.setBrokerName(null);
+        if (notStopped)
+        {
+            fail("brokers not stopped see exceptions above");
+        }
+        ServerSocket socket = null;
+        try
+        {
+            socket = new ServerSocket(61616);
+        }
+        catch (IOException e)
+        {
+            fail("61616 port not released");
+        }
+        finally
+        {
+            if (socket != null)
+            try
+            {
+                socket.close();
+            }
+            catch (IOException e)
+            {
+            }
+        }
+    }
+
+    @Override
     public void runBare() throws Throwable {
         if (combosEvaluated) {
             super.runBare();

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/38147ddb/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/JmsRedeliveredTest.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/JmsRedeliveredTest.java
b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/JmsRedeliveredTest.java
index e5d90d6..8a2cd62 100644
--- a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/JmsRedeliveredTest.java
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/JmsRedeliveredTest.java
@@ -59,6 +59,7 @@ public class JmsRedeliveredTest extends TestCase {
             connection.close();
             connection = null;
         }
+        CombinationTestSupport.checkStopped();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/38147ddb/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/MessageEvictionTest.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/MessageEvictionTest.java
b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/MessageEvictionTest.java
index b079070..efa86a9 100644
--- a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/MessageEvictionTest.java
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/MessageEvictionTest.java
@@ -80,8 +80,14 @@ public class MessageEvictionTest {
 
     @After
     public void tearDown() throws Exception {
-        connection.stop();
-        broker.stop();
+        if (connection != null)
+        {
+            connection.stop();
+        }
+        if (broker != null)
+        {
+            broker.stop();
+        }
     }
 
     @Test


Mime
View raw message