[jboss-cvs] JBossAS SVN: r58407 - in trunk/testsuite/src: main/org/jboss/test/jbossmq/support main/org/jboss/test/jbossmq/test resources/org/jboss/test/jbossmq/test

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Nov 15 11:56:31 EST 2006


Author: adrian at jboss.org
Date: 2006-11-15 11:56:26 -0500 (Wed, 15 Nov 2006)
New Revision: 58407

Added:
   trunk/testsuite/src/main/org/jboss/test/jbossmq/support/MockServerFailureInterceptor.java
   trunk/testsuite/src/main/org/jboss/test/jbossmq/test/ReceiveAfterErrorUnitTestCase.java
   trunk/testsuite/src/resources/org/jboss/test/jbossmq/test/ReceiveAfterErrorUnitTestCase.xml
Log:
[JBAS-3821] - Error from server during receive corrupts internal receiving state.

Added: trunk/testsuite/src/main/org/jboss/test/jbossmq/support/MockServerFailureInterceptor.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/jbossmq/support/MockServerFailureInterceptor.java	2006-11-15 16:53:02 UTC (rev 58406)
+++ trunk/testsuite/src/main/org/jboss/test/jbossmq/support/MockServerFailureInterceptor.java	2006-11-15 16:56:26 UTC (rev 58407)
@@ -0,0 +1,46 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.test.jbossmq.support;
+
+import javax.jms.JMSException;
+
+import org.jboss.mq.ConnectionToken;
+import org.jboss.mq.SpyMessage;
+import org.jboss.mq.server.JMSServerInterceptorSupport;
+
+/**
+ * MockServerFailureInterceptor.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MockServerFailureInterceptor extends JMSServerInterceptorSupport
+{
+   public boolean raiseReceiveError = false;
+
+   public SpyMessage receive(ConnectionToken dc, int subscriberId, long wait) throws JMSException
+   {
+      if (raiseReceiveError)
+         throw new JMSException("Error in receive as required.");
+      return super.receive(dc, subscriberId, wait);
+   }
+}

Added: trunk/testsuite/src/main/org/jboss/test/jbossmq/test/ReceiveAfterErrorUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/jbossmq/test/ReceiveAfterErrorUnitTestCase.java	2006-11-15 16:53:02 UTC (rev 58406)
+++ trunk/testsuite/src/main/org/jboss/test/jbossmq/test/ReceiveAfterErrorUnitTestCase.java	2006-11-15 16:56:26 UTC (rev 58407)
@@ -0,0 +1,136 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.test.jbossmq.test;
+
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+
+import junit.framework.Test;
+
+import org.jboss.mq.SpyDestination;
+import org.jboss.test.jbossmq.JBossMQMicrocontainerTest;
+
+/**
+ * A test to make sure an error during receive doesn't lead to corrupt "receiving" state
+ *
+ * @author <a href="mailto:adrian at jboss.org>Adrian Brock</a>
+ * @version <tt>$Revision: 57211 $</tt>
+ */
+public class ReceiveAfterErrorUnitTestCase extends JBossMQMicrocontainerTest
+{
+   public ReceiveAfterErrorUnitTestCase(String name) throws Exception
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(ReceiveAfterErrorUnitTestCase.class);
+   }
+   
+   public interface ReceiveOperation
+   {
+      Message receive(MessageConsumer consumer) throws JMSException;
+   }
+   
+   public void testReceiveAfterError() throws Exception
+   {
+      receiveAfterError(new ReceiveOperation()
+      {
+         public Message receive(MessageConsumer consumer) throws JMSException
+         {
+            return consumer.receive();
+         }
+      });
+   }
+   
+   public void testReceiveWithWaitAfterError() throws Exception
+   {
+      receiveAfterError(new ReceiveOperation()
+      {
+         public Message receive(MessageConsumer consumer) throws JMSException
+         {
+            return consumer.receive(1000);
+         }
+      });
+   }
+   
+   public void testReceiveNoWaitAfterError() throws Exception
+   {
+      receiveAfterError(new ReceiveOperation()
+      {
+         public Message receive(MessageConsumer consumer) throws JMSException
+         {
+            return consumer.receiveNoWait();
+         }
+      });
+   }
+   
+   protected void receiveAfterError(ReceiveOperation operation) throws Exception
+   {
+      SpyDestination destination = createQueue("testQueue");
+      try
+      {
+         Connection connection = createConnection();
+         try
+         {
+            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            connection.start();
+
+            MessageProducer producer = session.createProducer(destination);
+            Message message = session.createMessage();
+            producer.send(message);
+            
+            MessageConsumer consumer = session.createConsumer(destination);
+            
+            // Receive should now throw an error
+            raiseReceiveError(true);
+            try
+            {
+               operation.receive(consumer);
+               fail("Should not be here!");
+            }
+            catch (Throwable t)
+            {
+               checkThrowable(JMSException.class, t);
+            }
+            raiseReceiveError(false);
+            
+            message = operation.receive(consumer);
+            assertNotNull(message);
+         }
+         finally
+         {
+            connection.close();
+         }
+      }
+      finally
+      {
+         removeDestination(destination);
+      }
+   }
+}
+

Added: trunk/testsuite/src/resources/org/jboss/test/jbossmq/test/ReceiveAfterErrorUnitTestCase.xml
===================================================================
--- trunk/testsuite/src/resources/org/jboss/test/jbossmq/test/ReceiveAfterErrorUnitTestCase.xml	2006-11-15 16:53:02 UTC (rev 58406)
+++ trunk/testsuite/src/resources/org/jboss/test/jbossmq/test/ReceiveAfterErrorUnitTestCase.xml	2006-11-15 16:56:26 UTC (rev 58407)
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd"
+            xmlns="urn:jboss:bean-deployer">
+   
+   <bean name="PersistenceManager" class="org.jboss.mq.pm.none.PersistenceManager"/>
+   
+   <bean name="StateManager" class="org.jboss.mq.sm.none.NullStateManager"/>
+   
+   <bean name="MessageCache" class="org.jboss.mq.kernel.MessageCache">
+      <property name="persistenceManager"><inject bean="PersistenceManager"/></property>
+   </bean>
+   
+   <bean name="DestinationManager" class="org.jboss.mq.kernel.DestinationManager">
+      <property name="persistenceManagerInstance"><inject bean="PersistenceManager"/></property>
+      <property name="stateManagerInstance"><inject bean="StateManager"/></property>
+      <property name="messageCacheInstance"><inject bean="MessageCache"/></property>
+   </bean>
+
+   <bean name="JMSServer" class="org.jboss.mq.server.JMSDestinationManager">
+      <constructor factoryMethod="getInterceptor">
+         <factory bean="DestinationManager"/>
+      </constructor>
+   </bean>
+
+   <bean name="MockServerFailure" class="org.jboss.test.jbossmq.support.MockServerFailureInterceptor">
+      <property name="next"><inject bean="JMSServer"/></property>
+   </bean>
+   
+   <bean name="Invoker" class="org.jboss.mq.server.JMSServerInvoker">
+      <property name="next"><inject bean="MockServerFailure"/></property>
+   </bean>
+
+   <bean name="ServerIL" class="org.jboss.mq.il.jvm.JVMServerIL">
+      <constructor>
+         <parameter><inject bean="Invoker"/></parameter>
+      </constructor>
+   </bean>
+   
+   <bean name="GCF" class="org.jboss.mq.GenericConnectionFactory">
+      <constructor>
+         <parameter><inject bean="ServerIL"/></parameter>
+         <parameter>
+            <map class="java.util.Properties" keyClass="java.lang.String" valueClass="java.lang.String">
+               <entry>
+                  <key>ClientILService</key><value>org.jboss.mq.il.jvm.JVMClientILService</value>
+               </entry>
+            </map>
+         </parameter>
+      </constructor>
+   </bean>
+   
+   <bean name="ConnectionFactory" class="org.jboss.mq.SpyConnectionFactory">
+      <constructor>
+         <parameter class="org.jboss.mq.GenericConnectionFactory"><inject bean="GCF"/></parameter>
+      </constructor>
+   </bean>
+      
+</deployment>




More information about the jboss-cvs-commits mailing list