From b097ef381ee4971abc12a1b68ceaf0c4a624e9de Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Tue, 17 Oct 2017 22:30:59 -0400 Subject: [PATCH] ARTEMIS-1462 Fixing QueueControlTest (cherry picked from commit c66a7975e6834293eee52a87689b3a15839b4843) --- .../server/ActiveMQScheduledComponent.java | 4 +-- .../utils/ActiveMQScheduledComponentTest.java | 30 ++++++++++++------- 2 files changed, 21 insertions(+), 13 deletions(-) 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 21ca1f4794..1336aa3fe7 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); } 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 25cc3e110e..aa67582f12 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 @@ -78,6 +78,25 @@ public class ActiveMQScheduledComponentTest { Assert.assertTrue("just because one took a lot of time, it doesn't mean we can accumulate many, we got " + count + " executions", count.get() < 5); } + @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()); - } }