[jboss-cvs] JBossAS SVN: r84280 - in projects/ejb3/trunk/async-impl: src/main/java/org/jboss/ejb3/async/impl/interceptor and 8 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Feb 16 15:41:41 EST 2009


Author: ALRubinger
Date: 2009-02-16 15:41:40 -0500 (Mon, 16 Feb 2009)
New Revision: 84280

Added:
   projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/cancel/
   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/
   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/common/PausableProcessingAsyncContainer.java
   projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/common/Pojo.java
   projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/common/ThreadPoolAsyncContainer.java
Removed:
   projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/container/
   projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/simple/Pojo.java
Modified:
   projects/ejb3/trunk/async-impl/pom.xml
   projects/ejb3/trunk/async-impl/src/main/java/org/jboss/ejb3/async/impl/interceptor/AsynchronousInterceptor.java
   projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/common/TestConstants.java
   projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/security/unit/SecurityContextPropagationTestCase.java
   projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/simple/unit/SimpleAsyncTestCase.java
   projects/ejb3/trunk/async-impl/src/test/resources/log4j.xml
Log:
[EJBTHREE-1721] Tests and mucking with EJB 3.1 Async Future.cancel()

Modified: projects/ejb3/trunk/async-impl/pom.xml
===================================================================
--- projects/ejb3/trunk/async-impl/pom.xml	2009-02-16 20:27:35 UTC (rev 84279)
+++ projects/ejb3/trunk/async-impl/pom.xml	2009-02-16 20:41:40 UTC (rev 84280)
@@ -109,7 +109,6 @@
       <groupId>org.jboss.ejb3</groupId>
       <artifactId>jboss-ejb3-interceptors</artifactId>
       <version>${version.org.jboss.ejb3_jboss.ejb3.interceptors}</version>
-      <scope>test</scope>
     </dependency>
     
     <!-- 

Modified: projects/ejb3/trunk/async-impl/src/main/java/org/jboss/ejb3/async/impl/interceptor/AsynchronousInterceptor.java
===================================================================
--- projects/ejb3/trunk/async-impl/src/main/java/org/jboss/ejb3/async/impl/interceptor/AsynchronousInterceptor.java	2009-02-16 20:27:35 UTC (rev 84279)
+++ projects/ejb3/trunk/async-impl/src/main/java/org/jboss/ejb3/async/impl/interceptor/AsynchronousInterceptor.java	2009-02-16 20:41:40 UTC (rev 84280)
@@ -32,8 +32,8 @@
 import org.jboss.aop.joinpoint.Invocation;
 import org.jboss.aop.joinpoint.MethodInvocation;
 import org.jboss.ejb3.async.impl.future.AsyncFutureWrapper;
-import org.jboss.ejb3.async.impl.hack.DevelopmentHacks;
 import org.jboss.ejb3.async.spi.container.AsyncInvocationProcessor;
+import org.jboss.ejb3.interceptors.container.ManagedObjectAdvisor;
 import org.jboss.logging.Logger;
 import org.jboss.security.SecurityContext;
 
@@ -183,15 +183,7 @@
     */
    private AsyncInvocationProcessor getInvocationProcessor(Invocation invocation)
    {
-      //TODO Need to get at the container from here
-      return new AsyncInvocationProcessor()
-      {
-
-         public ExecutorService getAsynchronousExecutor()
-         {
-            return DevelopmentHacks.getDefaultAsyncExecutorService();
-         }
-      };
+      return (AsyncInvocationProcessor) ((ManagedObjectAdvisor) invocation.getAdvisor()).getContainer();
    }
 
    // --------------------------------------------------------------------------------||

Added: 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	                        (rev 0)
+++ projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/cancel/PausableBlockingQueue.java	2009-02-16 20:41:40 UTC (rev 84280)
@@ -0,0 +1,282 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.async.impl.test.cancel;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.jboss.logging.Logger;
+
+/**
+ * PausableBlockingQueue
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Deprecated
+//TODO 
+/*
+ * This implementation doesn't work with j.u.c out of the box
+ * because we're "pausing" at the wrong level.  Calls to Future.get(time,unit)
+ * block indefinitely because the task is never submitted while in pause mode.
+ * 
+ * Meaning we have to get at the work queue through some other mechanism, not through here
+ */
+public class PausableBlockingQueue<E> implements BlockingQueue<E>
+{
+   // --------------------------------------------------------------------------------||
+   // Class Members ------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   private static final Logger log = Logger.getLogger(PausableBlockingQueue.class);
+
+   // --------------------------------------------------------------------------------||
+   // Instance Members ---------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   private AtomicBoolean active = new AtomicBoolean(false);
+
+   private BlockingQueue<E> delegate;
+
+   private BlockingQueue<E> backlogQueue;
+
+   /**
+    * A reference to the current queue to be consulted in polling
+    * Access must be synchronized with itself
+    */
+   /*
+    * volatile because only one Thread may set this (pause/unpause),
+    * the main Thread from the test 
+    */
+   private volatile BlockingQueue<E> currentQueue;
+
+   private static final String MSG_UNSUPPORTED = "Should not be used in testing";
+
+   // --------------------------------------------------------------------------------||
+   // Constructor --------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   public PausableBlockingQueue(boolean active)
+   {
+      this.active.set(active);
+      this.delegate = new ArrayBlockingQueue<E>(10);
+      this.backlogQueue = new ArrayBlockingQueue<E>(10);
+      this.currentQueue = active ? this.delegate : this.backlogQueue;
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Functional Methods -------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   public boolean isActive()
+   {
+      return this.active.get();
+   }
+
+   public void pause()
+   {
+      if (!this.isActive())
+      {
+         //NOOP
+         return;
+      }
+
+      // Atomic
+      synchronized (this.currentQueue)
+      {
+         this.active.set(false);
+         this.currentQueue = this.backlogQueue;
+         log.info(this + ": Paused");
+      }
+   }
+
+   public void resume()
+   {
+      if (this.isActive())
+      {
+         //NOOP
+         return;
+      }
+
+      // Atomic
+      synchronized (this.currentQueue)
+      {
+         // Set active
+         this.active.set(true);
+
+         // Drain to the delegate from the backlog
+         this.backlogQueue.drainTo(this.delegate);
+
+         // Set the correct current queue
+         this.currentQueue = this.delegate;
+
+         // Log
+         log.info(this + ": Resumed");
+      }
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Required Implementations -------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Offers to the current queue in play
+    */
+   public boolean offer(E o)
+   {
+      BlockingQueue<E> current = this.currentQueue;
+      log.info("Offering: " + o + " to " + current);
+      return current.offer(o);
+   }
+
+   public E take() throws InterruptedException
+   {
+      BlockingQueue<E> current = this.currentQueue;
+      E obj = current.take();
+      log.info("Taking : " + obj);
+      return obj;
+   }
+
+   /*
+    * UNSUPPORTED below this marker
+    */
+
+   public boolean add(E o)
+   {
+      throw new UnsupportedOperationException(MSG_UNSUPPORTED);
+   }
+
+   public int drainTo(Collection<? super E> c)
+   {
+      throw new UnsupportedOperationException(MSG_UNSUPPORTED);
+   }
+
+   public int drainTo(Collection<? super E> c, int maxElements)
+   {
+      throw new UnsupportedOperationException(MSG_UNSUPPORTED);
+   }
+
+   public boolean offer(E o, long timeout, TimeUnit unit) throws InterruptedException
+   {
+      throw new UnsupportedOperationException(MSG_UNSUPPORTED);
+   }
+
+   public E poll(long timeout, TimeUnit unit) throws InterruptedException
+   {
+      throw new UnsupportedOperationException(MSG_UNSUPPORTED);
+   }
+
+   public void put(E o) throws InterruptedException
+   {
+      throw new UnsupportedOperationException(MSG_UNSUPPORTED);
+   }
+
+   public int remainingCapacity()
+   {
+      throw new UnsupportedOperationException(MSG_UNSUPPORTED);
+   }
+
+   public E element()
+   {
+      throw new UnsupportedOperationException(MSG_UNSUPPORTED);
+   }
+
+   public E peek()
+   {
+      throw new UnsupportedOperationException(MSG_UNSUPPORTED);
+   }
+
+   public E poll()
+   {
+      throw new UnsupportedOperationException(MSG_UNSUPPORTED);
+   }
+
+   public E remove()
+   {
+      throw new UnsupportedOperationException(MSG_UNSUPPORTED);
+   }
+
+   public boolean addAll(Collection<? extends E> c)
+   {
+      throw new UnsupportedOperationException(MSG_UNSUPPORTED);
+   }
+
+   public void clear()
+   {
+      throw new UnsupportedOperationException(MSG_UNSUPPORTED);
+   }
+
+   public boolean contains(Object o)
+   {
+      throw new UnsupportedOperationException(MSG_UNSUPPORTED);
+   }
+
+   public boolean containsAll(Collection<?> c)
+   {
+      throw new UnsupportedOperationException(MSG_UNSUPPORTED);
+   }
+
+   public boolean isEmpty()
+   {
+      throw new UnsupportedOperationException(MSG_UNSUPPORTED);
+   }
+
+   public Iterator<E> iterator()
+   {
+      throw new UnsupportedOperationException(MSG_UNSUPPORTED);
+   }
+
+   public boolean remove(Object o)
+   {
+      throw new UnsupportedOperationException(MSG_UNSUPPORTED);
+   }
+
+   public boolean removeAll(Collection<?> c)
+   {
+      throw new UnsupportedOperationException(MSG_UNSUPPORTED);
+   }
+
+   public boolean retainAll(Collection<?> c)
+   {
+      throw new UnsupportedOperationException(MSG_UNSUPPORTED);
+   }
+
+   public int size()
+   {
+      throw new UnsupportedOperationException(MSG_UNSUPPORTED);
+   }
+
+   public Object[] toArray()
+   {
+      throw new UnsupportedOperationException(MSG_UNSUPPORTED);
+   }
+
+   public <T> T[] toArray(T[] a)
+   {
+      throw new UnsupportedOperationException(MSG_UNSUPPORTED);
+   }
+
+}

Added: 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	                        (rev 0)
+++ projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/cancel/unit/CancelAsyncTaskTestCase.java	2009-02-16 20:41:40 UTC (rev 84280)
@@ -0,0 +1,149 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.async.impl.test.cancel.unit;
+
+import java.util.concurrent.Future;
+
+import junit.framework.TestCase;
+
+import org.jboss.aspects.common.AOPDeployer;
+import org.jboss.ejb3.async.impl.test.cancel.PausableBlockingQueue;
+import org.jboss.ejb3.async.impl.test.common.PausableProcessingAsyncContainer;
+import org.jboss.ejb3.async.impl.test.common.Pojo;
+import org.jboss.ejb3.async.impl.test.common.TestConstants;
+import org.jboss.ejb3.async.impl.test.simple.unit.SimpleAsyncTestCase;
+import org.jboss.ejb3.interceptors.container.BeanContext;
+import org.jboss.logging.Logger;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * CancelAsyncTaskTestCase
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class CancelAsyncTaskTestCase
+{
+   // --------------------------------------------------------------------------------||
+   // Class Members ------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   private static final Logger log = Logger.getLogger(SimpleAsyncTestCase.class);
+
+   private static AOPDeployer aopDeployer = new AOPDeployer(TestConstants.AOP_DEPLOYABLE_FILENAME_SIMPLE);
+
+   private static PausableProcessingAsyncContainer<Pojo> container;
+
+   // --------------------------------------------------------------------------------||
+   // Test Lifecycle -----------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   @BeforeClass
+   public static void beforeClass() throws Throwable
+   {
+      aopDeployer.deploy();
+      container = new PausableProcessingAsyncContainer<Pojo>("Test Pausable Async POJO Container",
+            TestConstants.DOMAIN_ASYNC, Pojo.class);
+   }
+
+   @AfterClass
+   public static void afterClass() throws Throwable
+   {
+      aopDeployer.undeploy();
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Tests --------------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /*
+    * In place just so Maven doesn't puke on no valid tests
+    */
+   @Test
+   @Deprecated
+   //TODO Remove
+   public void noopTest()
+   {
+   }
+
+   /**
+    * Tests that @Asynchronous invocations may be cancelled
+    * 
+    * @throws Throwable 
+    */
+   //@Test
+   @SuppressWarnings("unchecked")
+   public void testCancelAsyncInvocation() throws Throwable
+   {
+      // Make a new bean instance upon which we'll invoke
+      BeanContext<Pojo> bean = container.construct();
+
+      // Set the container to allow processing
+      PausableBlockingQueue<?> queue = (PausableBlockingQueue<?>) container.getAsynchronousExecutor().getQueue();
+      queue.resume();
+      log.info("Work queue is active");
+
+      // Get the counter
+      Future<Integer> initialCounterFuture = (Future<Integer>) container.invoke(bean,
+            TestConstants.METHOD_NAME_GET_COUNTER);
+      int initialCounter = initialCounterFuture.get();
+
+      // Ensure the counter starts at 0
+      TestCase.assertEquals("Counter should start at 0", 0, initialCounter);
+      log.info("Got counter at start: " + initialCounter);
+
+      // Increment the counter, then get the result
+      Future<Void> firstIncrementCounterFuture = (Future<Void>) container.invoke(bean,
+            TestConstants.METHOD_NAME_INCREMENT_COUNTER_ASYNCHRONOUS);
+      firstIncrementCounterFuture.get(); // Block until done
+      Future<Integer> firstIncrementCounterResultFuture = (Future<Integer>) container.invoke(bean,
+            TestConstants.METHOD_NAME_GET_COUNTER);
+      int firstIncrementCounterResult = firstIncrementCounterResultFuture.get();
+
+      // Ensure the counter has been incremented
+      TestCase.assertEquals("Counter should have been incrememted to 1", 1, firstIncrementCounterResult);
+      log.info("Got counter after first async increment: " + firstIncrementCounterResult);
+
+      // Set the container to pause processing
+      queue.pause();
+      log.info("Work queue is paused");
+
+      // Increment the counter, then get the result
+      Future<Void> secondIncrementCounterFuture = (Future<Void>) container.invoke(bean,
+            TestConstants.METHOD_NAME_INCREMENT_COUNTER_ASYNCHRONOUS);
+
+      // Cancel and test
+      boolean isCancelled = secondIncrementCounterFuture.cancel(true);
+      TestCase.assertTrue("Request to cancel() not honored", isCancelled);
+
+      // Get the counter again, testing that it hasn't been incremented
+      Future<Integer> secondIncrementCounterResultFuture = (Future<Integer>) container.invoke(bean,
+            TestConstants.METHOD_NAME_GET_COUNTER);
+      int secondIncrementCounterResult = secondIncrementCounterResultFuture.get();
+      TestCase.assertEquals("Second call to increment counter should have been cancelled", firstIncrementCounterResult,
+            secondIncrementCounterResult);
+
+   }
+
+}

Added: projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/common/PausableProcessingAsyncContainer.java
===================================================================
--- projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/common/PausableProcessingAsyncContainer.java	                        (rev 0)
+++ projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/common/PausableProcessingAsyncContainer.java	2009-02-16 20:41:40 UTC (rev 84280)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.async.impl.test.common;
+
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import org.jboss.ejb3.async.impl.test.cancel.PausableBlockingQueue;
+import org.jboss.ejb3.async.spi.container.AsyncInvocationProcessor;
+
+/**
+ * PausableProcessingAsyncContainer
+ * 
+ * A Container which permits blocking upon the work queue to pause processing
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class PausableProcessingAsyncContainer<T> extends ThreadPoolAsyncContainer<T>
+      implements
+         AsyncInvocationProcessor
+{
+   // --------------------------------------------------------------------------------||
+   // Instance Members ---------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * To be used for asynchronous invocations
+    */
+   private ThreadPoolExecutor asynchronousExecutor;
+
+   // --------------------------------------------------------------------------------||
+   // Constructors -------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   public PausableProcessingAsyncContainer(String name, String domainName, Class<? extends T> beanClass)
+   {
+      super(name, domainName, beanClass, new ThreadPoolExecutor(3, 6, 3, TimeUnit.SECONDS,
+            new PausableBlockingQueue<Runnable>(false)));
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Required Implementations -------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   public ThreadPoolExecutor getAsynchronousExecutor()
+   {
+      return asynchronousExecutor;
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Accessors / Mutators -----------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   public void setAsynchronousExecutor(ThreadPoolExecutor asynchronousExecutor)
+   {
+      this.asynchronousExecutor = asynchronousExecutor;
+   }
+
+}

Copied: projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/common/Pojo.java (from rev 84250, projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/simple/Pojo.java)
===================================================================
--- projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/common/Pojo.java	                        (rev 0)
+++ projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/common/Pojo.java	2009-02-16 20:41:40 UTC (rev 84280)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.async.impl.test.common;
+
+import java.util.concurrent.Future;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.ejb.AsyncResult;
+import javax.ejb.Asynchronous;
+
+/**
+ * Pojo
+ * 
+ * A simple POJO to act as BeanContext for a test Container,
+ * candidate for asynchronous interception
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class Pojo
+{
+   // --------------------------------------------------------------------------------||
+   // Class Members ------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   public static final String VALUE = "Test Value";
+
+   // --------------------------------------------------------------------------------||
+   // Instance Members ---------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   public AtomicInteger counter = new AtomicInteger();
+
+   // --------------------------------------------------------------------------------||
+   // Business Methods ---------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Obtains a contracted value, asynchronously
+    * 
+    * @return
+    */
+   public Future<String> getValueAsynchronous()
+   {
+      return new AsyncResult<String>(this.getValueSynchronous());
+   }
+
+   /**
+    * Obtains a contracted value
+    * 
+    * @return
+    */
+   public String getValueSynchronous()
+   {
+      return VALUE;
+   }
+
+   /**
+    * Increments the internal counter; intentionally
+    * void return to test @Asynchronous on void
+    */
+   @Asynchronous
+   public void incrementCounterAsynchronous()
+   {
+      // The @Asynchronous annotation here will spawn this off,
+      // so just delegate to the synchronous handling 
+      this.incrementCounterSynchronous();
+   }
+
+   /**
+    * Obtains the internal counter
+    * 
+    * @return
+    */
+   public Future<Integer> getCounter()
+   {
+      return new AsyncResult<Integer>(counter.intValue());
+   }
+
+   /**
+    * Increments the internal counter, though
+    * does so synchronously (not a candidate for
+    * interception)
+    */
+   public void incrementCounterSynchronous()
+   {
+      counter.incrementAndGet();
+   }
+
+}

Modified: projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/common/TestConstants.java
===================================================================
--- projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/common/TestConstants.java	2009-02-16 20:27:35 UTC (rev 84279)
+++ projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/common/TestConstants.java	2009-02-16 20:41:40 UTC (rev 84280)
@@ -31,7 +31,25 @@
  */
 public interface TestConstants
 {
+   // --------------------------------------------------------------------------------||
+   // Test Setup ---------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
    String DOMAIN_ASYNC = "Asynchronous Container";
 
    String AOP_DEPLOYABLE_FILENAME_SIMPLE = "simple/jboss-aop.xml";
+
+   // --------------------------------------------------------------------------------||
+   // Test POJO Method Names ---------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   String METHOD_NAME_INCREMENT_COUNTER_ASYNCHRONOUS = "incrementCounterAsynchronous";
+
+   String METHOD_NAME_INCREMENT_COUNTER_SYNCHRONOUS = "incrementCounterSynchronous";
+
+   String METHOD_NAME_GET_COUNTER = "getCounter";
+
+   String METHOD_NAME_GET_VALUE_ASYNCHRONOUS = "getValueAsynchronous";
+
+   String METHOD_NAME_GET_VALUE_SYNCHRONOUS = "getValueSynchronous";
 }

Copied: projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/common/ThreadPoolAsyncContainer.java (from rev 84250, projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/container/AsyncContainer.java)
===================================================================
--- projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/common/ThreadPoolAsyncContainer.java	                        (rev 0)
+++ projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/common/ThreadPoolAsyncContainer.java	2009-02-16 20:41:40 UTC (rev 84280)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.async.impl.test.common;
+
+import java.util.concurrent.ExecutorService;
+
+import org.jboss.ejb3.async.impl.hack.DevelopmentHacks;
+import org.jboss.ejb3.async.spi.container.AsyncInvocationProcessor;
+import org.jboss.ejb3.interceptors.direct.DirectContainer;
+
+/**
+ * ThreadPoolAsyncContainer
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ThreadPoolAsyncContainer<T> extends DirectContainer<T> implements AsyncInvocationProcessor
+{
+   // --------------------------------------------------------------------------------||
+   // Instance Members ---------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * To be used for asynchronous invocations
+    */
+   private ExecutorService asynchronousExecutor;
+
+   // --------------------------------------------------------------------------------||
+   // Constructors -------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   public ThreadPoolAsyncContainer(String name, String domainName, Class<? extends T> beanClass)
+   {
+      this(name, domainName, beanClass, DevelopmentHacks.getDefaultAsyncExecutorService());
+   }
+
+   public ThreadPoolAsyncContainer(String name, String domainName, Class<? extends T> beanClass,
+         ExecutorService asynchronousExecutor)
+   {
+      super(name, domainName, beanClass);
+      this.setAsynchronousExecutor(asynchronousExecutor);
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Required Implementations -------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   public ExecutorService getAsynchronousExecutor()
+   {
+      return asynchronousExecutor;
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Accessors / Mutators -----------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   public void setAsynchronousExecutor(ExecutorService asynchronousExecutor)
+   {
+      this.asynchronousExecutor = asynchronousExecutor;
+   }
+
+}


Property changes on: projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/common/ThreadPoolAsyncContainer.java
___________________________________________________________________
Name: svn:mergeinfo
   + 

Modified: projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/security/unit/SecurityContextPropagationTestCase.java
===================================================================
--- projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/security/unit/SecurityContextPropagationTestCase.java	2009-02-16 20:27:35 UTC (rev 84279)
+++ projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/security/unit/SecurityContextPropagationTestCase.java	2009-02-16 20:41:40 UTC (rev 84280)
@@ -26,9 +26,9 @@
 import junit.framework.TestCase;
 
 import org.jboss.aspects.common.AOPDeployer;
+import org.jboss.ejb3.async.impl.test.common.ThreadPoolAsyncContainer;
 import org.jboss.ejb3.async.impl.test.common.SecurityActions;
 import org.jboss.ejb3.async.impl.test.common.TestConstants;
-import org.jboss.ejb3.async.impl.test.container.AsyncContainer;
 import org.jboss.ejb3.async.impl.test.security.SecurityAwarePojo;
 import org.jboss.ejb3.interceptors.container.BeanContext;
 import org.jboss.logging.Logger;
@@ -59,7 +59,7 @@
 
    private static AOPDeployer aopDeployer = new AOPDeployer(TestConstants.AOP_DEPLOYABLE_FILENAME_SIMPLE);
 
-   private static AsyncContainer<SecurityAwarePojo> container;
+   private static ThreadPoolAsyncContainer<SecurityAwarePojo> container;
 
    /*
     * Method names in Test POJO
@@ -75,7 +75,7 @@
    public static void beforeClass() throws Throwable
    {
       aopDeployer.deploy();
-      container = new AsyncContainer<SecurityAwarePojo>("Test Security Aware POJO Container",
+      container = new ThreadPoolAsyncContainer<SecurityAwarePojo>("Test Security Aware POJO Container",
             TestConstants.DOMAIN_ASYNC, SecurityAwarePojo.class);
    }
 

Deleted: projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/simple/Pojo.java
===================================================================
--- projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/simple/Pojo.java	2009-02-16 20:27:35 UTC (rev 84279)
+++ projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/simple/Pojo.java	2009-02-16 20:41:40 UTC (rev 84280)
@@ -1,109 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
-  *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.ejb3.async.impl.test.simple;
-
-import java.util.concurrent.Future;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import javax.ejb.AsyncResult;
-import javax.ejb.Asynchronous;
-
-/**
- * Pojo
- * 
- * A simple POJO to act as BeanContext for a test Container,
- * candidate for asynchronous interception
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public class Pojo
-{
-   // --------------------------------------------------------------------------------||
-   // Class Members ------------------------------------------------------------------||
-   // --------------------------------------------------------------------------------||
-
-   public static final String VALUE = "Test Value";
-
-   // --------------------------------------------------------------------------------||
-   // Instance Members ---------------------------------------------------------------||
-   // --------------------------------------------------------------------------------||
-
-   public AtomicInteger counter = new AtomicInteger();
-
-   // --------------------------------------------------------------------------------||
-   // Business Methods ---------------------------------------------------------------||
-   // --------------------------------------------------------------------------------||
-
-   /**
-    * Obtains a contracted value, asynchronously
-    * 
-    * @return
-    */
-   public Future<String> getValueAsynchronous()
-   {
-      return new AsyncResult<String>(this.getValueSynchronous());
-   }
-
-   /**
-    * Obtains a contracted value
-    * 
-    * @return
-    */
-   public String getValueSynchronous()
-   {
-      return VALUE;
-   }
-
-   /**
-    * Increments the internal counter; intentionally
-    * void return to test @Asynchronous on void
-    */
-   @Asynchronous
-   public void incrementCounterAsynchronous()
-   {
-      // The @Asynchronous annotation here will spawn this off,
-      // so just delegate to the synchronous handling 
-      this.incrementCounterSynchronous();
-   }
-
-   /**
-    * Obtains the internal counter
-    * 
-    * @return
-    */
-   public Future<Integer> getCounter()
-   {
-      return new AsyncResult<Integer>(counter.intValue());
-   }
-
-   /**
-    * Increments the internal counter, though
-    * does so synchronously (not a candidate for
-    * interception)
-    */
-   public void incrementCounterSynchronous()
-   {
-      counter.incrementAndGet();
-   }
-
-}

Modified: projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/simple/unit/SimpleAsyncTestCase.java
===================================================================
--- projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/simple/unit/SimpleAsyncTestCase.java	2009-02-16 20:27:35 UTC (rev 84279)
+++ projects/ejb3/trunk/async-impl/src/test/java/org/jboss/ejb3/async/impl/test/simple/unit/SimpleAsyncTestCase.java	2009-02-16 20:41:40 UTC (rev 84280)
@@ -28,9 +28,9 @@
 import junit.framework.TestCase;
 
 import org.jboss.aspects.common.AOPDeployer;
+import org.jboss.ejb3.async.impl.test.common.Pojo;
 import org.jboss.ejb3.async.impl.test.common.TestConstants;
-import org.jboss.ejb3.async.impl.test.container.AsyncContainer;
-import org.jboss.ejb3.async.impl.test.simple.Pojo;
+import org.jboss.ejb3.async.impl.test.common.ThreadPoolAsyncContainer;
 import org.jboss.ejb3.interceptors.container.BeanContext;
 import org.jboss.logging.Logger;
 import org.junit.AfterClass;
@@ -56,22 +56,8 @@
 
    private static AOPDeployer aopDeployer = new AOPDeployer(TestConstants.AOP_DEPLOYABLE_FILENAME_SIMPLE);
 
-   private static AsyncContainer<Pojo> container;
+   private static ThreadPoolAsyncContainer<Pojo> container;
 
-   /*
-    * Method names in Test POJO
-    */
-
-   private static final String METHOD_NAME_INCREMENT_COUNTER_ASYNCHRONOUS = "incrementCounterAsynchronous";
-
-   private static final String METHOD_NAME_INCREMENT_COUNTER_SYNCHRONOUS = "incrementCounterSynchronous";
-
-   private static final String METHOD_NAME_GET_COUNTER = "getCounter";
-
-   private static final String METHOD_NAME_GET_VALUE_ASYNCHRONOUS = "getValueAsynchronous";
-
-   private static final String METHOD_NAME_GET_VALUE_SYNCHRONOUS = "getValueSynchronous";
-
    // --------------------------------------------------------------------------------||
    // Test Lifecycle -----------------------------------------------------------------||
    // --------------------------------------------------------------------------------||
@@ -80,7 +66,8 @@
    public static void beforeClass() throws Throwable
    {
       aopDeployer.deploy();
-      container = new AsyncContainer<Pojo>("Test Async POJO Container", TestConstants.DOMAIN_ASYNC, Pojo.class);
+      container = new ThreadPoolAsyncContainer<Pojo>("Test Async POJO Container", TestConstants.DOMAIN_ASYNC,
+            Pojo.class);
    }
 
    @AfterClass
@@ -106,7 +93,7 @@
       BeanContext<Pojo> bean = container.construct();
 
       // Use the container to get a contracted value from the bean
-      Future<?> futureResult = (Future<?>) container.invoke(bean, METHOD_NAME_GET_VALUE_ASYNCHRONOUS);
+      Future<?> futureResult = (Future<?>) container.invoke(bean, TestConstants.METHOD_NAME_GET_VALUE_ASYNCHRONOUS);
       log.info("Obtained result: " + futureResult);
 
       // Get the Future value
@@ -130,19 +117,21 @@
       BeanContext<Pojo> bean = container.construct();
 
       // Get the counter as it exists
-      Future<Integer> initialCounterFuture = (Future<Integer>) container.invoke(bean, METHOD_NAME_GET_COUNTER);
+      Future<Integer> initialCounterFuture = (Future<Integer>) container.invoke(bean,
+            TestConstants.METHOD_NAME_GET_COUNTER);
       int initialCounter = initialCounterFuture.get();
 
       // Increment the counter 
       Future<Void> incrementCounterFutureResult = (Future<Void>) container.invoke(bean,
-            METHOD_NAME_INCREMENT_COUNTER_ASYNCHRONOUS);
+            TestConstants.METHOD_NAME_INCREMENT_COUNTER_ASYNCHRONOUS);
       TestCase.assertNotNull("void return type not intercepted as asynchronous invocation",
             incrementCounterFutureResult);
       Object incrementedCounterResult = incrementCounterFutureResult.get();
       TestCase.assertNull("void return types should return null upon Future.get()", incrementedCounterResult);
 
       // Test the counter was incremented
-      Future<Integer> incrementedCounterFuture = (Future<Integer>) container.invoke(bean, METHOD_NAME_GET_COUNTER);
+      Future<Integer> incrementedCounterFuture = (Future<Integer>) container.invoke(bean,
+            TestConstants.METHOD_NAME_GET_COUNTER);
       int incrementedCounter = incrementedCounterFuture.get();
       TestCase.assertEquals("Counter was not incremented", initialCounter + 1, incrementedCounter);
    }
@@ -160,7 +149,7 @@
       BeanContext<Pojo> bean = container.construct();
 
       // Invoke and test
-      Object shouldBeNullReturnValue = container.invoke(bean, METHOD_NAME_INCREMENT_COUNTER_SYNCHRONOUS);
+      Object shouldBeNullReturnValue = container.invoke(bean, TestConstants.METHOD_NAME_INCREMENT_COUNTER_SYNCHRONOUS);
       TestCase.assertNull("methods with void return type not annotated with @" + Asynchronous.class.getSimpleName()
             + " should have null return type from container invocation", shouldBeNullReturnValue);
 
@@ -179,7 +168,7 @@
       BeanContext<Pojo> bean = container.construct();
 
       // Invoke and test
-      String value = container.invoke(bean, METHOD_NAME_GET_VALUE_SYNCHRONOUS);
+      String value = container.invoke(bean, TestConstants.METHOD_NAME_GET_VALUE_SYNCHRONOUS);
       TestCase.assertEquals("Contracted value not obtained as expected", Pojo.VALUE, value);
 
    }

Modified: projects/ejb3/trunk/async-impl/src/test/resources/log4j.xml
===================================================================
--- projects/ejb3/trunk/async-impl/src/test/resources/log4j.xml	2009-02-16 20:27:35 UTC (rev 84279)
+++ projects/ejb3/trunk/async-impl/src/test/resources/log4j.xml	2009-02-16 20:41:40 UTC (rev 84280)
@@ -39,7 +39,7 @@
 
     <layout class="org.apache.log4j.PatternLayout">
       <!-- The default pattern: Date Priority [Category] Message\n -->
-      <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
+      <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] (%t:%x) %m%n"/>
     </layout>
   </appender>
 




More information about the jboss-cvs-commits mailing list