ARTEMIS-1462 Fixing QueueControlTest (cherry picked from commit c66a7975e6834293eee52a87689b3a15839b4843)
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/b097ef38 Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/b097ef38 Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/b097ef38 Branch: refs/heads/1.x Commit: b097ef381ee4971abc12a1b68ceaf0c4a624e9de Parents: ed76ecb Author: Clebert Suconic <[email protected]> Authored: Tue Oct 17 22:30:59 2017 -0400 Committer: Clebert Suconic <[email protected]> Committed: Wed Mar 28 11:54:15 2018 -0400 ---------------------------------------------------------------------- .../core/server/ActiveMQScheduledComponent.java | 4 +-- .../utils/ActiveMQScheduledComponentTest.java | 30 +++++++++++++------- 2 files changed, 21 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b097ef38/artemis-commons/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQScheduledComponent.java ---------------------------------------------------------------------- diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQScheduledComponent.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQScheduledComponent.java index 21ca1f4..1336aa3 100644 --- a/artemis-commons/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQScheduledComponent.java +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQScheduledComponent.java @@ -90,7 +90,7 @@ public abstract class ActiveMQScheduledComponent implements ActiveMQComponent, R long checkPeriod, TimeUnit timeUnit, boolean onDemand) { - this(scheduledExecutorService, executor, checkPeriod, checkPeriod, timeUnit, onDemand); + this(scheduledExecutorService, executor, -1, checkPeriod, timeUnit, onDemand); } /** @@ -144,7 +144,7 @@ public abstract class ActiveMQScheduledComponent implements ActiveMQComponent, R this.millisecondsPeriod = timeUnit.convert(period, TimeUnit.MILLISECONDS); if (period >= 0) { - future = scheduledExecutorService.scheduleWithFixedDelay(runForScheduler, initialDelay, period, timeUnit); + future = scheduledExecutorService.scheduleWithFixedDelay(runForScheduler, initialDelay >= 0 ? initialDelay : period, period, timeUnit); } else { logger.tracef("did not start scheduled executor on %s because period was configured as %d", this, period); } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b097ef38/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/ActiveMQScheduledComponentTest.java ---------------------------------------------------------------------- diff --git a/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/ActiveMQScheduledComponentTest.java b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/ActiveMQScheduledComponentTest.java index 25cc3e1..aa67582 100644 --- a/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/ActiveMQScheduledComponentTest.java +++ b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/ActiveMQScheduledComponentTest.java @@ -79,6 +79,25 @@ public class ActiveMQScheduledComponentTest { } @Test + public void testVerifyInitialDelayChanged() { + final long initialDelay = 10; + final long period = 100; + final ActiveMQScheduledComponent local = new ActiveMQScheduledComponent(scheduledExecutorService, executorService, initialDelay, period, TimeUnit.MILLISECONDS, false) { + @Override + public void run() { + + } + }; + local.start(); + final long newInitialDelay = 1000; + //the parameters are valid? + assert initialDelay != newInitialDelay && newInitialDelay != period; + local.setInitialDelay(newInitialDelay); + local.stop(); + Assert.assertEquals("the initial dalay can't change", newInitialDelay, local.getInitialDelay()); + } + + @Test public void testAccumulationOwnPool() throws Exception { final AtomicInteger count = new AtomicInteger(0); @@ -187,15 +206,4 @@ public class ActiveMQScheduledComponentTest { local.stop(); } } - - @Test - public void testVerifyDefaultInitialDelay() throws InterruptedException { - final ActiveMQScheduledComponent local = new ActiveMQScheduledComponent(scheduledExecutorService, executorService, 100, TimeUnit.MILLISECONDS, false) { - @Override - public void run() { - - } - }; - Assert.assertEquals("The initial delay must be defaulted to the period", local.getPeriod(), local.getInitialDelay()); - } }
