Search in sources :

Example 1 with TimerHandle

use of javax.ejb.TimerHandle in project wildfly by wildfly.

the class TimerServicePersistenceFirstTestCase method createAndCancelTimerService.

@Test
public void createAndCancelTimerService() throws NamingException {
    InitialContext ctx = new InitialContext();
    CancelledTimerServiceBean bean = (CancelledTimerServiceBean) ctx.lookup("java:module/" + CancelledTimerServiceBean.class.getSimpleName());
    TimerHandle handle = bean.createTimer();
    Assert.assertTrue(CancelledTimerServiceBean.awaitTimerCall());
    Assert.assertEquals("info", handle.getTimer().getInfo());
    handle.getTimer().cancel();
}
Also used : TimerHandle(javax.ejb.TimerHandle) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 2 with TimerHandle

use of javax.ejb.TimerHandle in project wildfly by wildfly.

the class TimerServiceCancellationTestCase method testCancelCalendarWhileTimeoutActive.

@Test
public void testCancelCalendarWhileTimeoutActive() throws NamingException, InterruptedException {
    InitialContext ctx = new InitialContext();
    CalendarTimerServiceBean bean = (CalendarTimerServiceBean) ctx.lookup("java:module/" + CalendarTimerServiceBean.class.getSimpleName());
    TimerHandle handle = bean.createTimer();
    Assert.assertTrue(bean.getTimerEntry().await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS));
    //now the timeout is in progress cancel the timer
    handle.getTimer().cancel();
    bean.getTimerExit().countDown();
    Assert.assertFalse(CalendarTimerServiceBean.quickAwaitTimerCall());
    Assert.assertEquals(0, bean.getTimerCount());
}
Also used : TimerHandle(javax.ejb.TimerHandle) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 3 with TimerHandle

use of javax.ejb.TimerHandle in project wildfly by wildfly.

the class TimerServiceCancellationTestCase method testCancelSimpleWhileTimeoutActive.

@Test
public void testCancelSimpleWhileTimeoutActive() throws NamingException, InterruptedException {
    InitialContext ctx = new InitialContext();
    SimpleTimerServiceBean bean = (SimpleTimerServiceBean) ctx.lookup("java:module/" + SimpleTimerServiceBean.class.getSimpleName());
    TimerHandle handle = bean.createTimer();
    Assert.assertTrue(bean.getTimerEntry().await(TIMER_CALL_WAITING_S, TimeUnit.SECONDS));
    //now the timeout is in progress cancel the timer
    handle.getTimer().cancel();
    bean.getTimerExit().countDown();
    Assert.assertFalse(SimpleTimerServiceBean.quickAwaitTimerCall());
    Assert.assertEquals(0, bean.getTimerCount());
}
Also used : TimerHandle(javax.ejb.TimerHandle) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Aggregations

TimerHandle (javax.ejb.TimerHandle)3 InitialContext (javax.naming.InitialContext)3 Test (org.junit.Test)3