[jboss-cvs] JBossAS SVN: r74309 - in branches/JBPAPP_4_2_0_GA_CP/ejb3: src/main/org/jboss/ejb3/mdb and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jun 9 09:01:30 EDT 2008


Author: wolfc
Date: 2008-06-09 09:01:29 -0400 (Mon, 09 Jun 2008)
New Revision: 74309

Added:
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/mdb/MDBInstanceInterceptor.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree1239/
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree1239/Controller.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree1239/ControllerBean.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree1239/FailingMDB.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree1239/unit/
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree1239/unit/StopDeliveryUnitTestCase.java
Modified:
   branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/mdb/MDB.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateless/StatelessInstanceInterceptor.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/ejb3-interceptors-aop.xml
Log:
EJBTHREE-1239: stop delivery after a specified number of RuntimeExceptions

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml	2008-06-09 12:22:36 UTC (rev 74308)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml	2008-06-09 13:01:29 UTC (rev 74309)
@@ -2042,6 +2042,13 @@
       <build-simple-jar name="ejbthree1062"/>
    </target>
    
+   <target name="ejbthree1239"
+      description="Builds a simple jar files."
+      depends="compile-classes">
+      
+      <build-simple-jar name="ejbthree1239"/>
+   </target>
+   
    <target name="jbas4489"
       description="Builds a simple jar files."
       depends="compile-classes">
@@ -3736,6 +3743,7 @@
       ejbthree987,
       ejbthree921,
       ejbthree959, ejbthree963, ejbthree994, ejbthree1023, ejbthree1025, ejbthree1062,
+      ejbthree1239,
       jbas4489, epcpropagation, jaccpropagation, 
       aspectdomain, ejbcontext, schema, mail, scopedclassloader, dependency, jaxws,
       pkg, securitydomain, enventry, externalpersistenceunit,
@@ -4360,6 +4368,9 @@
          <param name="test" value="ejbthree1062"/>
       </antcall>
       <antcall target="test" inheritRefs="true">
+         <param name="test" value="ejbthree1239"/>
+      </antcall>
+      <antcall target="test" inheritRefs="true">
          <param name="test" value="jbas4489"/>
       </antcall>
    </target>

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/mdb/MDB.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/mdb/MDB.java	2008-06-09 12:22:36 UTC (rev 74308)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/mdb/MDB.java	2008-06-09 13:01:29 UTC (rev 74309)
@@ -21,37 +21,27 @@
  */
 package org.jboss.ejb3.mdb;
 
-import org.jboss.annotation.ejb.AcknowledgementMode;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
 import org.jboss.annotation.ejb.DefaultActivationSpecs;
-import org.jboss.annotation.ejb.ResourceAdapter;
 import org.jboss.aop.AspectManager;
 import org.jboss.aop.MethodInfo;
-import org.jboss.aop.advice.Interceptor;
 import org.jboss.aop.util.MethodHashing;
-import org.jboss.deployment.DeploymentException;
-import org.jboss.ejb3.*;
-import org.jboss.ejb3.mdb.inflow.JBossMessageEndpointFactory;
+import org.jboss.ejb3.Ejb3Deployment;
+import org.jboss.ejb3.ProxyFactoryHelper;
 import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
-import org.jboss.ejb3.timerservice.TimedObjectInvoker;
-import org.jboss.ejb3.timerservice.TimerServiceFactory;
-import org.jboss.jms.ConnectionFactoryHelper;
-import org.jboss.jms.jndi.JMSProviderAdapter;
 import org.jboss.logging.Logger;
 import org.jboss.metadata.ActivationConfigPropertyMetaData;
 
-import javax.ejb.*;
-import javax.ejb.Timer;
-import javax.jms.*;
-import javax.jms.Queue;
-import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-import javax.naming.Context;
-import javax.naming.NamingException;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.*;
-
 /**
  * Comment
  *
@@ -62,6 +52,8 @@
 {
    private static final Logger log = Logger.getLogger(MDB.class);
    
+   private static final String STOP_DELIVERY_THRESHOLD = "StopDeliveryThreshold";
+   
    protected Class messagingType = null;
    /**
     * Default destination type. Used when no message-driven-destination is given
@@ -69,6 +61,10 @@
     * successfull. Default value: javax.jms.Topic.
     */
    protected final static String DEFAULT_DESTINATION_TYPE = "javax.jms.Topic";
+   
+   private volatile int failedDeliveries = 0;
+   
+   private int stopDeliveryThreshold = -1;
 
    public MDB(String ejbName, AspectManager manager, ClassLoader cl, String beanClassName, Hashtable ctxProperties,
               InterceptorInfoRepository interceptorRepository, Ejb3Deployment deployment)
@@ -76,6 +72,23 @@
       super(ejbName, manager, cl, beanClassName, ctxProperties, interceptorRepository, deployment);
    }
    
+   /**
+    * Delivery has failed and bean instance is discarded, we might want to stop delivery.
+    */
+   protected void failedDelivery()
+   {
+      failedDeliveries++;
+      
+      if(stopDeliveryThreshold < 0)
+         return;
+      
+      if(failedDeliveries >= stopDeliveryThreshold)
+      {
+         log.warn("Failed deliveries (" + failedDeliveries + ") has reach the stop deliver threshold (" + stopDeliveryThreshold + "), stopping deliveries");
+         stopDeliveryAsync();
+      }
+   }
+   
    public Class getMessagingType()
    {
       if (messagingType == null)
@@ -102,7 +115,7 @@
 
    public Map getActivationConfigProperties()
    {
-      HashMap result = new HashMap();
+      Map<String, ActivationConfigPropertyMetaData> result = new HashMap<String, ActivationConfigPropertyMetaData>();
       MessageDriven mdAnnotation = (MessageDriven) resolveAnnotation(MessageDriven.class);
       for (ActivationConfigProperty property : mdAnnotation.activationConfig())
       {
@@ -118,6 +131,10 @@
          }
       }
       
+      ActivationConfigPropertyMetaData acp = result.remove(STOP_DELIVERY_THRESHOLD);
+      if(acp != null)
+         stopDeliveryThreshold = Integer.parseInt(acp.getValue());
+      
       return result;
    }
    
@@ -126,6 +143,44 @@
       super.start();
    }
 
+   @Override
+   protected void startDelivery()
+   {
+      super.startDelivery();
+      
+      // When (re-)starting deliveries we assume nothing has failed
+      failedDeliveries = 0;
+   }
+   
+   /**
+    * We can't stop delivery from within a delivery in progress. That
+    * would deadlock a JCA connector. So we start a thread and call
+    * stopDelivery from there and hope for the best.
+    */
+   protected void stopDeliveryAsync()
+   {
+      if(!isDeliveryActive())
+         return;
+      
+      Thread thread = new Thread()
+      {
+         public void run()
+         {
+            synchronized (MDB.this)
+            {
+               if(isDeliveryActive())
+                  stopDelivery();
+               else
+                  log.warn("Delivery was not active, ignoring stop request");
+            }
+         }
+      };
+      thread.setDaemon(true);
+      // We want to win the race against JMS delivering messages.
+      thread.setPriority(Thread.NORM_PRIORITY + 2);
+      thread.start();
+   }
+   
    public ObjectName getJmxName()
    {
       ObjectName jmxName = null;

Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/mdb/MDBInstanceInterceptor.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/mdb/MDBInstanceInterceptor.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/mdb/MDBInstanceInterceptor.java	2008-06-09 13:01:29 UTC (rev 74309)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.mdb;
+
+import org.jboss.ejb3.BeanContext;
+import org.jboss.ejb3.stateless.StatelessInstanceInterceptor;
+
+/**
+ * Add additional functionality to check the StopDeliveryThreshold 
+ * 
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MDBInstanceInterceptor extends StatelessInstanceInterceptor
+{
+   @Override
+   protected void discard(BeanContext ctx)
+   {
+      super.discard(ctx);
+      
+      MDB mdb = (MDB) ctx.getContainer();
+      mdb.failedDelivery();
+   }
+}


Property changes on: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/mdb/MDBInstanceInterceptor.java
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateless/StatelessInstanceInterceptor.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateless/StatelessInstanceInterceptor.java	2008-06-09 12:22:36 UTC (rev 74308)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateless/StatelessInstanceInterceptor.java	2008-06-09 13:01:29 UTC (rev 74309)
@@ -32,7 +32,8 @@
 import java.rmi.RemoteException;
 
 /**
- * Comment
+ * Attach a bean instance to the invocation from the container pool.
+ * (Should really be called PooledInstanceInterceptor.) 
  *
  * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
  * @version $Revision$
@@ -41,6 +42,13 @@
 {
    private static final Logger log = Logger.getLogger(StatelessInstanceInterceptor.class);
 
+   /* Allow subclasses to add extra behavior */
+   protected void discard(BeanContext ctx)
+   {
+      EJBContainer container = (EJBContainer) ctx.getContainer();
+      container.getPool().discard(ctx);
+   }
+   
    public String getName()
    {
       return "StatelessInstanceInterceptor";
@@ -71,7 +79,7 @@
       {                                                                                   
          ejb.setTargetObject(null);
          ejb.setBeanContext(null);
-         if (discard) pool.discard(ctx);
+         if (discard) discard(ctx);
          else pool.release(ctx);
       }
    }

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/ejb3-interceptors-aop.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/ejb3-interceptors-aop.xml	2008-06-09 12:22:36 UTC (rev 74308)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/ejb3-interceptors-aop.xml	2008-06-09 13:01:29 UTC (rev 74309)
@@ -71,6 +71,7 @@
    <interceptor factory="org.jboss.ejb3.security.AuthenticationInterceptorFactory" scope="PER_CLASS"/>
    <interceptor factory="org.jboss.ejb3.security.RunAsSecurityInterceptorFactory" scope="PER_CLASS"/>
    <interceptor class="org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor" scope="PER_VM"/>
+   <interceptor class="org.jboss.ejb3.mdb.MDBInstanceInterceptor" scope="PER_VM"/>
    <interceptor class="org.jboss.ejb3.stateless.StatelessInstanceInterceptor" scope="PER_VM"/>
    <interceptor class="org.jboss.ejb3.stateful.StatefulInstanceInterceptor" scope="PER_VM"/>
    <interceptor class="org.jboss.ejb3.stateful.SessionSynchronizationInterceptor" scope="PER_VM"/>
@@ -279,7 +280,7 @@
          <interceptor-ref name="org.jboss.ejb3.security.RunAsSecurityInterceptorFactory"/>
       </bind>
       <bind pointcut="execution(public * *->*(..))">
-         <interceptor-ref name="org.jboss.ejb3.stateless.StatelessInstanceInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.mdb.MDBInstanceInterceptor"/>
          <interceptor-ref name="org.jboss.ejb3.tx.TxInterceptorFactory"/>
          <interceptor-ref name="org.jboss.ejb3.AllowedOperationsInterceptor"/>
          <interceptor-ref name="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor"/>

Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree1239/Controller.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree1239/Controller.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree1239/Controller.java	2008-06-09 13:01:29 UTC (rev 74309)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.test.ejbthree1239;
+
+import javax.ejb.Remote;
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Remote
+public interface Controller
+{
+   boolean getFail();
+   
+   void setFail(boolean fail);
+}


Property changes on: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree1239/Controller.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree1239/ControllerBean.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree1239/ControllerBean.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree1239/ControllerBean.java	2008-06-09 13:01:29 UTC (rev 74309)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.test.ejbthree1239;
+
+import org.jboss.annotation.ejb.Service;
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Service
+public class ControllerBean implements Controller
+{
+   private boolean fail = false;
+
+   public boolean getFail()
+   {
+      return fail;
+   }
+   
+   public void setFail(boolean fail)
+   {
+      this.fail = fail;
+   }
+}


Property changes on: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree1239/ControllerBean.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree1239/FailingMDB.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree1239/FailingMDB.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree1239/FailingMDB.java	2008-06-09 13:01:29 UTC (rev 74309)
@@ -0,0 +1,113 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.test.ejbthree1239;
+
+import java.util.Date;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.EJB;
+import javax.ejb.MessageDriven;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+
+/**
+ * This MDB asks the Controller whether to fail or not with a RuntimeException
+ * and stops delivery after throwing one.
+ * 
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at MessageDriven(activationConfig =
+{
+   @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
+   @ActivationConfigProperty(propertyName="destination", propertyValue="queue/ejbthree1239"),
+   @ActivationConfigProperty(propertyName="StopDeliveryThreshold", propertyValue="1")
+})
+public class FailingMDB implements MessageListener
+{
+   @Resource(mappedName="ConnectionFactory")
+   private QueueConnectionFactory factory;
+   
+   @EJB
+   private Controller controller;
+   
+   private QueueConnection connection;
+   private QueueSession session;
+   private QueueSender sender;
+   
+   public void onMessage(Message message)
+   {
+      if(controller.getFail())
+         throw new RuntimeException("Requested to fail");
+      
+      try
+      {
+         Message reply = session.createObjectMessage(new Date());
+         sender.send(message.getJMSReplyTo(), reply);
+      }
+      catch (JMSException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   @PostConstruct
+   public void postConstruct()
+   {
+      try
+      {
+         connection = factory.createQueueConnection();
+         session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+         sender = session.createSender(null);
+      }
+      catch(JMSException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
+   @PreDestroy
+   public void preDestroy()
+   {
+      try
+      {
+         if(sender != null)
+            sender.close();
+         if(session != null)
+            session.close();
+         if(connection != null)
+            connection.close();
+      }
+      catch(JMSException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+}


Property changes on: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree1239/FailingMDB.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree1239/unit/StopDeliveryUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree1239/unit/StopDeliveryUnitTestCase.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree1239/unit/StopDeliveryUnitTestCase.java	2008-06-09 13:01:29 UTC (rev 74309)
@@ -0,0 +1,151 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.test.ejbthree1239.unit;
+
+import javax.jms.Message;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.TemporaryQueue;
+import javax.jms.TextMessage;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.naming.InitialContext;
+
+import junit.framework.Test;
+
+import org.jboss.ejb3.test.ejbthree1239.Controller;
+import org.jboss.test.JBossTestCase;
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class StopDeliveryUnitTestCase extends JBossTestCase
+{
+   public StopDeliveryUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      serverFound();
+   }
+   
+   public void test1() throws Exception
+   {
+      InitialContext ctx = new InitialContext();
+      Queue queue = (Queue) ctx.lookup("queue/ejbthree1239");
+      QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
+      QueueConnection connection = factory.createQueueConnection();
+      try
+      {
+         connection.start();
+         
+         QueueSession session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+         
+         TemporaryQueue replyQueue = session.createTemporaryQueue();
+         QueueReceiver receiver = session.createReceiver(replyQueue);
+         
+         QueueSender sender = session.createSender(queue);
+         TextMessage message = session.createTextMessage("Hello world");
+         message.setJMSReplyTo(replyQueue);
+         sender.send(message);
+         sender.close();
+         
+         MBeanServerConnection server = getServer();
+         ObjectName name = new ObjectName("jboss.j2ee:jar=ejbthree1239.jar,name=FailingMDB,service=EJB3");
+         assertTrue((Boolean) server.getAttribute(name, "DeliveryActive"));
+
+         Message msg = receiver.receive(5000);
+         assertNotNull(msg);
+         
+         receiver.close();
+         session.close();
+      }
+      finally
+      {
+         connection.close();
+      }
+   }
+   
+   public void testRuntimeException() throws Exception
+   {
+      InitialContext ctx = new InitialContext();
+      
+      Controller controller = (Controller) ctx.lookup("ControllerBean/remote");
+      
+      Queue queue = (Queue) ctx.lookup("queue/ejbthree1239");
+      QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
+      QueueConnection connection = factory.createQueueConnection();
+      try
+      {
+         connection.start();
+         
+         QueueSession session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+         
+         TemporaryQueue replyQueue = session.createTemporaryQueue();
+         QueueReceiver receiver = session.createReceiver(replyQueue);
+         
+         controller.setFail(true);
+         
+         QueueSender sender = session.createSender(queue);
+         TextMessage message = session.createTextMessage("Hello world");
+         message.setJMSReplyTo(replyQueue);
+         sender.send(message);
+         sender.close();
+         
+         Message msg = receiver.receive(5000);
+         assertNull(msg);
+         
+         MBeanServerConnection server = getServer();
+         ObjectName name = new ObjectName("jboss.j2ee:jar=ejbthree1239.jar,name=FailingMDB,service=EJB3");
+         assertFalse((Boolean) server.getAttribute(name, "DeliveryActive"));
+
+         controller.setFail(false);
+         
+         server.invoke(name, "startDelivery", null, null);
+         assertTrue((Boolean) server.getAttribute(name, "DeliveryActive"));
+         
+         msg = receiver.receive(5000);
+         assertNotNull(msg);
+         
+         receiver.close();
+         session.close();
+      }
+      finally
+      {
+         connection.close();
+      }
+   }
+   
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(StopDeliveryUnitTestCase.class, "ejbthree1239.jar");
+   }
+}


Property changes on: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/ejbthree1239/unit/StopDeliveryUnitTestCase.java
___________________________________________________________________
Name: svn:eol-style
   + native




More information about the jboss-cvs-commits mailing list