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 2018/03/01 19:40:39 UTC
[3/3] activemq-artemis git commit: NO-JIRA Speeding up ReattachTest
NO-JIRA Speeding up ReattachTest
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/e4e864d8
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/e4e864d8
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/e4e864d8
Branch: refs/heads/master
Commit: e4e864d88e3e0c8ea93816f359e5c2a87773d04d
Parents: bdd2c09
Author: Clebert Suconic <cl...@apache.org>
Authored: Wed Feb 28 17:07:00 2018 -0500
Committer: Clebert Suconic <cl...@apache.org>
Committed: Thu Mar 1 14:40:30 2018 -0500
----------------------------------------------------------------------
.../artemis/utils/ActiveMQThreadFactory.java | 25 +++++++++++++++++++-
.../core/remoting/impl/invm/InVMConnector.java | 11 +++++++++
.../cluster/reattach/ReattachTest.java | 22 ++++++++---------
3 files changed, 46 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/e4e864d8/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ActiveMQThreadFactory.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ActiveMQThreadFactory.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ActiveMQThreadFactory.java
index 1644715..419daa2 100644
--- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ActiveMQThreadFactory.java
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ActiveMQThreadFactory.java
@@ -20,6 +20,7 @@ import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
public final class ActiveMQThreadFactory implements ThreadFactory {
@@ -28,6 +29,8 @@ public final class ActiveMQThreadFactory implements ThreadFactory {
private final AtomicInteger threadCount = new AtomicInteger(0);
+ private final ReusableLatch active = new ReusableLatch(0);
+
private final int threadPriority;
private final boolean daemon;
@@ -96,8 +99,28 @@ public final class ActiveMQThreadFactory implements ThreadFactory {
}
}
+ /** It will wait all threads to finish */
+ public boolean join(int timeout, TimeUnit timeUnit) {
+ try {
+ return active.await(timeout, timeUnit);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ return false;
+ }
+ }
+
private Thread createThread(final Runnable command) {
- final Thread t = new Thread(command, prefix + threadCount.getAndIncrement() + " (" + groupName + ")");
+ active.countUp();
+ final Thread t = new Thread(command, prefix + threadCount.getAndIncrement() + " (" + groupName + ")") {
+ @Override
+ public void run() {
+ try {
+ command.run();
+ } finally {
+ active.countDown();
+ }
+ }
+ };
t.setDaemon(daemon);
t.setPriority(threadPriority);
t.setContextClassLoader(tccl);
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/e4e864d8/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/invm/InVMConnector.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/invm/InVMConnector.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/invm/InVMConnector.java
index e635bc4..5693d35 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/invm/InVMConnector.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/invm/InVMConnector.java
@@ -105,6 +105,17 @@ public class InVMConnector extends AbstractConnector {
public static synchronized void resetThreadPool() {
if (threadPoolExecutor != null) {
threadPoolExecutor.shutdownNow();
+ if (threadPoolExecutor instanceof ThreadPoolExecutor) {
+ ThreadPoolExecutor tp = (ThreadPoolExecutor) threadPoolExecutor;
+ if (tp.getThreadFactory() instanceof ActiveMQThreadFactory) {
+ ActiveMQThreadFactory tf = (ActiveMQThreadFactory)tp.getThreadFactory();
+ if (!tf.join(10, TimeUnit.SECONDS)) {
+ // resetThreadPool is only used on tests.
+ // no need to use a logger method, this is just fine.
+ logger.warn("Thread pool is still busy. couldn't stop on time");
+ }
+ }
+ }
threadPoolExecutor = null;
}
}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/e4e864d8/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/reattach/ReattachTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/reattach/ReattachTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/reattach/ReattachTest.java
index dbe6bcb..a20bf74 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/reattach/ReattachTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/reattach/ReattachTest.java
@@ -62,11 +62,11 @@ public class ReattachTest extends ActiveMQTestBase {
*/
@Test
public void testImmediateReattach() throws Exception {
- final long retryInterval = 500;
+ final long retryInterval = 50;
final double retryMultiplier = 1d;
- final int reconnectAttempts = 1;
+ final int reconnectAttempts = 10;
locator.setRetryInterval(retryInterval).setRetryIntervalMultiplier(retryMultiplier).setReconnectAttempts(reconnectAttempts).setConfirmationWindowSize(1024 * 1024);
@@ -189,7 +189,7 @@ public class ReattachTest extends ActiveMQTestBase {
*/
@Test
public void testDelayedReattach() throws Exception {
- final long retryInterval = 500;
+ final long retryInterval = 50;
final double retryMultiplier = 1d;
@@ -264,13 +264,13 @@ public class ReattachTest extends ActiveMQTestBase {
// Test an async (e.g. pinger) failure coming in while a connection manager is already reconnecting
@Test
public void testAsyncFailureWhileReattaching() throws Exception {
- final long retryInterval = 500;
+ final long retryInterval = 50;
final double retryMultiplier = 1d;
final int reconnectAttempts = 60;
- final long asyncFailDelay = 2000;
+ final long asyncFailDelay = 200;
locator.setRetryInterval(retryInterval).setRetryIntervalMultiplier(retryMultiplier).setReconnectAttempts(reconnectAttempts).setConfirmationWindowSize(1024 * 1024);
@@ -372,7 +372,7 @@ public class ReattachTest extends ActiveMQTestBase {
@Test
public void testReattachAttemptsFailsToReconnect() throws Exception {
- final long retryInterval = 500;
+ final long retryInterval = 50;
final double retryMultiplier = 1d;
@@ -539,7 +539,7 @@ public class ReattachTest extends ActiveMQTestBase {
@Test
public void testCreateSessionFailBeforeSendSeveralThreads() throws Throwable {
- final long retryInterval = 500;
+ final long retryInterval = 50;
final double retryMultiplier = 1d;
@@ -686,7 +686,7 @@ public class ReattachTest extends ActiveMQTestBase {
@Test
public void testReattachAttemptsSucceedsInReconnecting() throws Exception {
- final long retryInterval = 500;
+ final long retryInterval = 50;
final double retryMultiplier = 1d;
@@ -824,7 +824,7 @@ public class ReattachTest extends ActiveMQTestBase {
@Test
public void testExponentialBackoff() throws Exception {
- final long retryInterval = 500;
+ final long retryInterval = 50;
final double retryMultiplier = 2d;
@@ -891,13 +891,13 @@ public class ReattachTest extends ActiveMQTestBase {
@Test
public void testExponentialBackoffMaxRetryInterval() throws Exception {
- final long retryInterval = 500;
+ final long retryInterval = 50;
final double retryMultiplier = 2d;
final int reconnectAttempts = 60;
- final long maxRetryInterval = 1000;
+ final long maxRetryInterval = 100;
locator.setRetryInterval(retryInterval).setRetryIntervalMultiplier(retryMultiplier).setReconnectAttempts(reconnectAttempts).setMaxRetryInterval(maxRetryInterval).setConfirmationWindowSize(1024 * 1024);