ARTEMIS-1966 Improving SharedNothingReplicationFlowControlTest Tests should always extend ActiveMQTestBase whenever is possible. This is because there are a few rules to avoid thread leakages. The test was also leaking an executor and I believe it was not always stopping the servers, which I fixed here.
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/2a30b291 Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/2a30b291 Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/2a30b291 Branch: refs/heads/master Commit: 2a30b291be94b0283172b15fa573b86769a32070 Parents: 9f8288c Author: Clebert Suconic <clebertsuco...@apache.org> Authored: Thu Jul 12 13:35:59 2018 -0400 Committer: Clebert Suconic <clebertsuco...@apache.org> Committed: Thu Jul 12 13:49:17 2018 -0400 ---------------------------------------------------------------------- ...SharedNothingReplicationFlowControlTest.java | 26 ++++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/2a30b291/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/replication/SharedNothingReplicationFlowControlTest.java ---------------------------------------------------------------------- diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/replication/SharedNothingReplicationFlowControlTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/replication/SharedNothingReplicationFlowControlTest.java index 381b617..923ce3a 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/replication/SharedNothingReplicationFlowControlTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/replication/SharedNothingReplicationFlowControlTest.java @@ -21,7 +21,7 @@ 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; @@ -53,13 +53,29 @@ 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.spi.core.protocol.RemotingConnection; +import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; import org.jboss.logging.Logger; +import org.junit.After; import org.junit.Assert; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -public class SharedNothingReplicationFlowControlTest { +public class SharedNothingReplicationFlowControlTest extends ActiveMQTestBase { + + ExecutorService sendMessageExecutor; + + + @Before + public void setupExecutor() { + sendMessageExecutor = Executors.newCachedThreadPool(); + } + + @After + public void teardownExecutor() { + sendMessageExecutor.shutdownNow(); + } private static final Logger logger = Logger.getLogger(SharedNothingReplicationFlowControlTest.class); @@ -70,7 +86,7 @@ public class SharedNothingReplicationFlowControlTest { public void testReplicationIfFlowControlled() throws Exception { // start live Configuration liveConfiguration = createLiveConfiguration(); - ActiveMQServer liveServer = ActiveMQServers.newActiveMQServer(liveConfiguration); + ActiveMQServer liveServer = addServer(ActiveMQServers.newActiveMQServer(liveConfiguration)); liveServer.start(); Wait.waitFor(() -> liveServer.isStarted()); @@ -83,7 +99,7 @@ public class SharedNothingReplicationFlowControlTest { ClientSession sess = csf.createSession(); sess.createQueue("flowcontrol", RoutingType.ANYCAST, "flowcontrol", true); sess.close(); - Executor sendMessageExecutor = Executors.newCachedThreadPool(); + int i = 0; final int j = 100; @@ -91,7 +107,7 @@ public class SharedNothingReplicationFlowControlTest { // start backup Configuration backupConfiguration = createBackupConfiguration(); - ActiveMQServer backupServer = ActiveMQServers.newActiveMQServer(backupConfiguration); + ActiveMQServer backupServer = addServer(ActiveMQServers.newActiveMQServer(backupConfiguration)); backupServer.start(); Wait.waitFor(() -> backupServer.isStarted());