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.

(cherry picked from commit 2a30b291be94b0283172b15fa573b86769a32070)


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

Branch: refs/heads/2.6.x
Commit: 16f8674ae758af49e091f2526deacae68ff2399c
Parents: 8647ef6
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 14:51:11 2018 -0400

----------------------------------------------------------------------
 ...SharedNothingReplicationFlowControlTest.java | 26 ++++++++++++++++----
 1 file changed, 21 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/16f8674a/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());

Reply via email to