public void testStatelessSessionBeanTimerRetry()
throws Exception
{
log.info("testStatelessSessionBeanTimerRetry(): start");
TimerSLSBHome home = (TimerSLSBHome) getEJBHome(TimerSLSBHome.JNDI_NAME);
TimerSLSB bean = home.create();
// We need to make sure that the next timer interval occurs
// while the retry timeout is STILL running in order to test JBAS-1926
final long retryMs = bean.getRetryTimeoutPeriod();
log.info("testStatelessSessionBeanTimerRetry():GOT RETRY TIME:" + retryMs);
assertFalse("Failed to get valid retry timeout!", retryMs == -1);
final HashMap info = new HashMap();
info.put(TimerSLSB.INFO_EXEC_FAIL_COUNT,new Integer(1)); // fail only once
// RE: JIRA Issue JBAS-1926
// This is the amount of time the task will take to execute
// This is intentionlly more than the time of the interval
// so that the we can be sure that the interval will fire again
// WHILE the retry is still in progress.
final int taskTime = SHORT_PERIOD * 2;
info.put(TimerSLSB.INFO_TASK_RUNTIME,new Integer(taskTime)); // the time is takes to execute the task
final byte[] handle = bean.startTimer(SHORT_PERIOD,info);
// Wait for 1 SHORT_PERIOD for the first firing
// Another retryMs for the amount of time it takes for the retry to happen
// and finally the amount of time that it takes to execute the task and 200ms to be safe.
Thread.sleep(SHORT_PERIOD + retryMs + taskTime + 200);
int count = bean.getTimeoutCount(handle);
bean.stopTimer(handle);
assertEquals("Timeout was called too many times. Should have been once for the initial" +
", and once for the retry during the time allotted.",2,count);
bean.remove();
}