[jboss-cvs] JBossAS SVN: r58682 - in trunk/ejb3/src/test/org/jboss/ejb3/test/mdb: . unit

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Nov 27 07:35:29 EST 2006


Author: wolfc
Date: 2006-11-27 07:35:20 -0500 (Mon, 27 Nov 2006)
New Revision: 58682

Added:
   trunk/ejb3/src/test/org/jboss/ejb3/test/mdb/CMTTxNotSupportedTestMDB.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/mdb/ExpirationTestMDB.java
Modified:
   trunk/ejb3/src/test/org/jboss/ejb3/test/mdb/TestStatus.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/mdb/TestStatusBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/mdb/unit/MDBUnitTestCase.java
Log:
extra mdb unit tests

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/mdb/CMTTxNotSupportedTestMDB.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/mdb/CMTTxNotSupportedTestMDB.java	2006-11-27 11:15:38 UTC (rev 58681)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/mdb/CMTTxNotSupportedTestMDB.java	2006-11-27 12:35:20 UTC (rev 58682)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.mdb;
+
+import javax.annotation.Resource;
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.ejb.MessageDrivenContext;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+
+/**
+ * Comment
+ *
+ * @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/cmttxnotsupmdbtest"),
+   @ActivationConfigProperty(propertyName="DLQMaxResent", propertyValue="1")
+})
+ at TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
+public class CMTTxNotSupportedTestMDB implements MessageListener
+{
+   private static boolean thrownException = false;
+   @Resource MessageDrivenContext ctx;
+
+   public void onMessage(Message message)
+   {
+      System.out.println("*** CMTTxNotSupportedTestMDB onMessage " + thrownException);
+      if (ctx == null) throw new RuntimeException("FAILED ON CTX LOOKUP");
+      
+      if (!thrownException)
+      {
+         thrownException = true;
+         throw new RuntimeException();
+      }
+      
+      TestStatusBean.queueRan++;
+   }
+
+}

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/mdb/ExpirationTestMDB.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/mdb/ExpirationTestMDB.java	2006-11-27 11:15:38 UTC (rev 58681)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/mdb/ExpirationTestMDB.java	2006-11-27 12:35:20 UTC (rev 58682)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.mdb;
+
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+
+import org.jboss.annotation.ejb.PoolClass;
+
+/**
+ * Comment
+ *
+ * @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/expirationmdbtest")
+})
+ at PoolClass(value=org.jboss.ejb3.StrictMaxPool.class, maxSize=1)
+public class ExpirationTestMDB implements MessageListener
+{
+   public void onMessage(Message message)
+   {
+      System.out.println("*** ExpirationTestMDB onMessage " + TestStatusBean.expirationQueueRan);
+      
+      try
+      {
+         Thread.sleep(1000);
+      }
+      catch(InterruptedException e)
+      {
+         // ignore
+      }
+      
+      TestStatusBean.expirationQueueRan++;
+   }
+
+}

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/mdb/TestStatus.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/mdb/TestStatus.java	2006-11-27 11:15:38 UTC (rev 58681)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/mdb/TestStatus.java	2006-11-27 12:35:20 UTC (rev 58682)
@@ -61,4 +61,6 @@
    boolean preDestroy();
    
    int rollbackCmtQueueRan();
+   
+   int expirationQueueRan();
 }

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/mdb/TestStatusBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/mdb/TestStatusBean.java	2006-11-27 11:15:38 UTC (rev 58681)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/mdb/TestStatusBean.java	2006-11-27 12:35:20 UTC (rev 58682)
@@ -53,6 +53,7 @@
    public static boolean postConstruct = false;
    public static boolean preDestroy = false;
    static int rollbackCmtQueueRan = 0;
+   static int expirationQueueRan = 0;
 
    public void clear()
    {
@@ -140,4 +141,9 @@
    {
       return rollbackCmtQueueRan;
    }
+   
+   public int expirationQueueRan()
+   {
+      return expirationQueueRan;
+   }
 }

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/mdb/unit/MDBUnitTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/mdb/unit/MDBUnitTestCase.java	2006-11-27 11:15:38 UTC (rev 58681)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/mdb/unit/MDBUnitTestCase.java	2006-11-27 12:35:20 UTC (rev 58682)
@@ -360,6 +360,8 @@
       Thread.sleep(2000);
 
       assertSize(session, queue, 0);
+      
+      /* TODO: await implementation of JBMESSAGING-126
       assertSize(session, dlq, 1);
 
       QueueReceiver receiver = session.createReceiver(dlq);
@@ -372,10 +374,11 @@
       assertEquals(text, message.getText());
       assertEquals("bar", message.getStringProperty("foo"));
       assertNull(message.getStringProperty("null"));
-
+      
+      receiver.close();
+       */
       sender.close();
-      receiver.close();
-
+      
       session.close();
       connection.close();
    }
@@ -458,6 +461,110 @@
       assertEquals(1, status.rollbackCmtQueueRan());
    }
 
+   /**
+    * Test that expired messages are not delivered
+    */
+   public void testExpiration() throws Exception
+   {
+      TestStatus status = (TestStatus) getInitialContext().lookup("TestStatusBean/remote");
+      clear(status);
+      
+      QueueConnection connection = null;
+      QueueSender sender = null;
+      QueueSession session = null;
+
+      QueueConnectionFactory factory = getQueueConnectionFactory();
+      connection = factory.createQueueConnection();
+      connection.start();
+      session = connection.createQueueSession(false,
+            QueueSession.AUTO_ACKNOWLEDGE);
+
+      Queue queue = (Queue) getInitialContext().lookup("queue/expirationmdbtest");
+      sender = session.createSender(queue);
+
+      Queue dlq = (Queue) getInitialContext().lookup("queue/DLQ");
+
+      removeAllMessagesFromDLQ();
+
+      long now = System.currentTimeMillis();
+
+      {
+         TextMessage message = session.createTextMessage();
+         message.setStringProperty("foo", "bar");
+         message.setStringProperty("null", null);
+         String text = "do not expire on server";
+         message.setText(text);
+   
+         System.out.println("!!!! sending 1 ...");
+         sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 100);
+      }
+
+      {
+         TextMessage message = session.createTextMessage();
+         message.setStringProperty("foo", "bar");
+         message.setStringProperty("null", null);
+         String text = "expire on server";
+         message.setText(text);
+   
+         System.out.println("!!!! sending 2 ...");
+         sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 1);
+      }
+
+      System.out.println("!!!! sleeping ...");
+      Thread.sleep(2000);
+
+      assertSize(session, queue, 0);
+      
+      /* TODO: await implementation of JBMESSAGING-126
+      assertSize(session, dlq, 1);
+
+      QueueReceiver receiver = session.createReceiver(dlq);
+      message = (TextMessage) receiver.receiveNoWait();
+      assertNotNull(message);
+      assertEquals("QUEUE.expirytest", message
+            .getStringProperty("JBOSS_ORIG_DESTINATION"));
+      assertTrue(message.getLongProperty("JBOSS_ORIG_EXPIRATION") > now);
+      assertEquals(0L, message.getJMSExpiration());
+      assertEquals(text, message.getText());
+      assertEquals("bar", message.getStringProperty("foo"));
+      assertNull(message.getStringProperty("null"));
+      
+      receiver.close();
+       */
+      sender.close();
+      
+      session.close();
+      connection.close();
+      
+      // the second message should never have arrived, so the bean ran once
+      assertEquals(1, status.expirationQueueRan());
+   }
+
+   public void testCMTTxNotSupported() throws Exception
+   {
+      TestStatus status = (TestStatus) getInitialContext().lookup("TestStatusBean/remote");
+      clear(status);
+      QueueConnection cnn = null;
+      QueueSender sender = null;
+      QueueSession session = null;
+
+      Queue queue = (Queue) getInitialContext().lookup("queue/cmttxnotsupmdbtest");
+      QueueConnectionFactory factory = getQueueConnectionFactory();
+      cnn = factory.createQueueConnection();
+      session = cnn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+
+      TextMessage msg = session.createTextMessage("Hello World");
+      msg.setIntProperty("JMS_JBOSS_REDELIVERY_LIMIT", 1);
+
+      sender = session.createSender(queue);
+      sender.send(msg);
+      session.close();
+      cnn.close();
+
+      Thread.sleep(2000);
+      assertEquals(1, status.queueFired());
+   }
+
    private List list(QueueSession session, Queue queue) throws Exception
    {
       QueueBrowser browser = session.createBrowser(queue);




More information about the jboss-cvs-commits mailing list