1 Reply Latest reply on Feb 23, 2016 6:34 AM by elarbi

    Adding a delay to wait for EJB3 Timers

    elarbi

      Hi,

       

      I'm using Arquillian 1.0.0.Alpha1 foe remote testing on Wildfly 8.2.1.

      How can I test a method marked as @Timeout ?

      I want to be able to make my test wait for some seconds for ex.

      Since the test are in container tests I must not use Thread.sleep. So how can I do that ?

       

      This is an excerpt of my service under test :

       

       

      @Stateless

      public class PublicationService {

       

           @Resource

          TimerService timerService;

         

          /**

           * Publish a player for a certain period of time

           * @param player

           * @param periodInMillis

           * @return

           */

          public Publication publish(Player player, long periodInMillis) {

         

              Publication publication = playerRepository.createPublicationForPlayer(player);

              Timer time = timerService.createSingleActionTimer(periodInMillis, new TimerConfig(player, true));

              return publication;

             

          }

       

          @Timeout

          public void retract(Timer timer) {

           //do some domain stuffs...

          }

      }

       

       

       

      Thanks for your help.

        • 1. Re: Adding a delay to wait for EJB3 Timers
          elarbi

          Even if I use a Thread.sleep in my @Test method:

           

          try {

               Thread.sleep(TimeUnit.SECONDS.toMillis(30));

          } catch (InterruptedException e) {

               e.printStackTrace();

          }

           

          It does not wait, the test executes as if this code does not exist !