Package org.jboss.test.timer.interfaces

Examples of org.jboss.test.timer.interfaces.TimerSLSB


    */
   public void testStatelessSessionBeanTimer()
      throws Exception
   {
      TimerSLSBHome home = (TimerSLSBHome) getEJBHome(TimerSLSBHome.JNDI_NAME);
      TimerSLSB bean = home.create();
      byte[] handle = bean.startTimer(SHORT_PERIOD);
      Thread.sleep(12 * SHORT_PERIOD + SHORT_PERIOD);
      int count = bean.getTimeoutCount(handle);
      bean.stopTimer(handle);
      assertTrue("Timeout was expected to be called at least 10 times but was "
         + "only called: " + count + " times",
         count >= 10);
      Thread.sleep(5 * SHORT_PERIOD);
      int count2 = bean.getTimeoutCount(handle);
      assertTrue("After the timer was stopped no timeout should happen but "
         + "it was called " + count2 + " more times",
         count2 == 0);
      bean.remove();
   }
View Full Code Here


   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();
   }
View Full Code Here

    */
   public void testStatelessSessionBeanSingleTimer()
      throws Exception
   {
      TimerSLSBHome home = (TimerSLSBHome) getEJBHome(TimerSLSBHome.JNDI_NAME);
      TimerSLSB bean = home.create();
      byte[] handle = bean.startSingleTimer(SHORT_PERIOD);
      Thread.sleep(5 * SHORT_PERIOD);
      int lCount = bean.getTimeoutCount(handle);
      assertTrue("Timeout was expected to be called only once but was called: "
         + lCount + " times",
         lCount == 1);
      try
      {
         bean.stopTimer(handle);
         fail("A single timer should expire after the first event and therefore this "
            + "has to throw an NoSuchObjectLocalException");
      }
      catch (RemoteException re)
      {
         Throwable lCause = re.detail;
         if (lCause instanceof ServerException)
         {
            lCause = ((ServerException) lCause).detail;
            if (lCause instanceof NoSuchObjectLocalException)
            {
               // This exception is expected -> ignore
            }
            else
            {
               throw re;
            }
         }
      }

      // Test for the case where a transaction fails, the time should be retried once
      // This test assumes the FixedRetryPolicy is left at the default of 200ms.
      // The "fail-once" data in the timer will be used by the bean to fail the
      // transaction once, to make sure that it is automatically retried.
      log.info("testStatelessSessionBeanSingleTimer(): Testing retry on timer.");
      final HashMap info = new HashMap(1);
      info.put(TimerSLSB.INFO_EXEC_FAIL_COUNT,new Integer(1));
      handle = bean.startSingleTimer(SHORT_PERIOD,info);
      Thread.sleep(5 * SHORT_PERIOD);
      assertEquals("Timeout was expected to be called twice, once inititially, one once for the retry.",
               2,bean.getTimeoutCount(handle));


   }
View Full Code Here

    */
   public void testTimerImplementation()
      throws Exception
   {
      TimerSLSBHome home = (TimerSLSBHome) getEJBHome(TimerSLSBHome.JNDI_NAME);
      TimerSLSB bean = home.create();
      byte[] handle = bean.startTimer(LONG_PERIOD);
      Date lNextEvent = bean.getNextTimeout(handle);
      long lUntilNextEvent = lNextEvent.getTime() - new Date().getTime();
      Thread.sleep(SHORT_PERIOD);
      long lTimeRemaining = bean.getTimeRemaining(handle);
      Object info = bean.getInfo(handle);
      assertTrue("Date of the next event must be greater than 0", lUntilNextEvent > 0);
      assertTrue("Period until next event must be greater than 0", lTimeRemaining > 0);
      assertTrue("Period until next event must be smaller than time until next even because it "
         + "it is called later", lUntilNextEvent > lTimeRemaining);
      assertTrue("Info("+info+") must be 'TimerSLSBean.startTimer'",
         "TimerSLSBean.startTimer".equals(info));
      assertTrue("Must be able to get a handle", handle != null);
      bean.stopTimer(handle);
   }
View Full Code Here

    */
   public void testBadStatelessSessionBeanTimer()
      throws Exception
   {
      TimerSLSBHome home = (TimerSLSBHome) getEJBHome("ejb/test/timer/NoTimedObjectBean");
      TimerSLSB bean = home.create();
      try
      {
         bean.startTimer(SHORT_PERIOD);
         fail("Was able to call NoTimedObjectBean.startTimer");
      }
      catch(RemoteException e)
      {
         log.info("Saw exception as expected", e);
      }
      bean.remove();
   }
View Full Code Here

    */
   public void testStatelessSessionBeanTimer()
      throws Exception
   {
      TimerSLSBHome home = (TimerSLSBHome) getEJBHome(TimerSLSBHome.JNDI_NAME);
      TimerSLSB bean = home.create();
      byte[] handle = bean.startTimer(SHORT_PERIOD);
      Thread.sleep(12 * SHORT_PERIOD + SHORT_PERIOD);
      int count = bean.getTimeoutCount(handle);
      bean.stopTimer(handle);
      assertTrue("Timeout was expected to be called at least 10 times but was "
         + "only called: " + count + " times",
         count >= 10);
      Thread.sleep(5 * SHORT_PERIOD);
      int count2 = bean.getTimeoutCount(handle);
      assertTrue("After the timer was stopped no timeout should happen but "
         + "it was called " + count2 + " more times",
         count2 == 0);
      bean.remove();
   }
View Full Code Here

   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();
   }
View Full Code Here

    */
   public void testStatelessSessionBeanSingleTimer()
      throws Exception
   {
      TimerSLSBHome home = (TimerSLSBHome) getEJBHome(TimerSLSBHome.JNDI_NAME);
      TimerSLSB bean = home.create();
      byte[] handle = bean.startSingleTimer(SHORT_PERIOD);
      Thread.sleep(5 * SHORT_PERIOD);
      int lCount = bean.getTimeoutCount(handle);
      assertTrue("Timeout was expected to be called only once but was called: "
         + lCount + " times",
         lCount == 1);
      try
      {
         bean.stopTimer(handle);
         fail("A single timer should expire after the first event and therefore this "
            + "has to throw an NoSuchObjectLocalException");
      }
      catch (RemoteException re)
      {
         Throwable lCause = re.detail;
         if (lCause instanceof ServerException)
         {
            lCause = ((ServerException) lCause).detail;
            if (lCause instanceof NoSuchObjectLocalException)
            {
               // This exception is expected -> ignore
            }
            else
            {
               throw re;
            }
         }
      }

      // Test for the case where a transaction fails, the time should be retried once
      // This test assumes the FixedRetryPolicy is left at the default of 200ms.
      // The "fail-once" data in the timer will be used by the bean to fail the
      // transaction once, to make sure that it is automatically retried.
      log.info("testStatelessSessionBeanSingleTimer(): Testing retry on timer.");
      final HashMap info = new HashMap(1);
      info.put(TimerSLSB.INFO_EXEC_FAIL_COUNT,new Integer(1));
      handle = bean.startSingleTimer(SHORT_PERIOD,info);
      Thread.sleep(5 * SHORT_PERIOD);
      assertEquals("Timeout was expected to be called twice, once inititially, one once for the retry.",
               2,bean.getTimeoutCount(handle));


   }
View Full Code Here

    */
   public void testTimerImplementation()
      throws Exception
   {
      TimerSLSBHome home = (TimerSLSBHome) getEJBHome(TimerSLSBHome.JNDI_NAME);
      TimerSLSB bean = home.create();
      byte[] handle = bean.startTimer(LONG_PERIOD);
      Date lNextEvent = bean.getNextTimeout(handle);
      long lUntilNextEvent = lNextEvent.getTime() - new Date().getTime();
      Thread.sleep(SHORT_PERIOD);
      long lTimeRemaining = bean.getTimeRemaining(handle);
      Object info = bean.getInfo(handle);
      assertTrue("Date of the next event must be greater than 0", lUntilNextEvent > 0);
      assertTrue("Period until next event must be greater than 0", lTimeRemaining > 0);
      assertTrue("Period until next event must be smaller than time until next even because it "
         + "it is called later", lUntilNextEvent > lTimeRemaining);
      assertTrue("Info("+info+") must be 'TimerSLSBean.startTimer'",
         "TimerSLSBean.startTimer".equals(info));
      assertTrue("Must be able to get a handle", handle != null);
      bean.stopTimer(handle);
   }
View Full Code Here

    */
   public void testBadStatelessSessionBeanTimer()
      throws Exception
   {
      TimerSLSBHome home = (TimerSLSBHome) getEJBHome("ejb/test/timer/NoTimedObjectBean");
      TimerSLSB bean = home.create();
      try
      {
         bean.startTimer(SHORT_PERIOD);
         fail("Was able to call NoTimedObjectBean.startTimer");
      }
      catch(RemoteException e)
      {
         log.info("Saw exception as expected", e);
      }
      bean.remove();
   }
View Full Code Here

TOP

Related Classes of org.jboss.test.timer.interfaces.TimerSLSB

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.