ARTEMIS-1462 Fixing QueueControlTest

(cherry picked from commit c66a7975e6)
This commit is contained in:
Clebert Suconic 2017-10-17 22:30:59 -04:00
parent ed76ecb3c5
commit b097ef381e
2 changed files with 21 additions and 13 deletions

View File

@ -90,7 +90,7 @@ public abstract class ActiveMQScheduledComponent implements ActiveMQComponent, R
long checkPeriod, long checkPeriod,
TimeUnit timeUnit, TimeUnit timeUnit,
boolean onDemand) { 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); this.millisecondsPeriod = timeUnit.convert(period, TimeUnit.MILLISECONDS);
if (period >= 0) { if (period >= 0) {
future = scheduledExecutorService.scheduleWithFixedDelay(runForScheduler, initialDelay, period, timeUnit); future = scheduledExecutorService.scheduleWithFixedDelay(runForScheduler, initialDelay >= 0 ? initialDelay : period, period, timeUnit);
} else { } else {
logger.tracef("did not start scheduled executor on %s because period was configured as %d", this, period); logger.tracef("did not start scheduled executor on %s because period was configured as %d", this, period);
} }

View File

@ -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); 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 @Test
public void testAccumulationOwnPool() throws Exception { public void testAccumulationOwnPool() throws Exception {
final AtomicInteger count = new AtomicInteger(0); final AtomicInteger count = new AtomicInteger(0);
@ -187,15 +206,4 @@ public class ActiveMQScheduledComponentTest {
local.stop(); 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());
}
} }