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 2019/05/31 23:06:54 UTC

[activemq-artemis] branch master updated (64dae91 -> d4973ff)

This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git.


    from 64dae91  This closes #2690
     new b7047fa  NO-JIRA Adding checking for leaking server socket
     new a7e5e6d  NO-JIRA test improvements
     new d4973ff  This closes #2689

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../activemq/artemis/utils/PortCheckRule.java      | 74 ++++++++++++++++++++++
 .../core/message/impl/CoreMessagePersister.java    | 11 +++-
 .../artemis/tests/util/ActiveMQTestBase.java       | 30 ++-------
 .../tests/integration/client/SendAckFailTest.java  | 24 ++++++-
 .../cluster/distribution/ClusterTestBase.java      |  9 +--
 .../replication/SharedNothingReplicationTest.java  | 28 ++++----
 .../server/ActivationFailureListenerTest.java      |  4 +-
 tests/jms-tests/pom.xml                            |  7 ++
 .../remoting/impl/netty/NettyAcceptorTest.java     | 21 +++---
 .../impl/netty/NettyHandshakeTimeoutTest.java      | 16 ++---
 10 files changed, 157 insertions(+), 67 deletions(-)
 create mode 100644 artemis-commons/src/test/java/org/apache/activemq/artemis/utils/PortCheckRule.java


[activemq-artemis] 03/03: This closes #2689

Posted by cl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit d4973ff636c5283b599497c4d95ae19510acd60e
Merge: 64dae91 a7e5e6d
Author: Clebert Suconic <cl...@apache.org>
AuthorDate: Fri May 31 19:06:16 2019 -0400

    This closes #2689

 .../activemq/artemis/utils/PortCheckRule.java      | 74 ++++++++++++++++++++++
 .../core/message/impl/CoreMessagePersister.java    | 11 +++-
 .../artemis/tests/util/ActiveMQTestBase.java       | 30 ++-------
 .../tests/integration/client/SendAckFailTest.java  | 24 ++++++-
 .../cluster/distribution/ClusterTestBase.java      |  9 +--
 .../replication/SharedNothingReplicationTest.java  | 28 ++++----
 .../server/ActivationFailureListenerTest.java      |  4 +-
 tests/jms-tests/pom.xml                            |  7 ++
 .../remoting/impl/netty/NettyAcceptorTest.java     | 21 +++---
 .../impl/netty/NettyHandshakeTimeoutTest.java      | 16 ++---
 10 files changed, 157 insertions(+), 67 deletions(-)


[activemq-artemis] 01/03: NO-JIRA Adding checking for leaking server socket

Posted by cl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit b7047faea5f5fd309c71bcdcc7beedb75d6f32eb
Author: Clebert Suconic <cl...@apache.org>
AuthorDate: Fri May 31 13:45:15 2019 -0400

    NO-JIRA Adding checking for leaking server socket
---
 .../activemq/artemis/utils/PortCheckRule.java      | 74 ++++++++++++++++++++++
 .../artemis/tests/util/ActiveMQTestBase.java       | 30 ++-------
 .../cluster/distribution/ClusterTestBase.java      |  9 +--
 tests/jms-tests/pom.xml                            |  7 ++
 .../remoting/impl/netty/NettyAcceptorTest.java     | 21 +++---
 5 files changed, 101 insertions(+), 40 deletions(-)

diff --git a/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/PortCheckRule.java b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/PortCheckRule.java
new file mode 100644
index 0000000..6a3bab6
--- /dev/null
+++ b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/PortCheckRule.java
@@ -0,0 +1,74 @@
+/**
+ * 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.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.activemq.artemis.utils;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+
+import org.junit.Assert;
+import org.junit.rules.TestWatcher;
+import org.junit.runner.Description;
+
+/**
+ * This will make sure any properties changed through tests are cleaned up between tests.
+ */
+public class PortCheckRule extends TestWatcher {
+
+   final int[] port;
+
+   public PortCheckRule(int... port) {
+      this.port = port;
+   }
+
+   @Override
+   protected void starting(Description description) {
+      for (int p : port) {
+         if (!checkAvailable(p)) {
+            Assert.fail("a previous test is using port " + p + " on " + description);
+         }
+      }
+   }
+
+   @Override
+   protected void finished(Description description) {
+      for (int p : port) {
+         if (!checkAvailable(p)) {
+            Assert.fail(description + " has left a server socket open on port " + p);
+         }
+      }
+   }
+
+   public static boolean checkAvailable(int port) {
+      ServerSocket s = null;
+      try {
+         s = new ServerSocket();
+         s.bind(new InetSocketAddress("localhost", 61616));
+         return true;
+      } catch (IOException e) {
+         e.printStackTrace();
+         return false;
+      } finally {
+         try {
+            s.close();
+         } catch (Throwable ignored) {
+         }
+      }
+   }
+
+}
diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java b/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java
index 8f7880b..dc5c6cb 100644
--- a/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java
+++ b/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java
@@ -36,7 +36,6 @@ import java.io.ObjectOutputStream;
 import java.io.OutputStream;
 import java.lang.management.ManagementFactory;
 import java.lang.ref.WeakReference;
-import java.net.ServerSocket;
 import java.sql.Connection;
 import java.sql.Driver;
 import java.sql.DriverManager;
@@ -139,6 +138,7 @@ import org.apache.activemq.artemis.utils.ActiveMQThreadFactory;
 import org.apache.activemq.artemis.utils.CleanupSystemPropertiesRule;
 import org.apache.activemq.artemis.utils.Env;
 import org.apache.activemq.artemis.utils.FileUtil;
+import org.apache.activemq.artemis.utils.PortCheckRule;
 import org.apache.activemq.artemis.utils.RandomUtil;
 import org.apache.activemq.artemis.utils.ThreadDumpUtil;
 import org.apache.activemq.artemis.utils.ThreadLeakCheckRule;
@@ -148,6 +148,7 @@ import org.jboss.logging.Logger;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
+import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.rules.TemporaryFolder;
 import org.junit.rules.TestName;
@@ -167,13 +168,16 @@ public abstract class ActiveMQTestBase extends Assert {
    private static final Logger logger = Logger.getLogger(ActiveMQTestBase.class);
 
    /** This will make sure threads are not leaking between tests */
-   @Rule
-   public ThreadLeakCheckRule leakCheckRule = new ThreadLeakCheckRule();
+   @ClassRule
+   public static ThreadLeakCheckRule leakCheckRule = new ThreadLeakCheckRule();
 
    /** This will cleanup any system property changed inside tests */
    @Rule
    public CleanupSystemPropertiesRule propertiesRule = new CleanupSystemPropertiesRule();
 
+   @ClassRule
+   public static PortCheckRule portCheckRule = new PortCheckRule(61616);
+
    public static final String TARGET_TMP = "./target/tmp";
    public static final String INVM_ACCEPTOR_FACTORY = InVMAcceptorFactory.class.getCanonicalName();
    public static final String INVM_CONNECTOR_FACTORY = InVMConnectorFactory.class.getCanonicalName();
@@ -365,8 +369,6 @@ public abstract class ActiveMQTestBase extends Assert {
       OperationContextImpl.clearContext();
 
       InVMRegistry.instance.clear();
-
-      // checkFreePort(TransportConstants.DEFAULT_PORT);
    }
 
    public static void assertEqualsByteArrays(final byte[] expected, final byte[] actual) {
@@ -794,24 +796,6 @@ public abstract class ActiveMQTestBase extends Assert {
       return connectors;
    }
 
-   protected static final void checkFreePort(final int... ports) {
-      for (int port : ports) {
-         ServerSocket ssocket = null;
-         try {
-            ssocket = new ServerSocket(port);
-         } catch (Exception e) {
-            throw new IllegalStateException("port " + port + " is bound", e);
-         } finally {
-            if (ssocket != null) {
-               try {
-                  ssocket.close();
-               } catch (IOException e) {
-               }
-            }
-         }
-      }
-   }
-
    /**
     * @return the testDir
     */
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/distribution/ClusterTestBase.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/distribution/ClusterTestBase.java
index af041fc..15b96db 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/distribution/ClusterTestBase.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/distribution/ClusterTestBase.java
@@ -86,9 +86,11 @@ import org.apache.activemq.artemis.core.server.impl.AddressInfo;
 import org.apache.activemq.artemis.core.server.impl.InVMNodeManager;
 import org.apache.activemq.artemis.tests.integration.IntegrationTestLogger;
 import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
+import org.apache.activemq.artemis.utils.PortCheckRule;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
+import org.junit.ClassRule;
 
 public abstract class ClusterTestBase extends ActiveMQTestBase {
 
@@ -96,6 +98,9 @@ public abstract class ClusterTestBase extends ActiveMQTestBase {
 
    private static final int[] PORTS = {TransportConstants.DEFAULT_PORT, TransportConstants.DEFAULT_PORT + 1, TransportConstants.DEFAULT_PORT + 2, TransportConstants.DEFAULT_PORT + 3, TransportConstants.DEFAULT_PORT + 4, TransportConstants.DEFAULT_PORT + 5, TransportConstants.DEFAULT_PORT + 6, TransportConstants.DEFAULT_PORT + 7, TransportConstants.DEFAULT_PORT + 8, TransportConstants.DEFAULT_PORT + 9,};
 
+   @ClassRule
+   public static PortCheckRule rule = new PortCheckRule(PORTS);
+
    protected int getLargeMessageSize() {
       return 500;
    }
@@ -131,8 +136,6 @@ public abstract class ClusterTestBase extends ActiveMQTestBase {
 
       forceGC();
 
-      ActiveMQTestBase.checkFreePort(ClusterTestBase.PORTS);
-
       consumers = new ConsumerHolder[ClusterTestBase.MAX_CONSUMERS];
 
       servers = new ActiveMQServer[ClusterTestBase.MAX_SERVERS];
@@ -175,8 +178,6 @@ public abstract class ClusterTestBase extends ActiveMQTestBase {
 
       super.tearDown();
 
-      ActiveMQTestBase.checkFreePort(ClusterTestBase.PORTS);
-
    }
 
    // Private -------------------------------------------------------------------------------------------------------
diff --git a/tests/jms-tests/pom.xml b/tests/jms-tests/pom.xml
index 3f69947..3d5c821 100644
--- a/tests/jms-tests/pom.xml
+++ b/tests/jms-tests/pom.xml
@@ -41,6 +41,13 @@
       </dependency>
       <dependency>
          <groupId>org.apache.activemq</groupId>
+         <artifactId>artemis-commons</artifactId>
+         <version>${project.version}</version>
+         <scope>test</scope>
+         <type>test-jar</type>
+      </dependency>
+      <dependency>
+         <groupId>org.apache.activemq</groupId>
          <artifactId>artemis-core-client</artifactId>
          <version>${project.version}</version>
       </dependency>
diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/impl/netty/NettyAcceptorTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/impl/netty/NettyAcceptorTest.java
index 6206bf9..2ab990d 100644
--- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/impl/netty/NettyAcceptorTest.java
+++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/impl/netty/NettyAcceptorTest.java
@@ -34,6 +34,7 @@ import org.apache.activemq.artemis.spi.core.remoting.Connection;
 import org.apache.activemq.artemis.spi.core.remoting.ServerConnectionLifeCycleListener;
 import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
 import org.apache.activemq.artemis.utils.ActiveMQThreadFactory;
+import org.apache.activemq.artemis.utils.PortCheckRule;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -48,24 +49,18 @@ public class NettyAcceptorTest extends ActiveMQTestBase {
    @Before
    public void setUp() throws Exception {
       super.setUp();
-
-      ActiveMQTestBase.checkFreePort(TransportConstants.DEFAULT_PORT);
    }
 
    @Override
    @After
    public void tearDown() throws Exception {
-      try {
-         ActiveMQTestBase.checkFreePort(TransportConstants.DEFAULT_PORT);
-      } finally {
+      if (pool3 != null)
+         pool3.shutdown();
 
-         if (pool3 != null)
-            pool3.shutdown();
+      if (pool2 != null)
+         pool2.shutdownNow();
 
-         if (pool2 != null)
-            pool2.shutdownNow();
-         super.tearDown();
-      }
+      super.tearDown();
    }
 
    @Test
@@ -107,13 +102,13 @@ public class NettyAcceptorTest extends ActiveMQTestBase {
       Assert.assertTrue(acceptor.isStarted());
       acceptor.stop();
       Assert.assertFalse(acceptor.isStarted());
-      ActiveMQTestBase.checkFreePort(TransportConstants.DEFAULT_PORT);
+      Assert.assertTrue(PortCheckRule.checkAvailable(TransportConstants.DEFAULT_PORT));
 
       acceptor.start();
       Assert.assertTrue(acceptor.isStarted());
       acceptor.stop();
       Assert.assertFalse(acceptor.isStarted());
-      ActiveMQTestBase.checkFreePort(TransportConstants.DEFAULT_PORT);
+      Assert.assertTrue(PortCheckRule.checkAvailable(TransportConstants.DEFAULT_PORT));
    }
 
 }


[activemq-artemis] 02/03: NO-JIRA test improvements

Posted by cl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit a7e5e6d074aa3be0fa8369c9ceefe17abaae9821
Author: Clebert Suconic <cl...@apache.org>
AuthorDate: Fri May 31 13:45:22 2019 -0400

    NO-JIRA test improvements
---
 .../core/message/impl/CoreMessagePersister.java    | 11 ++++++++-
 .../tests/integration/client/SendAckFailTest.java  | 24 ++++++++++++++++---
 .../replication/SharedNothingReplicationTest.java  | 28 ++++++++++++----------
 .../server/ActivationFailureListenerTest.java      |  4 ++--
 .../impl/netty/NettyHandshakeTimeoutTest.java      | 16 ++++++-------
 5 files changed, 56 insertions(+), 27 deletions(-)

diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/message/impl/CoreMessagePersister.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/message/impl/CoreMessagePersister.java
index 115b29b..cbd565d 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/message/impl/CoreMessagePersister.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/message/impl/CoreMessagePersister.java
@@ -26,7 +26,16 @@ import org.apache.activemq.artemis.utils.DataConstants;
 public class CoreMessagePersister implements Persister<Message> {
    public static final byte ID = 1;
 
-   public static CoreMessagePersister theInstance;
+   private static CoreMessagePersister theInstance;
+
+   /** This is a hook for testing */
+   public static void registerPersister(CoreMessagePersister newPersister) {
+      theInstance = newPersister;
+   }
+
+   public static void resetPersister() {
+      theInstance = null;
+   }
 
    public static CoreMessagePersister getInstance() {
       if (theInstance == null) {
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/SendAckFailTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/SendAckFailTest.java
index 9364aa0..ab1932f 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/SendAckFailTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/SendAckFailTest.java
@@ -128,7 +128,7 @@ public class SendAckFailTest extends SpawnedTestBase {
             ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
             ServerLocator locator = factory.getServerLocator();
 
-            locator.setConfirmationWindowSize(0).setInitialConnectAttempts(100).setRetryInterval(100).setBlockOnDurableSend(false).setReconnectAttempts(0);
+            locator.setConfirmationWindowSize(0).setInitialConnectAttempts(10000).setRetryInterval(10).setBlockOnDurableSend(false).setReconnectAttempts(0);
 
             ClientSessionFactory sf = locator.createSessionFactory();
 
@@ -213,14 +213,31 @@ public class SendAckFailTest extends SpawnedTestBase {
 
    public ActiveMQServer startServer(boolean fail) {
       try {
-         //ActiveMQServerImpl server = (ActiveMQServerImpl) createServer(true, true);
-
          AtomicInteger count = new AtomicInteger(0);
 
          ActiveMQSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), new SecurityConfiguration());
 
          Configuration configuration = createDefaultConfig(true);
 
+
+         if (fail) {
+            new Thread() {
+               @Override
+               public void run() {
+                  try {
+
+                     // this is a protection, if the process is left forgoten for any amount of time,
+                     // this will kill it
+                     // This is to avoid rogue processes on the CI
+                     Thread.sleep(10000);
+                     System.err.println("Halting process, protecting the CI from rogue processes");
+                     Runtime.getRuntime().halt(-1);
+                  } catch (Throwable e) {
+                  }
+               }
+            }.start();
+         }
+
          ActiveMQServer server = new ActiveMQServerImpl(configuration, ManagementFactory.getPlatformMBeanServer(), securityManager) {
             @Override
             public StorageManager createStorageManager() {
@@ -249,6 +266,7 @@ public class SendAckFailTest extends SpawnedTestBase {
 
 
          System.out.println("Location::" + server.getConfiguration().getJournalLocation().getAbsolutePath());
+         addServer(server);
          server.start();
          return server;
       } catch (Exception e) {
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/replication/SharedNothingReplicationTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/replication/SharedNothingReplicationTest.java
index 3997c1d..e6e997f 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/replication/SharedNothingReplicationTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/replication/SharedNothingReplicationTest.java
@@ -46,6 +46,7 @@ import org.apache.activemq.artemis.core.server.ActiveMQServer;
 import org.apache.activemq.artemis.core.server.ActiveMQServers;
 import org.apache.activemq.artemis.core.server.JournalType;
 import org.apache.activemq.artemis.junit.Wait;
+import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
 import org.jboss.logging.Logger;
 import org.junit.After;
 import org.junit.Assert;
@@ -58,12 +59,12 @@ import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
-public class SharedNothingReplicationTest {
+public class SharedNothingReplicationTest extends ActiveMQTestBase {
 
    private static final Logger logger = Logger.getLogger(SharedNothingReplicationTest.class);
 
@@ -71,30 +72,32 @@ public class SharedNothingReplicationTest {
    public TemporaryFolder brokersFolder = new TemporaryFolder();
 
    private SlowMessagePersister slowMessagePersister;
+   ExecutorService sendMessageExecutor;
 
    @Before
+   @Override
    public void setUp() throws Exception {
-      slowMessagePersister = new SlowMessagePersister();
-      CoreMessagePersister.theInstance = slowMessagePersister;
+      super.setUp();
+      sendMessageExecutor = Executors.newSingleThreadExecutor();
+      CoreMessagePersister.registerPersister(SlowMessagePersister._getInstance());
    }
 
    @After
+   @Override
    public void tearDown() throws Exception {
-      if (slowMessagePersister != null) {
-         CoreMessagePersister.theInstance = slowMessagePersister.persister;
-      }
+      CoreMessagePersister.resetPersister();
+      sendMessageExecutor.shutdownNow();
+      super.tearDown();
    }
 
    @Test
    public void testReplicateFromSlowLive() throws Exception {
       // start live
       Configuration liveConfiguration = createLiveConfiguration();
-      ActiveMQServer liveServer = ActiveMQServers.newActiveMQServer(liveConfiguration);
+      ActiveMQServer liveServer = addServer(ActiveMQServers.newActiveMQServer(liveConfiguration));
       liveServer.start();
 
-      Wait.waitFor(() -> liveServer.isStarted());
-
-      CoreMessagePersister.theInstance = SlowMessagePersister._getInstance();
+      Wait.waitFor(liveServer::isStarted);
 
       final CountDownLatch replicated = new CountDownLatch(1);
 
@@ -120,7 +123,6 @@ public class SharedNothingReplicationTest {
       ClientSession sess = csf.createSession();
       sess.createQueue("slow", RoutingType.ANYCAST, "slow", true);
       sess.close();
-      Executor sendMessageExecutor = Executors.newCachedThreadPool();
 
       // let's write some messages
       int i = 0;
@@ -150,7 +152,7 @@ public class SharedNothingReplicationTest {
 
       // start backup
       Configuration backupConfiguration = createBackupConfiguration();
-      ActiveMQServer backupServer = ActiveMQServers.newActiveMQServer(backupConfiguration);
+      ActiveMQServer backupServer = addServer(ActiveMQServers.newActiveMQServer(backupConfiguration));
       backupServer.start();
 
       Wait.waitFor(() -> backupServer.isStarted());
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/server/ActivationFailureListenerTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/server/ActivationFailureListenerTest.java
index 597751b..3d6d307 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/server/ActivationFailureListenerTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/server/ActivationFailureListenerTest.java
@@ -18,7 +18,7 @@
 package org.apache.activemq.artemis.tests.integration.server;
 
 import java.net.InetSocketAddress;
-import java.net.Socket;
+import java.net.ServerSocket;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
@@ -36,7 +36,7 @@ public class ActivationFailureListenerTest extends ActiveMQTestBase {
 
    @Test
    public void simpleTest() throws Exception {
-      Socket s = new Socket();
+      ServerSocket s = new ServerSocket();
       try {
          s.bind(new InetSocketAddress("127.0.0.1", 61616));
          server = createServer(false, createDefaultNettyConfig());
diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/impl/netty/NettyHandshakeTimeoutTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/impl/netty/NettyHandshakeTimeoutTest.java
index ec9c995..515a893 100644
--- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/impl/netty/NettyHandshakeTimeoutTest.java
+++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/impl/netty/NettyHandshakeTimeoutTest.java
@@ -17,6 +17,10 @@
 
 package org.apache.activemq.artemis.tests.unit.core.remoting.impl.netty;
 
+import java.net.URI;
+import java.util.HashMap;
+import java.util.concurrent.TimeUnit;
+
 import io.netty.buffer.ByteBuf;
 import org.apache.activemq.artemis.api.core.TransportConfiguration;
 import org.apache.activemq.artemis.core.config.Configuration;
@@ -30,10 +34,6 @@ import org.apache.activemq.transport.netty.NettyTransportFactory;
 import org.apache.activemq.transport.netty.NettyTransportListener;
 import org.junit.Test;
 
-import java.net.URI;
-import java.util.HashMap;
-import java.util.concurrent.TimeUnit;
-
 public class NettyHandshakeTimeoutTest extends ActiveMQTestBase {
 
    protected ActiveMQServer server;
@@ -43,8 +43,6 @@ public class NettyHandshakeTimeoutTest extends ActiveMQTestBase {
    public void testHandshakeTimeout() throws Exception {
       int handshakeTimeout = 3;
 
-      setUp();
-      ActiveMQTestBase.checkFreePort(TransportConstants.DEFAULT_PORT);
       HashMap<String, Object> params = new HashMap<>();
       params.put(TransportConstants.HANDSHAKE_TIMEOUT, handshakeTimeout);
 
@@ -70,10 +68,12 @@ public class NettyHandshakeTimeoutTest extends ActiveMQTestBase {
 
       try {
          transport.connect();
-         assertTrue("Connection should be closed now", Wait.waitFor(() -> !transport.isConnected(), TimeUnit.SECONDS.toMillis(handshakeTimeout + 1)));
+         assertTrue("Connection should be closed now", Wait.waitFor(() -> !transport.isConnected(), TimeUnit.SECONDS.toMillis(handshakeTimeout + 10)));
       } finally {
          transport.close();
-         tearDown();
       }
+
+      server.stop();
+
    }
 }