Repository: activemq
Updated Branches:
  refs/heads/master 91d277ccb -> 6cf8bed0c


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

Update test with additional checks and logging to try and see what is
happening when it is failing in CI.

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

Branch: refs/heads/master
Commit: 6cf8bed0c55640306923dd94eb1209e7815fd7e9
Parents: 91d277c
Author: Timothy Bish <[email protected]>
Authored: Mon May 9 16:57:39 2016 -0400
Committer: Timothy Bish <[email protected]>
Committed: Mon May 9 16:57:39 2016 -0400

----------------------------------------------------------------------
 .../activemq/broker/LinkStealingTest.java       | 50 ++++++++++----------
 1 file changed, 26 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/6cf8bed0/activemq-broker/src/test/java/org/apache/activemq/broker/LinkStealingTest.java
----------------------------------------------------------------------
diff --git 
a/activemq-broker/src/test/java/org/apache/activemq/broker/LinkStealingTest.java
 
b/activemq-broker/src/test/java/org/apache/activemq/broker/LinkStealingTest.java
index bd88430..2a2fb90 100644
--- 
a/activemq-broker/src/test/java/org/apache/activemq/broker/LinkStealingTest.java
+++ 
b/activemq-broker/src/test/java/org/apache/activemq/broker/LinkStealingTest.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
@@ -16,11 +16,9 @@
  */
 package org.apache.activemq.broker;
 
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
-import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
 
 import javax.jms.Connection;
@@ -31,9 +29,13 @@ import org.apache.activemq.command.ConnectionInfo;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class LinkStealingTest {
 
+    private static final Logger LOG = 
LoggerFactory.getLogger(LinkStealingTest.class);
+
     private BrokerService brokerService;
     private final AtomicReference<Throwable> removeException = new 
AtomicReference<Throwable>();
 
@@ -45,15 +47,14 @@ public class LinkStealingTest {
     public void setUp() throws Exception {
         brokerService = new BrokerService();
         brokerService.setPersistent(false);
-        brokerService.setPlugins(new BrokerPlugin[]{
-            new BrokerPluginSupport() {
-                @Override
-                public void removeConnection(ConnectionContext context, 
ConnectionInfo info, Throwable error) throws Exception {
-                    removeException.set(error);
-                    super.removeConnection(context, info, error);
-                }
+        brokerService.setPlugins(new BrokerPlugin[] { new 
BrokerPluginSupport() {
+            @Override
+            public void removeConnection(ConnectionContext context, 
ConnectionInfo info, Throwable error) throws Exception {
+                LOG.info("Remove Connection called for connection [{}] with 
error: {}", info.getConnectionId(), error);
+                removeException.set(error);
+                super.removeConnection(context, info, error);
             }
-        });
+        }});
 
         stealableConnectionURI = 
brokerService.addConnector("tcp://0.0.0.0:0?allowLinkStealing=true").getPublishableConnectString();
         unstealableConnectionURI = 
brokerService.addConnector("tcp://0.0.0.0:0?allowLinkStealing=false").getPublishableConnectString();
@@ -65,50 +66,51 @@ public class LinkStealingTest {
     public void tearDown() throws Exception {
         if (brokerService != null) {
             brokerService.stop();
+            brokerService = null;
         }
     }
 
-    @Test(timeout=60000)
+    @Test(timeout = 60000)
     public void testStealLinkFails() throws Exception {
-
         final String clientID = "ThisIsAClientId";
         ActiveMQConnectionFactory factory = new 
ActiveMQConnectionFactory(unstealableConnectionURI);
         Connection connection1 = factory.createConnection();
         connection1.setClientID(clientID);
         connection1.start();
 
-        AtomicBoolean exceptionFlag = new AtomicBoolean();
         try {
             Connection connection2 = factory.createConnection();
             connection2.setClientID(clientID);
             connection2.start();
+            fail("Should not have been able to steal the link.");
         } catch (InvalidClientIDException e) {
-            exceptionFlag.set(true);
+            LOG.info("Caught expected error on trying to steal link: {}", 
e.getMessage());
+            LOG.trace("Error: ", e);
         }
-
-        assertTrue(exceptionFlag.get());
     }
 
-    @Test(timeout=60000)
+    @Test(timeout = 60000)
     public void testStealLinkSuccess() throws Exception {
-
         final String clientID = "ThisIsAClientId";
         ActiveMQConnectionFactory factory = new 
ActiveMQConnectionFactory(stealableConnectionURI);
         Connection connection1 = factory.createConnection();
         connection1.setClientID(clientID);
         connection1.start();
 
-        AtomicBoolean exceptionFlag = new AtomicBoolean();
         try {
             Connection connection2 = factory.createConnection();
             connection2.setClientID(clientID);
             connection2.start();
         } catch (InvalidClientIDException e) {
-            e.printStackTrace();
-            exceptionFlag.set(true);
+            LOG.info("Should not have failed while stealing the link: {}", 
e.getMessage());
+            LOG.info("Error details: ", e);
+            fail("Shouldn't have failed when stealing the link");
+        } catch (Throwable error) {
+            LOG.info("Unexpected exception ", error);
+            fail("Unexcpected exception causes test failure");
         }
 
-        assertFalse(exceptionFlag.get());
         assertNotNull(removeException.get());
+        LOG.info("removeException: {}", removeException.get().getMessage());
     }
 }

Reply via email to