[jboss-cvs] JBossAS SVN: r84357 - in projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/cancel: unit and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Feb 18 00:57:46 EST 2009


Author: ALRubinger
Date: 2009-02-18 00:57:46 -0500 (Wed, 18 Feb 2009)
New Revision: 84357

Modified:
   projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/cancel/PausableBlockingQueue.java
   projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/cancel/unit/CancelAsyncTaskTestCase.java
Log:
[EJBTHREE-1721] Strengthen the Future.cancel() test to ensure that the PausableBlockingQueue actually passes the backlog through for processing

Modified: projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/cancel/PausableBlockingQueue.java
===================================================================
--- projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/cancel/PausableBlockingQueue.java	2009-02-18 05:56:58 UTC (rev 84356)
+++ projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/cancel/PausableBlockingQueue.java	2009-02-18 05:57:46 UTC (rev 84357)
@@ -150,6 +150,11 @@
       return obj;
    }
 
+   public boolean isEmpty()
+   {
+      return this.currentQueue.isEmpty();
+   }
+
    /*
     * UNSUPPORTED below this marker
     */
@@ -229,11 +234,6 @@
       throw new UnsupportedOperationException(MSG_UNSUPPORTED);
    }
 
-   public boolean isEmpty()
-   {
-      throw new UnsupportedOperationException(MSG_UNSUPPORTED);
-   }
-
    public Iterator<E> iterator()
    {
       throw new UnsupportedOperationException(MSG_UNSUPPORTED);

Modified: projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/cancel/unit/CancelAsyncTaskTestCase.java
===================================================================
--- projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/cancel/unit/CancelAsyncTaskTestCase.java	2009-02-18 05:56:58 UTC (rev 84356)
+++ projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/cancel/unit/CancelAsyncTaskTestCase.java	2009-02-18 05:57:46 UTC (rev 84357)
@@ -23,6 +23,7 @@
 
 import java.util.concurrent.Future;
 import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
 
 import junit.framework.TestCase;
 
@@ -87,16 +88,23 @@
    @SuppressWarnings("unchecked")
    public void testCancelAsyncInvocation() throws Throwable
    {
+      /*
+       * Setup of environment
+       */
+
       // Make a new bean instance upon which we'll invoke
       final BeanContext<Pojo> bean = container.construct();
 
       // Set the container to allow processing
-      //TODO Relying on impls?
       final ThreadPoolExecutor executor = (ThreadPoolExecutor) container.getAsynchronousExecutor();
       final PausableBlockingQueue<?> queue = (PausableBlockingQueue<?>) executor.getQueue();
       queue.resume();
       log.info("Work queue is active");
 
+      /*
+       * Control
+       */
+
       // Get the counter
       final Future<Integer> initialCounterFuture = (Future<Integer>) container.invoke(bean,
             TestConstants.METHOD_NAME_GET_COUNTER);
@@ -118,6 +126,10 @@
       TestCase.assertEquals("Counter should have been incrememted to 1", 1, firstIncrementCounterResult);
       log.info("Got counter after first async increment: " + firstIncrementCounterResult);
 
+      /*
+       * Test cancel() works
+       */
+
       // Set the container to pause processing
       queue.pause();
       log.info("Work queue is paused");
@@ -148,6 +160,45 @@
             secondIncrementCounterResult);
       log.info("Second call to increment counter was cancelled, counter = " + secondIncrementCounterResult);
 
+      /*
+       * Test that the test itself is valid (ie.
+       * jobs submitted while paused will pull through
+       * when resumed)
+       */
+
+      // Set the container to pause processing
+      queue.pause();
+      log.info("Work queue is paused");
+
+      // Increment the counter, then get the result
+      final Future<Void> incrementCounterWhilePauseFuture = (Future<Void>) container.invoke(bean,
+            TestConstants.METHOD_NAME_INCREMENT_COUNTER_ASYNCHRONOUS);
+      log.info("Sent another request to increment the counter while work queue is paused");
+
+      // Block until done (w/ some sensible Timeout in case of bad blocking)
+      incrementCounterWhilePauseFuture.get(3, TimeUnit.SECONDS);
+
+      // Resume the work queue
+      queue.resume();
+      log.info("Work queue is active again");
+
+      // Block until the last request has gone through the work queue
+      while (!queue.isEmpty())
+      {
+
+      }
+
+      // ...and wait a bit just to be extra sure the work has been done
+      Thread.sleep(500);
+
+      // Get the counter again, testing that it hasn't been incremented
+      final Future<Integer> incrementCounterAfterPausedResultFuture = (Future<Integer>) container.invoke(bean,
+            TestConstants.METHOD_NAME_GET_COUNTER);
+      final int incrementCounterAfterPausedResult = incrementCounterAfterPausedResultFuture.get();
+      TestCase.assertEquals("Call to increment counter during pause should have been honored after release",
+            firstIncrementCounterResult + 1, incrementCounterAfterPausedResult);
+      log.info("Jobs submitted while queue was paused are processed upon unpause, counter = "
+            + incrementCounterAfterPausedResult);
    }
 
 }




More information about the jboss-cvs-commits mailing list