@Test
public void testIntervalTimersDoNotBackUp() throws NamingException, IOException, InterruptedException {
SuspendTimerServiceBean.resetTimerServiceCalled();
InitialContext ctx = new InitialContext();
SuspendTimerServiceBean bean = (SuspendTimerServiceBean) ctx.lookup("java:module/" + SuspendTimerServiceBean.class.getSimpleName());
Timer timer = null;
try {
long start = 0;
ModelNode op = new ModelNode();
try {
op.get(ModelDescriptionConstants.OP).set("suspend");
managementClient.getControllerClient().execute(op);
//create the timer while the container is suspended
start = System.currentTimeMillis();
timer = bean.getTimerService().createIntervalTimer(100, 100, new TimerConfig("", false));
Thread.sleep(5000);
Assert.assertEquals(0, SuspendTimerServiceBean.getTimerServiceCount());
} finally {
op = new ModelNode();
op.get(ModelDescriptionConstants.OP).set("resume");
managementClient.getControllerClient().execute(op);
}
Thread.sleep(300); //if they were backed up we give them some time to run
int timerServiceCount = SuspendTimerServiceBean.getTimerServiceCount();
Assert.assertTrue("Interval " + (System.currentTimeMillis() - start) + " count " + timerServiceCount, timerServiceCount < 40);
} finally {
if (timer != null) {
timer.cancel();
Thread.sleep(100);
}
}
}