diff --git a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v11/StompFrameHandlerV11.java b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v11/StompFrameHandlerV11.java index d994161810e..868ccf9de6c 100644 --- a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v11/StompFrameHandlerV11.java +++ b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v11/StompFrameHandlerV11.java @@ -266,6 +266,8 @@ private class HeartBeater extends ActiveMQScheduledComponent { private static final int MIN_SERVER_PING = 500; + private boolean previouslyStopped = false; + long serverPingPeriod = 0; long clientPingResponse; AtomicLong lastPingTimestamp = new AtomicLong(0); @@ -321,7 +323,14 @@ private HeartBeater(ScheduledExecutorService scheduledExecutorService, public void shutdown() { this.stop(); + previouslyStopped = true; + } + @Override + public void start() { + if (!previouslyStopped) { + super.start(); + } } public void pinged() { diff --git a/artemis-unit-test-support/src/main/java/org/apache/activemq/artemis/utils/Wait.java b/artemis-unit-test-support/src/main/java/org/apache/activemq/artemis/utils/Wait.java index 0522c45acce..0864f5a8bdd 100644 --- a/artemis-unit-test-support/src/main/java/org/apache/activemq/artemis/utils/Wait.java +++ b/artemis-unit-test-support/src/main/java/org/apache/activemq/artemis/utils/Wait.java @@ -152,6 +152,10 @@ public static void assertFalse(String failureMessage, Condition condition, final assertTrue(failureMessage, () -> !condition.isSatisfied(), duration, SLEEP_MILLIS); } + public static void assertFalse(Supplier failureMessage, Condition condition, final long duration, final long sleep) { + assertTrue(failureMessage, () -> !condition.isSatisfied(), duration, sleep); + } + public static void assertFalse(Condition condition, final long duration, final long sleep) { assertTrue(DEFAULT_FAILURE_MESSAGE, () -> !condition.isSatisfied(), duration, sleep); } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/v11/StompV11Test.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/v11/StompV11Test.java index 212db668692..d2cc4b5802c 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/v11/StompV11Test.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/v11/StompV11Test.java @@ -2255,6 +2255,8 @@ public void testHeartBeat4() throws Exception { subFrame.addHeader("destination", getTopicPrefix() + getTopicName()); subFrame.addHeader("id", "0"); + Wait.assertTrue(() -> "HeartBeater is not running!! -> " + System.identityHashCode(stompFrameHandler.getHeartBeater()), () -> stompFrameHandler.getHeartBeater().isStarted(), 5000, 100); + ClientStompFrame f = conn.sendFrame(subFrame); f = conn.sendFrame(subFrame); @@ -2269,7 +2271,7 @@ public void testHeartBeat4() throws Exception { Wait.assertEquals(0, () -> server.getRemotingService().getConnections().size()); - Wait.assertFalse("HeartBeater is still running!!", () -> stompFrameHandler.getHeartBeater().isStarted()); + Wait.assertFalse(() -> "HeartBeater is still running!! -> " + System.identityHashCode(stompFrameHandler.getHeartBeater()), () -> stompFrameHandler.getHeartBeater().isStarted(), 5000, 100); }