use of javax.ejb.Timer in project wildfly by wildfly.
the class TimerServiceSuspendTestCase method testIntervalTimersDoNotBackUp.
/**
* This test makes sure that interval timers that are scheduled while a timer is suspended do not back up, and only a single
* run will occur when the container is resumed
*/
@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);
}
//if they were backed up we give them some time to run
Thread.sleep(300);
int timerServiceCount = SuspendTimerServiceBean.getTimerServiceCount();
Assert.assertTrue("Interval " + (System.currentTimeMillis() - start) + " count " + timerServiceCount, timerServiceCount < 40);
} finally {
if (timer != null) {
timer.cancel();
Thread.sleep(100);
}
}
}
use of javax.ejb.Timer in project wildfly by wildfly.
the class TimerServiceSuspendTestCase method testSuspendWithIntervalTimer.
@Test
public void testSuspendWithIntervalTimer() throws NamingException, IOException, InterruptedException {
SuspendTimerServiceBean.resetTimerServiceCalled();
InitialContext ctx = new InitialContext();
SuspendTimerServiceBean bean = (SuspendTimerServiceBean) ctx.lookup("java:module/" + SuspendTimerServiceBean.class.getSimpleName());
ModelNode op = new ModelNode();
Timer timer = null;
try {
try {
timer = bean.getTimerService().createIntervalTimer(100, 100, new TimerConfig("", false));
Assert.assertTrue(SuspendTimerServiceBean.awaitTimerServiceCount() > 0);
op.get(ModelDescriptionConstants.OP).set("suspend");
managementClient.getControllerClient().execute(op);
SuspendTimerServiceBean.resetTimerServiceCalled();
Thread.sleep(200);
Assert.assertEquals(0, SuspendTimerServiceBean.getTimerServiceCount());
} finally {
op = new ModelNode();
op.get(ModelDescriptionConstants.OP).set("resume");
managementClient.getControllerClient().execute(op);
}
Assert.assertTrue(SuspendTimerServiceBean.awaitTimerServiceCount() > 0);
} finally {
if (timer != null) {
timer.cancel();
Thread.sleep(100);
}
}
}
use of javax.ejb.Timer in project wildfly by wildfly.
the class ActiveTimerServiceCountTestCase method removeSheduleOneTimerOfOtherTimerBean.
private boolean removeSheduleOneTimerOfOtherTimerBean(final Collection<Timer> timers) {
for (final Timer activeTimer : timers) {
// see if it's @Schedule one in OtherTimerBeanInSameModule
final Serializable info = activeTimer.getInfo();
if (OtherTimerBeanInSameModule.SCHEDULE_ONE_INFO.equals(info)) {
Assert.assertTrue("Unexpected timer type of timer on " + OtherTimerBeanInSameModule.class.getSimpleName(), activeTimer.isCalendarTimer());
Assert.assertFalse("Unexpected persistence type of timer on " + OtherTimerBeanInSameModule.class.getSimpleName(), activeTimer.isPersistent());
// remove this matched timer from the collection
return timers.remove(activeTimer);
}
}
return false;
}
use of javax.ejb.Timer in project wildfly by wildfly.
the class ActiveTimerServiceCountTestCase method removeSheduleTwoTimerOfSimpleTimerBean.
private boolean removeSheduleTwoTimerOfSimpleTimerBean(final Collection<Timer> timers) {
for (final Timer activeTimer : timers) {
// see if it's @Schedule two in SimpleTimerBean
final Serializable info = activeTimer.getInfo();
if (SimpleTimerBean.SCHEDULE_TWO_INFO.equals(info)) {
Assert.assertTrue("Unexpected timer type of timer on " + SimpleTimerBean.class.getSimpleName(), activeTimer.isCalendarTimer());
Assert.assertTrue("Unexpected persistence type of timer on " + SimpleTimerBean.class.getSimpleName(), activeTimer.isPersistent());
// remove this matched timer from the collection
return timers.remove(activeTimer);
}
}
return false;
}
use of javax.ejb.Timer in project wildfly by wildfly.
the class TimerAttributeDefinition method addTimers.
public static void addTimers(final EJBComponent ejb, final ModelNode response) {
response.setEmptyList();
final String name = ejb.getComponentName();
TimerService ts = ejb.getTimerService();
if (ts != null) {
for (Timer timer : ts.getTimers()) {
ModelNode timerNode = response.add();
addTimeRemaining(timer, timerNode, name);
addNextTimeout(timer, timerNode, name);
addCalendarTimer(timer, timerNode, name);
addPersistent(timer, timerNode, name);
addSchedule(timer, timerNode, name);
}
}
}
Aggregations