[jboss-cvs] JBossAS SVN: r102094 - in projects/ejb-book/trunk/ch08-statusupdate: src/main/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Mar 8 17:35:25 EST 2010


Author: ALRubinger
Date: 2010-03-08 17:35:24 -0500 (Mon, 08 Mar 2010)
New Revision: 102094

Added:
   projects/ejb-book/trunk/ch08-statusupdate/src/test/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/TwitterUpdateBlockingTestMdb.java
Modified:
   projects/ejb-book/trunk/ch08-statusupdate/pom.xml
   projects/ejb-book/trunk/ch08-statusupdate/src/main/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/TwitterUpdateMdb.java
   projects/ejb-book/trunk/ch08-statusupdate/src/test/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/StatusUpdateIntegrationTest.java
Log:
[EJBBOOK-13] Move out the barrier into a test-only MDB

Modified: projects/ejb-book/trunk/ch08-statusupdate/pom.xml
===================================================================
--- projects/ejb-book/trunk/ch08-statusupdate/pom.xml	2010-03-08 22:32:23 UTC (rev 102093)
+++ projects/ejb-book/trunk/ch08-statusupdate/pom.xml	2010-03-08 22:35:24 UTC (rev 102094)
@@ -141,6 +141,32 @@
     </dependency>
 
   </dependencies>
+  
+  <dependencyManagement>
+  
+  <dependencies>
+  <!--
+    Manually use an older version of ShrinkWrap to support EmbeddedAS
+    for now
+  -->
+  <dependency>
+    <groupId>org.jboss.shrinkwrap</groupId>
+    <artifactId>shrinkwrap-impl-base</artifactId>
+    <version>1.0.0-alpha-2</version>
+  </dependency>
+  <dependency>
+    <groupId>org.jboss.shrinkwrap</groupId>
+    <artifactId>shrinkwrap-api</artifactId>
+    <version>1.0.0-alpha-2</version>
+  </dependency>
+  <dependency>
+    <groupId>org.jboss.shrinkwrap</groupId>
+    <artifactId>shrinkwrap-spi</artifactId>
+    <version>1.0.0-alpha-2</version>
+  </dependency>
+</dependencies>
+  
+  </dependencyManagement>
 
   <profiles>
 

Modified: projects/ejb-book/trunk/ch08-statusupdate/src/main/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/TwitterUpdateMdb.java
===================================================================
--- projects/ejb-book/trunk/ch08-statusupdate/src/main/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/TwitterUpdateMdb.java	2010-03-08 22:32:23 UTC (rev 102093)
+++ projects/ejb-book/trunk/ch08-statusupdate/src/main/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/TwitterUpdateMdb.java	2010-03-08 22:35:24 UTC (rev 102094)
@@ -21,17 +21,12 @@
  */
 package org.jboss.ejb3.examples.ch08.statusupdate.mdb;
 
-import java.util.concurrent.CountDownLatch;
 import java.util.logging.Logger;
 
 import javax.annotation.PostConstruct;
-import javax.ejb.ActivationConfigProperty;
-import javax.ejb.MessageDriven;
 import javax.jms.MessageListener;
 
-import org.jboss.ejb3.annotation.Depends;
 import org.jboss.ejb3.examples.ch08.statusupdate.api.StatusUpdate;
-import org.jboss.ejb3.examples.ch08.statusupdate.api.StatusUpdateConstants;
 
 import twitter4j.Twitter;
 
@@ -48,12 +43,6 @@
  * @see http://yusuke.homeip.net/twitter4j/en/index.html
  * @version $Revision: $
  */
- at MessageDriven(activationConfig =
-{
-      @ActivationConfigProperty(propertyName = "destinationType", propertyValue = StatusUpdateConstants.TYPE_DESTINATION_STATUSUPDATE),
-      @ActivationConfigProperty(propertyName = "destination", propertyValue = StatusUpdateConstants.JNDI_NAME_TOPIC_STATUSUPDATE)})
- at Depends(StatusUpdateConstants.OBJECT_NAME_TOPIC_STATUSUPDATE)
-// Dependency matches the name in the topic descriptor XML
 public class TwitterUpdateMdb extends StatusUpdateBeanBase implements MessageListener
 {
 
@@ -67,14 +56,9 @@
    private static final Logger log = Logger.getLogger(TwitterUpdateMdb.class.getName());
 
    /**
-    * Shared latch, so tests can wait until the MDB is processed.  In POJO
-    * testing this is wholly unnecessary as we've got a single-threaded environment, but 
-    * when testing in an EJB Container running in the *same* JVM as the test, the test 
-    * can use this to wait until the MDB has been invoked, strengthening the integrity
-    * of the test.  It's not recommended to put this piece into a production EJB; instead
-    * test an extension of your EJB which adds this (and only this) support.
+    * EJB Name
     */
-   public static CountDownLatch LATCH = new CountDownLatch(1);
+   static final String NAME = "TwitterUpdateMdb";
 
    //-------------------------------------------------------------------------------------||
    // Constructors -----------------------------------------------------------------------||
@@ -148,10 +132,5 @@
 
       // Update status
       client.updateStatus(status);
-
-      // Count down the latch so that the test knows we're here
-      log.info("Counting down the latch...");
-      LATCH.countDown();
-
    }
 }

Modified: projects/ejb-book/trunk/ch08-statusupdate/src/test/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/StatusUpdateIntegrationTest.java
===================================================================
--- projects/ejb-book/trunk/ch08-statusupdate/src/test/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/StatusUpdateIntegrationTest.java	2010-03-08 22:32:23 UTC (rev 102093)
+++ projects/ejb-book/trunk/ch08-statusupdate/src/test/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/StatusUpdateIntegrationTest.java	2010-03-08 22:35:24 UTC (rev 102094)
@@ -26,6 +26,7 @@
 import java.net.URL;
 import java.util.HashSet;
 import java.util.Set;
+import java.util.concurrent.BrokenBarrierException;
 import java.util.concurrent.TimeUnit;
 import java.util.logging.Logger;
 
@@ -208,10 +209,11 @@
          return;
       }
 
-      // Package up the MDB, all required classes, and a Topic descriptor
+      // Package up the test MDB, all required classes, and a Topic descriptor
       final JavaArchive archive = Archives.create(NAME_MDB_ARCHIVE, JavaArchive.class).addClasses(StatusUpdate.class,
             StatusUpdateConstants.class, LoggingStatusUpdateMdb.class, StatusUpdateBeanBase.class,
-            TwitterUpdateMdb.class, SecurityActions.class).addResource(NAME_RESOURCE_TOPIC_DEPLOYMENT);
+            TwitterUpdateBlockingTestMdb.class, SecurityActions.class, TwitterUpdateMdb.class).addResource(
+            NAME_RESOURCE_TOPIC_DEPLOYMENT);
 
       // Deploy the archive
       log.info("Deploying archive: " + archive.toString(true));
@@ -225,11 +227,10 @@
 
       // Wait for the MDB to process, as it's doing so in another Thread.
       // This is *only* possible when we test MDBs in the same JVM as the test.
-      final boolean processed;
       try
       {
          log.info("Waiting on the MDB...");
-         processed = TwitterUpdateMdb.LATCH.await(10, TimeUnit.SECONDS);
+         TwitterUpdateBlockingTestMdb.BARRIER.await(10, TimeUnit.SECONDS);
       }
       catch (final InterruptedException e)
       {
@@ -238,12 +239,11 @@
          throw new RuntimeException(
                "Thread was interrupted while waiting for MDB processing; should not happen in this test");
       }
-
-      // Ensure the MDB processed the message
-      if (!processed)
+      catch (final BrokenBarrierException bbe)
       {
          TestCase.fail("The MDB did not process the status update in the allotted time.");
       }
+
       log.info("MDB signaled it's done processing, so we can resume");
 
       // Test

Added: projects/ejb-book/trunk/ch08-statusupdate/src/test/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/TwitterUpdateBlockingTestMdb.java
===================================================================
--- projects/ejb-book/trunk/ch08-statusupdate/src/test/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/TwitterUpdateBlockingTestMdb.java	                        (rev 0)
+++ projects/ejb-book/trunk/ch08-statusupdate/src/test/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/TwitterUpdateBlockingTestMdb.java	2010-03-08 22:35:24 UTC (rev 102094)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.examples.ch08.statusupdate.mdb;
+
+import java.util.concurrent.CyclicBarrier;
+import java.util.logging.Logger;
+
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.jms.MessageListener;
+
+import org.jboss.ejb3.annotation.Depends;
+import org.jboss.ejb3.examples.ch08.statusupdate.api.StatusUpdate;
+import org.jboss.ejb3.examples.ch08.statusupdate.api.StatusUpdateConstants;
+
+/**
+ * Extends the {@link TwitterUpdateMdb} example to add a barrier to
+ * be shared in testing only, such that tests can be sure we're done 
+ * processing before they proceed
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at MessageDriven(name = TwitterUpdateMdb.NAME, activationConfig =
+{
+      @ActivationConfigProperty(propertyName = "destinationType", propertyValue = StatusUpdateConstants.TYPE_DESTINATION_STATUSUPDATE),
+      @ActivationConfigProperty(propertyName = "destination", propertyValue = StatusUpdateConstants.JNDI_NAME_TOPIC_STATUSUPDATE)})
+ at Depends(StatusUpdateConstants.OBJECT_NAME_TOPIC_STATUSUPDATE)
+// Dependency matches the name in the topic descriptor XML
+public class TwitterUpdateBlockingTestMdb extends TwitterUpdateMdb implements MessageListener
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Logger
+    */
+   private static final Logger log = Logger.getLogger(TwitterUpdateBlockingTestMdb.class.getName());
+
+   /**
+    * Shared barrier, so tests can wait until the MDB is processed.  In POJO
+    * testing this is wholly unnecessary as we've got a single-threaded environment, but 
+    * when testing in an EJB Container running in the *same* JVM as the test, the test 
+    * can use this to wait until the MDB has been invoked, strengthening the integrity
+    * of the test.  It's not recommended to put this piece into a production EJB; instead
+    * test an extension of your EJB which adds this (and only this) support.
+    */
+   public static CyclicBarrier BARRIER = new CyclicBarrier(2);
+
+   //-------------------------------------------------------------------------------------||
+   // Overridden Implementations ---------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * {@inheritDoc}
+    * Additionally waits upon a shared barrier so that the test can ensure we're done before
+    * it proceeds
+    * @see org.jboss.ejb3.examples.ch08.statusupdate.mdb.TwitterUpdateMdb#updateStatus(org.jboss.ejb3.examples.ch08.statusupdate.api.StatusUpdate)
+    */
+   @Override
+   public void updateStatus(final StatusUpdate newStatus) throws IllegalArgumentException, Exception
+   {
+      // Call the super implementation
+      super.updateStatus(newStatus);
+
+      // Wait on the barrier
+      log.info("Waiting on the barrier...");
+      BARRIER.await();
+   }
+
+}




More information about the jboss-cvs-commits mailing list