use of javax.ejb.NoMoreTimeoutsException in project wildfly by wildfly.
the class ExpiredTimerTestCase method testInvocationOnExpiredTimer.
@Test
public void testInvocationOnExpiredTimer() throws Exception {
final CountDownLatch timeoutNotifier = new CountDownLatch(1);
final CountDownLatch timeoutWaiter = new CountDownLatch(1);
this.bean.createSingleActionTimer(TIMER_TIMEOUT_TIME_MS, new TimerConfig(null, false), timeoutNotifier, timeoutWaiter);
// wait for the timeout to be invoked
final boolean timeoutInvoked = timeoutNotifier.await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS);
Assert.assertTrue("timeout method was not invoked (within " + TIMER_CALL_WAITING_S + " seconds)", timeoutInvoked);
// the timer stays in timeout method - checking how the invoke of method getNext and getTimeRemaining behave
try {
bean.invokeTimeRemaining();
Assert.fail("Expecting exception " + NoMoreTimeoutsException.class.getSimpleName());
} catch (NoMoreTimeoutsException e) {
log.trace("Expected exception " + e.getClass().getSimpleName() + " was thrown on method getTimeRemaining");
}
try {
bean.invokeGetNext();
Assert.fail("Expecting exception " + NoMoreTimeoutsException.class.getSimpleName());
} catch (NoMoreTimeoutsException e) {
log.trace("Expected exception " + e.getClass().getSimpleName() + " was thrown on method getNextTimeout");
}
// the timeout can finish
timeoutWaiter.countDown();
// as we can't be exactly sure when the timeout method is finished in this moment
// we invoke in a loop, can check the exception type.
int count = 0;
boolean passed = false;
while (count < 20 && !passed) {
try {
bean.invokeTimeRemaining();
Assert.fail("Expected to fail on invoking on an expired timer");
} catch (NoSuchObjectLocalException nsole) {
// expected
log.trace("Got the expected exception " + nsole);
passed = true;
} catch (NoMoreTimeoutsException e) {
//this will be thrown if the timer is still active
Thread.sleep(100);
count++;
}
}
if (!passed) {
Assert.fail("Got NoMoreTimeoutsException rather than NoSuchObjectLocalException");
}
}
use of javax.ejb.NoMoreTimeoutsException in project tomee by apache.
the class TimerImpl method getNextTimeout.
public Date getNextTimeout() throws IllegalStateException, NoSuchObjectLocalException {
checkState();
final Date nextTimeout = timerData.getNextTimeout();
if (nextTimeout == null) {
throw new NoMoreTimeoutsException("The timer has no future timeouts");
}
return timerData.getNextTimeout();
}
use of javax.ejb.NoMoreTimeoutsException in project tomee by apache.
the class TimerImpl method getTimeRemaining.
public long getTimeRemaining() throws IllegalStateException, NoSuchObjectLocalException {
checkState();
final Date nextTimeout = timerData.getNextTimeout();
if (nextTimeout == null) {
throw new NoMoreTimeoutsException("The timer has no future timeouts");
}
return timerData.getTimeRemaining();
}
Aggregations