[jboss-cvs] JBossAS SVN: r64641 - in branches/JBPAPP_4_2: messaging/src/etc/server-jbm and 13 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Aug 16 17:42:11 EDT 2007
Author: fnasser at redhat.com
Date: 2007-08-16 17:42:11 -0400 (Thu, 16 Aug 2007)
New Revision: 64641
Added:
branches/JBPAPP_4_2/messaging/src/etc/server-jbm/
branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/
branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/
branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/
branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/META-INF/
branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/META-INF/MANIFEST.MF
branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/META-INF/jboss-service.xml
branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/connection-factories-service.xml
branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/destinations-service.xml
branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/hsqldb-persistence-service.xml
branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/messaging-service.xml
branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/remoting-bisocket-service.xml
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/JBossMessagingAdmin.java
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/JMSBase.java
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/JMSTestCase.java
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/MockServerSessionPool.java
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/perf/
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/perf/JMSPerfStressTestCase.java
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/perf/JMSReconnectStressTestCase.java
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/perf/ReceiveNackClientStressTestCase.java
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/perf/SendReplyPerfStressTestCase.java
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/ra/
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/ra/RaJMSSessionUnitTestCase.java
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/ra/RaQueueUnitTestCase.java
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/ra/RaSyncRecUnitTestCase.java
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/ra/RaTest.java
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/ra/RaTopicUnitTestCase.java
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/ConcurrentDeliveryUnitTestCase.java
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/ConnectionConsumerUnitTestCase.java
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/JBossJMSUnitTest.java
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/JBossMessagingJoramUnitTestCase.java
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/JBossSessionRecoverUnitTestCase.java
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/Jms11UnitTest.java
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/MessageBodyUnitTestCase.java
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/MessageTypesUnitTestCase.java
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/RollBackUnitTestCase.java
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/SecurityUnitTestCase.java
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/SessionCloseStressTestCase.java
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/TemporarySessionConnectionUnitTestCase.java
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/UnackedUnitTestCase.java
branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/XAResourceUnitTestCase.java
branches/JBPAPP_4_2/testsuite/src/resources/jbossmessaging/
branches/JBPAPP_4_2/testsuite/src/resources/jbossmessaging/provider.properties
branches/JBPAPP_4_2/testsuite/src/resources/jbossmessaging/test-destinations-full-service.xml
branches/JBPAPP_4_2/testsuite/src/resources/mdb4jbm/
branches/JBPAPP_4_2/testsuite/src/resources/mdb4jbm/META-INF/
branches/JBPAPP_4_2/testsuite/src/resources/mdb4jbm/META-INF/ejb-jar.xml
branches/JBPAPP_4_2/testsuite/src/resources/mdb4jbm/META-INF/jboss.xml
branches/JBPAPP_4_2/testsuite/src/resources/mdb4jbm/client.policy
branches/JBPAPP_4_2/testsuite/src/resources/mdb4jbm/jboss-service.xml
Log:
>From clebert.suconic at jboss.com : JBAS-4600 - Renaming mq variables on build and adding jboss-messaging into build-thirdparty (Part2: new files)
Added: branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/META-INF/MANIFEST.MF
===================================================================
--- branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/META-INF/MANIFEST.MF (rev 0)
+++ branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/META-INF/MANIFEST.MF 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,13 @@
+Manifest-Version: 1.0
+Ant-Version: Apache Ant 1.6.2
+Created-By: 1.5.0_07-b03 (Sun Microsystems Inc.)
+Specification-Title: JBoss Messaging
+Specification-Version: 1.3.0.GA
+Specification-Vendor: JBoss Inc. (http://www.jboss.org/)
+Implementation-Title: JBoss Messaging
+Implementation-URL: http://www.jboss.org/
+Implementation-Version: 1.3.0.GA (build: CVSTag=JBossMessaging_1_3_0_G
+ A date=200706111737)
+Implementation-Vendor: JBoss Inc. (http://www.jboss.org/)
+Implementation-Vendor-Id: http://www.jboss.org/
+
Added: branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/META-INF/jboss-service.xml
===================================================================
--- branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/META-INF/jboss-service.xml (rev 0)
+++ branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/META-INF/jboss-service.xml 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Bootstrap - starts the messaging server peer
+
+ $Id$
+ -->
+
+<server>
+
+ <mbean code="org.jboss.jms.server.Bootstrap"
+ name="jboss.messaging:service=Bootstrap"
+ xmbean-dd="xmdesc/Bootstrap-xmbean.xml">
+ <depends>jboss.messaging:service=ServerPeer</depends>
+ </mbean>
+
+</server>
\ No newline at end of file
Added: branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/connection-factories-service.xml
===================================================================
--- branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/connection-factories-service.xml (rev 0)
+++ branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/connection-factories-service.xml 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,141 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Messaging Connection Factories deployment descriptor.
+
+ $Id$
+ -->
+
+<server>
+
+ <!-- The default connection factory does not support automatic failover or load balancing-
+ this is so we can maintain compatiblity with applications written for JBoss MQ which use this
+ connection factory.
+ -->
+ <mbean code="org.jboss.jms.server.connectionfactory.ConnectionFactory"
+ name="jboss.messaging.connectionfactory:service=ConnectionFactory"
+ xmbean-dd="xmdesc/ConnectionFactory-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends optional-attribute-name="Connector">jboss.messaging:service=Connector,transport=bisocket</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+
+ <attribute name="JNDIBindings">
+ <bindings>
+ <binding>/ConnectionFactory</binding>
+ <binding>/XAConnectionFactory</binding>
+ <binding>java:/ConnectionFactory</binding>
+ <binding>java:/XAConnectionFactory</binding>
+ </bindings>
+ </attribute>
+ </mbean>
+
+ <!-- A clustered connection factory that supports automatic failover and load balancing of created
+ connections.
+ This factory is not suitable to be used by MDBs.
+ -->
+ <mbean code="org.jboss.jms.server.connectionfactory.ConnectionFactory"
+ name="jboss.messaging.connectionfactory:service=ClusteredConnectionFactory"
+ xmbean-dd="xmdesc/ConnectionFactory-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends optional-attribute-name="Connector">jboss.messaging:service=Connector,transport=bisocket</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+
+ <attribute name="JNDIBindings">
+ <bindings>
+ <binding>/ClusteredConnectionFactory</binding>
+ <binding>/ClusteredXAConnectionFactory</binding>
+ <binding>java:/ClusteredConnectionFactory</binding>
+ <binding>java:/ClusteredXAConnectionFactory</binding>
+ </bindings>
+ </attribute>
+
+ <attribute name="SupportsFailover">true</attribute>
+ <attribute name="SupportsLoadBalancing">true</attribute>
+ </mbean>
+
+ <!-- A connection factory with no JNDI bindings that is used in clustering to create the connections that
+ pull messages from one node to another
+ -->
+ <mbean code="org.jboss.jms.server.connectionfactory.ConnectionFactory"
+ name="jboss.messaging.connectionfactory:service=ClusterPullConnectionFactory"
+ xmbean-dd="xmdesc/ConnectionFactory-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends optional-attribute-name="Connector">jboss.messaging:service=Connector,transport=bisocket</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ <attribute name="SupportsFailover">false</attribute>
+ <attribute name="SupportsLoadBalancing">false</attribute>
+ </mbean>
+
+ <!-- An example connection factory with all attributes shown
+
+ <mbean code="org.jboss.jms.server.connectionfactory.ConnectionFactory"
+ name="jboss.messaging.connectionfactory:service=MyExampleConnectionFactory"
+ xmbean-dd="xmdesc/ConnectionFactory-xmbean.xml">
+
+ <constructor>
+
+ <!- - You can specify the default Client ID to use for connections created using this factory - ->
+
+ <arg type="java.lang.String" value="MyClientID"/>
+
+ </constructor>
+
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+
+ <!- - The transport to use - can be bisocket, sslbisocket or http - ->
+
+ <depends optional-attribute-name="Connector">jboss.messaging:service=Connector,transport=http</depends>
+
+ <depends>jboss.messaging:service=PostOffice</depends>
+
+ <!- - PrefetchSize determines the approximate maximum number of messages the client consumer will buffer locally - ->
+
+ <attribute name="PrefetchSize">150</attribute>
+
+ <!- - Paging params to be used for temporary queues - ->
+
+ <attribute name="DefaultTempQueueFullSize">200000</attribute>
+
+ <attribute name="DefaultTempQueuePageSizeSize">2000</attribute>
+
+ <attribute name="DefaultTempQueueDownCacheSize">2000</attribute>
+
+ <!- - The batch size to use when using the DUPS_OK_ACKNOWLEDGE acknowledgement mode - ->
+
+ <attribute name="DupsOKBatchSize">5000</attribute>
+
+ <!- - Does this connection factory support automatic failover? - ->
+
+ <attribute name="SupportsFailover">false</attribute>
+
+ <!- - Does this connection factory support automatic client side load balancing? - ->
+
+ <attribute name="SupportsLoadBalancing">false</attribute>
+
+ <!- - The class name of the factory used to create the load balancing policy to use on the client side - ->
+
+ <attribute name="LoadBalancingFactory">org.jboss.jms.client.plugin.RoundRobinLoadBalancingFactory</attribute>
+
+ <!- - The connection factory will be bound in the following places in JNDI - ->
+
+ <attribute name="JNDIBindings">
+
+ <bindings>
+
+ <binding>/acme/MyExampleConnectionFactory</binding>
+
+ <binding>/acme/MyExampleConnectionFactoryDupe</binding>
+
+ <binding>java:/xyz/CF1</binding>
+
+ <binding>java:/connectionfactories/acme/connection_factory</binding>
+
+ </bindings>
+
+ </attribute>
+
+ </mbean>
+
+ -->
+
+</server>
\ No newline at end of file
Added: branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/destinations-service.xml
===================================================================
--- branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/destinations-service.xml (rev 0)
+++ branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/destinations-service.xml 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,199 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Messaging Destinations deployment descriptor.
+
+ $Id$
+ -->
+
+<server>
+
+ <!--
+ The Default Dead Letter Queue. This destination is a dependency of an EJB MDB container.
+ -->
+
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.messaging.destination:service=Queue,name=DLQ"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+
+ <!--
+ The Default Expiry Queue.
+ -->
+
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.messaging.destination:service=Queue,name=ExpiryQueue"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+
+ <!--
+ Example destinations.
+ -->
+
+ <mbean code="org.jboss.jms.server.destination.TopicService"
+ name="jboss.messaging.destination:service=Topic,name=testTopic"
+ xmbean-dd="xmdesc/Topic-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ <attribute name="SecurityConfig">
+ <security>
+ <role name="guest" read="true" write="true"/>
+ <role name="publisher" read="true" write="true" create="false"/>
+ <role name="durpublisher" read="true" write="true" create="true"/>
+ </security>
+ </attribute>
+ </mbean>
+
+ <mbean code="org.jboss.jms.server.destination.TopicService"
+ name="jboss.messaging.destination:service=Topic,name=securedTopic"
+ xmbean-dd="xmdesc/Topic-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ <attribute name="SecurityConfig">
+ <security>
+ <role name="publisher" read="true" write="true" create="false"/>
+ </security>
+ </attribute>
+ </mbean>
+
+ <mbean code="org.jboss.jms.server.destination.TopicService"
+ name="jboss.messaging.destination:service=Topic,name=testDurableTopic"
+ xmbean-dd="xmdesc/Topic-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ <attribute name="SecurityConfig">
+ <security>
+ <role name="guest" read="true" write="true"/>
+ <role name="publisher" read="true" write="true" create="false"/>
+ <role name="durpublisher" read="true" write="true" create="true"/>
+ </security>
+ </attribute>
+ </mbean>
+
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.messaging.destination:service=Queue,name=testQueue"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ <attribute name="SecurityConfig">
+ <security>
+ <role name="guest" read="true" write="true"/>
+ <role name="publisher" read="true" write="true" create="false"/>
+ <role name="noacc" read="false" write="false" create="false"/>
+ </security>
+ </attribute>
+ </mbean>
+
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.messaging.destination:service=Queue,name=A"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.messaging.destination:service=Queue,name=B"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.messaging.destination:service=Queue,name=C"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.messaging.destination:service=Queue,name=D"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.messaging.destination:service=Queue,name=ex"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+
+ <!-- It's possible for indiviual queues and topics to use a specific queue for
+ an expiry or DLQ -->
+
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.messaging.destination:service=Queue,name=PrivateDLQ"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.messaging.destination:service=Queue,name=PrivateExpiryQueue"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.messaging.destination:service=Queue,name=QueueWithOwnDLQAndExpiryQueue"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ <attribute name="DLQ">jboss.messaging.destination:service=Queue,name=PrivateDLQ</attribute>
+ <attribute name="ExpiryQueue">jboss.messaging.destination:service=Queue,name=PrivateExpiryQueue</attribute>
+ </mbean>
+
+ <mbean code="org.jboss.jms.server.destination.TopicService"
+ name="jboss.messaging.destination:service=Topic,name=TopicWithOwnDLQAndExpiryQueue"
+ xmbean-dd="xmdesc/Topic-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ <attribute name="DLQ">jboss.messaging.destination:service=Queue,name=PrivateDLQ</attribute>
+ <attribute name="ExpiryQueue">jboss.messaging.destination:service=Queue,name=PrivateExpiryQueue</attribute>
+ </mbean>
+
+ <!-- Queues and Topics can also specify their own redelivery delay -->
+
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.messaging.destination:service=Queue,name=QueueWithOwnRedeliveryDelay"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ <attribute name="RedeliveryDelay">5000</attribute>
+ </mbean>
+
+ <mbean code="org.jboss.jms.server.destination.TopicService"
+ name="jboss.messaging.destination:service=Topic,name=TopicWithOwnRedeliveryDelay"
+ xmbean-dd="xmdesc/Topic-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ <attribute name="RedeliveryDelay">5000</attribute>
+ </mbean>
+
+ <!--
+ Example clustered destinations.
+ -->
+
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.messaging.destination:service=Queue,name=testDistributedQueue"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ <attribute name="Clustered">true</attribute>
+ </mbean>
+
+ <mbean code="org.jboss.jms.server.destination.TopicService"
+ name="jboss.messaging.destination:service=Topic,name=testDistributedTopic"
+ xmbean-dd="xmdesc/Topic-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ <attribute name="Clustered">true</attribute>
+ </mbean>
+
+</server>
\ No newline at end of file
Added: branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/hsqldb-persistence-service.xml
===================================================================
--- branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/hsqldb-persistence-service.xml (rev 0)
+++ branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/hsqldb-persistence-service.xml 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Hypersonic persistence deployment descriptor.
+
+ DO NOT USE HYPERSONIC IN PRODUCTION or in a clustered environment- Hypersonic does not have transaction isolation
+
+ $Id$
+ -->
+
+<server>
+
+ <!-- Persistence Manager MBean configuration
+ ======================================= -->
+
+ <mbean code="org.jboss.messaging.core.jmx.JDBCPersistenceManagerService"
+ name="jboss.messaging:service=PersistenceManager"
+ xmbean-dd="xmdesc/JDBCPersistenceManager-xmbean.xml">
+
+ <depends>jboss.jca:service=DataSourceBinding,name=DefaultDS</depends>
+
+ <depends optional-attribute-name="TransactionManager">jboss:service=TransactionManager</depends>
+
+ <!-- The datasource to use for the persistence manager -->
+
+ <attribute name="DataSource">java:/DefaultDS</attribute>
+
+ <!-- If true will attempt to create tables and indexes on every start-up -->
+
+ <attribute name="CreateTablesOnStartup">true</attribute>
+
+ <!-- If true then will use JDBC batch updates -->
+
+ <attribute name="UsingBatchUpdates">false</attribute>
+
+ <!-- The maximum number of parameters to include in a prepared statement -->
+
+ <attribute name="MaxParams">500</attribute>
+ </mbean>
+
+ <!-- Messaging Post Office MBean configuration
+ ========================================= -->
+
+ <mbean code="org.jboss.messaging.core.jmx.MessagingPostOfficeService"
+ name="jboss.messaging:service=PostOffice"
+ xmbean-dd="xmdesc/MessagingPostOffice-xmbean.xml">
+
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+
+ <depends>jboss.jca:service=DataSourceBinding,name=DefaultDS</depends>
+
+ <depends optional-attribute-name="TransactionManager">jboss:service=TransactionManager</depends>
+
+ <!-- The name of the post office -->
+
+ <attribute name="PostOfficeName">JMS post office</attribute>
+
+ <!-- The datasource used by the post office to access it's binding information -->
+
+ <attribute name="DataSource">java:/DefaultDS</attribute>
+
+ <!-- If true will attempt to create tables and indexes on every start-up -->
+
+ <attribute name="CreateTablesOnStartup">true</attribute>
+
+ <!-- This post office is NON CLUSTERED - do not use clustering with Hypersonic!! -->
+
+ <attribute name="Clustered">false</attribute>
+ </mbean>
+
+ <!-- Messaging JMS User Manager MBean config
+ ======================================= -->
+
+ <mbean code="org.jboss.jms.server.plugin.JDBCJMSUserManagerService"
+ name="jboss.messaging:service=JMSUserManager"
+ xmbean-dd="xmdesc/JMSUserManager-xmbean.xml">
+
+ <depends>jboss.jca:service=DataSourceBinding,name=DefaultDS</depends>
+
+ <depends optional-attribute-name="TransactionManager">jboss:service=TransactionManager</depends>
+
+ <attribute name="DataSource">java:/DefaultDS</attribute>
+
+ <attribute name="CreateTablesOnStartup">true</attribute>
+
+ <attribute name="SqlProperties"><![CDATA[
+POPULATE.TABLES.1 = INSERT INTO JBM_USER (USER_ID, PASSWD) VALUES ('guest', 'guest')
+POPULATE.TABLES.2 = INSERT INTO JBM_USER (USER_ID, PASSWD) VALUES ('j2ee', 'j2ee')
+POPULATE.TABLES.3 = INSERT INTO JBM_USER (USER_ID, PASSWD, CLIENTID) VALUES ('john', 'needle', 'DurableSubscriberExample')
+POPULATE.TABLES.4 = INSERT INTO JBM_USER (USER_ID, PASSWD) VALUES ('nobody', 'nobody')
+POPULATE.TABLES.5 = INSERT INTO JBM_USER (USER_ID, PASSWD) VALUES ('dynsub', 'dynsub')
+POPULATE.TABLES.6 = INSERT INTO JBM_ROLE (ROLE_ID, USER_ID) VALUES ('guest','guest')
+POPULATE.TABLES.7 = INSERT INTO JBM_ROLE (ROLE_ID, USER_ID) VALUES ('j2ee','guest')
+POPULATE.TABLES.8 = INSERT INTO JBM_ROLE (ROLE_ID, USER_ID) VALUES ('john','guest')
+POPULATE.TABLES.9 = INSERT INTO JBM_ROLE (ROLE_ID, USER_ID) VALUES ('subscriber','john')
+POPULATE.TABLES.10 = INSERT INTO JBM_ROLE (ROLE_ID, USER_ID) VALUES ('publisher','john')
+POPULATE.TABLES.11 = INSERT INTO JBM_ROLE (ROLE_ID, USER_ID) VALUES ('publisher','dynsub')
+POPULATE.TABLES.12 = INSERT INTO JBM_ROLE (ROLE_ID, USER_ID) VALUES ('durpublisher','john')
+POPULATE.TABLES.13 = INSERT INTO JBM_ROLE (ROLE_ID, USER_ID) VALUES ('durpublisher','dynsub')
+POPULATE.TABLES.14 = INSERT INTO JBM_ROLE (ROLE_ID, USER_ID) VALUES ('noacc','nobody')
+ ]]></attribute>
+ </mbean>
+
+</server>
\ No newline at end of file
Added: branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/messaging-service.xml
===================================================================
--- branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/messaging-service.xml (rev 0)
+++ branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/messaging-service.xml 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ The JBoss Messaging service deployment descriptor.
+
+ $Id$
+ -->
+
+<server>
+
+ <!-- ServerPeer MBean configuration
+ ============================== -->
+
+ <mbean code="org.jboss.jms.server.ServerPeer"
+ name="jboss.messaging:service=ServerPeer"
+ xmbean-dd="xmdesc/ServerPeer-xmbean.xml">
+
+ <!-- The unique id of the server peer - in a cluster each node MUST have a unique value - must be an integer -->
+
+ <attribute name="ServerPeerID">0</attribute>
+
+ <!-- The default JNDI context to use for queues when they are deployed without specifying one -->
+
+ <attribute name="DefaultQueueJNDIContext">/queue</attribute>
+
+ <!-- The default JNDI context to use for topics when they are deployed without specifying one -->
+
+ <attribute name="DefaultTopicJNDIContext">/topic</attribute>
+
+ <attribute name="PostOffice">jboss.messaging:service=PostOffice</attribute>
+
+ <!-- The JAAS security domain to use for JBoss Messaging -->
+
+ <attribute name="SecurityDomain">java:/jaas/messaging</attribute>
+
+ <!-- The default security configuration to apply to destinations - this can be overridden on a per destination basis -->
+
+ <attribute name="DefaultSecurityConfig">
+ <security>
+ <role name="guest" read="true" write="true" create="true"/>
+ </security>
+ </attribute>
+
+ <!-- The default Dead Letter Queue (DLQ) to use for destinations.
+ This can be overridden on a per destinatin basis -->
+
+ <attribute name="DefaultDLQ">jboss.messaging.destination:service=Queue,name=DLQ</attribute>
+
+ <!-- The default maximum number of times to attempt delivery of a message before sending to the DLQ (if configured).
+ This can be overridden on a per destinatin basis -->
+
+ <attribute name="DefaultMaxDeliveryAttempts">10</attribute>
+
+ <!-- The default Expiry Queue to use for destinations. This can be overridden on a per destinatin basis -->
+
+ <attribute name="DefaultExpiryQueue">jboss.messaging.destination:service=Queue,name=ExpiryQueue</attribute>
+
+ <!-- The default redelivery delay to impose. This can be overridden on a per destination basis -->
+
+ <attribute name="DefaultRedeliveryDelay">0</attribute>
+
+ <!-- The periodicity of the message counter manager enquiring on queues for statistics -->
+
+ <attribute name="MessageCounterSamplePeriod">5000</attribute>
+
+ <!-- The maximum amount of time for a client to wait for failover to start on the server side after
+ it has detected failure -->
+
+ <attribute name="FailoverStartTimeout">60000</attribute>
+
+ <!-- The maximum amount of time for a client to wait for failover to complete on the server side after
+ it has detected failure -->
+
+ <attribute name="FailoverCompleteTimeout">300000</attribute>
+
+ <!-- The maximum number of days results to maintain in the message counter history -->
+
+ <attribute name="DefaultMessageCounterHistoryDayLimit">-1</attribute>
+
+ <!-- The name of the connection factory to use for creating connections between nodes to pull messages -->
+
+ <attribute name="ClusterPullConnectionFactoryName">jboss.messaging.connectionfactory:service=ClusterPullConnectionFactory</attribute>
+
+ <!-- Use XA when pulling persistent messages from a remote node to this one. -->
+
+ <attribute name="UseXAForMessagePull">true</attribute>
+
+ <!-- When redistributing messages in the cluster. Do we need to preserve the order of messages received
+ by a particular consumer from a particular producer? -->
+
+ <attribute name="DefaultPreserveOrdering">false</attribute>
+
+ <!-- Max. time to hold previously delivered messages back waiting for clients to reconnect after failover -->
+
+ <attribute name="RecoverDeliveriesTimeout">300000</attribute>
+
+ <depends optional-attribute-name="PersistenceManager">jboss.messaging:service=PersistenceManager</depends>
+
+ <depends optional-attribute-name="JMSUserManager">jboss.messaging:service=JMSUserManager</depends>
+
+ <depends>jboss.messaging:service=Connector,transport=bisocket</depends>
+
+ </mbean>
+
+</server>
Added: branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/remoting-bisocket-service.xml
===================================================================
--- branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/remoting-bisocket-service.xml (rev 0)
+++ branches/JBPAPP_4_2/messaging/src/etc/server-jbm/default/deploy/jboss-messaging.sar/remoting-bisocket-service.xml 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Standard bisocket-based Remoting service deployment descriptor.
+
+ $Id$
+ -->
+
+<server>
+
+ <!-- Standard bisocket connector - the bisocket transport only opens connection from client->server
+ so can be used with firewalls where only outgoing connections are allowed.
+ For examples of HTTP and SSL transports see docs/examples -->
+ <mbean code="org.jboss.remoting.transport.Connector"
+ name="jboss.messaging:service=Connector,transport=bisocket"
+ display-name="Bisocket Transport Connector">
+ <attribute name="Configuration">
+ <config>
+ <invoker transport="bisocket">
+ <attribute name="marshaller" isParam="true">org.jboss.jms.wireformat.JMSWireFormat</attribute>
+ <attribute name="unmarshaller" isParam="true">org.jboss.jms.wireformat.JMSWireFormat</attribute>
+ <attribute name="dataType" isParam="true">jms</attribute>
+ <attribute name="socket.check_connection" isParam="true">false</attribute>
+ <attribute name="timeout" isParam="true">0</attribute>
+ <attribute name="serverBindAddress">${jboss.bind.address}</attribute>
+ <attribute name="serverBindPort">4457</attribute>
+ <attribute name="leasePeriod">10000</attribute>
+ <attribute name="clientSocketClass" isParam="true">org.jboss.jms.client.remoting.ClientSocketWrapper</attribute>
+ <attribute name="serverSocketClass" isParam="true">org.jboss.jms.server.remoting.ServerSocketWrapper</attribute>
+ <attribute name="numberOfRetries" isParam="true">1</attribute>
+ <attribute name="numberOfCallRetries" isParam="true">1</attribute>
+ <attribute name="clientMaxPoolSize" isParam="true">50</attribute>
+ </invoker>
+ <handlers>
+ <handler subsystem="JMS">org.jboss.jms.server.remoting.JMSServerInvocationHandler</handler>
+ </handlers>
+ </config>
+ </attribute>
+ </mbean>
+
+</server>
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/JBossMessagingAdmin.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/JBossMessagingAdmin.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/JBossMessagingAdmin.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,220 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.jbossmessaging;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.jboss.logging.Logger;
+import org.jboss.util.NestedRuntimeException;
+
+import org.objectweb.jtests.jms.admin.Admin;
+
+/**
+ * JBossMessagingAdmin.
+ *
+ * @author <a href="richard.achmatowicz at jboss.com">Richard Achmatowicz</a>
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 64152 $
+ */
+public class JBossMessagingAdmin implements Admin
+{
+ private Logger log = Logger.getLogger(JBossMessagingAdmin.class);
+
+ private InitialContext initialContext ;
+ private MBeanServerConnection server ;
+
+ protected static final String name ;
+ protected static final ObjectName serverPeer;
+ protected static final ObjectName namingService;
+
+ static
+ {
+ try
+ {
+ name = JBossMessagingAdmin.class.getName() ;
+ serverPeer = new ObjectName("jboss.messaging:service=ServerPeer");
+ namingService = new ObjectName("jboss:service=Naming");
+ }
+ catch (Exception e)
+ {
+ throw new NestedRuntimeException(e);
+ }
+ }
+
+ public JBossMessagingAdmin(Class clazz) throws Exception
+ {
+ this();
+ }
+ public JBossMessagingAdmin() throws Exception
+ {
+ try {
+ log.info("Initializing...") ;
+
+ // set up the initial naming service context
+ initialContext = new InitialContext() ;
+
+ // set up the MBean server connection
+ String adaptorName = System.getProperty("jbosstest.server.name","jmx/invoker/RMIAdaptor") ;
+ server = (MBeanServerConnection) initialContext.lookup(adaptorName) ;
+
+ } catch (Exception e) {
+ throw new NestedRuntimeException(e);
+ }
+ }
+
+ public String getName() {
+ return name ;
+ }
+
+ private MBeanServerConnection getServer() {
+ return server ;
+ }
+
+ public InitialContext createInitialContext() throws NamingException {
+ return initialContext ;
+ }
+
+ public void createQueue(String name)
+ {
+ try
+ {
+ MBeanServerConnection server = getServer();
+ try
+ {
+ server.invoke(serverPeer, "deployQueue", new Object[] { name, name }, new String[] { String.class.getName(), String.class.getName() } );
+ }
+ catch (Exception ignored)
+ {
+ log.trace("Ignored", ignored);
+ }
+ ObjectName queueName = new ObjectName("jboss.messaging.destination:service=Queue,name=" + name);
+ server.invoke(queueName, "removeAllMessages", null, null);
+ }
+ catch (Exception e)
+ {
+ throw new NestedRuntimeException(e);
+ }
+ }
+
+ public void deleteQueue(String name)
+ {
+ try
+ {
+ MBeanServerConnection server = getServer();
+ ObjectName queueName = new ObjectName("jboss.messaging.destination:service=Queue,name=" + name);
+ server.invoke(queueName, "removeAllMessages", null, null);
+ server.invoke(serverPeer, "destroyQueue", new Object[] { name }, new String[] { String.class.getName() } );
+ }
+ catch (Exception e)
+ {
+ throw new NestedRuntimeException(e);
+ }
+ }
+
+ public void createTopic(String name)
+ {
+ try
+ {
+ MBeanServerConnection server = getServer();
+ try
+ {
+ server.invoke(serverPeer, "deployTopic", new Object[] { name, name }, new String[] { String.class.getName(), String.class.getName() } );
+ }
+ catch (Exception ignored)
+ {
+ ignored.printStackTrace();
+ }
+ ObjectName topicName = new ObjectName("jboss.messaging.destination:service=Topic,name=" + name);
+ server.invoke(topicName, "removeAllMessages", null, null);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw new NestedRuntimeException(e);
+ }
+ }
+
+ public void deleteTopic(String name)
+ {
+ try
+ {
+ MBeanServerConnection server = getServer();
+ ObjectName topicName = new ObjectName("jboss.messaging.destination:service=Topic,name=" + name);
+ server.invoke(topicName, "removeAllMessages", null, null);
+ server.invoke(serverPeer, "destroyTopic", new Object[] { name }, new String[] { String.class.getName() } );
+ }
+ catch (Exception e)
+ {
+ throw new NestedRuntimeException(e);
+ }
+ }
+
+ public void createConnectionFactory(String name)
+ {
+ try
+ {
+ MBeanServerConnection server = getServer();
+ server.invoke(namingService, "createAlias", new Object[] { name, "ConnectionFactory" }, new String[] { String.class.getName(), String.class.getName() } );
+ }
+ catch (Exception e)
+ {
+ throw new NestedRuntimeException(e);
+ }
+ }
+
+ public void deleteConnectionFactory(String name)
+ {
+ try
+ {
+ MBeanServerConnection server = getServer();
+ server.invoke(namingService, "removeAlias", new Object[] { name }, new String[] { String.class.getName() } );
+ }
+ catch (Exception e)
+ {
+ throw new NestedRuntimeException(e);
+ }
+ }
+
+ public void createQueueConnectionFactory(String name)
+ {
+ createConnectionFactory(name) ;
+ }
+
+ public void deleteQueueConnectionFactory(String name)
+ {
+ deleteConnectionFactory(name) ;
+ }
+
+ public void createTopicConnectionFactory(String name)
+ {
+ createConnectionFactory(name) ;
+ }
+
+ public void deleteTopicConnectionFactory(String name)
+ {
+ deleteConnectionFactory(name) ;
+ }
+
+}
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/JMSBase.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/JMSBase.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/JMSBase.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,894 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbossmessaging;
+
+import java.util.Enumeration;
+
+import javax.jms.Connection;
+import javax.jms.DeliveryMode;
+import javax.jms.Destination;
+import javax.jms.ExceptionListener;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.QueueBrowser;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicPublisher;
+import javax.jms.TopicSession;
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import org.jboss.test.jbossmessaging.JMSTestCase;
+import org.apache.log4j.Logger;
+
+/**
+ * JMS tests base class.
+ *
+ * Your test extends this class, and can then use common methods. To do
+ * the tests you use TopicWorker or QueueWorker and the MessageCreator,
+ * MessageFilter and perhaps MessageQos classes, directly or by extending
+ * them.
+ *
+ * You can change the connection factories and destinations used by the
+ * properties: jbosstest.queuefactory, jbosstest.topicfactory,
+ * jbosstest.queue or jbosstest.topic.
+ *
+ * @author <a href="mailto:richard.achmatowicz at jboss.com">Richard Achmatowicz</a>
+ * @author <a href="pra at tim.se">Peter Antman</a>
+ * @version $Revision: 64261 $
+ */
+public class JMSBase extends JMSTestCase
+{
+ public static final int PUBLISHER = 0;
+ public static final int SUBSCRIBER = 1;
+ public static final int GETTER = 2;
+ public static final int CONNECTOR = 3;
+ public static final int FAILSAFE_SUBSCRIBER = 4;
+ public static final int TRANS_NONE = 0;
+ public static final int TRANS_INDIVIDUAL = 1;
+ public static final int TRANS_TOTAL = 2;
+ public static final String[] TRANS_DESC = {"NOT", "individually", "totally"};
+ public static final int DEFAULT_RUNSLEEP = 50;
+ public final Logger log = getLog();
+
+ // Provider specific
+ public String TOPIC_FACTORY = "ConnectionFactory";
+ public String QUEUE_FACTORY = "ConnectionFactory";
+
+ public String TEST_QUEUE = "queue/testQueue";
+ public String TEST_TOPIC = "topic/testTopic";
+
+ public Context context;
+ public QueueConnectionFactory queueFactory;
+ public TopicConnectionFactory topicFactory;
+
+ public JMSBase(String name)
+ {
+ super(name);
+ }
+
+ public long getRunSleep()
+ {
+ log.info("run.sleep: " + System.getProperty("run.sleep"));
+ return 1000L * Integer.getInteger("run.sleep", DEFAULT_RUNSLEEP).intValue();
+ }
+
+ public void sleep(long sleep)
+ {
+ try
+ {
+ Thread.sleep(sleep);
+ }
+ catch (InterruptedException e)
+ {
+ }
+ }
+
+ public void drainTopic() throws JMSException
+ {
+ TopicWorker sub1 = new TopicWorker(GETTER,
+ TRANS_NONE,
+ null
+ );
+ sub1.connect();
+ sub1.get();
+ sub1.close();
+ }
+
+ public void drainQueue() throws JMSException
+ {
+ QueueWorker sub1 = new QueueWorker(GETTER,
+ TRANS_NONE,
+ null
+ );
+ sub1.connect();
+ sub1.get();
+ sub1.close();
+ }
+
+ /**
+ * The JUnit setup method
+ *
+ * @exception Exception Description of Exception
+ */
+ protected void setUp() throws Exception
+ {
+ // call setUp() method of the superclass
+ super.setUp() ;
+
+ // Reconfigure acording to props
+ QUEUE_FACTORY = System.getProperty("jbosstest.queuefactory", QUEUE_FACTORY);
+ TOPIC_FACTORY = System.getProperty("jbosstest.topicfactory", TOPIC_FACTORY);
+ TEST_QUEUE = System.getProperty("jbosstest.queue", TEST_QUEUE);
+ TEST_TOPIC = System.getProperty("jbosstest.topic", TEST_TOPIC);
+
+ if (context == null)
+ {
+
+ context = getInitialContext();
+
+ queueFactory = (QueueConnectionFactory) context.lookup(QUEUE_FACTORY);
+ topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+
+ getLog().debug("Connection to JMS provider established.");
+ }
+
+ }
+
+
+ public static void main(String[] args)
+ {
+
+ }
+
+ public abstract class JMSWorker implements Runnable, MessageListener, ExceptionListener
+ {
+
+ protected boolean stopRequested = false;
+ protected int messageHandled = 0;
+ protected Exception runEx = null;
+ protected MessageFilter filter;
+ protected MessageCreator creator;
+ protected int number = 1;
+ protected int type = -1;
+ protected int transacted;
+ protected QosConfig qosConfig = new QosConfig();
+ protected String userName;
+ protected String password;
+ protected String clientID;
+
+ // Generic ones, should be set by sublcasses
+ public Connection connection;
+ public Destination destination;
+ public Session session;
+ public MessageProducer producer;
+ public MessageConsumer consumer;
+
+ /**
+ * Create one without any settings, use mutators instead. Makes it easier to owerride.
+ */
+ public JMSWorker()
+ {
+ }
+
+ public JMSWorker(int type, int transacted, MessageFilter filter)
+ {
+ this.type = type;
+ this.transacted = transacted;
+ this.filter = filter;
+ }
+
+ public JMSWorker(int type,
+ int transacted,
+ MessageCreator creator,
+ int number
+ )
+ {
+ this.type = type;
+ this.transacted = transacted;
+ this.creator = creator;
+ this.number = number;
+ }
+
+ public void setSubscriberAttrs(int type, int transacted, MessageFilter filter)
+ {
+ this.type = type;
+ this.transacted = transacted;
+ this.filter = filter;
+ }
+
+ public void setPublisherAttrs(int type,
+ int transacted,
+ MessageCreator creator,
+ int number)
+ {
+ this.type = type;
+ this.transacted = transacted;
+ this.creator = creator;
+ this.number = number;
+ }
+
+ public void setUser(String userName, String password)
+ {
+ this.userName = userName;
+ this.password = password;
+ }
+
+ public void setClientID(String ID)
+ {
+ this.clientID = ID;
+ }
+
+ abstract public void publish() throws JMSException;
+
+ abstract public void publish(int nr) throws JMSException;
+
+ /**
+ * Subsribes, collects, checking any set filters. A messageComsumer must be created before calling this.
+ */
+ public void subscribe() throws JMSException
+ {
+ subscribe(false);
+ }
+
+ /**
+ * Subsribes, collects, checking any set filters. A messageComsumer must be created before calling this. If arg set to true, do a failsafe sub
+ */
+ public void subscribe(boolean failsafe) throws JMSException
+ {
+ if (consumer == null)
+ throw new JMSException("No messageConsumer created");
+
+ if (failsafe)
+ connection.setExceptionListener(this);
+
+ consumer.setMessageListener(this);
+
+ }
+
+ public void get() throws JMSException
+ {
+ Message msg = consumer.receive(2000);
+ while (msg != null)
+ {
+ if (filter != null)
+ {
+ if (filter.ok(msg))
+ messageHandled++;
+ }
+ else
+ {
+ messageHandled++;
+ }
+ msg = consumer.receive(2000);
+ }
+ }
+
+ abstract public void connect() throws JMSException;
+
+ public void setQosConfig(QosConfig qosConfig)
+ {
+ this.qosConfig = qosConfig;
+ }
+
+ public void setStoped() throws JMSException
+ {
+ stopRequested = true;
+ }
+
+ public int getMessageHandled()
+ {
+ return messageHandled;
+ }
+
+ public Exception getException()
+ {
+ return runEx;
+ }
+
+ public void reset()
+ {
+ messageHandled = 0;
+ stopRequested = false;
+ runEx = null;
+ }
+
+ public void close()
+ {
+ try
+ {
+ if (consumer != null)
+ consumer.close();
+ if (producer != null)
+ producer.close();
+ if (session != null)
+ session.close();
+ }
+ catch (JMSException ex)
+ {
+ }
+ finally
+ {
+ if (connection != null)
+ {
+ try
+ {
+ connection.close();
+ }
+ catch (JMSException ex)
+ {
+ }
+ }
+ }
+ }
+
+ public void onMessage(Message msg)
+ {
+ try
+ {
+ if (filter != null)
+ {
+ if (filter.ok(msg))
+ messageHandled++;
+ }
+ else
+ {
+ messageHandled++;
+ }
+ if (session.getTransacted())
+ session.commit();
+ }
+ catch (Exception ex)
+ {
+ log.warn("Exception in on message: " + ex, ex);
+ runEx = ex;
+ }
+ }
+
+ /**
+ * onException handling is only for subscriber. Will try to to
+ * a connect followed by a subscribe
+ */
+ public void onException(JMSException ex)
+ {
+ log.error("Ex in connection: " + ex);
+
+ try
+ {
+ connection.setExceptionListener(null);
+ close();
+ }
+ catch (JMSException c)
+ {
+ }
+
+ // Try reconnect, loops until success or shut down
+ try
+ {
+ boolean tryIt = true;
+ while (tryIt && !stopRequested)
+ {
+ log.info("Trying reconnect...");
+ try
+ {
+ Thread.sleep(10000);
+ }
+ catch (InterruptedException ie)
+ {
+ }
+ try
+ {
+ connect();
+ subscribe(true);
+ tryIt = false;
+ log.info("Reconnect OK");
+ //return;
+ }
+ catch (JMSException e)
+ {
+ log.error("Error in reconnect: " + e);
+ }
+ }
+
+ }
+ catch (Exception je)
+ {
+ log.error("Strange error in failsafe handling" + je, je);
+ }
+ }
+
+ public void run()
+ {
+ try
+ {
+ switch (type)
+ {
+ case -1:
+ log.info("Nothing to do for type " + type);
+ break;
+ case PUBLISHER:
+ connect();
+ publish();
+ break;
+ case SUBSCRIBER:
+ connect();
+ subscribe();
+ break;
+ case GETTER:
+ connect();
+ get();
+ break;
+ case CONNECTOR:
+ connect();
+ break;
+ case FAILSAFE_SUBSCRIBER:
+ connect();
+ subscribe(true);
+ break;
+ }
+
+ //if the method does not hold an own thread, we do it here
+ while (!stopRequested)
+ {
+ try
+ {
+ Thread.sleep(1000);
+ }
+ catch (InterruptedException ex)
+ {
+
+ }
+ }
+ }
+ catch (JMSException ex)
+ {
+ runEx = ex;
+ log.error("Could not run: " + ex, ex);
+ }
+ }
+ }
+
+ public interface MessageCreator
+ {
+ public void setSession(Session session);
+
+ public Message createMessage(int nr) throws JMSException;
+ }
+
+ public abstract class BaseMessageCreator implements MessageCreator
+ {
+ protected Session session;
+ protected String property;
+
+ public BaseMessageCreator(String property)
+ {
+ this.property = property;
+ }
+
+ public void setSession(Session session)
+ {
+ this.session = session;
+ }
+
+ abstract public Message createMessage(int nr) throws JMSException;
+ }
+
+
+ public class IntRangeMessageCreator extends BaseMessageCreator
+ {
+ int start = 0;
+
+ public IntRangeMessageCreator(String property)
+ {
+ super(property);
+ }
+
+ public IntRangeMessageCreator(String property, int start)
+ {
+ super(property);
+ this.start = start;
+ }
+
+ public Message createMessage(int nr) throws JMSException
+ {
+ if (session == null)
+ throw new JMSException("Session not allowed to be null");
+
+ Message msg = session.createMessage();
+ msg.setStringProperty(property, String.valueOf(start + nr));
+ return msg;
+ }
+ }
+
+ public interface MessageFilter
+ {
+ public boolean ok(Message msg) throws JMSException;
+ }
+
+ public class IntRangeMessageFilter implements MessageFilter
+ {
+ Class messageClass;
+ String className;
+ String property;
+ int low;
+ int max;
+ int counter = 0;
+ int report = 1000;
+
+ public IntRangeMessageFilter(Class messageClass, String property, int low, int max)
+ {
+ this.messageClass = messageClass;
+ this.property = property;
+ className = messageClass.getName();
+ this.low = low;
+ this.max = max;
+ }
+
+ private boolean validateClass(Message msg)
+ {
+ Class clazz = null;
+ if (msg instanceof javax.jms.TextMessage)
+ clazz = javax.jms.TextMessage.class;
+ else if (msg instanceof javax.jms.BytesMessage)
+ clazz = javax.jms.BytesMessage.class;
+ else if (msg instanceof javax.jms.MapMessage)
+ clazz = javax.jms.MapMessage.class;
+ else if (msg instanceof javax.jms.ObjectMessage)
+ clazz = javax.jms.ObjectMessage.class;
+ else if (msg instanceof javax.jms.StreamMessage)
+ clazz = javax.jms.StreamMessage.class;
+ else
+ clazz = javax.jms.Message.class;
+
+ return clazz.equals(messageClass);
+ }
+
+ public boolean ok(Message msg) throws JMSException
+ {
+ boolean res = false;
+ if (validateClass(msg))
+ {
+ if (msg.propertyExists(property))
+ {
+ String p = msg.getStringProperty(property);
+ try
+ {
+ int i = Integer.parseInt(p);
+ //log.debug("Received message " + property +"=" +i);
+ if (i >= low && i < max)
+ res = true;
+ }
+ catch (NumberFormatException ex)
+ {
+ throw new JMSException("Property " + property + " was not int: " + p);
+ }
+ }
+ }
+ counter++;
+ int mod = counter % report;
+ if (mod == 0)
+ log.debug("Have received " + counter + " messages");
+ return res;
+ }
+
+ }
+
+ /*
+ public class REMessageFilter implements MessageFilter {
+ Class messageClass;
+ String className;
+ String property;
+ RE re = null;
+ public REMessageFilter(Class messageClass, String property, String regexp) throws REException{
+ this.messageClass = messageClass;
+ this.property = property;
+ re = new RE(regexp);
+ className = messageClass.getName();
+ }
+
+ public boolean ok(Message msg) throws JMSException{
+ boolean res = false;
+ if (className.equals(msg.getClass().getName())) {
+ if (msg.propertyExists(property)) {
+ String p = msg.getStringProperty(property);
+ if (re.getMatch(p)!=null)
+ res = true;
+ }
+ }
+ return true;
+ }
+ }
+ */
+ /**
+ * Defines quality of service for message publishing. Defaults are the same
+ * ase defined in SpyMessage.
+ */
+ public class QosConfig
+ {
+ int deliveryMode = DeliveryMode.PERSISTENT;
+ int priority = 4;
+ long ttl = 0;
+ }
+
+ public class TopicWorker extends JMSWorker
+ {
+ String durableHandle;
+
+ /**
+ * If using this, use mutators to add attrs.
+ */
+ public TopicWorker()
+ {
+ super();
+ }
+
+ public TopicWorker(int type, int transacted, MessageFilter filter)
+ {
+ super(type, transacted, filter);
+ }
+
+ public TopicWorker(int type,
+ int transacted,
+ MessageCreator creator,
+ int number
+ )
+ {
+ super(type, transacted, creator, number);
+ }
+
+
+ public void publish() throws JMSException
+ {
+ publish(number);
+ }
+
+ public void publish(int nr) throws JMSException
+ {
+ if (producer == null)
+ producer = ((TopicSession) session).createPublisher((Topic) destination);
+ if (creator == null)
+ throw new JMSException("Publish must have a MessageCreator set");
+
+ creator.setSession(session);
+ System.out.println("Publishing " + nr + " messages");
+ for (int i = 0; i < nr; i++)
+ {
+ System.out.println("Sending Message");
+ if (qosConfig != null)
+ {
+ System.out.println("Sending Message(a)");
+ ((TopicPublisher) producer).publish(creator.createMessage(i),
+ qosConfig.deliveryMode,
+ qosConfig.priority,
+ qosConfig.ttl);
+ }
+ else
+ {
+ System.out.println("Sending Message(b)");
+ ((TopicPublisher) producer).publish(creator.createMessage(i));
+ }
+
+ messageHandled++;
+ }
+ if (session.getTransacted())
+ session.commit();
+ log.debug("Finished publishing");
+ }
+
+ public void subscribe() throws JMSException
+ {
+ subscribe(false);
+ }
+
+ public void subscribe(boolean failsafe) throws JMSException
+ {
+ if (durableHandle != null)
+ consumer = ((TopicSession) session).createDurableSubscriber((Topic) destination, durableHandle);
+ else
+ consumer = ((TopicSession) session).createSubscriber((Topic) destination);
+ super.subscribe(failsafe);
+ connection.start();
+ }
+
+ public void get() throws JMSException
+ {
+ consumer = ((TopicSession) session).createSubscriber((Topic) destination);
+ super.subscribe();
+ connection.start();
+ }
+
+ public void connect() throws JMSException
+ {
+ log.debug("Connecting: " + this.toString());
+ if (userName != null)
+ connection = topicFactory.createTopicConnection(userName, password);
+ else
+ connection = topicFactory.createTopicConnection();
+
+ if (clientID != null)
+ {
+ log.debug("Setting clientID" + clientID);
+ connection.setClientID(clientID);
+ }
+
+ session = ((TopicConnection) connection).createTopicSession(transacted != TRANS_NONE, Session.AUTO_ACKNOWLEDGE);
+ try
+ {
+ destination = (Destination) context.lookup(TEST_TOPIC);
+ }
+ catch (NamingException ex)
+ {
+ throw new JMSException("Could not lookup topic " + ex);
+ }
+ }
+
+ // Topic specific stuff
+ public void setDurable(String userId, String pwd, String handle)
+ {
+ this.userName = userId;
+ this.password = pwd;
+ this.durableHandle = handle;
+ }
+
+ public void setDurable(String handle)
+ {
+ this.durableHandle = handle;
+ }
+
+ public void unsubscribe() throws JMSException
+ {
+ if (durableHandle != null)
+ ((TopicSession) session).unsubscribe(durableHandle);
+ }
+
+ public String toString()
+ {
+ return "(userId=" + userName + " pwd=" + password + " handle=" + durableHandle + ")";
+ }
+
+ }
+
+ public class QueueWorker extends JMSWorker
+ {
+ String userId;
+ String pwd;
+ String handle;
+
+ /**
+ * If using this, use mutators to add attrs.
+ */
+ public QueueWorker()
+ {
+ super();
+ }
+
+ public QueueWorker(int type, int transacted, MessageFilter filter)
+ {
+ super(type, transacted, filter);
+ }
+
+ public QueueWorker(int type,
+ int transacted,
+ MessageCreator creator,
+ int number
+ )
+ {
+ super(type, transacted, creator, number);
+ }
+
+
+ public void publish() throws JMSException
+ {
+ publish(number);
+ }
+
+ public void publish(int nr) throws JMSException
+ {
+ if (producer == null)
+ producer = ((QueueSession) session).createSender((Queue) destination);
+ if (creator == null)
+ throw new JMSException("Publish must have a MessageCreator set");
+
+ creator.setSession(session);
+ log.debug("Publishing " + nr + " messages");
+ for (int i = 0; i < nr; i++)
+ {
+ if (qosConfig != null)
+ {
+ ((QueueSender) producer).send(creator.createMessage(i),
+ qosConfig.deliveryMode,
+ qosConfig.priority,
+ qosConfig.ttl);
+ }
+ else
+ {
+ ((QueueSender) producer).send(creator.createMessage(i));
+ }
+
+ messageHandled++;
+ }
+ if (session.getTransacted())
+ session.commit();
+ log.debug("Finished publishing");
+ }
+
+ public void subscribe() throws JMSException
+ {
+ subscribe(false);
+ }
+
+ public void subscribe(boolean failsafe) throws JMSException
+ {
+
+ consumer = ((QueueSession) session).createReceiver((Queue) destination);
+ super.subscribe(failsafe);
+ connection.start();
+ }
+
+ public void get() throws JMSException
+ {
+ consumer = ((QueueSession) session).createReceiver((Queue) destination);
+ super.subscribe();
+ connection.start();
+ }
+
+ public void connect() throws JMSException
+ {
+ log.debug("Connecting: " + this.toString());
+ if (userName != null)
+ connection = queueFactory.createQueueConnection(userName, password);
+ else
+ connection = queueFactory.createQueueConnection();
+
+ if (clientID != null)
+ connection.setClientID(clientID);
+
+ session = ((QueueConnection) connection).createQueueSession(transacted != TRANS_NONE, Session.AUTO_ACKNOWLEDGE);
+ try
+ {
+ destination = (Destination) context.lookup(TEST_QUEUE);
+ }
+ catch (NamingException ex)
+ {
+ throw new JMSException("Could not lookup topic " + ex);
+ }
+ }
+
+
+ // Queue specific
+ public Enumeration browse() throws JMSException
+ {
+ QueueBrowser b = ((QueueSession) session).createBrowser((Queue) destination);
+ return b.getEnumeration();
+ }
+ }
+} // JMSBase
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/JMSTestCase.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/JMSTestCase.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/JMSTestCase.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,267 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbossmessaging;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Properties;
+import javax.naming.InitialContext;
+import javax.naming.NamingEnumeration;
+import javax.naming.NameClassPair;
+
+import org.objectweb.jtests.jms.admin.Admin;
+import org.objectweb.jtests.jms.admin.AdminFactory;
+
+import org.jboss.util.NestedRuntimeException;
+import org.jboss.test.JBossTestCase;
+
+/**
+ * JMSTestCase. A base test case for all JMS generic test cases.
+ *
+ * Warning: If you override setUp() or tearDown(), rememeber to call the
+ * superclass versions of these methods within your overriding methods.
+ * AbstractTestCase uses setUp() and tearDown() to initialise logging.
+ *
+ * @author <a href="richard.achmatowicz at jboss.com">Richard Achmatowicz</a>
+ * @version $Revision: 64130 $
+ */
+public class JMSTestCase extends JBossTestCase
+{
+ /** JBM provider properties resource name */
+ private static String PROP_FILE_NAME = "jbossmessaging/provider.properties";
+
+ private static String PROP_NAME = "jms.provider.resources.dir";
+
+ protected Admin admin;
+
+ /**
+ * Constructor for JMSTestCase object
+ *
+ * @param name
+ * test case name
+ */
+ public JMSTestCase(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * Create the Admin object to perform all JMS adminsitrative functions in a
+ * JMS provider-independent manner
+ */
+ protected void setUp() throws Exception
+ {
+ // perform any setUp required in the superclass
+ super.setUp();
+
+ try
+ {
+ log.info("setting up Admin");
+ // get the Admin implementation for the current JMS provider
+ // specified in provider.properties
+ Properties props = getProviderProperties();
+ admin = AdminFactory.getAdmin(props);
+ }
+ catch (Exception e)
+ {
+ throw new NestedRuntimeException("getAdmin() operation failed", e);
+ }
+ }
+
+ /**
+ * Create a JMS Queue.
+ *
+ * The Queue is created dynamically, in a JMS provider-specific manner,
+ * according to the instance of the Admin interface currently in use.
+ *
+ * @param name
+ * The name of the Queue to be created.
+ */
+ public void createQueue(String name)
+ {
+ try
+ {
+ admin.createQueue(name);
+ }
+ catch (Exception e)
+ {
+ throw new NestedRuntimeException("createQueue() operation failed", e);
+ }
+ }
+
+ /**
+ * Delete a JMS Queue.
+ *
+ * The Queue is deleted dynamically, in a JMS provider-specific manner,
+ * according to the instance of the Admin interface currently in use.
+ *
+ * @param name
+ * The name of the Queue to be deleted.
+ */
+ public void deleteQueue(String name)
+ {
+ try
+ {
+ admin.deleteQueue(name);
+ }
+ catch (Exception e)
+ {
+ throw new NestedRuntimeException("deleteQueue() operation failed", e);
+ }
+ }
+
+ /**
+ * Create a JMS Topic.
+ *
+ * The Topic is created dynamically, in a JMS provider-specific manner,
+ * according to the instance of the Admin interface currently in use.
+ *
+ * @param name
+ * The name of the Topic to be created.
+ */
+ public void createTopic(String name)
+ {
+ try
+ {
+ admin.createTopic(name);
+ }
+ catch (Exception e)
+ {
+ throw new NestedRuntimeException("createTopic() operation failed", e);
+ }
+ }
+
+ /**
+ * Delete a JMS Topic.
+ *
+ * The Topic is deleted dynamically, in a JMS provider-specific manner,
+ * according to the instance of the Admin interface currently in use.
+ *
+ * @param name
+ * The name of the Topic to be deleted.
+ */
+ public void deleteTopic(String name)
+ {
+ try
+ {
+ admin.deleteTopic(name);
+ }
+ catch (Exception e)
+ {
+ throw new NestedRuntimeException("deleteTopic() operation failed", e);
+ }
+ }
+
+ /**
+ * Create a JMS ConnectionFactory.
+ *
+ * The ConnectionFactory is created dynamically, in a JMS provider-specific
+ * manner, according to the instance of the Admin interface currently in use.
+ *
+ * @param name
+ * The name of the ConnectionFactory to be created.
+ */
+ public void createConnectionFactory(String name)
+ {
+ try
+ {
+ admin.createConnectionFactory(name);
+ }
+ catch (Exception e)
+ {
+ throw new NestedRuntimeException(
+ "createConnectionFactory() operation failed", e);
+ }
+ }
+
+ /**
+ * Delete a JMS ConnectionFactory.
+ *
+ * The ConnectionFactory is deleted dynamically, in a JMS provider-specific
+ * manner, according to the instance of the Admin interface currently in use.
+ *
+ * @param name
+ * The name of the ConnectionFactory to be deleted.
+ */
+ public void deleteConnectionFactory(String name)
+ {
+ try
+ {
+ admin.deleteConnectionFactory(name);
+ }
+ catch (Exception e)
+ {
+ throw new NestedRuntimeException(
+ "deleteConnectionFactory() operation failed", e);
+ }
+ }
+
+ protected void dumpJNDIContext(String context)
+ {
+ try
+ {
+ log.info("Dumping JNDI context:" + context);
+
+ // dump out the context name-value bindings
+ InitialContext ic = getInitialContext();
+ NamingEnumeration list = ic.list(context);
+
+ while (list.hasMore())
+ {
+ NameClassPair nc = (NameClassPair) list.next();
+ log.info(nc.toString());
+ }
+ log.info("Dumped JNDI context");
+ }
+ catch (Exception e)
+ {
+ throw new NestedRuntimeException("error dumping JNDI context", e);
+ }
+ }
+
+ public static Properties getProviderProperties()
+ throws IOException
+ {
+ Properties props = new Properties();
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ URL propsURL = loader.getResource(PROP_FILE_NAME);
+ System.err.println("using provider.properties: " + propsURL);
+ props.load(propsURL.openStream());
+ return props;
+ }
+
+ /**
+ * Given a resource file name, prepend a directory qualifier to that name,
+ * according to the instance of the JMS provider currently in use.
+ *
+ * The directory name prepended is determined by the value of the property
+ * jms.provider.resources.dir in the provider.properties resources file.
+ *
+ * @param name
+ * The name of the resources file.
+ */
+ public static String getJMSResourceRelativePathname(String name)
+ {
+ // return the resource name with directory prepended
+ return "jbossmessaging/" + name;
+ }
+}
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/MockServerSessionPool.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/MockServerSessionPool.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/MockServerSessionPool.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,50 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.jbossmessaging;
+
+import javax.jms.JMSException;
+import javax.jms.ServerSession;
+import javax.jms.ServerSessionPool;
+
+/**
+ * MockServerSessionPool.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 64130 $
+ */
+public class MockServerSessionPool implements ServerSessionPool
+{
+ /**
+ * Get a new instance of the mock
+ *
+ * @return the instance
+ */
+ public static ServerSessionPool getServerSessionPool()
+ {
+ return new MockServerSessionPool();
+ }
+
+ public ServerSession getServerSession() throws JMSException
+ {
+ throw new org.jboss.util.NotImplementedException("FIXME NYI getServerSession");
+ }
+}
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/perf/JMSPerfStressTestCase.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/perf/JMSPerfStressTestCase.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/perf/JMSPerfStressTestCase.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,790 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbossmessaging.perf;
+
+import javax.jms.BytesMessage;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicPublisher;
+import javax.jms.TopicSession;
+import javax.jms.TopicSubscriber;
+import javax.jms.Queue;
+import javax.naming.Context;
+
+import org.apache.log4j.Logger;
+import org.jboss.test.jbossmessaging.JMSTestCase;
+/**
+ * JMSPerfStressTestCase.java Some simple tests of JMS provider
+ *
+ * @author <a href="mailto:richard.achmatowicz at jboss.com">Richard Achmatowicz</a>
+ * @author
+ * @version
+ */
+
+public class JMSPerfStressTestCase extends JMSTestCase
+{
+
+ // Provider specific
+ static String TOPIC_FACTORY = "ConnectionFactory";
+ static String QUEUE_FACTORY = "ConnectionFactory";
+
+ static String TEST_QUEUE = "queue/testQueue";
+ static String TEST_TOPIC = "topic/testTopic";
+
+ // static int PERFORMANCE_TEST_ITERATIONS = 1000;
+ static byte[] PERFORMANCE_TEST_DATA_PAYLOAD = new byte[10 * 1024];
+
+ static int TRANS_NONE = 0;
+ static int TRANS_INDIVIDUAL = 1;
+ static int TRANS_TOTAL = 2;
+ static String[] TRANS_DESC = {"NOT", "individually", "totally"};
+
+ //JMSProviderAdapter providerAdapter;
+ static Context context;
+ static QueueConnection queueConnection;
+ static TopicConnection topicConnection;
+
+ /**
+ * Constructor for the JMSPerfStressTestCase object
+ *
+ * @param name Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ public JMSPerfStressTestCase(String name) throws Exception
+ {
+ super(name);
+ }
+
+
+ /**
+ * #Description of the Method
+ *
+ * @param transacted Description of Parameter
+ * @param persistence Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ public void runAsynchQueuePerformance(final int transacted, final int persistence) throws Exception
+ {
+ {
+ queueConnection.start();
+ drainQueue();
+ queueConnection.stop();
+ }
+ final int iterationCount = getIterationCount();
+ final Logger log = getLog();
+
+ Thread sendThread =
+ new Thread()
+ {
+ /**
+ * Main processing method for the JBossMQPerfStressTestCase object
+ */
+ public void run()
+ {
+ try
+ {
+ QueueSession session = queueConnection.createQueueSession(transacted != TRANS_NONE, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue)context.lookup(TEST_QUEUE);
+
+ QueueSender sender = session.createSender(queue);
+
+ BytesMessage message = session.createBytesMessage();
+ message.writeBytes(PERFORMANCE_TEST_DATA_PAYLOAD);
+
+ long startTime = System.currentTimeMillis();
+ for (int i = 0; i < iterationCount; i++)
+ {
+ //sender.send(queue, message, persistence, 4, 0);
+ sender.send(message, persistence, 4, 0);
+ //getLog().debug(" Sent #"+i);
+ if (transacted == TRANS_INDIVIDUAL)
+ {
+ session.commit();
+ }
+ }
+
+ if (transacted == TRANS_TOTAL)
+ {
+ session.commit();
+ }
+
+ long endTime = System.currentTimeMillis();
+
+ session.close();
+
+ long pTime = endTime - startTime;
+ log.debug(" sent all messages in " + ((double)pTime / 1000) + " seconds. ");
+ }
+ catch (Exception e)
+ {
+ log.error("error", e);
+ }
+ }
+ };
+
+ final QueueSession session = queueConnection.createQueueSession(transacted != TRANS_NONE, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue)context.lookup(TEST_QUEUE);
+ QueueReceiver receiver = session.createReceiver(queue);
+
+ MessageListener listener =
+ new MessageListener()
+ {
+ long startTime = System.currentTimeMillis();
+ int i = 0;
+
+ /**
+ * #Description of the Method
+ *
+ * @param message Description of Parameter
+ */
+ public void onMessage(Message message)
+ {
+ try
+ {
+ if( transacted == TRANS_INDIVIDUAL )
+ session.commit();
+ i++;
+ }
+ catch (JMSException e)
+ {
+ getLog().error("Unable to commit", e);
+ synchronized (this)
+ {
+ this.notify();
+ }
+ }
+ if (i >= iterationCount)
+ {
+ long endTime = System.currentTimeMillis();
+ long pTime = endTime - startTime;
+ log.debug(" received all messages in " + ((double)pTime / 1000) + " seconds. ");
+
+ synchronized (this)
+ {
+ this.notify();
+ }
+ }
+ }
+ };
+
+ getLog().debug(" Asynch Queue: This test will send " + getIterationCount() + " "
+ + (persistence == DeliveryMode.PERSISTENT ? "persistent" : "non-persistent") + " messages. Each with a payload of "
+ + ((double)PERFORMANCE_TEST_DATA_PAYLOAD.length / 1024) + "Kb"
+ + " Session is " + TRANS_DESC[transacted] + " transacted");
+ long startTime = System.currentTimeMillis();
+ sendThread.start();
+ receiver.setMessageListener(listener);
+ synchronized (listener)
+ {
+ queueConnection.start();
+ listener.wait();
+ }
+
+ if (transacted == TRANS_TOTAL)
+ {
+ session.commit();
+ }
+
+ session.close();
+ sendThread.join();
+ long endTime = System.currentTimeMillis();
+ long pTime = endTime - startTime;
+ getLog().debug(" All threads finished after: " + ((double)pTime / 1000) + " seconds. ");
+
+ }
+
+ /**
+ * #Description of the Method
+ *
+ * @param transacted Description of Parameter
+ * @param persistence Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ public void runAsynchTopicPerformance(final int transacted, final int persistence) throws Exception
+ {
+ {
+ queueConnection.start();
+ drainQueue();
+ }
+
+ final int iterationCount = getIterationCount();
+ final Logger log = getLog();
+
+ Thread sendThread =
+ new Thread()
+ {
+ /**
+ * Main processing method for the JMSPerfStressTestCase object
+ */
+ public void run()
+ {
+ try
+ {
+
+ TopicSession session = topicConnection.createTopicSession(transacted != TRANS_NONE, Session.AUTO_ACKNOWLEDGE);
+ Topic topic = (Topic)context.lookup(TEST_TOPIC);
+
+ TopicPublisher publisher = session.createPublisher(topic);
+
+ waitForSynchMessage();
+
+ BytesMessage message = session.createBytesMessage();
+ message.writeBytes(PERFORMANCE_TEST_DATA_PAYLOAD);
+
+ long startTime = System.currentTimeMillis();
+ for (int i = 0; i < iterationCount; i++)
+ {
+ publisher.publish(message, persistence, 4, 0);
+ //publisher.publish(topic, message, persistence, 4, 0);
+ //getLog().debug(" Sent #"+i);
+ if (transacted == TRANS_INDIVIDUAL)
+ {
+ session.commit();
+ }
+ }
+
+ if (transacted == TRANS_TOTAL)
+ {
+ session.commit();
+ }
+
+ long endTime = System.currentTimeMillis();
+ session.close();
+
+ long pTime = endTime - startTime;
+ log.debug(" sent all messages in " + ((double)pTime / 1000) + " seconds. ");
+ }
+ catch (Exception e)
+ {
+ log.error("error", e);
+ }
+ }
+ };
+
+ final TopicSession session = topicConnection.createTopicSession(transacted != TRANS_NONE, Session.AUTO_ACKNOWLEDGE);
+ Topic topic = (Topic)context.lookup(TEST_TOPIC);
+ TopicSubscriber subscriber = session.createSubscriber(topic);
+
+ MessageListener listener =
+ new MessageListener()
+ {
+ long startTime = System.currentTimeMillis();
+ int i = 0;
+
+ /**
+ * #Description of the Method
+ *
+ * @param message Description of Parameter
+ */
+ public void onMessage(Message message)
+ {
+ try
+ {
+ if( transacted == TRANS_INDIVIDUAL )
+ session.commit();
+ i++;
+ }
+ catch (JMSException e)
+ {
+ getLog().error("Unable to commit", e);
+ synchronized (this)
+ {
+ this.notify();
+ }
+ }
+ if (i >= iterationCount)
+ {
+ long endTime = System.currentTimeMillis();
+ long pTime = endTime - startTime;
+ log.debug(" received all messages in " + ((double)pTime / 1000) + " seconds. ");
+
+ synchronized (this)
+ {
+ this.notify();
+ }
+ }
+ }
+ };
+
+ getLog().debug(" Asynch Topic: This test will send " + getIterationCount() + " "
+ + (persistence == DeliveryMode.PERSISTENT ? "persistent" : "non-persistent") + " messages. Each with a payload of "
+ + ((double)PERFORMANCE_TEST_DATA_PAYLOAD.length / 1024) + "Kb"
+ + " Session is " + TRANS_DESC[transacted] + " transacted");
+ long startTime = System.currentTimeMillis();
+ sendThread.start();
+ subscriber.setMessageListener(listener);
+ sendSynchMessage();
+ synchronized (listener)
+ {
+ topicConnection.start();
+ listener.wait();
+ }
+
+ if (transacted == TRANS_TOTAL)
+ {
+ session.commit();
+ }
+
+ session.close();
+ sendThread.join();
+ long endTime = System.currentTimeMillis();
+ long pTime = endTime - startTime;
+ getLog().debug(" All threads finished after: " + ((double)pTime / 1000) + " seconds. ");
+
+ }
+
+ /**
+ * #Description of the Method
+ *
+ * @param transacted Description of Parameter
+ * @param persistence Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ public void runSynchQueuePerformance(final int transacted, final int persistence) throws Exception
+ {
+ {
+ queueConnection.start();
+ drainQueue();
+ }
+ final int iterationCount = getIterationCount();
+ final Logger log = getLog();
+
+ Thread sendThread =
+ new Thread()
+ {
+ /**
+ * Main processing method for the JMSPerfStressTestCase object
+ */
+ public void run()
+ {
+ try
+ {
+ QueueSession session = queueConnection.createQueueSession(transacted != TRANS_NONE, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue)context.lookup(TEST_QUEUE);
+
+ QueueSender sender = session.createSender(queue);
+
+ BytesMessage message = session.createBytesMessage();
+ message.writeBytes(PERFORMANCE_TEST_DATA_PAYLOAD);
+
+ long startTime = System.currentTimeMillis();
+ for (int i = 0; i < iterationCount; i++)
+ {
+ sender.send( message, persistence, 4, 0);
+ //sender.send(queue, message, persistence, 4, 0);
+ //getLog().debug(" Sent #"+i);
+ if (transacted == TRANS_INDIVIDUAL)
+ {
+ session.commit();
+ }
+ }
+
+ if (transacted == TRANS_TOTAL)
+ {
+ session.commit();
+ }
+
+ session.close();
+
+ long endTime = System.currentTimeMillis();
+
+ long pTime = endTime - startTime;
+ log.debug(" sent all messages in " + ((double)pTime / 1000) + " seconds. ");
+ }
+ catch (Exception e)
+ {
+ log.error("error", e);
+ }
+ }
+ };
+
+ Thread recvThread =
+ new Thread()
+ {
+ /**
+ * Main processing method for the JMSPerfStressTestCase object
+ */
+ public void run()
+ {
+ try
+ {
+
+ QueueSession session = queueConnection.createQueueSession(transacted != TRANS_NONE, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue)context.lookup(TEST_QUEUE);
+
+ QueueReceiver receiver = session.createReceiver(queue);
+ long startTime = System.currentTimeMillis();
+ for (int i = 0; i < iterationCount; i++)
+ {
+ receiver.receive();
+ //getLog().debug(" Received #"+i);
+ if (transacted == TRANS_INDIVIDUAL)
+ {
+ session.commit();
+ }
+ }
+
+ if (transacted == TRANS_TOTAL)
+ {
+ session.commit();
+ }
+
+ long endTime = System.currentTimeMillis();
+
+ session.close();
+
+ long pTime = endTime - startTime;
+ log.debug(" received all messages in " + ((double)pTime / 1000) + " seconds. ");
+
+ }
+ catch (Exception e)
+ {
+ log.error("error", e);
+ }
+ }
+ };
+
+ getLog().debug(" Synch Queue: This test will send " + getIterationCount() + " "
+ + (persistence == DeliveryMode.PERSISTENT ? "persistent" : "non-persistent") + " messages. Each with a payload of "
+ + ((double)PERFORMANCE_TEST_DATA_PAYLOAD.length / 1024) + "Kb"
+ + " Session is " + TRANS_DESC[transacted] + " transacted");
+ long startTime = System.currentTimeMillis();
+ sendThread.start();
+ recvThread.start();
+ sendThread.join();
+ recvThread.join();
+ long endTime = System.currentTimeMillis();
+ long pTime = endTime - startTime;
+ getLog().debug(" All threads finished after: " + ((double)pTime / 1000) + " seconds. ");
+
+ }
+
+ /**
+ * #Description of the Method
+ *
+ * @param transacted Description of Parameter
+ * @param persistence Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ public void runSynchTopicPerformance(final int transacted, final int persistence) throws Exception
+ {
+ {
+ queueConnection.start();
+ topicConnection.start();
+ drainQueue();
+ }
+ final int iterationCount = getIterationCount();
+ final Logger log = getLog();
+
+ Thread sendThread =
+ new Thread()
+ {
+ /**
+ * Main processing method for the JBossMQPerfStressTestCase object
+ */
+ public void run()
+ {
+ try
+ {
+
+ TopicSession session = topicConnection.createTopicSession(transacted != TRANS_NONE, Session.AUTO_ACKNOWLEDGE);
+ Topic topic = (Topic)context.lookup(TEST_TOPIC);
+
+ TopicPublisher publisher = session.createPublisher(topic);
+
+ waitForSynchMessage();
+
+ BytesMessage message = session.createBytesMessage();
+ message.writeBytes(PERFORMANCE_TEST_DATA_PAYLOAD);
+
+ long startTime = System.currentTimeMillis();
+ for (int i = 0; i < iterationCount; i++)
+ {
+ publisher.publish(message, persistence, 4, 0);
+ //publisher.publish(topic, message, persistence, 4, 0);
+ //getLog().debug(" Sent #"+i);
+ if (transacted == TRANS_INDIVIDUAL)
+ {
+ session.commit();
+ }
+ }
+
+ if (transacted == TRANS_TOTAL)
+ {
+ session.commit();
+ }
+
+ long endTime = System.currentTimeMillis();
+
+ session.close();
+
+ long pTime = endTime - startTime;
+ log.debug(" sent all messages in " + ((double)pTime / 1000) + " seconds. ");
+ }
+ catch (Exception e)
+ {
+ log.error("error", e);
+ }
+ }
+ };
+
+ Thread recvThread =
+ new Thread()
+ {
+ /**
+ * Main processing method for the JBossMQPerfStressTestCase object
+ */
+ public void run()
+ {
+ try
+ {
+
+ TopicSession session = topicConnection.createTopicSession(transacted != TRANS_NONE, Session.AUTO_ACKNOWLEDGE);
+ Topic topic = (Topic)context.lookup(TEST_TOPIC);
+ TopicSubscriber subscriber = session.createSubscriber(topic);
+
+ sendSynchMessage();
+
+ long startTime = System.currentTimeMillis();
+ for (int i = 0; i < iterationCount; i++)
+ {
+ subscriber.receive();
+ //getLog().debug(" Received #"+i);
+ if (transacted == TRANS_INDIVIDUAL)
+ {
+ session.commit();
+ }
+ }
+
+ if (transacted == TRANS_TOTAL)
+ {
+ session.commit();
+ }
+
+ long endTime = System.currentTimeMillis();
+
+ session.close();
+
+ long pTime = endTime - startTime;
+ log.debug(" received all messages in " + ((double)pTime / 1000) + " seconds. ");
+
+ }
+ catch (Exception e)
+ {
+ log.error("error", e);
+ }
+ }
+ };
+
+ getLog().debug(" Synch Topic: This test will send " + getIterationCount() + " "
+ + (persistence == DeliveryMode.PERSISTENT ? "persistent" : "non-persistent") + " messages. Each with a payload of "
+ + ((double)PERFORMANCE_TEST_DATA_PAYLOAD.length / 1024) + "Kb"
+ + " Session is " + TRANS_DESC[transacted] + " transacted");
+ long startTime = System.currentTimeMillis();
+ sendThread.start();
+ recvThread.start();
+ sendThread.join();
+ recvThread.join();
+ long endTime = System.currentTimeMillis();
+ long pTime = endTime - startTime;
+ getLog().debug(" All threads finished after: " + ((double)pTime / 1000) + " seconds. ");
+
+ }
+
+ /**
+ * A unit test for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
+ public void testAsynchQueuePerformance() throws Exception
+ {
+
+ getLog().debug("Starting AsynchQueuePerformance test");
+
+ runAsynchQueuePerformance(TRANS_NONE, DeliveryMode.NON_PERSISTENT);
+ runAsynchQueuePerformance(TRANS_NONE, DeliveryMode.PERSISTENT);
+ runAsynchQueuePerformance(TRANS_INDIVIDUAL, DeliveryMode.NON_PERSISTENT);
+ runAsynchQueuePerformance(TRANS_INDIVIDUAL, DeliveryMode.PERSISTENT);
+ runAsynchQueuePerformance(TRANS_TOTAL, DeliveryMode.NON_PERSISTENT);
+ runAsynchQueuePerformance(TRANS_TOTAL, DeliveryMode.PERSISTENT);
+
+ getLog().debug("AsynchQueuePerformance passed");
+ }
+
+ /**
+ * A unit test for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
+ public void testAsynchTopicPerformance() throws Exception
+ {
+
+ getLog().debug("Starting AsynchTopicPerformance test");
+
+ runAsynchTopicPerformance(TRANS_NONE, DeliveryMode.NON_PERSISTENT);
+ runAsynchTopicPerformance(TRANS_NONE, DeliveryMode.PERSISTENT);
+ runAsynchTopicPerformance(TRANS_INDIVIDUAL, DeliveryMode.NON_PERSISTENT);
+ runAsynchTopicPerformance(TRANS_INDIVIDUAL, DeliveryMode.PERSISTENT);
+ runAsynchTopicPerformance(TRANS_TOTAL, DeliveryMode.NON_PERSISTENT);
+ runAsynchTopicPerformance(TRANS_TOTAL, DeliveryMode.PERSISTENT);
+
+ getLog().debug("AsynchTopicPerformance passed");
+ }
+
+ /**
+ * A unit test for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
+ public void testSynchQueuePerformance() throws Exception
+ {
+
+ getLog().debug("Starting SynchQueuePerformance test");
+
+ runSynchQueuePerformance(TRANS_NONE, DeliveryMode.NON_PERSISTENT);
+ runSynchQueuePerformance(TRANS_NONE, DeliveryMode.PERSISTENT);
+ runSynchQueuePerformance(TRANS_INDIVIDUAL, DeliveryMode.NON_PERSISTENT);
+ runSynchQueuePerformance(TRANS_INDIVIDUAL, DeliveryMode.PERSISTENT);
+ runSynchQueuePerformance(TRANS_TOTAL, DeliveryMode.NON_PERSISTENT);
+ runSynchQueuePerformance(TRANS_TOTAL, DeliveryMode.PERSISTENT);
+
+ getLog().debug("SynchQueuePerformance passed");
+ }
+
+ /**
+ * A unit test for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
+ public void testSynchTopicPerformance() throws Exception
+ {
+
+ getLog().debug("Starting SynchTopicPerformance test");
+
+ runSynchTopicPerformance(TRANS_NONE, DeliveryMode.NON_PERSISTENT);
+ runSynchTopicPerformance(TRANS_NONE, DeliveryMode.PERSISTENT);
+ runSynchTopicPerformance(TRANS_INDIVIDUAL, DeliveryMode.NON_PERSISTENT);
+ runSynchTopicPerformance(TRANS_INDIVIDUAL, DeliveryMode.PERSISTENT);
+ runSynchTopicPerformance(TRANS_TOTAL, DeliveryMode.NON_PERSISTENT);
+ runSynchTopicPerformance(TRANS_TOTAL, DeliveryMode.PERSISTENT);
+
+ getLog().debug("SynchTopicPerformance passed");
+ }
+
+ /**
+ * The JUnit setup method
+ *
+ * @exception Exception Description of Exception
+ */
+ protected void setUp() throws Exception
+ {
+ // perform any setUp() required by the base class
+ super.setUp() ;
+
+ if (context == null)
+ {
+ Logger log = getLog() ;
+ if (log == null)
+ System.out.println("JMSPerfStressTestCase: getLog() returned null") ;
+
+ getLog().debug("JMSPerfStresTestCase - setUp") ;
+
+ context = getInitialContext();
+ }
+
+ QueueConnectionFactory queueFactory = (QueueConnectionFactory)context.lookup(QUEUE_FACTORY);
+ queueConnection = queueFactory.createQueueConnection();
+
+ TopicConnectionFactory topicFactory = (TopicConnectionFactory)context.lookup(TOPIC_FACTORY);
+ topicConnection = topicFactory.createTopicConnection();
+
+ getLog().debug("Connection to JMS provider established.");
+
+ }
+
+ protected void tearDown() throws Exception
+ {
+ try {queueConnection.close();} catch (Throwable ignored){}
+ try {topicConnection.close();} catch (Throwable ignored){}
+ }
+
+
+ // Emptys out all the messages in a queue
+ private void drainQueue() throws Exception
+ {
+
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue)context.lookup(TEST_QUEUE);
+
+ QueueReceiver receiver = session.createReceiver(queue);
+ Message message = receiver.receive(50);
+ int c = 0;
+ while (message != null)
+ {
+ message = receiver.receive(50);
+ c++;
+ }
+
+ if (c != 0)
+ {
+ getLog().debug(" Drained " + c + " messages from the queue");
+ }
+
+ session.close();
+
+ }
+
+ private void waitForSynchMessage() throws Exception
+ {
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue)context.lookup(TEST_QUEUE);
+
+ QueueReceiver receiver = session.createReceiver(queue);
+ receiver.receive();
+ session.close();
+ }
+
+ private void sendSynchMessage() throws Exception
+ {
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue)context.lookup(TEST_QUEUE);
+
+ QueueSender sender = session.createSender(queue);
+
+ Message message = session.createMessage();
+ sender.send(message);
+
+ session.close();
+ }
+
+}
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/perf/JMSReconnectStressTestCase.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/perf/JMSReconnectStressTestCase.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/perf/JMSReconnectStressTestCase.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,107 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbossmessaging.perf;
+
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.naming.InitialContext;
+
+import org.jboss.test.jbossmessaging.JMSTestCase;
+
+/**
+ * Reconnect stress
+ *
+ * @author <a href="mailto:richard.achmatowicz at jboss.com">Richard Achmatowicz</a>
+ * @author
+ * @version
+ */
+
+public class JMSReconnectStressTestCase extends JMSTestCase
+{
+ static String QUEUE_FACTORY = "ConnectionFactory";
+
+ public JMSReconnectStressTestCase(String name) throws Exception
+ {
+ super(name);
+ }
+
+ public void testReconnectStress() throws Throwable
+ {
+ InitialContext ctx = new InitialContext();
+ QueueConnectionFactory qcf = (QueueConnectionFactory) ctx.lookup(QUEUE_FACTORY);
+
+ ReconnectThread[] threads = new ReconnectThread[getThreadCount()];
+ for (int i = 0; i < threads.length; ++i)
+ threads[i] = new ReconnectThread(qcf, "Reconnect-"+i);
+ for (int i = 0; i < threads.length; ++i)
+ threads[i].start();
+ for (int i = 0; i < threads.length; ++i)
+ threads[i].join();
+ for (int i = 0; i < threads.length; ++i)
+ {
+ if (threads[i].error != null)
+ throw threads[i].error;
+ }
+ }
+
+ public class ReconnectThread extends Thread
+ {
+ public Throwable error;
+ public QueueConnectionFactory qcf;
+
+ public ReconnectThread(QueueConnectionFactory qcf, String name)
+ {
+ super(name);
+ this.qcf = qcf;
+ }
+
+ public void run()
+ {
+ QueueConnection c = null;
+ try
+ {
+ for (int i = 0; i < getIterationCount(); ++i)
+ {
+ log.info(Thread.currentThread() + " connect " + i);
+ c = qcf.createQueueConnection();
+ log.info(Thread.currentThread() + " close " + i);
+ c.close();
+ c = null;
+ }
+ }
+ catch (Throwable t)
+ {
+ if (c != null)
+ {
+ try
+ {
+ c.close();
+ }
+ catch (Throwable ignored)
+ {
+ log.warn("Ignored: ", ignored);
+ }
+ }
+ }
+ }
+ }
+}
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/perf/ReceiveNackClientStressTestCase.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/perf/ReceiveNackClientStressTestCase.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/perf/ReceiveNackClientStressTestCase.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,139 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbossmessaging.perf;
+
+import java.io.Serializable;
+import java.util.HashMap;
+
+import javax.jms.ExceptionListener;
+import javax.jms.JMSException;
+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.Session;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.naming.InitialContext;
+
+import org.jboss.test.jbossmessaging.JMSTestCase;
+import org.jboss.util.NestedRuntimeException;
+
+/**
+ * A stress test for an impatient receiver
+ *
+ * @author <a href="mailto:richard.achmatowicz at jboss.com">Richard Achmatowicz</a>
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 64130 $
+ */
+public class ReceiveNackClientStressTestCase extends JMSTestCase implements ExceptionListener
+{
+ protected QueueConnection queueConnection;
+
+ public ReceiveNackClientStressTestCase(String name) throws Exception
+ {
+ super(name);
+ }
+
+ public void onException(JMSException e)
+ {
+ log.error("Error: ", e);
+ try
+ {
+ queueConnection.close();
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+
+ private void drainQueue(String name) throws Exception
+ {
+ InitialContext context = getInitialContext() ;
+
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue)context.lookup(name);
+
+ QueueReceiver receiver = session.createReceiver(queue);
+ queueConnection.start();
+ Message message = receiver.receive(50);
+ int c = 0;
+ while (message != null)
+ {
+ message = receiver.receive(50);
+ c++;
+ }
+
+ if (c != 0)
+ getLog().debug(" Drained " + c + " messages from the queue");
+ session.close();
+ queueConnection.stop();
+
+ }
+
+ public void testImpatient() throws Exception
+ {
+ int target = getIterationCount();
+ createQueue("Impatient");
+ try
+ {
+ InitialContext context = getInitialContext();
+ QueueConnectionFactory queueFactory = (QueueConnectionFactory) context.lookup("ConnectionFactory");
+ Queue queue = (Queue) context.lookup("Impatient");
+ queueConnection = queueFactory.createQueueConnection();
+ drainQueue("Impatient") ;
+ try
+ {
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ QueueSender sender = session.createSender(queue);
+ QueueReceiver receiver = session.createReceiver(queue);
+ Serializable payload = new HashMap();
+ Message message = session.createObjectMessage(payload);
+ queueConnection.start();
+ int count = 0;
+ int sendCount = 0;
+ while (count < target)
+ {
+ if (sendCount <= target)
+ {
+ for (int i = 0; i < 10 && ++sendCount <= target; ++i)
+ sender.send(message);
+ }
+ if (receiver.receive(1) != null)
+ ++count;
+ }
+ }
+ finally
+ {
+ drainQueue("Impatient") ;
+ queueConnection.close();
+ }
+ }
+ finally
+ {
+ deleteQueue("Impatient");
+ }
+ }
+}
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/perf/SendReplyPerfStressTestCase.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/perf/SendReplyPerfStressTestCase.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/perf/SendReplyPerfStressTestCase.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,336 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbossmessaging.perf;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.jms.TemporaryQueue;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicPublisher;
+import javax.jms.TopicSession;
+import javax.jms.TopicSubscriber;
+import javax.jms.Queue;
+import javax.naming.Context;
+
+import org.jboss.test.jbossmessaging.JMSTestCase;
+
+/**
+ * SendReplyPerfStressTestCase.java
+ * Some send/reply performance tests
+ *
+ * @author <a href="mailto:richard.achmatowicz at jboss.com">Richard Achmatowicz</a>
+ * @author
+ * @version
+ */
+public class SendReplyPerfStressTestCase extends JMSTestCase
+{
+ // Provider specific
+ static String TOPIC_FACTORY = "ConnectionFactory";
+ static String QUEUE_FACTORY = "ConnectionFactory";
+
+ static String TEST_QUEUE = "queue/testQueue";
+ static String TEST_TOPIC = "topic/testTopic";
+
+ static byte[] PERFORMANCE_TEST_DATA_PAYLOAD = new byte[10];
+
+ //JMSProviderAdapter providerAdapter;
+ static Context context;
+ static QueueConnection queueConnection;
+ static TopicConnection topicConnection;
+
+ public SendReplyPerfStressTestCase(String name) throws Exception
+ {
+ super(name);
+ }
+
+ /**
+ * The main entry-point for the SendReplyPerfStressTestCase class
+ *
+ * @param args The command line arguments
+ */
+ public static void main(String[] args)
+ {
+
+ String newArgs[] = {"org.jboss.test.jbossmessaging.perf.SendReplyPerfStressTestCase"};
+ junit.swingui.TestRunner.main(newArgs);
+ }
+
+ public static class State
+ {
+ public int expected;
+ public int finished = 0;
+ public ArrayList errors = new ArrayList();
+ public State(int expected)
+ {
+ this.expected = expected;
+ }
+ public synchronized void addError(Throwable t)
+ {
+ errors.add(t);
+ }
+ public synchronized void finished()
+ {
+ ++finished;
+ if (finished == expected)
+ notifyAll();
+ }
+ public synchronized void waitForFinish() throws Exception
+ {
+ if (finished == expected)
+ return;
+ wait();
+ }
+ }
+
+ public static class MessageQueueSender
+ implements Runnable
+ {
+ State state;
+ public MessageQueueSender(State state)
+ {
+ this.state = state;
+ }
+
+ public void run()
+ {
+ try
+ {
+ Queue queue = (Queue)context.lookup(TEST_QUEUE);
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ TemporaryQueue temp = session.createTemporaryQueue();
+ Message message = session.createTextMessage();
+ message.setJMSReplyTo(temp);
+
+ QueueSender sender = session.createSender(queue);
+ sender.send(message);
+
+ QueueReceiver receiver = session.createReceiver(temp);
+ receiver.receive();
+ receiver.close();
+ temp.delete();
+
+ session.close();
+ }
+ catch (Throwable t)
+ {
+ state.addError(t);
+ }
+ finally
+ {
+ state.finished();
+ }
+ }
+ }
+
+ public static class MessageTopicSender
+ implements Runnable
+ {
+ State state;
+ public MessageTopicSender(State state)
+ {
+ this.state = state;
+ }
+
+ public void run()
+ {
+ try
+ {
+ Topic topic = (Topic)context.lookup(TEST_TOPIC);
+ TopicSession session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ Message message = session.createTextMessage();
+
+ QueueSession qsession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ TemporaryQueue temp = qsession.createTemporaryQueue();
+ message.setJMSReplyTo(temp);
+
+ TopicPublisher publisher = session.createPublisher(topic);
+ publisher.publish(message);
+
+ QueueReceiver receiver = qsession.createReceiver(temp);
+ receiver.receive();
+ receiver.close();
+
+ session.close();
+ }
+ catch (Throwable t)
+ {
+ state.addError(t);
+ }
+ finally
+ {
+ state.finished();
+ }
+ }
+ }
+
+ public static class MessageReplier
+ implements MessageListener
+ {
+ State state;
+ public MessageReplier(State state)
+ {
+ this.state = state;
+ }
+ public void onMessage(Message message)
+ {
+ try
+ {
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue replyQueue = session.createQueue(((Queue)message.getJMSReplyTo()).getQueueName());
+ QueueSender sender = session.createSender(replyQueue);
+ sender.send(message);
+ sender.close();
+ session.close();
+ }
+ catch (Throwable t)
+ {
+ state.addError(t);
+ }
+ }
+ }
+
+ public void testSendReplyQueue() throws Exception
+ {
+ drainQueue();
+
+ // Set up the workers
+ State state = new State(getThreadCount());
+ MessageReplier replier = new MessageReplier(state);
+ Thread[] threads = new Thread[getThreadCount()];
+ for (int i = 0; i < threads.length; ++i)
+ threads[i] = new Thread(new MessageQueueSender(state));
+
+ // Register the message listener
+ Queue queue = (Queue)context.lookup(TEST_QUEUE);
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ QueueReceiver receiver = session.createReceiver(queue);
+ receiver.setMessageListener(replier);
+ queueConnection.start();
+
+ // Start the senders
+ for (int i = 0; i < threads.length; ++i)
+ threads[i].start();
+
+ // Wait for it to finish
+ state.waitForFinish();
+
+ // Report the result
+ for (Iterator i = state.errors.iterator(); i.hasNext();)
+ getLog().error("Error", (Throwable) i.next());
+ if (state.errors.size() > 0)
+ throw new RuntimeException("Test failed with " + state.errors.size() + " errors");
+ }
+
+ public void testSendReplyTopic() throws Exception
+ {
+ // Set up the workers
+ State state = new State(getThreadCount());
+ MessageReplier replier = new MessageReplier(state);
+
+ Thread[] threads = new Thread[getThreadCount()];
+ for (int i = 0; i < threads.length; ++i)
+ threads[i] = new Thread(new MessageTopicSender(state));
+
+
+ // Register the message listener
+ Topic topic = (Topic)context.lookup(TEST_TOPIC);
+ TopicSession session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ TopicSubscriber subscriber = session.createSubscriber(topic);
+ subscriber.setMessageListener(replier);
+ topicConnection.start();
+ queueConnection.start();
+
+ // Start the senders
+ for (int i = 0; i < threads.length; ++i)
+ threads[i].start();
+
+ // Wait for it to finish
+ state.waitForFinish();
+
+ // Report the result
+ for (Iterator i = state.errors.iterator(); i.hasNext();)
+ getLog().error("Error", (Throwable) i.next());
+ if (state.errors.size() > 0)
+ throw new RuntimeException("Test failed with " + state.errors.size() + " errors");
+ }
+
+ protected void setUp() throws Exception
+ {
+ // call setUp() of superclass
+ super.setUp() ;
+
+ getLog().info("Starting test: " + getName());
+
+ context = getInitialContext();
+
+ QueueConnectionFactory queueFactory = (QueueConnectionFactory)context.lookup(QUEUE_FACTORY);
+ queueConnection = queueFactory.createQueueConnection();
+
+ TopicConnectionFactory topicFactory = (TopicConnectionFactory)context.lookup(TOPIC_FACTORY);
+ topicConnection = topicFactory.createTopicConnection();
+
+ getLog().debug("Connection to JMS provider established.");
+ }
+
+ protected void tearDown() throws Exception
+ {
+ getLog().info("Ended test: " + getName());
+ queueConnection.close();
+ topicConnection.close();
+
+ // call tearDown() of superclass
+ super.tearDown() ;
+ }
+
+ private void drainQueue() throws Exception
+ {
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue)context.lookup(TEST_QUEUE);
+
+ QueueReceiver receiver = session.createReceiver(queue);
+ queueConnection.start();
+ Message message = receiver.receive(50);
+ int c = 0;
+ while (message != null)
+ {
+ message = receiver.receive(50);
+ c++;
+ }
+
+ if (c != 0)
+ getLog().debug(" Drained " + c + " messages from the queue");
+ session.close();
+ queueConnection.stop();
+
+ }
+
+}
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/ra/RaJMSSessionUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/ra/RaJMSSessionUnitTestCase.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/ra/RaJMSSessionUnitTestCase.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbossmessaging.ra;
+
+import javax.jms.*;
+import javax.naming.InitialContext;
+
+import org.jboss.test.jbossmessaging.JMSTestCase;
+import org.jboss.test.JBossTestSetup;
+import org.jboss.test.client.test.AppClientUnitTestCase;
+
+import org.jboss.test.jmsra.bean.*;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test for jmsra.
+ *
+ * @author <a href="richard.achmatowicz at jboss.com">Richard Achmatowicz</a>
+ * @author <a href="mailto:Adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 64130 $
+ */
+
+public class RaJMSSessionUnitTestCase extends JMSTestCase
+{
+ public RaJMSSessionUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testSendToQueueAndTopic()
+ throws Exception
+ {
+ JMSSessionHome home = (JMSSessionHome) getInitialContext().lookup("JMSSession");
+ JMSSession session = home.create();
+ session.sendToQueueAndTopic();
+ }
+
+ public static Test suite() throws Exception
+ {
+ TestSuite suite = new TestSuite();
+
+ suite.addTest(new JBossTestSetup(new TestSuite(RaJMSSessionUnitTestCase.class))
+ {
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ deploy ("jmsra.jar");
+ }
+ protected void tearDown() throws Exception
+ {
+ undeploy ("jmsra.jar");
+ super.tearDown();
+ }
+ });
+
+ return suite;
+ }
+}
+
+
+
+
+
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/ra/RaQueueUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/ra/RaQueueUnitTestCase.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/ra/RaQueueUnitTestCase.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbossmessaging.ra;
+
+import javax.jms.MessageConsumer;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+
+import javax.management.ObjectName;
+
+import javax.naming.Context;
+
+import junit.framework.Test;
+
+import org.jboss.test.JBossTestSetup;
+
+/**
+ * Test cases for JMS Resource Adapter use a <em>Queue</em> . <p>
+ *
+ * Created: Mon Apr 23 21:35:25 2001
+ *
+ * @author <a href="mailto:peter.antman at tim.se">Peter Antman</a>
+ * @author <a href="mailto:jason at planet57.com">Jason Dillon</a>
+ * @version $Revision: 64130 $
+ */
+public class RaQueueUnitTestCase
+ extends RaTest
+{
+ private final static String QUEUE_FACTORY = "ConnectionFactory";
+ private final static String QUEUE = "queue/testQueue";
+ private final static String JNDI = "TxPublisher";
+
+ /**
+ * Constructor for the RaQueueUnitTestCase object
+ *
+ * @param name Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ public RaQueueUnitTestCase(String name) throws Exception
+ {
+ super(name, JNDI);
+ }
+
+ /**
+ * #Description of the Method
+ *
+ * @param context Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ protected void init(final Context context) throws Exception
+ {
+ QueueConnectionFactory factory =
+ (QueueConnectionFactory)context.lookup(QUEUE_FACTORY);
+
+ connection = factory.createQueueConnection();
+
+ session = ((QueueConnection)connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Queue queue = (Queue)context.lookup(QUEUE);
+
+ consumer = ((QueueSession)session).createReceiver(queue);
+ }
+
+ public static Test suite() throws Exception
+ {
+ return getDeploySetup(RaQueueUnitTestCase.class, "jmsra.jar");
+ }
+
+
+}
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/ra/RaSyncRecUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/ra/RaSyncRecUnitTestCase.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/ra/RaSyncRecUnitTestCase.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,193 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbossmessaging.ra;
+
+import javax.jms.Connection;
+import javax.jms.Message;
+
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Queue;
+import javax.naming.Context;
+
+import javax.management.ObjectName;
+
+import javax.naming.InitialContext;
+import junit.framework.Assert;
+
+import junit.framework.Test;
+
+import org.jboss.test.jbossmessaging.JMSTestCase;
+import org.jboss.test.JBossTestSetup;
+
+import org.jboss.test.jmsra.bean.*;
+
+/**
+ *
+ * <p>Test sync receive.
+ *
+ * <p>Created: Sat Sep 22 13:31:54 2001.
+ *
+ * @author <a href="mailto:richard.achmatowicz at jboss.com">Richard Achmatowicz</a>
+ * @author <a href="mailto:peter.antman at tim.se">Peter Antman</a>
+ * @version $Revision: 64130 $
+ */
+
+public class RaSyncRecUnitTestCase extends JMSTestCase {
+
+ private final static String BEAN_JNDI = "QueueRec";
+ private final static String QUEUE_FACTORY = "ConnectionFactory";
+ private final static String QUEUE = "queue/A";
+ private final static int MESSAGE_NR = 10;
+
+ /**
+ * JMS connection
+ */
+ protected QueueConnection connection;
+ /**
+ * JMS session
+ */
+ protected QueueSession session;
+ /**
+ * JMS sender
+ */
+ protected QueueSender sender;
+
+ /**
+ * Receiving bean
+ */
+ protected QueueRec rec;
+
+ /**
+ *
+ * Constructor for the RaSyncRecUnitTestCase object
+ *
+ * @param name Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ public RaSyncRecUnitTestCase(String name) {
+ super(name);
+ }
+
+ /**
+ * The JUnit setup method
+ *
+ * @exception Exception Description of Exception
+ */
+ protected void setUp() throws Exception
+ {
+ // call setUp() in super class
+ super.setUp() ;
+
+ // Create a receiver
+ Context context = getInitialContext();
+ try
+ {
+ QueueRecHome home = (QueueRecHome)context.lookup(BEAN_JNDI);
+ rec = home.create();
+
+ init(context);
+ }
+ finally
+ {
+ context.close();
+ }
+
+ // start up the session
+ connection.start();
+
+ }
+
+ /**
+ * #Description of the Method
+ *
+ * @param context Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ protected void init(final Context context) throws Exception
+ {
+ QueueConnectionFactory factory =
+ (QueueConnectionFactory)context.lookup(QUEUE_FACTORY);
+
+ connection = factory.createQueueConnection();
+
+ session = ((QueueConnection)connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Queue queue = (Queue)context.lookup(QUEUE);
+
+ sender = ((QueueSession)session).createSender(queue);
+ }
+
+ /**
+ * The teardown method for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
+ protected void tearDown() throws Exception
+ {
+ if (sender != null)
+ {
+ sender.close();
+ }
+ if (session != null) {
+ session.close();
+ }
+ if (connection != null)
+ {
+ connection.close();
+ }
+
+ // call tearDown() in superclass
+ super.tearDown() ;
+ }
+
+ /**
+ * Test sync receive of message with jms ra.
+ */
+ public void testSyncRec() throws Exception {
+ // Send a message to queue
+ TextMessage message = session.createTextMessage();
+ message.setText(String.valueOf(MESSAGE_NR));
+ message.setIntProperty(Publisher.JMS_MESSAGE_NR, MESSAGE_NR);
+ sender.send(message);
+ getLog().debug("sent message with nr = " + MESSAGE_NR);
+
+ // Let bean fetch it sync
+ int res = rec.getMessage();
+ Assert.assertEquals(MESSAGE_NR, res);
+ getLog().debug("testSyncRec() OK");
+ }
+
+ public static Test suite() throws Exception
+ {
+ return getDeploySetup(RaSyncRecUnitTestCase.class, "jmsra.jar");
+ }
+} // RaSyncRecUnitTestCase
+
+
+
+
+
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/ra/RaTest.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/ra/RaTest.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/ra/RaTest.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,294 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbossmessaging.ra;
+
+import javax.jms.Connection;
+import javax.jms.Message;
+
+import javax.jms.MessageConsumer;
+import javax.jms.Session;
+import javax.naming.Context;
+
+import javax.naming.InitialContext;
+import junit.framework.Assert;
+
+import junit.framework.TestCase;
+
+import org.jboss.test.jbossmessaging.JMSTestCase;
+
+import org.jboss.test.jmsra.bean.*;
+
+/**
+ * Abstract test cases for JMS Resource Adapter. <p>
+ *
+ * Created: Mon Apr 23 21:35:25 2001
+ *
+ * @author <a href="richard.achmatowicz at jboss.com">Richard Achmatowicz</a>
+ * @author <a href="mailto:peter.antman at tim.se">Peter Antman</a>
+ * @author <a href="mailto:jason at planet57.com">Jason Dillon</a>
+ * @version $Revision: 64130 $
+ */
+public abstract class RaTest extends JMSTestCase
+{
+ /**
+ * Description of the Field
+ */
+ public final static long DEFAULT_TIMEOUT = 500L;
+ /**
+ * Description of the Field
+ */
+ public final static long FLUSH_TIMEOUT = 500L;
+
+ /**
+ * Description of the Field
+ */
+ protected String beanJNDI;
+ /**
+ * Description of the Field
+ */
+ protected MessageConsumer consumer;
+ /**
+ * Description of the Field
+ */
+ protected Publisher publisher;
+ /**
+ * Description of the Field
+ */
+ protected Connection connection;
+ /**
+ * Description of the Field
+ */
+ protected Session session;
+
+ /**
+ * Constructor for the RaTest object
+ *
+ * @param name Description of Parameter
+ * @param beanJNDI Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ protected RaTest(final String name, final String beanJNDI)
+ throws Exception
+ {
+ super(name);
+ this.beanJNDI = beanJNDI;
+ }
+
+ /**
+ * A unit test for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
+ public void testSimple() throws Exception
+ {
+ printHeader();
+ getLog().debug("Verify simple send of message");
+ publisher.simple(1);
+
+ Assert.assertEquals(1, getJmsMessage());
+ printOK();
+ }
+
+ /**
+ * A unit test for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
+ public void testSimpleFail() throws Exception
+ {
+ printHeader();
+ getLog().debug("Verify simple failed transaction");
+ publisher.simpleFail(2);
+
+ Assert.assertEquals(-1, getJmsMessage());
+ printOK();
+ }
+
+ /**
+ * A unit test for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
+ public void testBeanOk() throws Exception
+ {
+ printHeader();
+ getLog().debug("Verify bean ok");
+ publisher.beanOk(3);
+
+ Assert.assertEquals(3, getJmsMessage());
+ printOK();
+ }
+
+ /**
+ * A unit test for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
+ public void testBeanError() throws Exception
+ {
+ printHeader();
+ getLog().debug("Verify bean eroor failed transaction");
+
+ try
+ {
+ publisher.beanError(4);
+ }
+ catch (Exception ignore)
+ {
+ }
+
+ Assert.assertEquals(-1, getJmsMessage());
+ printOK();
+ }
+
+ /**
+ * The JUnit setup method
+ *
+ * @exception Exception Description of Exception
+ */
+ protected void setUp() throws Exception
+ {
+ // call setUp() in superclass
+ super.setUp() ;
+
+ // Create a publisher
+ Context context = getInitialContext();
+ PublisherHome home = (PublisherHome)context.lookup(beanJNDI);
+ publisher = home.create();
+
+ init(context);
+
+ // start up the session
+ connection.start();
+
+ // flush the destination
+ flush();
+ }
+
+ /**
+ * Check if we got a message.
+ *
+ * @return Publisher.JMS_MESSAGE_NR int property or -1 if no
+ * message was received.
+ * @exception Exception Description of Exception
+ */
+ protected int getJmsMessage() throws Exception
+ {
+ return getJmsMessage(DEFAULT_TIMEOUT);
+ }
+
+ /**
+ * Check if we got a message.
+ *
+ * @param timeout The time to wait for a message.
+ * @return Publisher.JMS_MESSAGE_NR int property or -1 if no
+ * message was received.
+ * @exception Exception Description of Exception
+ */
+ protected int getJmsMessage(long timeout) throws Exception
+ {
+ Message msg = consumer.receive(timeout);
+ if (msg != null)
+ {
+ getLog().debug("Recived message: " + msg);
+ int nr = msg.getIntProperty(Publisher.JMS_MESSAGE_NR);
+ getLog().debug("nr: " + nr);
+ return nr;
+ }
+ else
+ {
+ getLog().debug("NO message recived");
+ return -1;
+ }
+ }
+
+ /**
+ * #Description of the Method
+ *
+ * @param context Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ protected abstract void init(final Context context) throws Exception;
+
+ /**
+ * The teardown method for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
+ protected void tearDown() throws Exception
+ {
+ if (consumer != null)
+ {
+ consumer.close();
+ }
+ if (connection != null)
+ {
+ connection.close();
+ }
+
+ //call tearDown() in superclass
+ super.tearDown() ;
+ }
+
+ /**
+ * #Description of the Method
+ */
+ protected void printHeader()
+ {
+ getLog().debug("\n---- Testing method " + getName() +
+ " for bean " + beanJNDI);
+ }
+
+ /**
+ * #Description of the Method
+ */
+ protected void printOK()
+ {
+ getLog().debug("---- Test OK\n");
+ }
+
+ /**
+ * Flush the destiniation so we know that it contains no messages which might
+ * mess up the test.
+ *
+ * @exception Exception Description of Exception
+ */
+ protected void flush() throws Exception
+ {
+ // getLog().debug(" > Flushing Destination");
+
+ int nr = 0;
+ do
+ {
+ try
+ {
+ nr = getJmsMessage(FLUSH_TIMEOUT);
+ }
+ catch (Exception ignore)
+ {
+ }
+ } while (nr != -1);
+ // getLog().debug(" > Flushed");
+ }
+
+
+}
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/ra/RaTopicUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/ra/RaTopicUnitTestCase.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/ra/RaTopicUnitTestCase.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbossmessaging.ra;
+
+import javax.jms.MessageConsumer;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicSession;
+
+import javax.management.ObjectName;
+
+import javax.naming.Context;
+
+import junit.framework.Test;
+
+import org.jboss.test.JBossTestSetup;
+
+/**
+ * Test cases for JMS Resource Adapter using a <em>Topic</em> . <p>
+ *
+ * Created: Mon Apr 23 21:35:25 2001
+ *
+ * @author <a href="mailto:peter.antman at tim.se">Peter Antman</a>
+ * @author <a href="mailto:jason at planet57.com">Jason Dillon</a>
+ * @version $Revision: 64130 $
+ */
+public class RaTopicUnitTestCase
+ extends RaTest
+{
+ private final static String TOPIC_FACTORY = "ConnectionFactory";
+ private final static String TOPIC = "topic/testTopic";
+ private final static String JNDI = "TxTopicPublisher";
+
+ /**
+ * Constructor for the RaTopicUnitTestCase object
+ *
+ * @param name Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ public RaTopicUnitTestCase(String name) throws Exception
+ {
+ super(name, JNDI);
+ }
+
+ /**
+ * #Description of the Method
+ *
+ * @param context Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ protected void init(final Context context) throws Exception
+ {
+ TopicConnectionFactory factory =
+ (TopicConnectionFactory)context.lookup(TOPIC_FACTORY);
+
+ connection = factory.createTopicConnection();
+
+ session = ((TopicConnection)connection).createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Topic topic = (Topic)context.lookup(TOPIC);
+
+ consumer = ((TopicSession)session).createSubscriber(topic);
+ }
+
+ public static Test suite() throws Exception
+ {
+ return getDeploySetup(RaQueueUnitTestCase.class, "jmsra.jar");
+ }
+
+
+}
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/ConcurrentDeliveryUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/ConcurrentDeliveryUnitTestCase.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/ConcurrentDeliveryUnitTestCase.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,155 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbossmessaging.test;
+
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.jms.TemporaryQueue;
+import javax.naming.Context;
+
+import org.jboss.test.jbossmessaging.JMSTestCase;
+
+/**
+ * Concurrent delivery tests
+ *
+ * @author <a href="mailto:richard.achmatowicz at jboss.org">Richard Achmatowicz</a>
+ * @author <a href="mailto:adrian at jboss.org>Adrian Brock</a>
+ * @version <tt>$Revision: 64130 $</tt>
+ */
+public class ConcurrentDeliveryUnitTestCase extends JMSTestCase
+{
+ static String QUEUE_FACTORY = "ConnectionFactory";
+
+ QueueConnection queueConnection;
+
+ int completed = 0;
+ boolean inDelivery = false;
+ boolean concurrent = false;
+
+ public ConcurrentDeliveryUnitTestCase(String name) throws Exception
+ {
+ super(name);
+ }
+
+ public void testConcurrentDelivery() throws Exception
+ {
+ connect();
+ try
+ {
+ MyMessageListener messageListener = new MyMessageListener();
+
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ TemporaryQueue queue1 = session.createTemporaryQueue();
+ QueueSender sender1 = session.createSender(queue1);
+ QueueReceiver receiver1 = session.createReceiver(queue1);
+ receiver1.setMessageListener(messageListener);
+ TemporaryQueue queue2 = session.createTemporaryQueue();
+ QueueSender sender2 = session.createSender(queue2);
+ QueueReceiver receiver2 = session.createReceiver(queue2);
+ receiver2.setMessageListener(messageListener);
+ Message message = session.createMessage();
+ queueConnection.start();
+
+ sender1.send(message);
+ sender2.send(message);
+
+ synchronized (messageListener)
+ {
+ while (completed < 2)
+ {
+ getLog().debug("Waiting for completion " + completed);
+ messageListener.wait();
+ }
+ }
+ getLog().debug("Completed");
+
+ if (concurrent)
+ fail("Concurrent delivery");
+ }
+ finally
+ {
+ disconnect();
+ }
+ }
+
+ protected void connect() throws Exception
+ {
+ Context context = getInitialContext();
+ QueueConnectionFactory queueFactory = (QueueConnectionFactory) context.lookup(QUEUE_FACTORY);
+ queueConnection = queueFactory.createQueueConnection();
+
+ getLog().debug("Connection established.");
+ }
+
+ protected void disconnect()
+ {
+ try
+ {
+ if (queueConnection != null)
+ queueConnection.close();
+ }
+ catch (Throwable ignored)
+ {
+ getLog().warn("Ignored", ignored);
+ }
+
+ getLog().debug("Connection closed.");
+ }
+
+ public class MyMessageListener implements MessageListener
+ {
+ public void onMessage(Message message)
+ {
+ synchronized (this)
+ {
+ if (inDelivery)
+ concurrent = true;
+ inDelivery = true;
+ getLog().debug("In delivery " + message);
+ }
+
+ try
+ {
+ Thread.sleep(10000);
+ }
+ catch (Throwable ignored)
+ {
+ getLog().warn("Ignored ", ignored);
+ }
+
+ synchronized (this)
+ {
+ inDelivery = false;
+ ++completed;
+ notifyAll();
+ getLog().debug("Completed " + message);
+ }
+ }
+ }
+}
+
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/ConnectionConsumerUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/ConnectionConsumerUnitTestCase.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/ConnectionConsumerUnitTestCase.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,151 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.jbossmessaging.test;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicSession;
+import javax.naming.InitialContext;
+
+import org.jboss.test.jbossmessaging.JMSTestCase;
+import org.jboss.test.jbossmessaging.MockServerSessionPool;
+
+/**
+ * ConnectionConsumerUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 64130 $
+ */
+public class ConnectionConsumerUnitTestCase extends JMSTestCase
+{
+ /**
+ * Create a new ConnectionConsumerUnitTestCase.
+ *
+ * @param name the test name
+ */
+ public ConnectionConsumerUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testConnectionConsumerWrongTemporaryDestination() throws Exception
+ {
+ InitialContext ctx = getInitialContext();
+ ConnectionFactory factory = (ConnectionFactory) ctx.lookup("ConnectionFactory");
+ Queue queue = null;
+ Connection connection = factory.createConnection();
+ try
+ {
+ Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ queue = s.createTemporaryQueue();
+ Connection connection2 = factory.createConnection();
+ try
+ {
+ connection2.createConnectionConsumer(queue, "", MockServerSessionPool.getServerSessionPool(), 1);
+ fail("Expected an error listening to a temporary destination from a different connection");
+ }
+ catch (JMSException expected)
+ {
+ log.debug("Got the expected jms exception", expected);
+ }
+ finally
+ {
+ connection2.close();
+ }
+ }
+ finally
+ {
+ connection.close();
+ }
+ }
+
+ public void testQueueConnectionConsumerWrongTemporaryDestination() throws Exception
+ {
+ InitialContext ctx = getInitialContext();
+ QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
+ Queue queue = null;
+ QueueConnection connection = factory.createQueueConnection();
+ try
+ {
+ QueueSession s = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ queue = s.createTemporaryQueue();
+ QueueConnection connection2 = factory.createQueueConnection();
+ try
+ {
+ connection2.createConnectionConsumer(queue, "", MockServerSessionPool.getServerSessionPool(), 1);
+ fail("Expected an error listening to a temporary destination from a different connection");
+ }
+ catch (JMSException expected)
+ {
+ log.debug("Got the expected jms exception", expected);
+ }
+ finally
+ {
+ connection2.close();
+ }
+ }
+ finally
+ {
+ connection.close();
+ }
+ }
+
+ public void testTopicConnectionConsumerWrongTemporaryDestination() throws Exception
+ {
+ InitialContext ctx = getInitialContext();
+ TopicConnectionFactory factory = (TopicConnectionFactory) ctx.lookup("ConnectionFactory");
+ Topic topic = null;
+ TopicConnection connection = factory.createTopicConnection();
+ try
+ {
+ TopicSession s = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ topic = s.createTemporaryTopic();
+ TopicConnection connection2 = factory.createTopicConnection();
+ try
+ {
+ connection2.createConnectionConsumer(topic, "", MockServerSessionPool.getServerSessionPool(), 1);
+ fail("Expected an error listening to a temporary destination from a different connection");
+ }
+ catch (JMSException expected)
+ {
+ log.debug("Got the expected jms exception", expected);
+ }
+ finally
+ {
+ connection2.close();
+ }
+ }
+ finally
+ {
+ connection.close();
+ }
+ }
+}
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/JBossJMSUnitTest.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/JBossJMSUnitTest.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/JBossJMSUnitTest.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,1355 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbossmessaging.test;
+
+import java.util.Enumeration;
+
+import javax.jms.DeliveryMode;
+import javax.jms.InvalidDestinationException;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.Queue;
+import javax.jms.QueueBrowser;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueRequestor;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.ServerSession;
+import javax.jms.ServerSessionPool;
+import javax.jms.Session;
+import javax.jms.TemporaryQueue;
+import javax.jms.TemporaryTopic;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicPublisher;
+import javax.jms.TopicSession;
+import javax.jms.TopicSubscriber;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.jboss.logging.Logger;
+import org.jboss.test.jbossmessaging.JMSTestCase;
+
+import EDU.oswego.cs.dl.util.concurrent.CountDown;
+
+/**
+ * Basic jms tests.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 64261 $
+ */
+public class JBossJMSUnitTest extends JMSTestCase
+{
+ /** The default TopicFactory jndi name */
+ static String TOPIC_FACTORY = "ConnectionFactory";
+ /** The default QueueFactory jndi name */
+ static String QUEUE_FACTORY = "ConnectionFactory";
+
+ static String TEST_QUEUE = "queue/testQueue";
+ static String TEST_TOPIC = "topic/testTopic";
+ static String TEST_DURABLE_TOPIC = "topic/testDurableTopic";
+
+ //JMSProviderAdapter providerAdapter;
+ static Context context;
+ static QueueConnection queueConnection;
+ static TopicConnection topicConnection;
+
+ public JBossJMSUnitTest(String name) throws Exception
+ {
+ super(name);
+ }
+
+ // Emptys out all the messages in a queue
+ protected void drainQueue() throws Exception
+ {
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue) context.lookup(TEST_QUEUE);
+
+ QueueReceiver receiver = session.createReceiver(queue);
+ Message message = receiver.receive(50);
+ int c = 0;
+ while (message != null)
+ {
+ message = receiver.receive(50);
+ c++;
+ }
+
+ if (c != 0)
+ getLog().debug(" Drained " + c + " messages from the queue");
+
+ session.close();
+ }
+
+ protected void connect() throws Exception
+ {
+
+ if (context == null)
+ {
+
+ context = new InitialContext();
+
+ }
+ QueueConnectionFactory queueFactory = (QueueConnectionFactory) context.lookup(QUEUE_FACTORY);
+ queueConnection = queueFactory.createQueueConnection();
+
+ TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+ topicConnection = topicFactory.createTopicConnection();
+
+ getLog().debug("Connection to spyderMQ established.");
+
+ }
+
+ protected void disconnect() throws Exception
+ {
+ if (queueConnection != null)
+ {
+ queueConnection.close();
+ queueConnection = null;
+ }
+
+ if (topicConnection != null)
+ {
+ topicConnection.close();
+ topicConnection = null;
+ }
+ }
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ disconnect();
+ }
+
+ /**
+ * Test that messages are ordered by message arrival and priority.
+ * This also tests :
+ * Using a non-transacted AUTO_ACKNOWLEDGE session
+ * Using a QueueReceiver
+ * Using a QueueSender
+ * Sending PERSITENT and NON_PERSISTENT text messages.
+ * Using a QueueBrowser
+ */
+ public void testQueueMessageOrder() throws Exception
+ {
+
+ getLog().debug("Starting QueueMessageOrder test");
+
+ connect();
+
+ queueConnection.start();
+
+ drainQueue();
+
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue) context.lookup(TEST_QUEUE);
+ QueueSender sender = session.createSender(queue);
+
+ TextMessage message = session.createTextMessage();
+ message.setText("Normal message");
+ sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 0);
+ //sender.send(queue, message, DeliveryMode.NON_PERSISTENT, 4, 0);
+ message.setText("Persistent message");
+ sender.send(message, DeliveryMode.PERSISTENT, 4, 0);
+ //sender.send(queue, message, DeliveryMode.PERSISTENT, 4, 0);
+ message.setText("High Priority Persistent message");
+ sender.send(message, DeliveryMode.PERSISTENT, 10, 0);
+ //sender.send(queue, message, DeliveryMode.PERSISTENT, 10, 0);
+
+ //message.setText("Expiring Persistent message");
+ //sender.send(queue, message, DeliveryMode.NON_PERSISTENT, 4, 1);
+
+ QueueBrowser browser = session.createBrowser(queue);
+ Enumeration i = browser.getEnumeration();
+ //message = (TextMessage)enum.nextElement();
+ //if( !message.getText().equals("High Priority Persistent message") )
+ // throw new Exception("Queue is not prioritizing messages correctly. Unexpected Message:"+message);
+ getLog().debug(message.getText());
+
+ message = (TextMessage) i.nextElement();
+ //if( !message.getText().equals("Normal message") )
+ // throw new Exception("Queue is not ordering messages correctly. Unexpected Message:"+message);
+ getLog().debug(message.getText());
+
+ message = (TextMessage) i.nextElement();
+ //if( !message.getText().equals("Persistent message") )
+ // throw new Exception("Queue is not ordering messages correctly. Unexpected Message:"+message);
+ getLog().debug(message.getText());
+
+ // if( enum.hasMoreElements() )
+ // throw new Exception("Queue does not expire messages correctly. Unexpected Message:"+enum.nextElement());
+
+ disconnect();
+ getLog().debug("QueueMessageOrder passed");
+ }
+
+ /**
+ * Test that a using QueueRequestor works.
+ * this also tests that :
+ * temporary queues work.
+ */
+ public void testRequestReplyQueue() throws Exception
+ {
+
+ getLog().debug("Starting RequestReplyQueue test");
+ connect();
+
+ {
+ queueConnection.start();
+ drainQueue();
+ }
+
+ Thread serverThread = new Thread()
+ {
+ public void run()
+ {
+ Logger log = Logger.getLogger(getClass().getName());
+ try
+ {
+ log.debug("Server Thread Started");
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue) context.lookup(TEST_QUEUE);
+
+ QueueReceiver queueReceiver = session.createReceiver(queue);
+
+ boolean done = false;
+ while (!done)
+ {
+ TextMessage message = (TextMessage) queueReceiver.receive();
+ Queue tempQueue = (Queue) message.getJMSReplyTo();
+
+ QueueSender replySender = session.createSender(tempQueue);
+ TextMessage reply = session.createTextMessage();
+ reply.setText("Request Processed");
+ reply.setJMSCorrelationID(message.getJMSMessageID());
+ replySender.send(reply);
+
+ if (message.getText().equals("Quit"))
+ done = true;
+ }
+
+ session.close();
+ log.debug("Server Thread Finished");
+
+ }
+ catch (Exception e)
+ {
+ log.error("Error", e);
+ }
+ }
+ };
+
+ serverThread.start();
+
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue) context.lookup(TEST_QUEUE);
+
+ QueueRequestor queueRequestor = new QueueRequestor(session, queue);
+ TextMessage message = session.createTextMessage();
+ message.setText("Request Test");
+
+ for (int i = 0; i < 5; i++)
+ {
+
+ getLog().debug("Making client request #" + i);
+ TextMessage reply = (TextMessage) queueRequestor.request(message);
+ String replyID = new String(reply.getJMSCorrelationID());
+ if (!replyID.equals(message.getJMSMessageID()))
+ throw new Exception("REQUEST: ERROR: Reply does not match sent message");
+
+ }
+
+ getLog().debug("Making client request to shut server down.");
+ message.setText("Quit");
+ queueRequestor.request(message);
+
+ serverThread.join();
+ disconnect();
+
+ getLog().debug("RequestReplyQueue passed");
+ }
+
+ /**
+ * Test that temporary queues can be deleted.
+ */
+ public void testTemporaryQueueDelete() throws Exception
+ {
+
+ getLog().debug("Starting TemporaryQueueDelete test");
+ connect();
+
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ TemporaryQueue queue = session.createTemporaryQueue();
+
+ queue.delete();
+
+ disconnect();
+
+ getLog().debug("TemporaryQueueDelete passed");
+ }
+
+ /**
+ * Test that temporary topics can be deleted.
+ */
+ public void testTemporaryTopicDelete() throws Exception
+ {
+
+ getLog().debug("Starting TemporaryTopicDelete test");
+ connect();
+
+ TopicSession session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ TemporaryTopic topic = session.createTemporaryTopic();
+
+ topic.delete();
+
+ disconnect();
+
+ getLog().debug("TemporaryTopicDelete passed");
+ }
+
+ /**
+ * Test invalid destination trying to send a message.
+ */
+ public void testInvalidDestinationQueueSend() throws Exception
+ {
+
+ getLog().debug("Starting InvaidDestinationQueueSend test");
+ connect();
+
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ TemporaryQueue queue = session.createTemporaryQueue();
+ QueueSender sender = session.createSender(queue);
+ queue.delete();
+
+ TextMessage message = session.createTextMessage("hello");
+ boolean caught = false;
+ try
+ {
+ sender.send(message);
+ }
+ catch (InvalidDestinationException expected)
+ {
+ caught = true;
+ }
+
+ disconnect();
+
+ assertTrue("Expected an InvalidDestinationException", caught);
+
+ getLog().debug("InvaldDestinationQueueSend passed");
+ }
+
+ /**
+ * Test invalid destination trying to browse a message.
+ */
+ public void testInvalidDestinationQueueBrowse() throws Exception
+ {
+
+ getLog().debug("Starting InvalidDestinationQueueBrowse test");
+ connect();
+
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ TemporaryQueue queue = session.createTemporaryQueue();
+ QueueBrowser browser = session.createBrowser(queue);
+ queue.delete();
+
+ boolean caught = false;
+ try
+ {
+ browser.getEnumeration();
+ }
+ catch (InvalidDestinationException expected)
+ {
+ caught = true;
+ }
+
+ disconnect();
+
+ assertTrue("Expected an InvalidDestinationException", caught);
+
+ getLog().debug("InvalidDestinationQueueBrowse passed");
+ }
+
+ /**
+ * Test invalid destination trying to send a message.
+ */
+ public void testInvalidDestinationTopicPublish() throws Exception
+ {
+
+ getLog().debug("Starting InvaidDestinationTopicPublish test");
+ connect();
+
+ TopicSession session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ TemporaryTopic topic = session.createTemporaryTopic();
+ TopicPublisher publisher = session.createPublisher(topic);
+ topic.delete();
+
+ TextMessage message = session.createTextMessage("hello");
+ boolean caught = false;
+ try
+ {
+ publisher.publish(message);
+ }
+ catch (InvalidDestinationException expected)
+ {
+ caught = true;
+ }
+
+ disconnect();
+
+ assertTrue("Expected an InvalidDestinationException", caught);
+
+ getLog().debug("InvaldDestinationTopicPublish passed");
+ }
+
+ /**
+ * Test errors trying on topic subscribe.
+ */
+ public void testErrorsTopicSubscribe() throws Exception
+ {
+
+ getLog().debug("Starting InvalidDestinationTopicSubscribe test");
+ connect();
+
+ try
+ {
+ TopicSession session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic topic = (Topic) context.lookup(TEST_TOPIC);
+ TemporaryTopic temp = session.createTemporaryTopic();
+
+ boolean caught = false;
+ try
+ {
+ session.createSubscriber(null);
+ }
+ catch (InvalidDestinationException expected)
+ {
+ caught = true;
+ }
+ assertTrue("Expected an InvalidDestinationException for a null topic", caught);
+
+ caught = false;
+ try
+ {
+ session.createSubscriber(null, null, true);
+ }
+ catch (InvalidDestinationException expected)
+ {
+ caught = true;
+ }
+ assertTrue("Expected an InvalidDestinationException for a null topic", caught);
+
+ caught = false;
+ try
+ {
+ session.createDurableSubscriber(null, "NotUsed");
+ }
+ catch (InvalidDestinationException expected)
+ {
+ caught = true;
+ }
+ assertTrue("Expected an InvalidDestinationException for a null topic", caught);
+
+ caught = false;
+ try
+ {
+ session.createDurableSubscriber(temp, "NotUsed");
+ }
+ catch (InvalidDestinationException expected)
+ {
+ caught = true;
+ }
+ assertTrue("Expected an InvalidDestinationException for a temporary topic", caught);
+
+ caught = false;
+ try
+ {
+ session.createDurableSubscriber(null, "NotUsed", null, true);
+ }
+ catch (InvalidDestinationException expected)
+ {
+ caught = true;
+ }
+ assertTrue("Expected an InvalidDestinationException for a null topic", caught);
+
+ caught = false;
+ try
+ {
+ session.createDurableSubscriber(temp, "NotUsed", null, true);
+ }
+ catch (InvalidDestinationException expected)
+ {
+ caught = true;
+ }
+ assertTrue("Expected an InvalidDestinationException for a temporary topic", caught);
+
+ caught = false;
+ try
+ {
+ session.createDurableSubscriber(topic, null);
+ }
+ catch (Exception expected)
+ {
+ caught = true;
+ }
+ assertTrue("Expected a Exception for a null subscription", caught);
+
+ caught = false;
+ try
+ {
+ session.createDurableSubscriber(topic, null, null, false);
+ }
+ catch (Exception expected)
+ {
+ caught = true;
+ }
+ assertTrue("Expected a Exception for a null subscription", caught);
+
+ caught = false;
+ try
+ {
+ session.createDurableSubscriber(topic, " ");
+ }
+ catch (Exception expected)
+ {
+ caught = true;
+ }
+ assertTrue("Expected a Exception for an empty subscription", caught);
+
+ caught = false;
+ try
+ {
+ session.createDurableSubscriber(topic, " ", null, false);
+ }
+ catch (Exception expected)
+ {
+ caught = true;
+ }
+ assertTrue("Expected a Exception for an empty subscription", caught);
+ }
+ finally
+ {
+ disconnect();
+ }
+
+ getLog().debug("InvalidDestinationTopicSubscriber passed");
+ }
+
+ /**
+ * Test create queue.
+ */
+ public void testCreateQueue() throws Exception
+ {
+
+ getLog().debug("Starting create queue test");
+ connect();
+
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Queue jndiQueue = (Queue) getInitialContext().lookup("queue/testQueue");
+ Queue createQueue = session.createQueue(jndiQueue.getQueueName());
+ assertTrue("Failed for " + QUEUE_FACTORY, jndiQueue.equals(createQueue));
+
+ getLog().debug("InvalidDestinationTopicSubscriber passed");
+ }
+
+ public void testMessageListener() throws Exception
+ {
+ getLog().debug("Starting create queue test");
+
+ connect();
+ queueConnection.start();
+ drainQueue();
+ final CountDown counter1 = new CountDown(3);
+
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue) context.lookup(TEST_QUEUE);
+
+ QueueReceiver receiver = session.createReceiver(queue);
+ receiver.setMessageListener(new MessageListener()
+ {
+ public void onMessage(Message msg)
+ {
+ Logger log = Logger.getLogger(getClass().getName());
+ log.debug("ML");
+ try
+ {
+ if (msg instanceof TextMessage)
+ {
+ log.debug(((TextMessage) msg).getText());
+ counter1.release();
+ }
+ }
+ catch (Exception e)
+ {
+ }
+ }
+ });
+
+ QueueSender sender = session.createSender(queue);
+
+ TextMessage message = session.createTextMessage();
+ message.setText("Normal message");
+ sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 0);
+ //sender.send(queue, message, DeliveryMode.NON_PERSISTENT, 4, 0);
+ message.setText("Persistent message");
+ sender.send(message, DeliveryMode.PERSISTENT, 4, 0);
+ //sender.send(queue, message, DeliveryMode.PERSISTENT, 4, 0);
+ message.setText("High Priority Persistent message");
+ sender.send(message, DeliveryMode.PERSISTENT, 10, 0);
+ //sender.send(queue, message, DeliveryMode.PERSISTENT, 10, 0);
+
+ // Wait for the msgs to be received
+ counter1.acquire();
+ log.debug("MessageListener1 received the TMs sent");
+
+ final CountDown counter2 = new CountDown(2);
+ receiver.setMessageListener(new MessageListener()
+ {
+ public void onMessage(Message msg)
+ {
+ Logger log = Logger.getLogger(getClass().getName());
+ log.debug("ML 2");
+ try
+ {
+ if (msg instanceof TextMessage)
+ {
+ log.debug(((TextMessage) msg).getText());
+ counter2.release();
+ }
+ }
+ catch (Exception e)
+ {
+ }
+ }
+ });
+
+ message.setText("Persistent message");
+ sender.send(message, DeliveryMode.PERSISTENT, 4, 0);
+ //sender.send(queue, message, DeliveryMode.PERSISTENT, 4, 0);
+ message.setText("High Priority Persistent message");
+ sender.send(message, DeliveryMode.PERSISTENT, 10, 0);
+ //sender.send(queue, message, DeliveryMode.PERSISTENT, 10, 0);
+
+ // Wait for the msgs to be received
+ counter2.acquire();
+ log.debug("MessageListener2 received the TMs sent");
+
+ receiver.setMessageListener(null);
+
+ message.setText("Persistent message");
+ sender.send(message, DeliveryMode.PERSISTENT, 4, 0);
+ //sender.send(queue, message, DeliveryMode.PERSISTENT, 4, 0);
+ message.setText("High Priority Persistent message");
+ sender.send(message, DeliveryMode.PERSISTENT, 10, 0);
+ //sender.send(queue, message, DeliveryMode.PERSISTENT, 10, 0);
+
+ sender.close();
+ drainQueue();
+ disconnect();
+ getLog().debug("MessageListener test passed");
+ }
+
+ public void testApplicationServerStuff() throws Exception
+ {
+ getLog().debug("Starting testing app server stuff");
+ connect();
+
+ Queue testQueue = (Queue) context.lookup(TEST_QUEUE);
+ final QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ session.setMessageListener(new MessageListener()
+ {
+ public void onMessage(Message mess)
+ {
+ Logger log = Logger.getLogger(getClass().getName());
+ log.debug("Processing message");
+ try
+ {
+ if (mess instanceof TextMessage)
+ log.debug(((TextMessage) mess).getText());
+ }
+ catch (Exception e)
+ {
+ log.error("Error", e);
+ }
+ }
+ });
+
+ QueueSender sender = session.createSender(testQueue);
+ sender.send(session.createTextMessage("Hi"));
+ sender.send(session.createTextMessage("There"));
+ sender.send(session.createTextMessage("Guys"));
+ queueConnection.createConnectionConsumer(testQueue, null, new ServerSessionPool()
+ {
+ public ServerSession getServerSession()
+ {
+ Logger.getLogger(getClass().getName()).debug("Getting server session.");
+ return new ServerSession()
+ {
+ public Session getSession()
+ {
+ return session;
+ }
+ public void start()
+ {
+ Logger.getLogger(getClass().getName()).debug("Starting server session.");
+ session.run();
+ }
+ };
+ }
+ }, 10);
+
+ queueConnection.start();
+
+ try
+ {
+ Thread.sleep(5 * 1000);
+ }
+ catch (Exception e)
+ {
+ }
+
+ disconnect();
+ getLog().debug("Testing app server stuff passed");
+ }
+
+ //simply put a few messages on the test queue for next time.
+ /* public void testPM() throws Exception
+ {
+ getLog().debug("Starting testing pm");
+ connect();
+
+ Queue testQueue = (Queue)context.lookup(TEST_QUEUE);
+ QueueSession session = queueConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
+ QueueSender sender = session.createSender(testQueue);
+ sender.send(session.createTextMessage("From last time"));
+ sender.send(session.createTextMessage("From last time"));
+ sender.send(session.createTextMessage("From last time"));
+ sender.close();
+ session.close();
+ disconnect();
+ getLog().debug("Testing pm stuff passed");
+ }
+ */
+ private void drainMessagesForTopic(TopicSubscriber sub) throws JMSException
+ {
+ Message msg = sub.receive(50);
+ int c = 0;
+ while (msg != null)
+ {
+ c++;
+ if (msg instanceof TextMessage)
+ getLog().debug(((TextMessage) msg).getText());
+ msg = sub.receive(50);
+ }
+ getLog().debug("Received " + c + " messages from topic.");
+ }
+
+ public void testTopics() throws Exception
+ {
+ getLog().debug("Starting Topic test");
+ connect();
+
+ TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+ topicConnection = topicFactory.createTopicConnection("john", "needle");
+
+ topicConnection.start();
+
+ //set up some subscribers to the topic
+ TopicSession session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic topic = (Topic) context.lookup(TEST_TOPIC);
+
+ TopicSubscriber sub1 = session.createDurableSubscriber(topic, "sub1");
+ TopicSubscriber sub2 = session.createSubscriber(topic);
+ TopicSubscriber sub3 = session.createSubscriber(topic);
+
+ //Now a sender
+ TopicPublisher sender = session.createPublisher(topic);
+
+ //send some messages
+ sender.publish(session.createTextMessage("Message 1"));
+ sender.publish(session.createTextMessage("Message 2"));
+ sender.publish(session.createTextMessage("Message 3"));
+ drainMessagesForTopic(sub1);
+ drainMessagesForTopic(sub2);
+ drainMessagesForTopic(sub3);
+
+ //close some subscribers
+ sub1.close();
+ sub2.close();
+
+ //send some more messages
+ sender.publish(session.createTextMessage("Message 4"));
+ sender.publish(session.createTextMessage("Message 5"));
+ sender.publish(session.createTextMessage("Message 6"));
+
+ //give time for message 4 to be negatively acked (as it will be cause last receive timed out)
+ try
+ {
+ Thread.sleep(5 * 1000);
+ }
+ catch (InterruptedException e)
+ {
+ }
+
+ drainMessagesForTopic(sub3);
+
+ //open subscribers again.
+ sub1 = session.createDurableSubscriber(topic, "sub1");
+ sub2 = session.createSubscriber(topic);
+
+ //Send a final message
+ sender.publish(session.createTextMessage("Final message"));
+ sender.close();
+
+ drainMessagesForTopic(sub1);
+ drainMessagesForTopic(sub2);
+ drainMessagesForTopic(sub3);
+
+ sub1.close();
+ sub2.close();
+ sub3.close();
+
+ session.unsubscribe("sub1");
+
+ topicConnection.stop();
+ topicConnection.close();
+
+ disconnect();
+ getLog().debug("Topic test passed");
+ }
+
+ /**
+ * Test to seeif the NoLocal feature of topics works.
+ * Messages published from the same connection should not
+ * be received by Subscribers on the same connection.
+ */
+ public void testTopicNoLocal() throws Exception
+ {
+ getLog().debug("Starting TopicNoLocal test");
+ connect();
+
+ TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+ TopicConnection topicConnection1 = topicFactory.createTopicConnection();
+ topicConnection1.start();
+ TopicConnection topicConnection2 = topicFactory.createTopicConnection();
+ topicConnection2.start();
+
+ // We don't want local messages on this topic.
+ TopicSession session1 = topicConnection1.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic topic = (Topic) context.lookup(TEST_TOPIC);
+ TopicSubscriber subscriber1 = session1.createSubscriber(topic, null, true);
+ TopicPublisher sender1 = session1.createPublisher(topic);
+
+ //Now a sender
+ TopicSession session2 = topicConnection2.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ TopicPublisher sender2 = session2.createPublisher(topic);
+
+ drainMessagesForTopic(subscriber1);
+
+ //send some messages
+ sender1.publish(session1.createTextMessage("Local Message"));
+ sender2.publish(session2.createTextMessage("Remote Message"));
+
+ // Get the messages, we should get the remote message
+ // but not the local message
+ TextMessage msg1 = (TextMessage) subscriber1.receive(2000);
+ if (msg1 == null)
+ {
+ fail("Did not get any messages");
+ }
+ else
+ {
+ getLog().debug("Got message: " + msg1);
+ if (msg1.getText().equals("Local Message"))
+ {
+ fail("Got a local message");
+ }
+ TextMessage msg2 = (TextMessage) subscriber1.receive(2000);
+ if (msg2 != null)
+ {
+ getLog().debug("Got message: " + msg2);
+ fail("Got an extra message. msg1:" + msg1 + ", msg2:" + msg2);
+ }
+ }
+
+ topicConnection1.stop();
+ topicConnection1.close();
+ topicConnection2.stop();
+ topicConnection2.close();
+
+ disconnect();
+ getLog().debug("TopicNoLocal test passed");
+ }
+
+ /**
+ * Test to see whether no local works if a message
+ * was created somewhere else.
+ */
+ public void testTopicNoLocalBounce() throws Exception
+ {
+ getLog().debug("Starting TopicNoLocalBounce test");
+ connect();
+
+ TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+ TopicConnection topicConnection1 = topicFactory.createTopicConnection();
+ topicConnection1.start();
+ TopicConnection topicConnection2 = topicFactory.createTopicConnection();
+ topicConnection2.start();
+
+ // Session 1
+ TopicSession session1 = topicConnection1.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic topic = (Topic) context.lookup(TEST_TOPIC);
+ TopicSubscriber subscriber1 = session1.createSubscriber(topic, null, true);
+ TopicPublisher sender1 = session1.createPublisher(topic);
+
+ // Session 2
+ TopicSession session2 = topicConnection2.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ TopicSubscriber subscriber2 = session2.createSubscriber(topic, null, true);
+ TopicPublisher sender2 = session2.createPublisher(topic);
+
+ drainMessagesForTopic(subscriber1);
+ drainMessagesForTopic(subscriber2);
+
+ //send the message
+ sender1.publish(session1.createTextMessage("Message"));
+
+ assertTrue("Subscriber1 should not get a message", subscriber1.receiveNoWait() == null);
+ TextMessage msg = (TextMessage) subscriber2.receive(2000);
+ assertTrue("Subscriber2 should get a message, got " + msg, msg != null && msg.getText().equals("Message"));
+
+ //send it back
+ sender2.publish(msg);
+
+ msg = (TextMessage) subscriber1.receive(2000);
+ assertTrue("Subscriber1 should get a message, got " + msg, msg != null && msg.getText().equals("Message"));
+ assertTrue("Subscriber2 should not get a message", subscriber2.receiveNoWait() == null);
+
+ topicConnection1.stop();
+ topicConnection1.close();
+ topicConnection2.stop();
+ topicConnection2.close();
+
+ disconnect();
+ getLog().debug("TopicNoLocalBounce test passed");
+ }
+
+ /**
+ * Test subscribing to a topic with one selector, then changing to another
+ */
+ public void testTopicSelectorChange() throws Exception
+ {
+ getLog().debug("Starting TopicSelectorChange test");
+
+ getLog().debug("Create topic connection");
+ TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+ topicConnection = topicFactory.createTopicConnection("john", "needle");
+ topicConnection.start();
+
+ try
+ {
+ getLog().debug("Retrieving Topic");
+ Topic topic = (Topic) context.lookup(TEST_DURABLE_TOPIC);
+
+ getLog().debug("Creating a send session");
+ TopicSession sendSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ TopicPublisher sender = sendSession.createPublisher(topic);
+
+ getLog().debug("Clearing the topic");
+ TopicSession subSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ TopicSubscriber subscriber = subSession.createDurableSubscriber(topic, "test");
+ Message message = subscriber.receive(50);
+ while (message != null)
+ message = subscriber.receive(50);
+ subSession.close();
+
+ getLog().debug("Subscribing to topic, looking for Value = 'A'");
+ subSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ subscriber = subSession.createDurableSubscriber(topic, "test", "Value = 'A'", false);
+
+ getLog().debug("Send some messages");
+ message = sendSession.createTextMessage("Message1");
+ message.setStringProperty("Value", "A");
+ sender.publish(message);
+ message = sendSession.createTextMessage("Message2");
+ message.setStringProperty("Value", "A");
+ sender.publish(message);
+ message = sendSession.createTextMessage("Message3");
+ message.setStringProperty("Value", "B");
+ sender.publish(message);
+
+ getLog().debug("Retrieving the A messages");
+ message = subscriber.receive(2000);
+ assertTrue("Expected message 1", message != null);
+ assertTrue("Should get an A", message.getStringProperty("Value").equals("A"));
+ message = subscriber.receive(2000);
+ assertTrue("Expected message 2", message != null);
+ assertTrue("Should get a second A", message.getStringProperty("Value").equals("A"));
+ assertTrue("That should be it for A", subscriber.receive(2000) == null);
+
+ getLog().debug("Closing the subscriber without acknowledgement");
+ subSession.close();
+
+ getLog().debug("Subscribing to topic, looking for Value = 'B'");
+ subSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ subscriber = subSession.createDurableSubscriber(topic, "test", "Value = 'B'", false);
+
+ getLog().debug("Retrieving the non-existent B messages");
+ assertTrue("B should not be there", subscriber.receive(2000) == null);
+
+ getLog().debug("Closing the subscriber.");
+ subSession.close();
+
+ getLog().debug("Subscribing to topic, looking for those Value = 'A'");
+ subSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ subscriber = subSession.createDurableSubscriber(topic, "test", "Value = 'A'", false);
+ assertTrue("Should not be any A the subscription was changed", subscriber.receive(2000) == null);
+ subSession.close();
+
+ getLog().debug("Subscribing to topic, looking for everything");
+ subSession = topicConnection.createTopicSession(false, Session.CLIENT_ACKNOWLEDGE);
+ subscriber = subSession.createDurableSubscriber(topic, "test", null, false);
+
+ message = sendSession.createTextMessage("Message4");
+ message.setStringProperty("Value", "A");
+ sender.publish(message);
+
+ message = subscriber.receive(2000);
+ assertTrue("Expected message 4", message != null);
+ assertTrue("Should be an A which we don't acknowledge", message.getStringProperty("Value").equals("A"));
+ subSession.close();
+
+ getLog().debug("Subscribing to topic, looking for the Value = 'A'");
+ subSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ subscriber = subSession.createDurableSubscriber(topic, "test", "Value = 'A'", false);
+ assertTrue(
+ "Should not be any A, the subscription was changed. Even though the old and new selectors match the message",
+ subscriber.receive(2000) == null);
+ subSession.close();
+
+ getLog().debug("Closing the send session");
+ sendSession.close();
+
+ getLog().debug("Removing the subscription");
+ subSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ subSession.unsubscribe("test");
+
+ }
+ finally
+ {
+ getLog().debug("Closing the connection");
+ topicConnection.close();
+ }
+
+ getLog().debug("TopicSelectorChange test passed");
+ }
+
+ /**
+ * Test subscribing to a topic with a null and empty selector
+ */
+ public void testTopicSelectorNullOrEmpty() throws Exception
+ {
+ getLog().debug("Starting TopicSelectorNullOrEmpty test");
+
+ getLog().debug("Create topic connection");
+ TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+ topicConnection = topicFactory.createTopicConnection("john", "needle");
+ topicConnection.start();
+
+ try
+ {
+ getLog().debug("Retrieving Topic");
+ Topic topic = (Topic) context.lookup(TEST_DURABLE_TOPIC);
+
+ getLog().debug("Creating a send session");
+ TopicSession sendSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ TopicPublisher sender = sendSession.createPublisher(topic);
+
+ getLog().debug("Clearing the topic");
+ TopicSession subSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ TopicSubscriber subscriber = subSession.createDurableSubscriber(topic, "test");
+ TextMessage message = (TextMessage) subscriber.receive(50);
+ while (message != null)
+ message = (TextMessage) subscriber.receive(50);
+ subSession.close();
+
+ getLog().debug("Subscribing to topic, with null selector");
+ subSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ subscriber = subSession.createDurableSubscriber(topic, "test", null, false);
+
+ getLog().debug("Send a message");
+ message = sendSession.createTextMessage("Message1");
+ sender.publish(message);
+
+ getLog().debug("Retrieving the message");
+ message = (TextMessage) subscriber.receive(2000);
+ assertTrue("Expected message 1", message != null);
+ assertTrue("Should get Message1", message.getText().equals("Message1"));
+ getLog().debug("Closing the subscriber");
+ subSession.close();
+
+ getLog().debug("Subscribing to topic, with an empty selector");
+ subSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ subscriber = subSession.createDurableSubscriber(topic, "test", " ", false);
+
+ getLog().debug("Send a message");
+ message = sendSession.createTextMessage("Message2");
+ sender.publish(message);
+
+ getLog().debug("Retrieving the message");
+ message = (TextMessage) subscriber.receive(2000);
+ assertTrue("Expected message 2", message != null);
+ assertTrue("Should get Message2", message.getText().equals("Message2"));
+ getLog().debug("Closing the subscriber");
+
+ getLog().debug("Removing the subscription");
+ subSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ subSession.unsubscribe("test");
+ subSession.close();
+
+ }
+ finally
+ {
+ getLog().debug("Closing the connection");
+ topicConnection.close();
+ }
+
+ getLog().debug("TopicSelectorNullOrEmpty test passed");
+ }
+
+ /**
+ * Test sending/receiving an outdated message
+ */
+ public void testSendReceiveOutdated() throws Exception
+ {
+ getLog().debug("Starting SendReceiveOutdated test");
+
+ connect();
+ try
+ {
+ queueConnection.start();
+ drainQueue();
+ queueConnection.stop();
+
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue) context.lookup(TEST_QUEUE);
+ QueueSender sender = session.createSender(queue);
+ QueueReceiver receiver = session.createReceiver(queue);
+
+ // Send a message that has expired
+ TextMessage message = session.createTextMessage("Outdated");
+ sender.send(message, DeliveryMode.PERSISTENT, 4, 1);
+ Thread.sleep(100);
+
+ // Send a message that has not expired
+ message = session.createTextMessage("OK");
+ sender.send(message);
+
+ // Try to receive the message the not expired message
+ queueConnection.start();
+ message = (TextMessage) receiver.receiveNoWait();
+ assertEquals("OK", message.getText());
+
+ // Should be no more
+ assertTrue("Didn't expect anymore messages", receiver.receiveNoWait() == null);
+ }
+ finally
+ {
+ disconnect();
+ }
+
+ getLog().debug("SendReceiveOutdated test passed");
+ }
+
+ public void testSendReceiveExpired() throws Exception
+ {
+ getLog().debug("Starting testSendReceiveExpired test");
+
+ connect();
+ try
+ {
+ queueConnection.start();
+ drainQueue();
+
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue) context.lookup(TEST_QUEUE);
+ QueueSender sender = session.createSender(queue);
+ QueueReceiver receiver = session.createReceiver(queue);
+
+ // Send a message that expires in 5 seconds
+ TextMessage message = session.createTextMessage("5 Second Expiration");
+ sender.send(message, DeliveryMode.PERSISTENT, 4, 5*1000);
+ // Send a message that has not expired
+ message = session.createTextMessage("OK");
+ sender.send(message);
+ // Sleep 6 seconds
+ Thread.sleep(6*1000);
+ // Try to receive the OK message
+ message = (TextMessage) receiver.receiveNoWait();
+ assertEquals("OK", message.getText());
+
+ // Should be no more
+ assertTrue("Didn't expect anymore messages", receiver.receiveNoWait() == null);
+
+ // Send a message that expires in 10 seconds
+ message = session.createTextMessage("10 Second Expiration");
+ sender.send(message, DeliveryMode.PERSISTENT, 4, 10*1000);
+ // Send a message that has not expired
+ message = session.createTextMessage("OK");
+ sender.send(message);
+ // Sleep 1 seconds
+ Thread.sleep(1*1000);
+ // Try to receive the messages
+ message = (TextMessage) receiver.receiveNoWait();
+ assertEquals("10 Second Expiration", message.getText());
+ message = (TextMessage) receiver.receiveNoWait();
+ assertEquals("OK", message.getText());
+
+ // Should be no more
+ assertTrue("Didn't expect anymore messages", receiver.receiveNoWait() == null);
+
+ // Test that JMSExpiration has no affect
+ message = session.createTextMessage("5 Second Expiration");
+ message.setJMSExpiration(System.currentTimeMillis() + 5*1000);
+ sender.send(message, DeliveryMode.PERSISTENT, 4, 0);
+ // Send a message that has not expired
+ message = session.createTextMessage("OK");
+ sender.send(message);
+ // Sleep 6 seconds
+ Thread.sleep(6*1000);
+ // Try to receive the OK message
+ message = (TextMessage) receiver.receiveNoWait();
+ assertEquals("5 Second Expiration", message.getText());
+ message = (TextMessage) receiver.receiveNoWait();
+ assertEquals("OK", message.getText());
+ assertTrue("Didn't expect anymore messages", receiver.receiveNoWait() == null);
+ }
+ finally
+ {
+ disconnect();
+ }
+ }
+
+ class Synch
+ {
+ boolean waiting = false;
+ String text;
+ public synchronized void doWait(long timeout) throws InterruptedException
+ {
+ waiting = true;
+ this.wait(timeout);
+ }
+ public synchronized void doNotify() throws InterruptedException
+ {
+ while (waiting == false)
+ wait(100);
+ this.notifyAll();
+ }
+ public String getText()
+ {
+ return text;
+ }
+ public void setText(String text)
+ {
+ this.text = text;
+ }
+ }
+
+ /**
+ * Test sending/listening an outdated message
+ */
+ public void testSendListenOutdated() throws Exception
+ {
+ getLog().debug("Starting SendListenOutdated test");
+
+ connect();
+ try
+ {
+ queueConnection.start();
+ drainQueue();
+ queueConnection.stop();
+
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue) context.lookup(TEST_QUEUE);
+ QueueSender sender = session.createSender(queue);
+ QueueReceiver receiver = session.createReceiver(queue);
+
+ // Send a message that has expired
+ TextMessage message = session.createTextMessage("Outdated");
+ sender.send(message, DeliveryMode.PERSISTENT, 4, 1);
+ Thread.sleep(100);
+
+ // Send a message that has not expired
+ message = session.createTextMessage("OK");
+ sender.send(message);
+
+ // Try to receive the message the not expired message
+ final Synch synch = new Synch();
+ MessageListener messagelistener = new MessageListener()
+ {
+ public void onMessage(Message message)
+ {
+ listenOutdated(message, synch);
+ }
+ };
+ receiver.setMessageListener(messagelistener);
+ queueConnection.start();
+
+ synch.doWait(10000);
+ assertEquals("OK", synch.getText());
+ }
+ finally
+ {
+ disconnect();
+ }
+
+ getLog().debug("SendListenOutdated test passed");
+ }
+
+ private void listenOutdated(Message message, Synch synch)
+ {
+ try
+ {
+ synch.setText(((TextMessage) message).getText());
+ }
+ catch (Throwable t)
+ {
+ log.error("Error:", t);
+ }
+ finally
+ {
+ try
+ {
+ synch.doNotify();
+ }
+ catch (Throwable t)
+ {
+ log.error("Error:", t);
+ }
+ }
+ }
+}
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/JBossMessagingJoramUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/JBossMessagingJoramUnitTestCase.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/JBossMessagingJoramUnitTestCase.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbossmessaging.test;
+
+import junit.framework.Test;
+
+import org.jboss.test.AbstractTestDelegate;
+import org.jboss.test.jbossmq.test.JBossMQJoramUnitTestCase;
+
+/**
+ * Joram unit tests
+ *
+ * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
+ * @version $Revision: 64152 $
+ */
+public class JBossMessagingJoramUnitTestCase extends org.jboss.test.jms.JoramUnitTestCase
+{
+ public JBossMessagingJoramUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * Get the test delegate
+ *
+ * @param clazz the test class
+ * @return the delegate
+ * @throws Exception for any error
+ */
+ public static AbstractTestDelegate getDelegate(Class clazz) throws Exception
+ {
+ return getDelegate(clazz, "org.jboss.test.jbossmessaging.JBossMessagingAdmin");
+ }
+
+ public static Test suite() throws Exception
+ {
+ return getTestSuite(JBossMessagingJoramUnitTestCase.class);
+ }
+
+}
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/JBossSessionRecoverUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/JBossSessionRecoverUnitTestCase.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/JBossSessionRecoverUnitTestCase.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,555 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbossmessaging.test;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.ObjectMessage;
+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.Session;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.jboss.test.jbossmessaging.JMSTestCase;
+
+/**
+ * JBossSessionRecoverUnitTestCase.java
+ *
+ * a simple session.recover test of JBossMQ
+ *
+ * @author Seth Sites
+ * @version $Revision: 64130 $
+ */
+
+public class JBossSessionRecoverUnitTestCase extends JMSTestCase
+{
+ String QUEUE_FACTORY = "ConnectionFactory";
+ String TEST_QUEUE = "queue/testQueue";
+
+ Context context;
+ QueueConnection queueConnection;
+ QueueSession session;
+ int counter=0;
+ Exception exception=null;
+
+ public JBossSessionRecoverUnitTestCase(String name) throws Exception
+ {
+ super(name);
+ }
+
+ protected void setUp()
+ throws Exception
+ {
+ // call setUp() in superclass
+ super.setUp() ;
+
+ this.getLog().debug("JBossSessionRecoverUnitTestCase, ConnectionFactory started");
+ }
+
+ protected void tearDown() throws Exception
+ {
+ this.getLog().debug("JBossSessionRecoverUnitTestCase, ConnectionFactory done");
+
+ // call tearDown() in superclass
+ super.tearDown() ;
+ }
+
+ // Emptys out all the messages in a queue
+ private void drainQueue() throws Exception
+ {
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue)context.lookup(TEST_QUEUE);
+
+ QueueReceiver receiver = session.createReceiver(queue);
+ Message message = receiver.receive( 1000 );
+
+ int c=0;
+ while( message != null )
+ {
+ message = receiver.receive( 1000 );
+ c++;
+ }
+
+ if( c!=0 )
+ getLog().debug(" Drained "+c+" messages from the queue");
+
+ session.close();
+ }
+
+ static public void main ( String []args )
+ {
+ String newArgs[] = { "org.jboss.test.jbossmq.test.JBossSessionRecoverUnitTestCase" };
+ junit.swingui.TestRunner.main(newArgs);
+ }
+
+ protected void connect() throws Exception
+ {
+ if( context == null )
+ {
+ context = new InitialContext();
+ }
+
+ QueueConnectionFactory queueFactory = (QueueConnectionFactory) context.lookup(QUEUE_FACTORY);
+ queueConnection = queueFactory.createQueueConnection();
+
+ getLog().debug("Connection to JBossMQ established.");
+ }
+
+ /**
+ * Test that session.recover works with a message listener
+ */
+ public void testQueueSessionRecovermessageListener() throws Exception
+ {
+ counter = 0;
+ getLog().debug("Starting session.recover() Message Listener test");
+
+ connect();
+ queueConnection.start();
+ drainQueue();
+
+ session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue)context.lookup(TEST_QUEUE);
+ QueueSender sender = session.createSender(queue);
+
+ // send 20 messages to the queue
+ for ( int i=0; i<20; i++ )
+ {
+ sender.send(session.createObjectMessage(new Integer(i)));
+ }
+
+ //close the session, so we can start one with CLIENT_ACKNOWLEDGE
+ session.close();
+ queueConnection.stop();
+ session = queueConnection.createQueueSession( false, Session.CLIENT_ACKNOWLEDGE );
+
+ //create our receiver
+ QueueReceiver receiver = session.createReceiver( queue );
+ MessageListener messagelistener = new MessageListener()
+ {
+ public void onMessage(Message message)
+ {
+ processMessage( message );
+ }
+ };
+
+ receiver.setMessageListener( messagelistener );
+ queueConnection.start();
+
+ //since we put in 20 messages and recovered after receiving 20 we should receive those 20
+ //back and get 40 total
+ while ( counter < 40 && exception == null )
+ {
+ try
+ {
+ Thread.sleep( 500 );
+ }
+ catch ( InterruptedException ie )
+ {
+ }
+ }
+
+ if ( exception != null )
+ {
+ queueConnection.close();
+ throw exception;
+ }
+
+ queueConnection.close();
+ getLog().debug("session.recover() Message Listener passed");
+ }
+
+ private void processMessage ( Message message )
+ {
+ try
+ {
+ if ( message instanceof ObjectMessage )
+ {
+ counter++;
+ ObjectMessage objectmessage = (ObjectMessage)message;
+ Integer integer = (Integer)objectmessage.getObject();
+ int mynumber = integer.intValue();
+ getLog().debug("message object " + integer + " counter=" + counter );
+
+ if ( mynumber == 19 )
+ {
+ if (counter == 20)
+ {
+ session.recover();
+ }
+ else
+ {
+ message.acknowledge();
+ }
+ }
+ }
+ }
+ catch ( JMSException e )
+ {
+ exception = e;
+ }
+ }
+
+ class Synch
+ {
+ boolean waiting = false;
+ public synchronized void doWait(long timeout)
+ throws InterruptedException
+ {
+ waiting = true;
+ this.wait(timeout);
+ }
+ public synchronized void doNotify()
+ throws InterruptedException
+ {
+ while (waiting == false)
+ wait(100);
+ this.notifyAll();
+ }
+ }
+
+
+ /**
+ * Test that session.recover delivers messages in the correct orer
+ */
+ public void testQueueSessionRecoverMessageListenerOrder()
+ throws Exception
+ {
+ counter = 0;
+ exception = null;
+ getLog().debug("Starting session.recover() Message Listener Order test");
+
+ connect();
+ queueConnection.start();
+ drainQueue();
+
+ session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue)context.lookup(TEST_QUEUE);
+ QueueSender sender = session.createSender(queue);
+
+ // send 4 messages to the queue
+ for (int i=0; i<4; ++i)
+ {
+ sender.send(session.createObjectMessage(new Integer(i)));
+ }
+
+ //create our receiver
+ QueueReceiver receiver = session.createReceiver( queue );
+ final Synch synch = new Synch();
+ MessageListener messagelistener = new MessageListener()
+ {
+ public void onMessage(Message message)
+ {
+ checkMessagesInOrder(session, message, synch);
+ }
+ };
+
+ receiver.setMessageListener( messagelistener );
+ queueConnection.start();
+ synch.doWait(10000);
+
+ if ( exception != null )
+ {
+ queueConnection.close();
+ throw exception;
+ }
+
+ queueConnection.close();
+ getLog().debug("session.recover() Message Listener Order passed");
+ }
+
+ private void checkMessagesInOrder(Session session, Message message, Synch synch)
+ {
+ try
+ {
+ ObjectMessage objectmessage = (ObjectMessage)message;
+ Integer integer = (Integer)objectmessage.getObject();
+ int mynumber = integer.intValue();
+
+ if (message.getJMSRedelivered() == false)
+ {
+ log.debug("Recovering " + mynumber);
+ session.recover();
+ return;
+ }
+
+ log.debug("Checking " + mynumber);
+ assertTrue("Expected messages in order", mynumber == counter);
+ counter++;
+ if (counter == 4)
+ synch.doNotify();
+ }
+ catch (Exception e)
+ {
+ exception = e;
+ }
+ }
+
+
+
+ /**
+ * Test that session.recover works with receive
+ */
+ public void testQueueSessionRecoverReceive() throws Exception
+ {
+ counter = 0;
+ getLog().debug("Starting session.recover() receive test");
+
+ connect();
+ queueConnection.start();
+ drainQueue();
+
+ session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue)context.lookup(TEST_QUEUE);
+ QueueSender sender = session.createSender(queue);
+
+ // send 20 messages to the queue
+ for ( int i=0; i<20; i++ )
+ {
+ sender.send(session.createObjectMessage(new Integer(i)));
+ }
+
+ //close the session, so we can start one with CLIENT_ACKNOWLEDGE
+ session.close();
+ queueConnection.stop();
+ session = queueConnection.createQueueSession( false, Session.CLIENT_ACKNOWLEDGE );
+
+ //create our receiver
+ QueueReceiver receiver = session.createReceiver( queue );
+ queueConnection.start();
+
+ Message message = receiver.receive( 1000 );
+ int messagecounter=0;
+ while( message != null )
+ {
+ message = receiver.receive( 1000 );
+ messagecounter++;
+ }
+
+ if ( messagecounter != 20 )
+ {
+ throw new Exception ( "Not all sent messages were delivered! messagecounter=" + messagecounter );
+ }
+
+ //we got all of our messages, let's recover
+ session.recover();
+ message = receiver.receive();
+ messagecounter=0;
+
+ while( message != null )
+ {
+ if ( !message.getJMSRedelivered() )
+ {
+ throw new Exception ( "Message was not marked as redelivered! messagecounter=" + messagecounter );
+ }
+
+ message.acknowledge();
+ messagecounter++;
+
+ //workaround to keep from timing out since there are no more message on the server
+ if ( messagecounter < 15 )
+ {
+ message = receiver.receive();
+ }
+ else
+ {
+ message = receiver.receive ( 1000 );
+ }
+ }
+
+ if ( messagecounter != 20 )
+ {
+ throw new Exception ( "Not all unacknowledged messages were redelivered! messagecounter=" + messagecounter );
+ }
+
+ queueConnection.close();
+ getLog().debug("session.recover() receive passed");
+ }
+
+ /**
+ * Test that session.recover works with receive(timeout)
+ */
+ public void testQueueSessionRecoverReceiveTimeout() throws Exception
+ {
+ counter = 0;
+ getLog().debug("Starting session.recover() receive(timeout) test");
+
+ connect();
+ queueConnection.start();
+ drainQueue();
+
+
+
+ session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue)context.lookup(TEST_QUEUE);
+ QueueSender sender = session.createSender(queue);
+
+ // send 20 messages to the queue
+ for ( int i=0; i<20; i++ )
+ {
+ sender.send(session.createObjectMessage(new Integer(i)));
+ }
+
+ //close the session, so we can start one with CLIENT_ACKNOWLEDGE
+ session.close();
+ queueConnection.stop();
+ session = queueConnection.createQueueSession( false, Session.CLIENT_ACKNOWLEDGE );
+
+ //create our receiver
+ QueueReceiver receiver = session.createReceiver( queue );
+ queueConnection.start();
+
+ Message message = receiver.receive( 1000 );
+ int messagecounter=0;
+
+ while( message != null )
+ {
+ message = receiver.receive( 1000 );
+ messagecounter++;
+ }
+
+ if ( messagecounter != 20 )
+ {
+ throw new Exception ( "Not all sent messages were delivered! messagecounter=" + messagecounter );
+ }
+
+ //we got all of our messages, let's recover
+ session.recover();
+ message = receiver.receive(1000);
+ messagecounter=0;
+
+ while( message != null )
+ {
+ if ( !message.getJMSRedelivered() )
+ {
+ throw new Exception ( "Message was not marked as redelivered! messagecounter=" + messagecounter );
+ }
+
+ message.acknowledge();
+ messagecounter++;
+ message = receiver.receive( 1000 );
+ }
+
+ if ( messagecounter != 20 )
+ {
+ throw new Exception ( "Not all unacknowledged messages were redelivered! messagecounter=" + messagecounter );
+ }
+
+ queueConnection.close();
+ getLog().debug("session.recover() receive(timeout) passed");
+ }
+
+ /**
+ * Test that session.recover works with receiveNoWait
+ */
+ public void testQueueSessionRecoverReceiveNoWait() throws Exception
+ {
+ counter = 0;
+
+ getLog().debug("Starting session.recover() receiveNoWait test");
+
+
+
+ connect();
+
+
+ queueConnection.start();
+ drainQueue();
+
+ session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue)context.lookup(TEST_QUEUE);
+ QueueSender sender = session.createSender(queue);
+
+ // send 20 messages to the queue
+ for ( int i=0; i<20; i++ )
+ {
+ sender.send(session.createObjectMessage(new Integer(i)));
+ }
+
+ //close the session, so we can start one with CLIENT_ACKNOWLEDGE
+ session.close();
+ queueConnection.stop();
+ session = queueConnection.createQueueSession( false, Session.CLIENT_ACKNOWLEDGE );
+
+ //create our receiver
+ QueueReceiver receiver = session.createReceiver( queue );
+ queueConnection.start();
+
+ //NOTE! The semantics of receiveNoWait do not guarantee the message is available
+ //immediately after the message is sent
+ //It will be available some indeterminate time later.
+ //This is fine and as per spec.
+ //To implement receiveNoWait otherwise would be very costly
+ //Also other messaging systems e.g. Sun implement it this way
+
+ Thread.sleep(1000);
+
+ Message message = receiver.receiveNoWait();
+ int messagecounter=0;
+
+ while( message != null )
+ {
+ message = receiver.receiveNoWait();
+ messagecounter++;
+ }
+
+ if ( messagecounter != 20 )
+ {
+ throw new Exception ( "Not all sent messages were delivered! messagecounter=" + messagecounter );
+ }
+
+ //we got all of our messages, let's recover
+ session.recover();
+
+ // See previous note on sleep
+ Thread.sleep(1000);
+
+ message = receiver.receiveNoWait();
+ messagecounter=0;
+
+ while( message != null )
+ {
+ if ( !message.getJMSRedelivered() )
+ {
+ throw new Exception ( "Message was not marked as redelivered! messagecounter=" + messagecounter );
+ }
+
+ message.acknowledge();
+ messagecounter++;
+ message = receiver.receiveNoWait();
+ }
+
+ if ( messagecounter != 20 )
+ {
+ throw new Exception ( "Not all unacknowledged messages were redelivered! messagecounter=" + messagecounter );
+ }
+
+ queueConnection.close();
+ getLog().debug("session.recover() receiveNoWait passed");
+ }
+
+}
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/Jms11UnitTest.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/Jms11UnitTest.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/Jms11UnitTest.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,1226 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbossmessaging.test;
+
+import java.util.Enumeration;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.InvalidDestinationException;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.QueueBrowser;
+import javax.jms.ServerSession;
+import javax.jms.ServerSessionPool;
+import javax.jms.Session;
+import javax.jms.TemporaryQueue;
+import javax.jms.TemporaryTopic;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicSubscriber;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import EDU.oswego.cs.dl.util.concurrent.CountDown;
+import org.jboss.logging.Logger;
+import org.jboss.test.jbossmessaging.JMSTestCase;
+import org.jboss.test.jbossmessaging.perf.JMSPerfStressTestCase;
+
+/**
+ * Basic tests using the jms 1.1 producer/consumer apis.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 64261 $
+ */
+public class Jms11UnitTest extends JMSTestCase
+{
+ /** The default TopicFactory jndi name */
+ static String TOPIC_FACTORY = "ConnectionFactory";
+ /** The default QueueFactory jndi name */
+ static String QUEUE_FACTORY = "ConnectionFactory";
+
+ static String TEST_QUEUE = "queue/testQueue";
+ static String TEST_TOPIC = "topic/testTopic";
+ static String TEST_DURABLE_TOPIC = "topic/testDurableTopic";
+
+ //JMSProviderAdapter providerAdapter;
+ static Context context;
+ static Connection queueConnection;
+ static Connection topicConnection;
+
+ public Jms11UnitTest(String name) throws Exception
+ {
+ super(name);
+ }
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ disconnect();
+
+ }
+
+ // Emptys out all the messages in a queue
+ protected void drainQueue() throws Exception
+ {
+ Session session = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue) context.lookup(TEST_QUEUE);
+
+ MessageConsumer receiver = session.createConsumer(queue);
+ Message message = receiver.receive(50);
+ int c = 0;
+ while (message != null)
+ {
+ message = receiver.receive(50);
+ c++;
+ }
+
+ if (c != 0)
+ getLog().debug(" Drained " + c + " messages from the queue");
+
+ session.close();
+ }
+
+ protected void connect() throws Exception
+ {
+ if (context == null)
+ {
+ context = new InitialContext();
+ }
+ ConnectionFactory queueFactory = (ConnectionFactory) context.lookup(QUEUE_FACTORY);
+ queueConnection = queueFactory.createConnection();
+
+ ConnectionFactory topicFactory = (ConnectionFactory) context.lookup(TOPIC_FACTORY);
+ topicConnection = topicFactory.createConnection();
+ getLog().debug("Connection to JBossMQ established.");
+ }
+
+ protected void disconnect() throws Exception
+ {
+ if (queueConnection!=null)
+ {
+ queueConnection.close();
+ queueConnection = null;
+ }
+
+ if (topicConnection != null)
+ {
+ topicConnection.close();
+ topicConnection = null;
+ }
+ }
+
+ /**
+ * Test that messages are ordered by message arrival and priority.
+ * This also tests :
+ * Using a non-transacted AUTO_ACKNOWLEDGE session
+ * Using a MessageConsumer
+ * Using a QueueSender
+ * Sending PERSITENT and NON_PERSISTENT text messages.
+ * Using a QueueBrowser
+ */
+ public void testQueueMessageOrder() throws Exception
+ {
+
+ getLog().debug("Starting QueueMessageOrder test");
+
+ connect();
+
+ queueConnection.start();
+
+ drainQueue();
+
+ Session session = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue) context.lookup(TEST_QUEUE);
+ MessageProducer sender = session.createProducer(queue);
+
+ TextMessage message = session.createTextMessage();
+ message.setText("Normal message");
+ sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 0);
+ message.setText("Persistent message");
+ sender.send(message, DeliveryMode.PERSISTENT, 4, 0);
+ message.setText("High Priority Persistent message");
+ sender.send(message, DeliveryMode.PERSISTENT, 10, 0);
+
+ QueueBrowser browser = session.createBrowser(queue);
+ Enumeration i = browser.getEnumeration();
+ getLog().debug(message.getText());
+
+ message = (TextMessage) i.nextElement();
+ getLog().debug(message.getText());
+
+ message = (TextMessage) i.nextElement();
+ getLog().debug(message.getText());
+
+ disconnect();
+ getLog().debug("QueueMessageOrder passed");
+ }
+
+ /**
+ * Test that temporary queues can be deleted.
+ */
+ public void testTemporaryQueueDelete() throws Exception
+ {
+
+ getLog().debug("Starting TemporaryQueueDelete test");
+ connect();
+
+ Session session = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ TemporaryQueue queue = session.createTemporaryQueue();
+
+ queue.delete();
+
+ disconnect();
+
+ getLog().debug("TemporaryQueueDelete passed");
+ }
+
+ /**
+ * Test that temporary topics can be deleted.
+ */
+ public void testTemporaryTopicDelete() throws Exception
+ {
+
+ getLog().debug("Starting TemporaryTopicDelete test");
+ connect();
+
+ Session session = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ TemporaryTopic topic = session.createTemporaryTopic();
+
+ topic.delete();
+
+ disconnect();
+
+ getLog().debug("TemporaryTopicDelete passed");
+ }
+
+ /**
+ * Test invalid destination trying to send a message.
+ */
+ public void testInvalidDestinationQueueSend() throws Exception
+ {
+
+ getLog().debug("Starting InvaidDestinationQueueSend test");
+ connect();
+
+ Session session = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ TemporaryQueue queue = session.createTemporaryQueue();
+ MessageProducer sender = session.createProducer(queue);
+ queue.delete();
+
+ TextMessage message = session.createTextMessage("hello");
+ boolean caught = false;
+ try
+ {
+ sender.send(message);
+ }
+ catch (InvalidDestinationException expected)
+ {
+ caught = true;
+ }
+
+ disconnect();
+
+ assertTrue("Expected an InvalidDestinationException", caught);
+
+ getLog().debug("InvaldDestinationQueueSend passed");
+ }
+
+ /**
+ * Test invalid destination trying to browse a message.
+ */
+ public void testInvalidDestinationQueueBrowse() throws Exception
+ {
+
+ getLog().debug("Starting InvalidDestinationQueueBrowse test");
+ connect();
+
+ Session session = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ TemporaryQueue queue = session.createTemporaryQueue();
+ QueueBrowser browser = session.createBrowser(queue);
+ queue.delete();
+
+ boolean caught = false;
+ try
+ {
+ browser.getEnumeration();
+ }
+ catch (InvalidDestinationException expected)
+ {
+ caught = true;
+ }
+
+ disconnect();
+
+ assertTrue("Expected an InvalidDestinationException", caught);
+
+ getLog().debug("InvalidDestinationQueueBrowse passed");
+ }
+
+ /**
+ * Test invalid destination trying to send a message.
+ */
+ public void testInvalidDestinationTopicPublish() throws Exception
+ {
+
+ getLog().debug("Starting InvaidDestinationTopicPublish test");
+ connect();
+
+ Session session = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ TemporaryTopic topic = session.createTemporaryTopic();
+ MessageProducer publisher = session.createProducer(topic);
+ topic.delete();
+
+ TextMessage message = session.createTextMessage("hello");
+ boolean caught = false;
+ try
+ {
+ publisher.send(message);
+ }
+ catch (InvalidDestinationException expected)
+ {
+ caught = true;
+ }
+
+ disconnect();
+
+ assertTrue("Expected an InvalidDestinationException", caught);
+
+ getLog().debug("InvaldDestinationTopicPublish passed");
+ }
+
+ /**
+ * Test errors trying on topic subscribe.
+ */
+ public void testErrorsTopicSubscribe() throws Exception
+ {
+
+ getLog().debug("Starting InvalidDestinationTopicSubscribe test");
+ connect();
+
+ try
+ {
+ Session session = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic topic = (Topic) context.lookup(TEST_TOPIC);
+ TemporaryTopic temp = session.createTemporaryTopic();
+
+ boolean caught = false;
+ try
+ {
+ session.createConsumer(null);
+ }
+ catch (InvalidDestinationException expected)
+ {
+ caught = true;
+ }
+ assertTrue("Expected an InvalidDestinationException for a null topic", caught);
+
+ caught = false;
+ try
+ {
+ session.createConsumer(null, null, true);
+ }
+ catch (InvalidDestinationException expected)
+ {
+ caught = true;
+ }
+ assertTrue("Expected an InvalidDestinationException for a null topic", caught);
+
+ caught = false;
+ try
+ {
+ session.createDurableSubscriber(null, "NotUsed");
+ }
+ catch (InvalidDestinationException expected)
+ {
+ caught = true;
+ }
+ assertTrue("Expected an InvalidDestinationException for a null topic", caught);
+
+ caught = false;
+ try
+ {
+ session.createDurableSubscriber(temp, "NotUsed");
+ }
+ catch (InvalidDestinationException expected)
+ {
+ caught = true;
+ }
+ assertTrue("Expected an InvalidDestinationException for a temporary topic", caught);
+
+ caught = false;
+ try
+ {
+ session.createDurableSubscriber(null, "NotUsed", null, true);
+ }
+ catch (InvalidDestinationException expected)
+ {
+ caught = true;
+ }
+ assertTrue("Expected an InvalidDestinationException for a null topic", caught);
+
+ caught = false;
+ try
+ {
+ session.createDurableSubscriber(temp, "NotUsed", null, true);
+ }
+ catch (InvalidDestinationException expected)
+ {
+ caught = true;
+ }
+ assertTrue("Expected an InvalidDestinationException for a temporary topic", caught);
+
+ caught = false;
+ try
+ {
+ session.createDurableSubscriber(topic, null);
+ }
+ catch (Exception expected)
+ {
+ caught = true;
+ }
+ assertTrue("Expected a Exception for a null subscription", caught);
+
+ caught = false;
+ try
+ {
+ session.createDurableSubscriber(topic, null, null, false);
+ }
+ catch (Exception expected)
+ {
+ caught = true;
+ }
+ assertTrue("Expected a Exception for a null subscription", caught);
+
+ caught = false;
+ try
+ {
+ session.createDurableSubscriber(topic, " ");
+ }
+ catch (Exception expected)
+ {
+ caught = true;
+ }
+ assertTrue("Expected a Exception for an empty subscription", caught);
+
+ caught = false;
+ try
+ {
+ session.createDurableSubscriber(topic, " ", null, false);
+ }
+ catch (Exception expected)
+ {
+ caught = true;
+ }
+ assertTrue("Expected a Exception for an empty subscription", caught);
+ }
+ finally
+ {
+ disconnect();
+ }
+
+ getLog().debug("InvalidDestinationTopicSubscriber passed");
+ }
+
+ /**
+ * Test create queue.
+ */
+ public void testCreateQueue() throws Exception
+ {
+
+ getLog().debug("Starting create queue test");
+ connect();
+
+ Session session = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Queue jndiQueue = (Queue) getInitialContext().lookup("queue/testQueue");
+ Queue createQueue = session.createQueue(jndiQueue.getQueueName());
+ assertTrue("Failed for " + QUEUE_FACTORY, jndiQueue.equals(createQueue));
+
+ getLog().debug("InvalidDestinationTopicSubscriber passed");
+ }
+
+ public void testMessageListener() throws Exception
+ {
+ getLog().debug("Starting create queue test");
+
+ connect();
+ queueConnection.start();
+ drainQueue();
+ final CountDown counter1 = new CountDown(3);
+
+ Session session = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue) context.lookup(TEST_QUEUE);
+
+ MessageConsumer receiver = session.createConsumer(queue);
+ receiver.setMessageListener(new MessageListener()
+ {
+ public void onMessage(Message msg)
+ {
+ Logger log = Logger.getLogger(getClass().getName());
+ log.debug("ML");
+ try
+ {
+ if (msg instanceof TextMessage)
+ {
+ log.debug(((TextMessage) msg).getText());
+ counter1.release();
+ }
+ }
+ catch (Exception e)
+ {
+ }
+ }
+ });
+
+ MessageProducer sender = session.createProducer(queue);
+
+ TextMessage message = session.createTextMessage();
+ message.setText("Normal message");
+ sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 0);
+ //sender.send(queue, message, DeliveryMode.NON_PERSISTENT, 4, 0);
+ message.setText("Persistent message");
+ sender.send(message, DeliveryMode.PERSISTENT, 4, 0);
+ //sender.send(queue, message, DeliveryMode.PERSISTENT, 4, 0);
+ message.setText("High Priority Persistent message");
+ sender.send(message, DeliveryMode.PERSISTENT, 10, 0);
+ //sender.send(queue, message, DeliveryMode.PERSISTENT, 10, 0);
+
+ // Wait for the msgs to be received
+ counter1.acquire();
+ log.debug("MessageListener1 received the TMs sent");
+
+ final CountDown counter2 = new CountDown(2);
+ receiver.setMessageListener(new MessageListener()
+ {
+ public void onMessage(Message msg)
+ {
+ Logger log = Logger.getLogger(getClass().getName());
+ log.debug("ML 2");
+ try
+ {
+ if (msg instanceof TextMessage)
+ {
+ log.debug(((TextMessage) msg).getText());
+ counter2.release();
+ }
+ }
+ catch (Exception e)
+ {
+ }
+ }
+ });
+
+ message.setText("Persistent message");
+ sender.send(message, DeliveryMode.PERSISTENT, 4, 0);
+ //sender.send(queue, message, DeliveryMode.PERSISTENT, 4, 0);
+ message.setText("High Priority Persistent message");
+ sender.send(message, DeliveryMode.PERSISTENT, 10, 0);
+ //sender.send(queue, message, DeliveryMode.PERSISTENT, 10, 0);
+
+ // Wait for the msgs to be received
+ counter2.acquire();
+ log.debug("MessageListener2 received the TMs sent");
+
+ receiver.setMessageListener(null);
+
+ message.setText("Persistent message");
+ sender.send(message, DeliveryMode.PERSISTENT, 4, 0);
+ //sender.send(queue, message, DeliveryMode.PERSISTENT, 4, 0);
+ message.setText("High Priority Persistent message");
+ sender.send(message, DeliveryMode.PERSISTENT, 10, 0);
+ //sender.send(queue, message, DeliveryMode.PERSISTENT, 10, 0);
+
+ sender.close();
+ drainQueue();
+ disconnect();
+ getLog().debug("MessageListener test passed");
+ }
+
+ public void testApplicationServerStuff() throws Exception
+ {
+ getLog().debug("Starting testing app server stuff");
+ connect();
+
+ Queue testQueue = (Queue) context.lookup(TEST_QUEUE);
+ final Session session = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ session.setMessageListener(new MessageListener()
+ {
+ public void onMessage(Message mess)
+ {
+ Logger log = Logger.getLogger(getClass().getName());
+ log.debug("Processing message");
+ try
+ {
+ if (mess instanceof TextMessage)
+ log.debug(((TextMessage) mess).getText());
+ }
+ catch (Exception e)
+ {
+ log.error("Error", e);
+ }
+ }
+ });
+
+ MessageProducer sender = session.createProducer(testQueue);
+ sender.send(session.createTextMessage("Hi"));
+ sender.send(session.createTextMessage("There"));
+ sender.send(session.createTextMessage("Guys"));
+ queueConnection.createConnectionConsumer(testQueue, null, new ServerSessionPool()
+ {
+ public ServerSession getServerSession()
+ {
+ Logger.getLogger(getClass().getName()).debug("Getting server session.");
+ return new ServerSession()
+ {
+ public Session getSession()
+ {
+ return session;
+ }
+ public void start()
+ {
+ Logger.getLogger(getClass().getName()).debug("Starting server session.");
+ session.run();
+ }
+ };
+ }
+ }, 10);
+
+ queueConnection.start();
+
+ try
+ {
+ Thread.sleep(5 * 1000);
+ }
+ catch (Exception e)
+ {
+ }
+
+ disconnect();
+ getLog().debug("Testing app server stuff passed");
+ }
+
+ private void drainMessagesForTopic(MessageConsumer sub) throws JMSException
+ {
+ Message msg = sub.receive(50);
+ int c = 0;
+ while (msg != null)
+ {
+ c++;
+ if (msg instanceof TextMessage)
+ getLog().debug(((TextMessage) msg).getText());
+ msg = sub.receive(50);
+ }
+ getLog().debug("Received " + c + " messages from topic.");
+ }
+
+ public void testTopics() throws Exception
+ {
+ getLog().debug("Starting Topic test");
+ connect();
+
+ TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+ topicConnection = topicFactory.createTopicConnection("john", "needle");
+
+ topicConnection.start();
+
+ //set up some subscribers to the topic
+ Session session = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic topic = (Topic) context.lookup(TEST_TOPIC);
+
+ TopicSubscriber sub1 = session.createDurableSubscriber(topic, "sub1");
+ MessageConsumer sub2 = session.createConsumer(topic);
+ MessageConsumer sub3 = session.createConsumer(topic);
+
+ //Now a sender
+ MessageProducer sender = session.createProducer(topic);
+
+ //send some messages
+ sender.send(session.createTextMessage("Message 1"));
+ sender.send(session.createTextMessage("Message 2"));
+ sender.send(session.createTextMessage("Message 3"));
+ drainMessagesForTopic(sub1);
+ drainMessagesForTopic(sub2);
+ drainMessagesForTopic(sub3);
+
+ //close some subscribers
+ sub1.close();
+ sub2.close();
+
+ //send some more messages
+ sender.send(session.createTextMessage("Message 4"));
+ sender.send(session.createTextMessage("Message 5"));
+ sender.send(session.createTextMessage("Message 6"));
+
+ //give time for message 4 to be negatively acked (as it will be cause last receive timed out)
+ try
+ {
+ Thread.sleep(5 * 1000);
+ }
+ catch (InterruptedException e)
+ {
+ }
+
+ drainMessagesForTopic(sub3);
+
+ //open subscribers again.
+ sub1 = session.createDurableSubscriber(topic, "sub1");
+ sub2 = session.createConsumer(topic);
+
+ //Send a final message
+ sender.send(session.createTextMessage("Final message"));
+ sender.close();
+
+ drainMessagesForTopic(sub1);
+ drainMessagesForTopic(sub2);
+ drainMessagesForTopic(sub3);
+
+ sub1.close();
+ sub2.close();
+ sub3.close();
+
+ session.unsubscribe("sub1");
+
+ topicConnection.stop();
+ topicConnection.close();
+
+ disconnect();
+ getLog().debug("Topic test passed");
+ }
+
+ /**
+ * Test to seeif the NoLocal feature of topics works.
+ * Messages sended from the same connection should not
+ * be received by Subscribers on the same connection.
+ */
+ public void testTopicNoLocal() throws Exception
+ {
+ getLog().debug("Starting TopicNoLocal test");
+ connect();
+
+ TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+ TopicConnection topicConnection1 = topicFactory.createTopicConnection();
+ topicConnection1.start();
+ TopicConnection topicConnection2 = topicFactory.createTopicConnection();
+ topicConnection2.start();
+
+ // We don't want local messages on this topic.
+ Session session1 = topicConnection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic topic = (Topic) context.lookup(TEST_TOPIC);
+ MessageConsumer subscriber1 = session1.createConsumer(topic, null, true);
+ MessageProducer sender1 = session1.createProducer(topic);
+
+ //Now a sender
+ Session session2 = topicConnection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer sender2 = session2.createProducer(topic);
+
+ drainMessagesForTopic(subscriber1);
+
+ //send some messages
+ sender1.send(session1.createTextMessage("Local Message"));
+ sender2.send(session2.createTextMessage("Remote Message"));
+
+ // Get the messages, we should get the remote message
+ // but not the local message
+ TextMessage msg1 = (TextMessage) subscriber1.receive(2000);
+ if (msg1 == null)
+ {
+ fail("Did not get any messages");
+ }
+ else
+ {
+ getLog().debug("Got message: " + msg1);
+ if (msg1.getText().equals("Local Message"))
+ {
+ fail("Got a local message");
+ }
+ TextMessage msg2 = (TextMessage) subscriber1.receive(2000);
+ if (msg2 != null)
+ {
+ getLog().debug("Got message: " + msg2);
+ fail("Got an extra message. msg1:" + msg1 + ", msg2:" + msg2);
+ }
+ }
+
+ topicConnection1.stop();
+ topicConnection1.close();
+ topicConnection2.stop();
+ topicConnection2.close();
+
+ disconnect();
+ getLog().debug("TopicNoLocal test passed");
+ }
+
+ /**
+ * Test to see whether no local works if a message
+ * was created somewhere else.
+ */
+ public void testTopicNoLocalBounce() throws Exception
+ {
+ getLog().debug("Starting TopicNoLocalBounce test");
+ connect();
+
+ TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+ TopicConnection topicConnection1 = topicFactory.createTopicConnection();
+ topicConnection1.start();
+ TopicConnection topicConnection2 = topicFactory.createTopicConnection();
+ topicConnection2.start();
+
+ // Session 1
+ Session session1 = topicConnection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic topic = (Topic) context.lookup(TEST_TOPIC);
+ MessageConsumer subscriber1 = session1.createConsumer(topic, null, true);
+ MessageProducer sender1 = session1.createProducer(topic);
+
+ // Session 2
+ Session session2 = topicConnection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer subscriber2 = session2.createConsumer(topic, null, true);
+ MessageProducer sender2 = session2.createProducer(topic);
+
+ drainMessagesForTopic(subscriber1);
+ drainMessagesForTopic(subscriber2);
+
+ //send the message
+ sender1.send(session1.createTextMessage("Message"));
+
+ assertTrue("Subscriber1 should not get a message", subscriber1.receiveNoWait() == null);
+ TextMessage msg = (TextMessage) subscriber2.receive(2000);
+ assertTrue("Subscriber2 should get a message, got " + msg, msg != null && msg.getText().equals("Message"));
+
+ //send it back
+ sender2.send(msg);
+
+ msg = (TextMessage) subscriber1.receive(2000);
+ assertTrue("Subscriber1 should get a message, got " + msg, msg != null && msg.getText().equals("Message"));
+ assertTrue("Subscriber2 should not get a message", subscriber2.receiveNoWait() == null);
+
+ topicConnection1.stop();
+ topicConnection1.close();
+ topicConnection2.stop();
+ topicConnection2.close();
+
+ disconnect();
+ getLog().debug("TopicNoLocalBounce test passed");
+ }
+
+ /**
+ * Test subscribing to a topic with one selector, then changing to another
+ */
+ public void testTopicSelectorChange() throws Exception
+ {
+ getLog().debug("Starting TopicSelectorChange test");
+
+ getLog().debug("Create topic connection");
+ TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+ topicConnection = topicFactory.createTopicConnection("john", "needle");
+ topicConnection.start();
+
+ try
+ {
+ getLog().debug("Retrieving Topic");
+ Topic topic = (Topic) context.lookup(TEST_DURABLE_TOPIC);
+
+ getLog().debug("Creating a send session");
+ Session sendSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer sender = sendSession.createProducer(topic);
+
+ getLog().debug("Clearing the topic");
+ Session subSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer subscriber = subSession.createDurableSubscriber(topic, "test");
+ Message message = subscriber.receive(50);
+ while (message != null)
+ message = subscriber.receive(50);
+ subSession.close();
+
+ getLog().debug("Subscribing to topic, looking for Value = 'A'");
+ subSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ subscriber = subSession.createDurableSubscriber(topic, "test", "Value = 'A'", false);
+
+ getLog().debug("Send some messages");
+ message = sendSession.createTextMessage("Message1");
+ message.setStringProperty("Value", "A");
+ sender.send(message);
+ message = sendSession.createTextMessage("Message2");
+ message.setStringProperty("Value", "A");
+ sender.send(message);
+ message = sendSession.createTextMessage("Message3");
+ message.setStringProperty("Value", "B");
+ sender.send(message);
+
+ getLog().debug("Retrieving the A messages");
+ message = subscriber.receive(2000);
+ assertTrue("Expected message 1", message != null);
+ assertTrue("Should get an A", message.getStringProperty("Value").equals("A"));
+ message = subscriber.receive(2000);
+ assertTrue("Expected message 2", message != null);
+ assertTrue("Should get a second A", message.getStringProperty("Value").equals("A"));
+ assertTrue("That should be it for A", subscriber.receive(2000) == null);
+
+ getLog().debug("Closing the subscriber without acknowledgement");
+ subSession.close();
+
+ getLog().debug("Subscribing to topic, looking for Value = 'B'");
+ subSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ subscriber = subSession.createDurableSubscriber(topic, "test", "Value = 'B'", false);
+
+ getLog().debug("Retrieving the non-existent B messages");
+ assertTrue("B should not be there", subscriber.receive(2000) == null);
+
+ getLog().debug("Closing the subscriber.");
+ subSession.close();
+
+ getLog().debug("Subscribing to topic, looking for those Value = 'A'");
+ subSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ subscriber = subSession.createDurableSubscriber(topic, "test", "Value = 'A'", false);
+ assertTrue("Should not be any A the subscription was changed", subscriber.receive(2000) == null);
+ subSession.close();
+
+ getLog().debug("Subscribing to topic, looking for everything");
+ subSession = topicConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+ subscriber = subSession.createDurableSubscriber(topic, "test", null, false);
+
+ message = sendSession.createTextMessage("Message4");
+ message.setStringProperty("Value", "A");
+ sender.send(message);
+
+ message = subscriber.receive(2000);
+ assertTrue("Expected message 4", message != null);
+ assertTrue("Should be an A which we don't acknowledge", message.getStringProperty("Value").equals("A"));
+ subSession.close();
+
+ getLog().debug("Subscribing to topic, looking for the Value = 'A'");
+ subSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ subscriber = subSession.createDurableSubscriber(topic, "test", "Value = 'A'", false);
+ assertTrue(
+ "Should not be any A, the subscription was changed. Even though the old and new selectors match the message",
+ subscriber.receive(2000) == null);
+ subSession.close();
+
+ getLog().debug("Closing the send session");
+ sendSession.close();
+
+ getLog().debug("Removing the subscription");
+ subSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ subSession.unsubscribe("test");
+
+ }
+ finally
+ {
+ getLog().debug("Closing the connection");
+ topicConnection.close();
+ }
+
+ getLog().debug("TopicSelectorChange test passed");
+ }
+
+ /**
+ * Test subscribing to a topic with a null and empty selector
+ */
+ public void testTopicSelectorNullOrEmpty() throws Exception
+ {
+ getLog().debug("Starting TopicSelectorNullOrEmpty test");
+
+ getLog().debug("Create topic connection");
+ TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+ topicConnection = topicFactory.createTopicConnection("john", "needle");
+ topicConnection.start();
+
+ try
+ {
+ getLog().debug("Retrieving Topic");
+ Topic topic = (Topic) context.lookup(TEST_DURABLE_TOPIC);
+
+ getLog().debug("Creating a send session");
+ Session sendSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer sender = sendSession.createProducer(topic);
+
+ getLog().debug("Clearing the topic");
+ Session subSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer subscriber = subSession.createDurableSubscriber(topic, "test");
+ TextMessage message = (TextMessage) subscriber.receive(50);
+ while (message != null)
+ message = (TextMessage) subscriber.receive(50);
+ subSession.close();
+
+ getLog().debug("Subscribing to topic, with null selector");
+ subSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ subscriber = subSession.createDurableSubscriber(topic, "test", null, false);
+
+ getLog().debug("Send a message");
+ message = sendSession.createTextMessage("Message1");
+ sender.send(message);
+
+ getLog().debug("Retrieving the message");
+ message = (TextMessage) subscriber.receive(2000);
+ assertTrue("Expected message 1", message != null);
+ assertTrue("Should get Message1", message.getText().equals("Message1"));
+ getLog().debug("Closing the subscriber");
+ subSession.close();
+
+ getLog().debug("Subscribing to topic, with an empty selector");
+ subSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ subscriber = subSession.createDurableSubscriber(topic, "test", " ", false);
+
+ getLog().debug("Send a message");
+ message = sendSession.createTextMessage("Message2");
+ sender.send(message);
+
+ getLog().debug("Retrieving the message");
+ message = (TextMessage) subscriber.receive(2000);
+ assertTrue("Expected message 2", message != null);
+ assertTrue("Should get Message2", message.getText().equals("Message2"));
+ getLog().debug("Closing the subscriber");
+
+ getLog().debug("Removing the subscription");
+ subSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ subSession.unsubscribe("test");
+ subSession.close();
+
+ }
+ finally
+ {
+ getLog().debug("Closing the connection");
+ topicConnection.close();
+ }
+
+ getLog().debug("TopicSelectorNullOrEmpty test passed");
+ }
+
+ /**
+ * Test sending/receiving an outdated message
+ */
+ public void testSendReceiveOutdated() throws Exception
+ {
+ getLog().debug("Starting SendReceiveOutdated test");
+
+ connect();
+ try
+ {
+ queueConnection.start();
+ drainQueue();
+ queueConnection.stop();
+
+ Session session = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue) context.lookup(TEST_QUEUE);
+ MessageProducer sender = session.createProducer(queue);
+ MessageConsumer receiver = session.createConsumer(queue);
+
+ // Send a message that has expired
+ TextMessage message = session.createTextMessage("Outdated");
+ sender.send(message, DeliveryMode.PERSISTENT, 4, 1);
+ Thread.sleep(100);
+
+ // Send a message that has not expired
+ message = session.createTextMessage("OK");
+ sender.send(message);
+
+ // Try to receive the message the not expired message
+ queueConnection.start();
+ message = (TextMessage) receiver.receiveNoWait();
+ assertEquals("OK", message.getText());
+
+ // Should be no more
+ assertTrue("Didn't expect anymore messages", receiver.receiveNoWait() == null);
+ }
+ finally
+ {
+ disconnect();
+ }
+
+ getLog().debug("SendReceiveOutdated test passed");
+ }
+
+ public void testSendReceiveExpired() throws Exception
+ {
+ getLog().debug("Starting testSendReceiveExpired test");
+
+ connect();
+ try
+ {
+ queueConnection.start();
+ drainQueue();
+
+ Session session = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue) context.lookup(TEST_QUEUE);
+ MessageProducer sender = session.createProducer(queue);
+ MessageConsumer receiver = session.createConsumer(queue);
+
+ // Send a message that expires in 5 seconds
+ TextMessage message = session.createTextMessage("5 Second Expiration");
+ sender.send(message, DeliveryMode.PERSISTENT, 4, 5*1000);
+ // Send a message that has not expired
+ message = session.createTextMessage("OK");
+ sender.send(message);
+ // Sleep 6 seconds
+ Thread.sleep(6*1000);
+ // Try to receive the OK message
+ message = (TextMessage) receiver.receiveNoWait();
+ assertEquals("OK", message.getText());
+
+ // Should be no more
+ assertTrue("Didn't expect anymore messages", receiver.receiveNoWait() == null);
+
+ // Send a message that expires in 10 seconds
+ message = session.createTextMessage("10 Second Expiration");
+ sender.send(message, DeliveryMode.PERSISTENT, 4, 10*1000);
+ // Send a message that has not expired
+ message = session.createTextMessage("OK");
+ sender.send(message);
+ // Sleep 1 seconds
+ Thread.sleep(1*1000);
+ // Try to receive the messages
+ message = (TextMessage) receiver.receiveNoWait();
+ assertEquals("10 Second Expiration", message.getText());
+ message = (TextMessage) receiver.receiveNoWait();
+ assertEquals("OK", message.getText());
+
+ // Should be no more
+ assertTrue("Didn't expect anymore messages", receiver.receiveNoWait() == null);
+
+ // Test that JMSExpiration has no affect
+ message = session.createTextMessage("5 Second Expiration");
+ message.setJMSExpiration(System.currentTimeMillis() + 5*1000);
+ sender.send(message, DeliveryMode.PERSISTENT, 4, 0);
+ // Send a message that has not expired
+ message = session.createTextMessage("OK");
+ sender.send(message);
+ // Sleep 6 seconds
+ Thread.sleep(6*1000);
+ // Try to receive the OK message
+ message = (TextMessage) receiver.receiveNoWait();
+ assertEquals("5 Second Expiration", message.getText());
+ message = (TextMessage) receiver.receiveNoWait();
+ assertEquals("OK", message.getText());
+ assertTrue("Didn't expect anymore messages", receiver.receiveNoWait() == null);
+ }
+ finally
+ {
+ disconnect();
+ }
+ }
+
+ class Synch
+ {
+ boolean waiting = false;
+ String text;
+ public synchronized void doWait(long timeout) throws InterruptedException
+ {
+ waiting = true;
+ this.wait(timeout);
+ }
+ public synchronized void doNotify() throws InterruptedException
+ {
+ while (waiting == false)
+ wait(100);
+ this.notifyAll();
+ }
+ public String getText()
+ {
+ return text;
+ }
+ public void setText(String text)
+ {
+ this.text = text;
+ }
+ }
+
+ /**
+ * Test sending/listening an outdated message
+ */
+ public void testSendListenOutdated() throws Exception
+ {
+ getLog().debug("Starting SendListenOutdated test");
+
+ connect();
+ try
+ {
+ queueConnection.start();
+ drainQueue();
+ queueConnection.stop();
+
+ Session session = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue) context.lookup(TEST_QUEUE);
+ MessageProducer sender = session.createProducer(queue);
+ MessageConsumer receiver = session.createConsumer(queue);
+
+ // Send a message that has expired
+ TextMessage message = session.createTextMessage("Outdated");
+ sender.send(message, DeliveryMode.PERSISTENT, 4, 1);
+ Thread.sleep(100);
+
+ // Send a message that has not expired
+ message = session.createTextMessage("OK");
+ sender.send(message);
+
+ // Try to receive the message the not expired message
+ final Synch synch = new Synch();
+ MessageListener messagelistener = new MessageListener()
+ {
+ public void onMessage(Message message)
+ {
+ listenOutdated(message, synch);
+ }
+ };
+ receiver.setMessageListener(messagelistener);
+ queueConnection.start();
+
+ synch.doWait(10000);
+ assertEquals("OK", synch.getText());
+ }
+ finally
+ {
+ disconnect();
+ }
+
+ getLog().debug("SendListenOutdated test passed");
+ }
+
+ private void listenOutdated(Message message, Synch synch)
+ {
+ try
+ {
+ synch.setText(((TextMessage) message).getText());
+ }
+ catch (Throwable t)
+ {
+ log.error("Error:", t);
+ }
+ finally
+ {
+ try
+ {
+ synch.doNotify();
+ }
+ catch (Throwable t)
+ {
+ log.error("Error:", t);
+ }
+ }
+ }
+}
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/MessageBodyUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/MessageBodyUnitTestCase.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/MessageBodyUnitTestCase.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,340 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbossmessaging.test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.ObjectMessage;
+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.Session;
+import javax.jms.TextMessage;
+import javax.naming.Context;
+
+import org.jboss.logging.Logger;
+import org.jboss.test.jbossmessaging.JMSTestCase;
+
+/**
+ * Tests message bodies.
+ *
+ * @author <a href="mailto:richard.achmatowicz at jboss.com">Richard Achmatowicz</a>
+ * @author Loren Rosen (submitted patch)
+ * @author <a href="mailto:jason at planet57.com">Jason Dillon</a>
+ * @version $Revision: 64265 $
+ */
+public class MessageBodyUnitTestCase extends JMSTestCase
+{
+ // Provider specific
+ public static final String QUEUE_FACTORY = "ConnectionFactory";
+ public static final String TEST_QUEUE = "queue/testQueue";
+
+ Context context;
+ QueueConnection queueConnection;
+ QueueSession session;
+ Queue queue;
+
+ QueueReceiver receiver;
+ QueueSender sender;
+
+ public MessageBodyUnitTestCase(String name) throws Exception
+ {
+ super(name);
+ }
+
+ protected void setUp() throws Exception
+ {
+ // call setUp() in the superclass
+ super.setUp() ;
+
+ connect();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ disconnect();
+
+ // call tearDown() in the superclass to cleanup
+ super.tearDown() ;
+ }
+
+ protected void connect() throws Exception
+ {
+ getLog().debug("connecting");
+ if (context == null)
+ {
+ context = getInitialContext();
+ }
+
+ QueueConnectionFactory queueFactory = (QueueConnectionFactory) context.lookup(QUEUE_FACTORY);
+ queueConnection = queueFactory.createQueueConnection();
+ getLog().debug("connected");
+
+ queueConnection.start();
+ session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ getLog().debug("session established");
+
+ queue = (Queue) context.lookup(TEST_QUEUE);
+
+ receiver = session.createReceiver(queue);
+ sender = session.createSender(queue);
+ getLog().debug("sender established");
+
+ drainQueue();
+ getLog().debug("end of connect call");
+ }
+
+ protected void disconnect() throws Exception
+ {
+ queueConnection.close();
+ }
+
+ private void drainQueue() throws Exception
+ {
+ getLog().debug("draining queue");
+
+ Message message = receiver.receive(2000);
+ int c = 0;
+ while (message != null)
+ {
+ message = receiver.receive(2000);
+ c++;
+ }
+
+ if (c != 0)
+ getLog().debug("Drained " + c + " messages from the queue");
+
+ getLog().debug("drained queue");
+
+ }
+
+ protected void validate(String payload) throws Exception
+ {
+ getLog().debug("validating text |" + payload + "|");
+
+ TextMessage outMessage = session.createTextMessage();
+ outMessage.setText(payload);
+ getLog().debug("sending |" + payload + "|");
+ sender.send(outMessage);
+
+ getLog().debug("receiving |" + payload + "|");
+ TextMessage inMessage = (TextMessage) receiver.receive();
+ getLog().debug("received |" + payload + "|");
+ String inPayload = inMessage.getText();
+
+ assertEquals("Message body text test", payload, inPayload);
+ getLog().debug("validated text " + payload);
+ }
+
+ public void testTextMessageBody() throws Exception
+ {
+ getLog().debug("testing text");
+
+ validate("ordinary text");
+ validate(" ");
+ validate("");
+ // very long strings, non-printable ASCII strings
+ char c[] = new char[1024 * 32];
+ Arrays.fill(c, 'x');
+ validate(new String(c));
+ Arrays.fill(c, '\u0130'); // I with dot
+ validate(new String(c));
+ Arrays.fill(c, '\u0008');
+ validate(new String(c));
+ getLog().debug("tested text");
+ }
+
+ protected void validate(java.io.Serializable payload) throws Exception
+ {
+ ObjectMessage outMessage = session.createObjectMessage();
+ outMessage.setObject(payload);
+ sender.send(outMessage);
+
+ ObjectMessage inMessage = (ObjectMessage) receiver.receive();
+ Object inPayload = inMessage.getObject();
+
+ assertEquals("Message body object test", payload, inPayload);
+ }
+
+ public void testObjectMessageBody() throws Exception
+ {
+ getLog().debug("testing object");
+ validate(new Integer(0));
+ validate(new Integer(1));
+ validate(new Integer(-1));
+ validate(new Integer(Integer.MAX_VALUE));
+ validate(new Integer(Integer.MIN_VALUE));
+ validate(new Integer(-1));
+ validate(new Float(1.0));
+ validate(new Float(0.0));
+ validate(new Float(-1.0));
+ validate(new Float(Float.MAX_VALUE));
+ validate(new Float(Float.MIN_VALUE));
+ validate(new Float(Float.NaN));
+ validate(new Float(Float.POSITIVE_INFINITY));
+ validate(new Float(Float.NEGATIVE_INFINITY));
+ validate(new Float(1.0));
+ HashMap m = new HashMap(); // Fill with serializable stuff
+ m.put("file", new java.io.File("somefile.txt"));
+ m.put("url", new java.net.URL("http://example.net"));
+ validate(m);
+ validate((java.io.Serializable)Collections.nCopies(10000, "Repeat"));
+ }
+
+ /**
+ * Test null properties.
+ */
+ public void testNullProperties() throws Exception
+ {
+ TextMessage message = session.createTextMessage();
+
+ message.setStringProperty("THE_PROP", null);
+ message.setObjectProperty("THE_PROP2", null);
+
+ try
+ {
+ message.setStringProperty("", null);
+ fail("empty string property");
+ }
+ catch (IllegalArgumentException e) {}
+
+ try
+ {
+ message.setStringProperty(null, null);
+ fail("null property");
+ }
+ catch (IllegalArgumentException e) {}
+ }
+
+ public void testInvalidPropertyName() throws Exception
+ {
+ Message message = session.createMessage();
+
+ String[] invalid = new String[]
+ {
+ "invalid-hyphen",
+ "1digitfirst",
+ "NULL",
+ "TRUE",
+ "FALSE",
+ "NOT",
+ "AND",
+ "OR",
+ "BETWEEN",
+ "LIKE",
+ "IN",
+ "IS",
+ "ESCAPE"
+ };
+
+ for (int i = 0; i < invalid.length; ++i)
+ {
+ try
+ {
+ message.setStringProperty(invalid[i], "whatever");
+ fail("expected error for invalid property name " + invalid[i]);
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ }
+
+ String[] valid = new String[]
+ {
+ "identifier",
+ "_",
+ "$",
+ "_xSx",
+ "$x_x",
+ "A1",
+ "null",
+ "true",
+ "false",
+ "not",
+ "and",
+ "or",
+ "between",
+ "like",
+ "in",
+ "is",
+ "escape"
+ };
+
+ for (int i = 0; i < invalid.length; ++i)
+ message.setStringProperty(valid[i], "whatever");
+ }
+
+ /**
+ * Test vendor properties.
+ * Test disabled for JBossMessaging
+ */
+ /*public void testVendorProperties() throws Exception
+ {
+ TextMessage message = session.createTextMessage();
+
+ System.out.println("hello!!!");
+
+ try
+ {
+ message.setStringProperty("JMS_JBOSS_SCHEDULED_DELIVERY", "whenever");
+ fail("invalid type");
+ }
+ catch (JMSException e) {
+ e.printStackTrace();
+ }
+ try
+ {
+ message.setObjectProperty("JMS_JBOSS_SCHEDULED_DELIVERY", "10234");
+ fail("invalid type");
+ }
+ catch (JMSException e) {
+ e.printStackTrace();
+ }
+ try
+ {
+ message.setStringProperty("JMS_JBOSS_REDELIVERY_COUNT", "fruity");
+ fail("invalid type");
+ }
+ catch (JMSException e) {
+ e.printStackTrace();
+ }
+ try
+ {
+ message.setStringProperty("JMS_JBOSS_REDELIVERY_LIMIT", "fruity");
+ fail("invalid type");
+ }
+ catch (JMSException e) {
+ e.printStackTrace();
+ }
+
+ message.setLongProperty("JMS_JBOSS_SCHEDULED_DELIVERY", 10234);
+ message.setIntProperty("JMS_JBOSS_REDELIVERY_COUNT", 123);
+ message.setShortProperty("JMS_JBOSS_REDELIVERY_LIMIT", (short)1);
+ } */
+
+}
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/MessageTypesUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/MessageTypesUnitTestCase.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/MessageTypesUnitTestCase.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,267 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbossmessaging.test;
+
+import java.util.Arrays;
+import java.math.BigInteger;
+import javax.jms.DeliveryMode;
+import javax.jms.MapMessage;
+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.Session;
+import javax.jms.TextMessage;
+import javax.jms.BytesMessage;
+import javax.jms.ObjectMessage;
+import javax.jms.StreamMessage;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.jboss.test.jbossmessaging.JMSTestCase;
+
+/**
+ * Tests of sending/receiving all jms message types to/from a queue
+ *
+ * @author <a href="mailto:richard.achmatowicz at jboss.com">Richard Achmatowicz</a>
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 64130 $
+ */
+public class MessageTypesUnitTestCase extends JMSTestCase
+{
+ static String QUEUE_FACTORY = "ConnectionFactory";
+ static String TEST_QUEUE = "queue/testQueue";
+
+ private Context context;
+ private QueueConnection queueConnection;
+ private QueueSession session;
+ private QueueSender sender;
+ private QueueReceiver receiver;
+
+ public MessageTypesUnitTestCase(String name) throws Exception
+ {
+ super(name);
+ }
+
+ public void testMapMessage() throws Exception
+ {
+ log.info("+++ testMapMessage");
+ MapMessage sent = session.createMapMessage();
+ sent.setBoolean("Boolean", true);
+ sent.setByte("Byte", (byte) 1);
+ sent.setBytes("Bytes", "Bytes".getBytes());
+ sent.setChar("Char", 'c');
+ sent.setShort("Short", (short) 31415);
+ sent.setInt("Int", 314159);
+ sent.setLong("Long", 3141592653589793238L);
+ sent.setDouble("Double", 3.1415926535897932384626433832795);
+ sent.setFloat("Float", 3.141f);
+ sent.setObject("Object", "31415926535897932384626433832795");
+ sent.setString("String", "31415926535897932384626433832795");
+
+ MapMessage recv = (MapMessage) sendRecMsg(sent);
+ log.debug("recv: "+recv);
+ assertTrue("Boolean == true", recv.getBoolean("Boolean") == true);
+ assertTrue("Byte == 1", recv.getByte("Byte") == 1);
+ assertTrue("Bytes == Bytes[]",
+ Arrays.equals(recv.getBytes("Bytes"), "Bytes".getBytes()));
+ assertTrue("Char == c", recv.getChar("Char") == 'c');
+ assertTrue("Short == 314159", recv.getShort("Short") == 31415);
+ assertTrue("Int == 314159", recv.getInt("Int") == 314159);
+ assertTrue("Long == 3141592653589793238L",
+ recv.getLong("Long") == 3141592653589793238L);
+ assertTrue("Double == 3.1415926535897932384626433832795",
+ recv.getDouble("Double") == 3.1415926535897932384626433832795);
+ assertTrue("Float == true", recv.getFloat("Float") == 3.141f);
+ assertTrue("Object == 31415926535897932384626433832795",
+ recv.getObject("Object").equals("31415926535897932384626433832795"));
+ assertTrue("String == 31415926535897932384626433832795",
+ recv.getString("String").equals("31415926535897932384626433832795"));
+ }
+ public void testTextMessage() throws Exception
+ {
+ log.info("+++ testTextMessage");
+ String text = "A multiline text msg.\nSecond line.\n";
+ TextMessage sent = session.createTextMessage(text);
+ TextMessage recv = (TextMessage) sendRecMsg(sent);
+ log.debug("recv: "+recv);
+ assertTrue(recv.getText().equals(text));
+ }
+ public void testMessage() throws Exception
+ {
+ log.info("+++ testMessage");
+ Message sent = session.createMessage();
+ sent.setBooleanProperty("Boolean", true);
+ sent.setByteProperty("Byte", (byte) 1);
+ sent.setShortProperty("Short", (short) 31415);
+ sent.setIntProperty("Int", 314159);
+ sent.setLongProperty("Long", 3141592653589793238L);
+ sent.setDoubleProperty("Double", 3.1415926535897932384626433832795);
+ sent.setFloatProperty("Float", 3.141f);
+ sent.setObjectProperty("Object", "31415926535897932384626433832795");
+ sent.setStringProperty("String", "31415926535897932384626433832795");
+
+ Message recv = sendRecMsg(sent);
+ log.debug("recv: "+recv);
+ assertTrue("Boolean == true", recv.getBooleanProperty("Boolean") == true);
+ assertTrue("Byte == 1", recv.getByteProperty("Byte") == 1);
+ assertTrue("Short == 314159", recv.getShortProperty("Short") == 31415);
+ assertTrue("Int == 314159", recv.getIntProperty("Int") == 314159);
+ assertTrue("Long == 3141592653589793238L",
+ recv.getLongProperty("Long") == 3141592653589793238L);
+ assertTrue("Double == 3.1415926535897932384626433832795",
+ recv.getDoubleProperty("Double") == 3.1415926535897932384626433832795);
+ assertTrue("Float == true", recv.getFloatProperty("Float") == 3.141f);
+ assertTrue("Object == 31415926535897932384626433832795",
+ recv.getObjectProperty("Object").equals("31415926535897932384626433832795"));
+ assertTrue("String == 31415926535897932384626433832795",
+ recv.getStringProperty("String").equals("31415926535897932384626433832795"));
+ }
+ public void testBytesMessage() throws Exception
+ {
+ log.info("+++ testBytesMessage");
+ BytesMessage sent = session.createBytesMessage();
+ sent.writeBoolean(true);
+ sent.writeByte((byte) 1);
+ byte[] testBytes = "Bytes".getBytes();
+ sent.writeBytes(testBytes);
+ sent.writeChar('c');
+ sent.writeShort((short) 31415);
+ sent.writeInt(314159);
+ sent.writeLong(3141592653589793238L);
+ sent.writeDouble(3.1415926535897932384626433832795);
+ sent.writeFloat(3.141f);
+ sent.writeObject("31415926535897932384626433832795");
+ sent.writeUTF("31415926535897932384626433832795");
+
+ BytesMessage recv = (BytesMessage) sendRecMsg(sent);
+ log.debug("recv: "+recv);
+ assertTrue("Boolean == true", recv.readBoolean() == true);
+ assertTrue("Byte == 1", recv.readByte() == 1);
+ byte[] bytes = new byte[testBytes.length];
+ recv.readBytes(bytes);
+ assertTrue("Bytes == Bytes[]",
+ Arrays.equals(bytes, testBytes));
+ assertTrue("Char == c", recv.readChar() == 'c');
+ assertTrue("Short == 314159", recv.readShort() == 31415);
+ assertTrue("Int == 314159", recv.readInt() == 314159);
+ assertTrue("Long == 3141592653589793238L",
+ recv.readLong() == 3141592653589793238L);
+ assertTrue("Double == 3.1415926535897932384626433832795",
+ recv.readDouble() == 3.1415926535897932384626433832795);
+ assertTrue("Float == true", recv.readFloat() == 3.141f);
+ assertTrue("Object == 31415926535897932384626433832795",
+ recv.readUTF().equals("31415926535897932384626433832795"));
+ assertTrue("String == 31415926535897932384626433832795",
+ recv.readUTF().equals("31415926535897932384626433832795"));
+ }
+ public void testObjectMessage() throws Exception
+ {
+ log.info("+++ testObjectMessage");
+ BigInteger data = new BigInteger("31415926535897932384626433832795", 10);
+ ObjectMessage sent = session.createObjectMessage(data);
+ ObjectMessage recv = (ObjectMessage) sendRecMsg(sent);
+ log.debug("recv: "+recv);
+ BigInteger data2 = (BigInteger) recv.getObject();
+ assertTrue("BigInteger == BigInteger2", data2.equals(data));
+ }
+ public void testStreamMessage() throws Exception
+ {
+ log.info("+++ testStreamMessage");
+ StreamMessage sent = session.createStreamMessage();
+ sent.writeBoolean(true);
+ sent.writeByte((byte) 1);
+ byte[] testBytes = "Bytes".getBytes();
+ sent.writeBytes(testBytes);
+ sent.writeChar('c');
+ sent.writeShort((short) 31415);
+ sent.writeInt(314159);
+ sent.writeLong(3141592653589793238L);
+ sent.writeDouble(3.1415926535897932384626433832795);
+ sent.writeFloat(3.141f);
+ sent.writeObject("31415926535897932384626433832795");
+ sent.writeString("31415926535897932384626433832795");
+
+ StreamMessage recv = (StreamMessage) sendRecMsg(sent);
+ log.debug("recv: "+recv);
+ assertTrue("Boolean == true", recv.readBoolean() == true);
+ assertTrue("Byte == 1", recv.readByte() == 1);
+ // Quirky spec behavior requires a read past the end of the byte[] field
+ byte[] bytes = new byte[testBytes.length];
+ recv.readBytes(bytes);
+ assertTrue(recv.readBytes(bytes) < 0);
+ assertTrue("Bytes == Bytes[]",
+ Arrays.equals(bytes, testBytes));
+ char c = recv.readChar();
+ assertTrue("Char == c", c == 'c');
+ assertTrue("Short == 314159", recv.readShort() == 31415);
+ assertTrue("Int == 314159", recv.readInt() == 314159);
+ assertTrue("Long == 3141592653589793238L",
+ recv.readLong() == 3141592653589793238L);
+ assertTrue("Double == 3.1415926535897932384626433832795",
+ recv.readDouble() == 3.1415926535897932384626433832795);
+ assertTrue("Float == true", recv.readFloat() == 3.141f);
+ assertTrue("Object == 31415926535897932384626433832795",
+ recv.readObject().equals("31415926535897932384626433832795"));
+ assertTrue("String == 31415926535897932384626433832795",
+ recv.readString().equals("31415926535897932384626433832795"));
+ }
+
+ protected void setUp() throws Exception
+ {
+ // call setUp() in superclass
+ super.setUp() ;
+
+ context = new InitialContext();
+ QueueConnectionFactory queueFactory = (QueueConnectionFactory) context.lookup(QUEUE_FACTORY);
+ queueConnection = queueFactory.createQueueConnection();
+ queueConnection.start();
+ session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue) context.lookup(TEST_QUEUE);
+ sender = session.createSender(queue);
+ receiver = session.createReceiver(queue);
+
+ log.debug("Connection to jms established.");
+ }
+
+ protected void tearDown() throws Exception
+ {
+ sender.close();
+ receiver.close();
+ session.close();
+ queueConnection.close();
+
+ // call tearDown() in superclass
+ super.tearDown() ;
+ }
+
+ private Message sendRecMsg(Message in) throws Exception
+ {
+ sender.send(in, DeliveryMode.NON_PERSISTENT, 4, 0);
+ Message out = receiver.receive(5000);
+ return out;
+ }
+
+}
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/RollBackUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/RollBackUnitTestCase.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/RollBackUnitTestCase.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,729 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbossmessaging.test;
+
+import javax.jms.BytesMessage;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicPublisher;
+import javax.jms.TopicSession;
+import javax.jms.TopicSubscriber;
+import javax.jms.Queue;
+import javax.naming.Context;
+
+import org.apache.log4j.Logger;
+import org.jboss.test.jbossmessaging.JMSTestCase;
+
+/**
+ * Rollback tests
+ *
+ * @author <a href="mailto:richard.achmatowicz at jboss.com">Richard Achmatowicz</a>
+ * @author
+ * @version
+ */
+public class RollBackUnitTestCase extends JMSTestCase
+{
+
+ // Provider specific
+ static String TOPIC_FACTORY = "ConnectionFactory";
+
+ static String QUEUE_FACTORY = "ConnectionFactory";
+
+ static String TEST_QUEUE = "queue/testQueue";
+
+ static String TEST_TOPIC = "topic/testTopic";
+
+ static String TEST_DURABLE_TOPIC = "topic/testDurableTopic";
+
+ static byte[] PAYLOAD = new byte[10];
+
+ static Context context;
+
+ static QueueConnection queueConnection;
+
+ static TopicConnection topicConnection;
+
+ static TopicConnection topicDurableConnection;
+
+ /**
+ * Constructor the test
+ *
+ * @param name Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ public RollBackUnitTestCase(String name) throws Exception
+ {
+ super(name);
+ }
+
+ /**
+ * #Description of the Method
+ *
+ * @param persistence Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ public void runQueueSendRollBack(final int persistence, final boolean explicit) throws Exception
+ {
+ drainQueue();
+ final int iterationCount = getIterationCount();
+ final Logger log = getLog();
+
+ Thread sendThread = new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ QueueSession session = queueConnection.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue) context.lookup(TEST_QUEUE);
+
+ QueueSender sender = session.createSender(queue);
+
+ BytesMessage message = session.createBytesMessage();
+ message.writeBytes(PAYLOAD);
+ message.setStringProperty("TEST_NAME", "runQueueSendRollback");
+ message.setIntProperty("TEST_PERSISTENCE", persistence);
+ message.setBooleanProperty("TEST_EXPLICIT", explicit);
+
+ for (int i = 0; i < iterationCount; i++)
+ {
+ sender.send(message, persistence, 4, 0);
+ }
+
+ if (explicit)
+ session.rollback();
+ session.close();
+ }
+ catch (Exception e)
+ {
+ log.error("error", e);
+ }
+ }
+ };
+
+ sendThread.start();
+ sendThread.join();
+ assertTrue("Queue should be empty", drainQueue() == 0);
+ }
+
+ /**
+ * #Description of the Method
+ *
+ * @param persistence Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ public void runTopicSendRollBack(final int persistence, final boolean explicit) throws Exception
+ {
+ drainQueue();
+ drainTopic();
+
+ final int iterationCount = getIterationCount();
+ final Logger log = getLog();
+
+ Thread sendThread = new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+
+ TopicSession session = topicConnection.createTopicSession(true, Session.AUTO_ACKNOWLEDGE);
+ Topic topic = (Topic) context.lookup(TEST_TOPIC);
+
+ TopicPublisher publisher = session.createPublisher(topic);
+
+ BytesMessage message = session.createBytesMessage();
+ message.writeBytes(PAYLOAD);
+ message.setStringProperty("TEST_NAME", "runTopicSendRollback");
+ message.setIntProperty("TEST_PERSISTENCE", persistence);
+ message.setBooleanProperty("TEST_EXPLICIT", explicit);
+
+ for (int i = 0; i < iterationCount; i++)
+ {
+ publisher.publish(message, persistence, 4, 0);
+ }
+
+ session.close();
+ }
+ catch (Exception e)
+ {
+ log.error("error", e);
+ }
+ }
+ };
+
+ sendThread.start();
+ sendThread.join();
+ assertTrue("Topic should be empty", drainTopic() == 0);
+ }
+
+ /**
+ * #Description of the Method
+ *
+ * @param persistence Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ public void runAsynchQueueReceiveRollBack(final int persistence, final boolean explicit) throws Exception
+ {
+ drainQueue();
+
+ final int iterationCount = getIterationCount();
+ final Logger log = getLog();
+
+ Thread sendThread = new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue) context.lookup(TEST_QUEUE);
+
+ QueueSender sender = session.createSender(queue);
+
+ BytesMessage message = session.createBytesMessage();
+ message.writeBytes(PAYLOAD);
+ message.setStringProperty("TEST_NAME", "runAsynchQueueReceiveRollback");
+ message.setIntProperty("TEST_PERSISTENCE", persistence);
+ message.setBooleanProperty("TEST_EXPLICIT", explicit);
+
+ for (int i = 0; i < iterationCount; i++)
+ {
+ sender.send(message, persistence, 4, 0);
+ }
+
+ session.close();
+ }
+ catch (Exception e)
+ {
+ log.error("error", e);
+ }
+ }
+ };
+
+ QueueSession session = queueConnection.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue) context.lookup(TEST_QUEUE);
+ QueueReceiver receiver = session.createReceiver(queue);
+
+ MyMessageListener listener = new MyMessageListener(iterationCount, log);
+
+ sendThread.start();
+ receiver.setMessageListener(listener);
+ queueConnection.start();
+ synchronized (listener)
+ {
+ if (listener.i < iterationCount)
+ listener.wait();
+ }
+ receiver.setMessageListener(null);
+
+ if (explicit)
+ session.rollback();
+ session.close();
+
+ queueConnection.stop();
+
+ sendThread.join();
+
+ assertTrue("Queue should be full", drainQueue() == iterationCount);
+
+ }
+
+ /**
+ * #Description of the Method
+ *
+ * @param persistence Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ public void runAsynchTopicReceiveRollBack(final int persistence, final boolean explicit) throws Exception
+ {
+ drainQueue();
+ drainTopic();
+
+ final int iterationCount = getIterationCount();
+ final Logger log = getLog();
+
+ Thread sendThread = new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+
+ TopicSession session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic topic = (Topic) context.lookup(TEST_TOPIC);
+
+ TopicPublisher publisher = session.createPublisher(topic);
+
+ waitForSynchMessage();
+
+ BytesMessage message = session.createBytesMessage();
+ message.writeBytes(PAYLOAD);
+ message.setStringProperty("TEST_NAME", "runAsynchTopicReceiveRollback");
+ message.setIntProperty("TEST_PERSISTENCE", persistence);
+ message.setBooleanProperty("TEST_EXPLICIT", explicit);
+
+ for (int i = 0; i < iterationCount; i++)
+ {
+ publisher.publish(message, persistence, 4, 0);
+ log.debug("Published message " + i);
+ }
+
+ session.close();
+ }
+ catch (Exception e)
+ {
+ log.error("error", e);
+ }
+ }
+ };
+
+ TopicSession session = topicConnection.createTopicSession(true, Session.AUTO_ACKNOWLEDGE);
+ Topic topic = (Topic) context.lookup(TEST_TOPIC);
+ TopicSubscriber subscriber = session.createSubscriber(topic);
+
+ MyMessageListener listener = new MyMessageListener(iterationCount, log);
+
+ queueConnection.start();
+ sendThread.start();
+ subscriber.setMessageListener(listener);
+ topicConnection.start();
+ sendSynchMessage();
+ getLog().debug("Waiting for all messages");
+ synchronized (listener)
+ {
+ if (listener.i < iterationCount)
+ listener.wait();
+ }
+ getLog().debug("Got all messages");
+ subscriber.setMessageListener(null);
+
+ if (explicit)
+ session.rollback();
+ session.close();
+
+ sendThread.join();
+ topicConnection.stop();
+ queueConnection.stop();
+ assertTrue("Topic should be empty", drainTopic() == 0);
+ }
+
+ /**
+ * #Description of the Method
+ *
+ * @param persistence Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ public void runAsynchDurableTopicReceiveRollBack(final int persistence, final boolean explicit) throws Exception
+ {
+ getLog().debug("====> runAsynchDurableTopicReceiveRollBack persistence=" + persistence + " explicit=" + explicit);
+ drainQueue();
+ drainDurableTopic();
+
+ final int iterationCount = getIterationCount();
+ final Logger log = getLog();
+
+ Thread sendThread = new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+
+ TopicSession session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic topic = (Topic) context.lookup(TEST_DURABLE_TOPIC);
+
+ TopicPublisher publisher = session.createPublisher(topic);
+
+ waitForSynchMessage();
+
+ BytesMessage message = session.createBytesMessage();
+ message.writeBytes(PAYLOAD);
+ message.setStringProperty("TEST_NAME", "runAsynchDurableTopicReceiveRollback");
+ message.setIntProperty("TEST_PERSISTENCE", persistence);
+ message.setBooleanProperty("TEST_EXPLICIT", explicit);
+
+ for (int i = 0; i < iterationCount; i++)
+ {
+ publisher.publish(message, persistence, 4, 0);
+ log.debug("Published message " + i);
+ }
+
+ session.close();
+ }
+ catch (Exception e)
+ {
+ log.error("error", e);
+ }
+ }
+ };
+
+ TopicSession session = topicDurableConnection.createTopicSession(true, Session.AUTO_ACKNOWLEDGE);
+ Topic topic = (Topic) context.lookup(TEST_DURABLE_TOPIC);
+ TopicSubscriber subscriber = session.createDurableSubscriber(topic, "test");
+ try
+ {
+ MyMessageListener listener = new MyMessageListener(iterationCount, log);
+
+ queueConnection.start();
+ sendThread.start();
+ subscriber.setMessageListener(listener);
+ topicDurableConnection.start();
+ sendSynchMessage();
+ getLog().debug("Waiting for all messages");
+ synchronized (listener)
+ {
+ if (listener.i < iterationCount)
+ listener.wait();
+ }
+ getLog().debug("Got all messages");
+ subscriber.setMessageListener(null);
+ subscriber.close();
+
+ if (explicit)
+ session.rollback();
+ session.close();
+
+ sendThread.join();
+ topicDurableConnection.stop();
+ queueConnection.stop();
+ assertTrue("Topic should be full", drainDurableTopic() == iterationCount);
+ }
+ finally
+ {
+ removeDurableSubscription();
+ }
+ }
+
+ /**
+ * A unit test for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
+ public void testQueueSendRollBack() throws Exception
+ {
+
+ getLog().debug("Starting AsynchQueueSendRollBack test");
+
+ runQueueSendRollBack(DeliveryMode.NON_PERSISTENT, false);
+ runQueueSendRollBack(DeliveryMode.PERSISTENT, false);
+ runQueueSendRollBack(DeliveryMode.NON_PERSISTENT, true);
+ runQueueSendRollBack(DeliveryMode.PERSISTENT, true);
+
+ getLog().debug("AsynchQueueSendRollBack passed");
+ }
+
+ /**
+ * A unit test for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
+ public void testAsynchQueueReceiveBack() throws Exception
+ {
+
+ getLog().debug("Starting AsynchQueueReceiveRollBack test");
+
+ runAsynchQueueReceiveRollBack(DeliveryMode.NON_PERSISTENT, false);
+ runAsynchQueueReceiveRollBack(DeliveryMode.PERSISTENT, false);
+ runQueueSendRollBack(DeliveryMode.NON_PERSISTENT, true);
+ runQueueSendRollBack(DeliveryMode.PERSISTENT, true);
+
+ getLog().debug("AsynchQueueReceiveRollBack passed");
+ }
+
+ /**
+ * A unit test for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
+ public void testTopicSendRollBack() throws Exception
+ {
+
+ getLog().debug("Starting AsynchTopicSendRollBack test");
+
+ runTopicSendRollBack(DeliveryMode.NON_PERSISTENT, false);
+ runTopicSendRollBack(DeliveryMode.PERSISTENT, false);
+ runTopicSendRollBack(DeliveryMode.NON_PERSISTENT, true);
+ runTopicSendRollBack(DeliveryMode.PERSISTENT, true);
+
+ getLog().debug("AsynchTopicSendRollBack passed");
+ }
+
+ /**
+ * A unit test for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
+ public void testAsynchTopicReceiveRollBack() throws Exception
+ {
+
+ getLog().debug("Starting AsynchTopicReceiveRollBack test");
+
+ runAsynchTopicReceiveRollBack(DeliveryMode.NON_PERSISTENT, false);
+ runAsynchTopicReceiveRollBack(DeliveryMode.PERSISTENT, false);
+ runAsynchTopicReceiveRollBack(DeliveryMode.NON_PERSISTENT, true);
+ runAsynchTopicReceiveRollBack(DeliveryMode.PERSISTENT, true);
+
+ getLog().debug("AsynchTopicReceiveRollBack passed");
+ }
+
+ /**
+ * A unit test for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
+ public void testAsynchDurableTopicReceiveRollBack() throws Exception
+ {
+
+ getLog().debug("Starting AsynchDurableTopicReceiveRollBack test");
+
+ runAsynchDurableTopicReceiveRollBack(DeliveryMode.NON_PERSISTENT, false);
+ runAsynchDurableTopicReceiveRollBack(DeliveryMode.PERSISTENT, false);
+ runAsynchDurableTopicReceiveRollBack(DeliveryMode.NON_PERSISTENT, true);
+ runAsynchDurableTopicReceiveRollBack(DeliveryMode.PERSISTENT, true);
+
+ getLog().debug("AsynchDurableTopicReceiveRollBack passed");
+ }
+
+ /**
+ * A unit test for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
+ public void removeDurableSubscription() throws Exception
+ {
+
+ TopicSession session = topicDurableConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ session.unsubscribe("test");
+ }
+
+ /**
+ * The JUnit setup method
+ *
+ * @exception Exception Description of Exception
+ */
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ getLog().debug("START TEST " + getName());
+ context = getInitialContext();
+
+ QueueConnectionFactory queueFactory = (QueueConnectionFactory) context.lookup(QUEUE_FACTORY);
+ queueConnection = queueFactory.createQueueConnection();
+
+ TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+ topicConnection = topicFactory.createTopicConnection();
+ topicDurableConnection = topicFactory.createTopicConnection("john", "needle");
+
+ getLog().debug("Connection to JBossMQ established.");
+ }
+
+ protected void tearDown() throws Exception
+ {
+ try
+ {
+ if (topicDurableConnection != null)
+ {
+ topicDurableConnection.close();
+ topicDurableConnection = null;
+ }
+ }
+ catch (JMSException ignored)
+ {
+ }
+ try
+ {
+ if (topicConnection != null)
+ {
+ topicConnection.close();
+ topicConnection = null;
+ }
+ }
+ catch (JMSException ignored)
+ {
+ }
+ try
+ {
+ if (queueConnection != null)
+ {
+ queueConnection.close();
+ queueConnection = null;
+ }
+ }
+ catch (JMSException ignored)
+ {
+ }
+ super.tearDown();
+ }
+
+ // Emptys out all the messages in a queue
+ private int drainQueue() throws Exception
+ {
+ getLog().debug("Draining Queue");
+ queueConnection.start();
+
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue) context.lookup(TEST_QUEUE);
+
+ QueueReceiver receiver = session.createReceiver(queue);
+ Message message = receiver.receive(50);
+ int c = 0;
+ while (message != null)
+ {
+ c++;
+ message = receiver.receive(50);
+ }
+
+ getLog().debug(" Drained " + c + " messages from the queue");
+
+ session.close();
+
+ queueConnection.stop();
+
+ return c;
+ }
+
+ // Emptys out all the messages in a topic
+ private int drainTopic() throws Exception
+ {
+ getLog().debug("Draining Topic");
+ topicConnection.start();
+
+ final TopicSession session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic topic = (Topic) context.lookup(TEST_TOPIC);
+ TopicSubscriber subscriber = session.createSubscriber(topic);
+
+ Message message = subscriber.receive(50);
+ int c = 0;
+ while (message != null)
+ {
+ c++;
+ message = subscriber.receive(50);
+ }
+
+ getLog().debug(" Drained " + c + " messages from the topic");
+
+ session.close();
+
+ topicConnection.stop();
+
+ return c;
+ }
+
+ // Emptys out all the messages in a durable topic
+ private int drainDurableTopic() throws Exception
+ {
+ getLog().debug("Draining Durable Topic");
+ topicDurableConnection.start();
+
+ final TopicSession session = topicDurableConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic topic = (Topic) context.lookup(TEST_DURABLE_TOPIC);
+ TopicSubscriber subscriber = session.createDurableSubscriber(topic, "test");
+
+ Message message = subscriber.receive(50);
+ int c = 0;
+ while (message != null)
+ {
+ c++;
+ message = subscriber.receive(50);
+ }
+
+ getLog().debug(" Drained " + c + " messages from the durable topic");
+
+ session.close();
+
+ topicDurableConnection.stop();
+
+ return c;
+ }
+
+ private void waitForSynchMessage() throws Exception
+ {
+ getLog().debug("Waiting for Synch Message");
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue) context.lookup(TEST_QUEUE);
+
+ QueueReceiver receiver = session.createReceiver(queue);
+ receiver.receive();
+ session.close();
+ getLog().debug("Got Synch Message");
+ }
+
+ private void sendSynchMessage() throws Exception
+ {
+ getLog().debug("Sending Synch Message");
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue) context.lookup(TEST_QUEUE);
+
+ QueueSender sender = session.createSender(queue);
+
+ Message message = session.createMessage();
+ sender.send(message);
+
+ session.close();
+ getLog().debug("Sent Synch Message");
+ }
+
+ public class MyMessageListener implements MessageListener
+ {
+ public int i = 0;
+
+ public int iterationCount;
+
+ public Logger log;
+
+ public MyMessageListener(int iterationCount, Logger log)
+ {
+ this.iterationCount = iterationCount;
+ this.log = log;
+ }
+
+ public void onMessage(Message message)
+ {
+ synchronized (this)
+ {
+ i++;
+ log.debug("Got message " + i);
+ if (i >= iterationCount)
+ this.notify();
+ }
+ }
+ }
+
+ public int getIterationCount()
+ {
+ return 5;
+ }
+
+}
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/SecurityUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/SecurityUnitTestCase.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/SecurityUnitTestCase.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,1170 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbossmessaging.test;
+
+import javax.management.ObjectName;
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.jboss.test.JBossTestSetup;
+import org.jboss.test.jbossmessaging.JMSBase;
+/**
+ * Test of security features in JMS providers
+ *
+ * @author <a href="mailto:richard.achmatowicz">Richard Achmatowicz</a>
+ * @author <a href="pra at tim.se">Peter Antman</a>
+ * @version $Revision: 64201 $
+ */
+public class SecurityUnitTestCase extends JMSBase
+{
+ public SecurityUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testLoginTest() throws Exception
+ {
+ TopicWorker sub1 = null;
+ TopicWorker pub1 = null;
+ try
+ {
+ drainTopic();
+ int ic = 5;
+ IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message.class, "USER_NR", 0, ic);
+ sub1 = new TopicWorker(SUBSCRIBER, TRANS_NONE, f1);
+ sub1.setUser("john", "needle");
+ Thread t1 = new Thread(sub1);
+ t1.start();
+ // Publish
+ IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0);
+ pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, c1, ic);
+ pub1.connect();
+ pub1.publish();
+ Assert.assertEquals("Publisher did not publish correct number of messages " + pub1.getMessageHandled(), ic,
+ pub1.getMessageHandled());
+ // let sub1 have some time to handle the messages.
+ log.debug("Sleeping for " + ((ic * 10) / 60000) + " minutes");
+ sleep(ic * 100);
+ Assert.assertEquals("Subscriber did not get correct number of messages " + sub1.getMessageHandled(), ic, sub1
+ .getMessageHandled());
+ sub1.close();
+ pub1.close();
+ }
+ catch (Throwable t)
+ {
+ if (t instanceof junit.framework.AssertionFailedError)
+ throw (junit.framework.AssertionFailedError) t;
+ log.error("Error in test: " + t, t);
+ throw new Exception(t.getMessage());
+ }
+ finally
+ {
+ try
+ {
+ if (sub1 != null)
+ sub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ try
+ {
+ if (pub1 != null)
+ pub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ /**
+ Tests that check authentication
+ 1. Login without cred
+ 2. Login with valid usedid,pwd
+ 3. Login with valid user, unvalid pwd
+ 4. Login with unvalid user.
+ */
+ public void testLoginNoCred() throws Exception
+ {
+ TopicWorker pub1 = null;
+ try
+ {
+ drainTopic();
+ pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, null, 0);
+ pub1.connect();
+ }
+ catch (Exception ex)
+ {
+ Assert.fail("Could lot login without any cred");
+ }
+ finally
+ {
+ try
+ {
+ pub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ public void testLoginValidCred() throws Exception
+ {
+ TopicWorker pub1 = null;
+ try
+ {
+ drainTopic();
+ pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, null, 0);
+ pub1.setUser("john", "needle");
+ pub1.connect();
+ }
+ catch (Exception ex)
+ {
+ Assert.fail("Could lot login with valid cred");
+ }
+ finally
+ {
+ try
+ {
+ pub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ public void testLoginInvalidPwd() throws Exception
+ {
+ TopicWorker pub1 = null;
+ try
+ {
+ drainTopic();
+ pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, null, 0);
+ pub1.setUser("john", "bogus");
+ Exception e = null;
+ try
+ {
+ pub1.connect();
+ }
+ catch (Exception ex)
+ {
+ e = ex;
+ }
+ log.debug(e);
+ Assert.assertTrue("Loggin in with invalid password did not throw correct exception",
+ e instanceof javax.jms.JMSSecurityException);
+ }
+ finally
+ {
+ try
+ {
+ pub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ public void testLoginInvalidCred() throws Exception
+ {
+ TopicWorker pub1 = null;
+ try
+ {
+ drainTopic();
+ pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, null, 0);
+ pub1.setUser("bogus", "bogus");
+ Exception e = null;
+ try
+ {
+ pub1.connect();
+ }
+ catch (Exception ex)
+ {
+ e = ex;
+ }
+ log.debug(e);
+ Assert.assertTrue("Loggin in with invalid user did not throw correct exception",
+ e instanceof javax.jms.JMSSecurityException);
+ }
+ finally
+ {
+ try
+ {
+ pub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ /**
+ An number of tests to verrify that clientID works as expected:
+
+ This tests a specific a specific behavior from JBossMQ.
+ This tests creates a TopicSession and expects the clientID to be set. There is no requirement for this on JMS Spec.
+ */
+ /*public void testClientIDNormalTest() throws Exception
+ {
+ TopicWorker pub1 = null;
+ try
+ {
+ drainTopic();
+ int ic = 5;
+ // Publish
+ IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0);
+ pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, c1, ic);
+ pub1.connect();
+ pub1.publish();
+ Assert.assertTrue("Client did not get a valid clientID", pub1.connection.getClientID().startsWith("ID"));
+ pub1.close();
+ }
+ catch (Throwable t)
+ {
+ if (t instanceof junit.framework.AssertionFailedError)
+ throw (junit.framework.AssertionFailedError) t;
+ log.error("Error in test: " + t, t);
+ throw new Exception(t.getMessage());
+ }
+ finally
+ {
+ try
+ {
+ pub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ } */
+
+ public void testClientIDPreconfTest() throws Exception
+ {
+ TopicWorker pub1 = null;
+ try
+ {
+ drainTopic();
+ int ic = 5;
+ // Publish
+ IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0);
+ pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, c1, ic);
+ pub1.setUser("john", "needle");
+ pub1.connect();
+ pub1.publish();
+ Assert.assertEquals("Client did not get a valid clientID", "DurableSubscriberExample", pub1.connection
+ .getClientID());
+ pub1.close();
+ }
+ catch (Throwable t)
+ {
+ if (t instanceof junit.framework.AssertionFailedError)
+ throw (junit.framework.AssertionFailedError) t;
+ log.error("Error in test: " + t, t);
+ throw new Exception(t.getMessage());
+ }
+ finally
+ {
+ try
+ {
+ pub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ public void testClientIDSetTest() throws Exception
+ {
+ TopicWorker pub1 = null;
+ try
+ {
+ drainTopic();
+ int ic = 5;
+ // Publish
+ IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0);
+ pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, c1, ic);
+ pub1.setClientID("myId");
+ pub1.connect();
+ pub1.publish();
+ Assert.assertEquals("Client did not get a valid clientID", "myId", pub1.connection.getClientID());
+ pub1.close();
+ }
+ finally
+ {
+ try
+ {
+ pub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ /*
+ * Test only valid on JBossMQ - commented out.
+ * public void testClientIDSetSteelPreconf() throws Exception
+ {
+ TopicWorker pub1 = null;
+ try
+ {
+ drainTopic();
+ int ic = 5;
+ // Publish
+ IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0);
+ pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, c1, ic);
+ pub1.setClientID("DurableSubscriberExample");
+ Exception e = null;
+ try
+ {
+ pub1.connect();
+ }
+ catch (Exception ex)
+ {
+ e = ex;
+ }
+ log.debug(e);
+ Assert.assertTrue("Setting a clientID wich is preconfigured did not throw correct exception",
+ e instanceof javax.jms.InvalidClientIDException);
+ pub1.close();
+ }
+ finally
+ {
+ try
+ {
+ pub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ } */
+
+ public void testClientIDSetAfterInvoke() throws Exception
+ {
+ TopicWorker pub1 = null;
+ try
+ {
+ drainTopic();
+ int ic = 5;
+ // Publish
+ IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0);
+ pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, c1, ic);
+ pub1.connect();
+ pub1.publish();
+ Exception e = null;
+ try
+ {
+ pub1.connection.setClientID("myID");
+ }
+ catch (Exception ex)
+ {
+ e = ex;
+ }
+ log.debug(e);
+ Assert.assertTrue("Setting a clientID after connection is used did not throw correct exception: " + e,
+ e instanceof javax.jms.IllegalStateException);
+ pub1.close();
+ }
+ finally
+ {
+ try
+ {
+ pub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ /**
+ Tests to check autorization.
+
+ Remember there are actuallt two types of fails:
+ a) You are a user, but do no belong to a group that has acl.
+ b) You belong to a group, but that group does not have acl.
+ we test the first for topics and the second for queues, by
+ configuration in jbossmq-testsuite-service.xml
+
+ Tests that check autorization.
+ 1. test valid topic publisher
+ 2. test invalid topic publisher
+ 3. test valid topic subscriber
+ 4. test invalid topic subscriber
+ 5. test valid queue sender
+ 6. test invalid queue sender
+ 7. test valid queue receiver
+ 8. test invalid queue receiver
+ 9. test valid queue browser.
+ 10. test invalid queue browser
+ 11. test preconf dur sub, to valid dest.
+ 12. test preconf dur sub, to invalid dest.
+ 13. test dyn dur sub, to valid dest.
+ 14. test dyn dur sub, to valid dest.
+ */
+ public void testAuzValidTopicPublisher() throws Exception
+ {
+ TopicWorker pub1 = null;
+ try
+ {
+ IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0);
+ pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, c1, 1);
+ pub1.setUser("john", "needle");
+ pub1.connect();
+ pub1.publish();
+ }
+ catch (Exception ex)
+ {
+ Assert.fail("Could not publish to valid destination");
+ }
+ finally
+ {
+ try
+ {
+ pub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ public void testAuzValidTopicPublisherTransaction() throws Exception
+ {
+ TopicWorker pub1 = null;
+ try
+ {
+ IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0);
+ pub1 = new TopicWorker(PUBLISHER, TRANS_INDIVIDUAL, c1, 1);
+ pub1.setUser("john", "needle");
+ pub1.connect();
+ pub1.publish();
+ }
+ catch (Exception ex)
+ {
+ Assert.fail("Could not publish to valid destination");
+ }
+ finally
+ {
+ try
+ {
+ pub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ public void testAuzInvalidTopicPublisher() throws Exception
+ {
+ TopicWorker pub1 = null;
+ try
+ {
+ IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0);
+ pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, c1, 1);
+ pub1.setUser("nobody", "nobody");
+ pub1.connect();
+ Exception e = null;
+ try
+ {
+ pub1.publish();
+ }
+ catch (Exception ex)
+ {
+ e = ex;
+ }
+ log.debug(e);
+ Assert.assertTrue("Unauz topic publishing throw wrong exception: " + e,
+ e instanceof javax.jms.JMSSecurityException);
+ }
+ finally
+ {
+ try
+ {
+ pub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ public void testAuzInvalidTopicPublisherTransaction() throws Exception
+ {
+ TopicWorker pub1 = null;
+ try
+ {
+ IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0);
+ pub1 = new TopicWorker(PUBLISHER, TRANS_INDIVIDUAL, c1, 1);
+ pub1.setUser("nobody", "nobody");
+ pub1.connect();
+ Exception e = null;
+ try
+ {
+ pub1.publish();
+ }
+ catch (Exception ex)
+ {
+ e = ex;
+ }
+ log.debug(e);
+ Assert.assertTrue("Unauz topic publishing throw wrong exception: " + e,
+ e instanceof javax.jms.JMSSecurityException);
+ }
+ finally
+ {
+ try
+ {
+ pub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ public void testAuzValidTopicSubscriber() throws Exception
+ {
+ TopicWorker sub1 = null;
+ try
+ {
+ drainTopic();
+ IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message.class, "USER_NR", 0, 1);
+ sub1 = new TopicWorker(SUBSCRIBER, TRANS_NONE, f1);
+ sub1.setUser("john", "needle");
+ Thread t1 = new Thread(sub1);
+ t1.start();
+ sleep(1000L);
+ Exception ex = sub1.getException();
+ t1.interrupt();
+ Assert.assertTrue("Autz topic subscriber did not work", ex == null);
+ }
+ finally
+ {
+ try
+ {
+ sub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ public void testAuzValidTopicSubscriberTransaction() throws Exception
+ {
+ TopicWorker sub1 = null;
+ try
+ {
+ drainTopic();
+ IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message.class, "USER_NR", 0, 1);
+ sub1 = new TopicWorker(SUBSCRIBER, TRANS_INDIVIDUAL, f1);
+ sub1.setUser("john", "needle");
+ Thread t1 = new Thread(sub1);
+ t1.start();
+ sleep(1000L);
+ Exception ex = sub1.getException();
+ t1.interrupt();
+ Assert.assertTrue("Autz topic subscriber did not work", ex == null);
+ }
+ finally
+ {
+ try
+ {
+ sub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ public void testAuzInvalidTopicSubscriber() throws Exception
+ {
+ TopicWorker sub1 = null;
+ try
+ {
+ drainTopic();
+ IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message.class, "USER_NR", 0, 1);
+ sub1 = new TopicWorker(SUBSCRIBER, TRANS_NONE, f1);
+ sub1.setUser("nobody", "nobody");
+ Thread t1 = new Thread(sub1);
+ t1.start();
+ sleep(1000L);
+ Exception ex = sub1.getException();
+ t1.interrupt();
+ Assert.assertTrue("Unautz topic subscriber throw wrong exception: " + ex,
+ ex instanceof javax.jms.JMSSecurityException);
+ }
+ finally
+ {
+ try
+ {
+ sub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ public void testAuzInvalidTopicSubscriberTransaction() throws Exception
+ {
+ TopicWorker sub1 = null;
+ try
+ {
+ drainTopic();
+ IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message.class, "USER_NR", 0, 1);
+ sub1 = new TopicWorker(SUBSCRIBER, TRANS_INDIVIDUAL, f1);
+ sub1.setUser("nobody", "nobody");
+ Thread t1 = new Thread(sub1);
+ t1.start();
+ sleep(1000L);
+ Exception ex = sub1.getException();
+ t1.interrupt();
+ Assert.assertTrue("Unautz topic subscriber throw wrong exception: " + ex,
+ ex instanceof javax.jms.JMSSecurityException);
+ }
+ finally
+ {
+ try
+ {
+ sub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ public void testAuzValidQueueSender() throws Exception
+ {
+ QueueWorker pub1 = null;
+ try
+ {
+ IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0);
+ pub1 = new QueueWorker(PUBLISHER, TRANS_NONE, c1, 1);
+ pub1.setUser("john", "needle");
+ pub1.connect();
+ pub1.publish();
+ }
+ catch (Exception ex)
+ {
+ Assert.fail("Could not publish to valid destination");
+ }
+ finally
+ {
+ try
+ {
+ pub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ public void testAuzValidQueueSenderTransaction() throws Exception
+ {
+ QueueWorker pub1 = null;
+ try
+ {
+ IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0);
+ pub1 = new QueueWorker(PUBLISHER, TRANS_INDIVIDUAL, c1, 1);
+ pub1.setUser("john", "needle");
+ pub1.connect();
+ pub1.publish();
+ }
+ catch (Exception ex)
+ {
+ Assert.fail("Could not publish to valid destination");
+ }
+ finally
+ {
+ try
+ {
+ pub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ public void testAuzInvalidQueueSender() throws Exception
+ {
+ QueueWorker pub1 = null;
+ try
+ {
+ IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0);
+ pub1 = new QueueWorker(PUBLISHER, TRANS_NONE, c1, 1);
+ pub1.setUser("nobody", "nobody");
+ pub1.connect();
+ Exception e = null;
+ try
+ {
+ pub1.publish();
+ }
+ catch (Exception ex)
+ {
+ e = ex;
+ }
+ log.debug(e);
+ Assert.assertTrue("Unauz queue publishing throw wrong exception: " + e,
+ e instanceof javax.jms.JMSSecurityException);
+ }
+ finally
+ {
+ try
+ {
+ pub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ public void testAuzInvalidQueueSenderTransaction() throws Exception
+ {
+ QueueWorker pub1 = null;
+ try
+ {
+ IntRangeMessageCreator c1 = new IntRangeMessageCreator("USER_NR", 0);
+ pub1 = new QueueWorker(PUBLISHER, TRANS_INDIVIDUAL, c1, 1);
+ pub1.setUser("nobody", "nobody");
+ pub1.connect();
+ Exception e = null;
+ try
+ {
+ pub1.publish();
+ }
+ catch (Exception ex)
+ {
+ e = ex;
+ }
+ log.debug(e);
+ Assert.assertTrue("Unauz queue publishing throw wrong exception: " + e,
+ e instanceof javax.jms.JMSSecurityException);
+ }
+ finally
+ {
+ try
+ {
+ pub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ public void testAuzValidQueueReceiver() throws Exception
+ {
+ QueueWorker sub1 = null;
+ try
+ {
+ IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message.class, "USER_NR", 0, 1);
+ sub1 = new QueueWorker(GETTER, TRANS_NONE, f1);
+ sub1.setUser("john", "needle");
+ sub1.connect();
+ Exception ex = null;
+ try
+ {
+ sub1.get();
+ }
+ catch (Exception e)
+ {
+ ex = e;
+ log.error("ValidQueueReceiver got an exception: " + e, e);
+ }
+ Assert.assertTrue("Autz queue receiver did not work", ex == null);
+ }
+ finally
+ {
+ try
+ {
+ sub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ public void testAuzValidQueueReceiverTransaction() throws Exception
+ {
+ QueueWorker sub1 = null;
+ try
+ {
+ IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message.class, "USER_NR", 0, 1);
+ sub1 = new QueueWorker(GETTER, TRANS_INDIVIDUAL, f1);
+ sub1.setUser("john", "needle");
+ sub1.connect();
+ Exception ex = null;
+ try
+ {
+ sub1.get();
+ }
+ catch (Exception e)
+ {
+ ex = e;
+ log.error("ValidQueueReceiver got an exception: " + e, e);
+ }
+ Assert.assertTrue("Autz queue receiver did not work", ex == null);
+ }
+ finally
+ {
+ try
+ {
+ sub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ public void testAuzInvalidQueueReceiver() throws Exception
+ {
+ QueueWorker sub1 = null;
+ try
+ {
+ IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message.class, "USER_NR", 0, 1);
+ sub1 = new QueueWorker(GETTER, TRANS_NONE, f1);
+ sub1.setUser("nobody", "nobody");
+ sub1.connect();
+ Exception ex = null;
+ try
+ {
+ sub1.get();
+ }
+ catch (Exception e)
+ {
+ ex = e;
+ }
+ Assert.assertTrue("Unautz queue receiver throw wrong exception: " + ex,
+ ex instanceof javax.jms.JMSSecurityException);
+ }
+ finally
+ {
+ try
+ {
+ sub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ public void testAuzInvalidQueueReceiverTransaction() throws Exception
+ {
+ QueueWorker sub1 = null;
+ try
+ {
+ IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message.class, "USER_NR", 0, 1);
+ sub1 = new QueueWorker(GETTER, TRANS_INDIVIDUAL, f1);
+ sub1.setUser("nobody", "nobody");
+ sub1.connect();
+ Exception ex = null;
+ try
+ {
+ sub1.get();
+ }
+ catch (Exception e)
+ {
+ ex = e;
+ }
+ Assert.assertTrue("Unautz queue receiver throw wrong exception: " + ex,
+ ex instanceof javax.jms.JMSSecurityException);
+ }
+ finally
+ {
+ try
+ {
+ sub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ public void testAuzValidQueueBrowser() throws Exception
+ {
+ QueueWorker sub1 = null;
+ try
+ {
+ IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message.class, "USER_NR", 0, 1);
+ sub1 = new QueueWorker(GETTER, TRANS_NONE, f1);
+ sub1.setUser("john", "needle");
+ sub1.connect();
+ Exception ex = null;
+ try
+ {
+ sub1.browse();
+ }
+ catch (Exception e)
+ {
+ ex = e;
+ log.error("ValidQueueBrowser throw exception: " + e, e);
+ }
+ Assert.assertTrue("Autz queue receiver did not work", ex == null);
+ }
+ finally
+ {
+ try
+ {
+ sub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ public void testAuzInvalidQueueBrowser() throws Exception
+ {
+ QueueWorker sub1 = null;
+ try
+ {
+ IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message.class, "USER_NR", 0, 1);
+ sub1 = new QueueWorker(GETTER, TRANS_NONE, f1);
+ sub1.setUser("nobody", "nobody");
+ sub1.connect();
+ Exception ex = null;
+ try
+ {
+ sub1.browse();
+ }
+ catch (Exception e)
+ {
+ ex = e;
+ }
+ Assert.assertTrue("Unautz queue receiver throw wrong exception: " + ex,
+ ex instanceof javax.jms.JMSSecurityException);
+ }
+ finally
+ {
+ try
+ {
+ sub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ public void testValidPreconfDurSub() throws Exception
+ {
+ TopicWorker sub1 = null;
+ TopicWorker pub1 = null;
+ try
+ {
+ // Clean testarea up
+ drainTopic();
+ int ic = 5;
+ // Set up a durable subscriber
+ IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message.class, "DURABLE_NR", 0, ic);
+ sub1 = new TopicWorker(SUBSCRIBER, TRANS_NONE, f1);
+ sub1.setDurable("john", "needle", "sub2");
+ Thread t1 = new Thread(sub1);
+ t1.start();
+ // Let is take some time to really set up the dur sub
+ sleep(2000);
+ // Publish
+ IntRangeMessageCreator c1 = new IntRangeMessageCreator("DURABLE_NR", 0);
+ pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, c1, ic);
+ pub1.connect();
+ pub1.publish();
+ Assert.assertEquals("Publisher did not publish correct number of messages " + pub1.getMessageHandled(), ic,
+ pub1.getMessageHandled());
+ // let sub1 have some time to handle the messages.
+ log.debug("Sleeping for " + ((ic * 100) / 60000) + " minutes");
+ sleep(ic * 100);
+ Exception ex = sub1.getException();
+ if (ex != null)
+ log.error("ValidPreconfDurSub got an exception: " + ex, ex);
+ Assert.assertTrue("ValidPreconfDurSub did not work", ex == null);
+ Assert.assertEquals("Subscriber did not get correct number of messages " + sub1.getMessageHandled(), ic, sub1
+ .getMessageHandled());
+ t1.interrupt();
+ }
+ finally
+ {
+ try
+ {
+ pub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ try
+ {
+ // if this stops working it might be that we have become spec
+ // compliant an do not allow unsubscribe with an open consumer.
+ sub1.unsubscribe();
+ sub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ public void testInvalidPreconfDurSub() throws Exception
+ {
+ TopicWorker sub1 = null;
+ try
+ {
+ // Clean testarea up
+ TEST_TOPIC = "topic/securedTopic";
+ //drainTopic();
+ int ic = 5;
+ // Set up a durable subscriber
+ IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message.class, "DURABLE_NR", 0, ic);
+ sub1 = new TopicWorker(SUBSCRIBER, TRANS_NONE, f1);
+ sub1.setDurable("john", "needle", "sub3");
+ Thread t1 = new Thread(sub1);
+ t1.start();
+ // Let is take some time to really set up the dur sub
+ sleep(2000);
+ Exception ex = sub1.getException();
+ Assert.assertTrue("InvalidPreconfDurSub did not get correct exception:" + ex,
+ ex instanceof javax.jms.JMSSecurityException);
+ t1.interrupt();
+ }
+ finally
+ {
+ try
+ {
+ sub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ public void testValidDynDurSub() throws Exception
+ {
+ TopicWorker sub1 = null;
+ TopicWorker pub1 = null;
+ try
+ {
+ // Clean testarea up
+ drainTopic();
+ int ic = 5;
+ // Set up a durable subscriber
+ IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message.class, "DURABLE_NR", 0, ic);
+ sub1 = new TopicWorker(SUBSCRIBER, TRANS_NONE, f1);
+ sub1.setDurable("dynsub", "dynsub", "sub4");
+ sub1.setClientID("myId");
+ Thread t1 = new Thread(sub1);
+ t1.start();
+ // Let is take some time to really set up the dur sub
+ sleep(2000);
+ // Publish
+ IntRangeMessageCreator c1 = new IntRangeMessageCreator("DURABLE_NR", 0);
+ pub1 = new TopicWorker(PUBLISHER, TRANS_NONE, c1, ic);
+ pub1.connect();
+ pub1.publish();
+ Assert.assertEquals("Publisher did not publish correct number of messages " + pub1.getMessageHandled(), ic,
+ pub1.getMessageHandled());
+ // let sub1 have some time to handle the messages.
+ log.debug("Sleeping for " + ((ic * 100) / 60000) + " minutes");
+ sleep(ic * 100);
+ Exception ex = sub1.getException();
+ if (ex != null)
+ log.error("ValidDynDurSub got an exception: " + ex, ex);
+ Assert.assertTrue("ValidDynDurSub did not work", ex == null);
+ Assert.assertEquals("Subscriber did not get correct number of messages " + sub1.getMessageHandled(), ic, sub1
+ .getMessageHandled());
+ t1.interrupt();
+ }
+ finally
+ {
+ try
+ {
+ pub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ try
+ {
+ // if this stops working it might be that we have become spec
+ // compliant an do not allow unsubscribe with an open consumer.
+ sub1.unsubscribe();
+ sub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ public void testInvalidDynDurSub() throws Exception
+ {
+ TopicWorker sub1 = null;
+ try
+ {
+ // Clean testarea up
+ TEST_TOPIC = "topic/securedTopic";
+ //drainTopic();
+ int ic = 5;
+ // Set up a durable subscriber
+ IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message.class, "DURABLE_NR", 0, ic);
+ sub1 = new TopicWorker(SUBSCRIBER, TRANS_NONE, f1);
+ sub1.setDurable("dynsub", "dynsub", "sub5");
+ sub1.setClientID("myId2");
+ Thread t1 = new Thread(sub1);
+ t1.start();
+ // Let is take some time to really set up the dur sub
+ sleep(2000);
+ Exception ex = sub1.getException();
+ Assert.assertTrue("InvalidDynDurSub did not get correct exception:" + ex,
+ ex instanceof javax.jms.JMSSecurityException);
+ t1.interrupt();
+ }
+ finally
+ {
+ try
+ {
+ sub1.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+}
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/SessionCloseStressTestCase.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/SessionCloseStressTestCase.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/SessionCloseStressTestCase.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,333 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.jbossmessaging.test;
+
+import java.util.Random;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.naming.Context;
+
+import junit.framework.Test;
+
+import org.jboss.test.jbossmessaging.JMSTestCase;
+
+/**
+ * Tests for receiving while closing the session
+ *
+ * @author <a href="mailto:richard.achmatowicz at jboss.com">Richard Achmatowicz</a>
+ * @author <a href="mailto:adrian at jboss.org>Adrian Brock</a>
+ * @version <tt>$Revision: 64130 $</tt>
+ */
+public class SessionCloseStressTestCase extends JMSTestCase
+{
+ static String QUEUE_FACTORY = "ConnectionFactory";
+ static String QUEUE = "queue/testQueue";
+
+ QueueConnection queueConnection;
+ Queue queue;
+
+ public SessionCloseStressTestCase(String name) throws Exception
+ {
+ super(name);
+ }
+
+ public abstract class TestRunnable implements Runnable
+ {
+ public Throwable error = null;
+
+ public abstract void doRun() throws Exception;
+
+ public void run()
+ {
+ try
+ {
+ doRun();
+ }
+ catch (Throwable t)
+ {
+ log.error("Error in " + Thread.currentThread(), t);
+ error = t;
+ }
+ }
+ }
+
+ public class SessionRunnable extends TestRunnable
+ {
+ MessageConsumer consumer;
+
+ int received = 0;
+
+ public void doRun() throws Exception
+ {
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer producer = session.createProducer(queue);
+ for (int i = 0; i < getIterationCount(); ++i)
+ {
+ Message message = session.createTextMessage("" + i);
+ producer.send(message);
+ }
+ producer.close();
+ consumer = session.createConsumer(queue);
+ waitForMessages();
+ session.close();
+ }
+
+ public synchronized MessageConsumer getConsumer() throws Exception
+ {
+ while (true)
+ {
+ if (consumer != null)
+ return consumer;
+ wait();
+ }
+ }
+
+ public synchronized void incReceived()
+ {
+ ++received;
+ notifyAll();
+ }
+
+ public synchronized void waitForMessages() throws Exception
+ {
+ notifyAll();
+ int target = new Random().nextInt(getIterationCount());
+ while (received < target)
+ wait();
+ }
+ }
+
+ public class ReceiverRunnable extends TestRunnable
+ {
+ SessionRunnable sessionRunnable;
+
+ public ReceiverRunnable(SessionRunnable sessionRunnable)
+ {
+ this.sessionRunnable = sessionRunnable;
+ }
+
+ public void doRun() throws Exception
+ {
+ MessageConsumer consumer = sessionRunnable.getConsumer();
+ try
+ {
+ while (true)
+ {
+ consumer.receive();
+ sessionRunnable.incReceived();
+ }
+ }
+ catch (JMSException expected)
+ {
+ if (expected.getMessage().indexOf("closed") == -1)
+ throw expected;
+ }
+ }
+ }
+
+ public class ReceiverNoWaitRunnable extends TestRunnable
+ {
+ SessionRunnable sessionRunnable;
+
+ public ReceiverNoWaitRunnable(SessionRunnable sessionRunnable)
+ {
+ this.sessionRunnable = sessionRunnable;
+ }
+
+ public void doRun() throws Exception
+ {
+ MessageConsumer consumer = sessionRunnable.getConsumer();
+ try
+ {
+ while (true)
+ {
+ if (consumer.receiveNoWait() != null)
+ sessionRunnable.incReceived();
+ }
+ }
+ catch (JMSException expected)
+ {
+ if (expected.getMessage().indexOf("closed") == -1)
+ throw expected;
+ }
+ }
+ }
+
+ public class ReceiverMessageListenerRunnable extends TestRunnable implements MessageListener
+ {
+ SessionRunnable sessionRunnable;
+
+ public ReceiverMessageListenerRunnable(SessionRunnable sessionRunnable)
+ {
+ this.sessionRunnable = sessionRunnable;
+ }
+
+ public void onMessage(Message message)
+ {
+ sessionRunnable.incReceived();
+ }
+
+ public void doRun() throws Exception
+ {
+ MessageConsumer consumer = sessionRunnable.getConsumer();
+ try
+ {
+ consumer.setMessageListener(this);
+ }
+ catch (JMSException expected)
+ {
+ if (expected.getMessage().indexOf("closed") == -1)
+ throw expected;
+ }
+ }
+ }
+
+ public void testSessionCloseCompetesWithReceive() throws Exception
+ {
+ connect();
+ try
+ {
+ for (int i = 0; i < getThreadCount(); ++i)
+ {
+ SessionRunnable sessionRunnable = new SessionRunnable();
+ Thread sessionThread = new Thread(sessionRunnable, "Session");
+ Thread consumerThread = new Thread(new ReceiverRunnable(sessionRunnable), "Consumer");
+ consumerThread.start();
+ sessionThread.start();
+ sessionThread.join();
+ consumerThread.join();
+ assertNull(sessionRunnable.error);
+
+ // Drain the queue
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer consumer = session.createConsumer(queue);
+ while (consumer.receiveNoWait() != null);
+ session.close();
+ }
+ }
+ finally
+ {
+ disconnect();
+ }
+ }
+
+ public void testSessionCloseCompetesWithReceiveNoWait() throws Exception
+ {
+ connect();
+ try
+ {
+ for (int i = 0; i < getThreadCount(); ++i)
+ {
+ SessionRunnable sessionRunnable = new SessionRunnable();
+ Thread sessionThread = new Thread(sessionRunnable, "Session");
+ Thread consumerThread = new Thread(new ReceiverNoWaitRunnable(sessionRunnable), "Consumer");
+ consumerThread.start();
+ sessionThread.start();
+ sessionThread.join();
+ consumerThread.join();
+ assertNull(sessionRunnable.error);
+
+ // Drain the queue
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer consumer = session.createConsumer(queue);
+ while (consumer.receiveNoWait() != null);
+ session.close();
+ }
+ }
+ finally
+ {
+ disconnect();
+ }
+ }
+
+ public void testSessionCloseCompetesWithMessageListener() throws Exception
+ {
+ connect();
+ try
+ {
+ for (int i = 0; i < getThreadCount(); ++i)
+ {
+ SessionRunnable sessionRunnable = new SessionRunnable();
+ Thread sessionThread = new Thread(sessionRunnable, "Session");
+ Thread consumerThread = new Thread(new ReceiverMessageListenerRunnable(sessionRunnable), "Consumer");
+ consumerThread.start();
+ sessionThread.start();
+ sessionThread.join();
+ consumerThread.join();
+ assertNull(sessionRunnable.error);
+
+ // Drain the queue
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer consumer = session.createConsumer(queue);
+ while (consumer.receiveNoWait() != null);
+ session.close();
+ }
+ }
+ finally
+ {
+ disconnect();
+ }
+ }
+
+ protected void connect() throws Exception
+ {
+ Context context = getInitialContext();
+ queue = (Queue) context.lookup(QUEUE);
+ QueueConnectionFactory queueFactory = (QueueConnectionFactory) context.lookup(QUEUE_FACTORY);
+ queueConnection = queueFactory.createQueueConnection();
+ queueConnection.start();
+
+ getLog().debug("Connection established.");
+ }
+
+ protected void disconnect()
+ {
+ try
+ {
+ if (queueConnection != null)
+ queueConnection.close();
+ }
+ catch (Exception ignored)
+ {
+ }
+
+ getLog().debug("Connection closed.");
+ }
+
+ public static Test suite() throws Exception
+ {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ String resourceName = getJMSResourceRelativePathname("tests-destinations-service.xml") ;
+
+ return getDeploySetup(SessionCloseStressTestCase.class,
+ loader.getResource(resourceName).toString());
+ }
+}
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/TemporarySessionConnectionUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/TemporarySessionConnectionUnitTestCase.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/TemporarySessionConnectionUnitTestCase.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,119 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbossmessaging.test;
+
+import javax.jms.JMSException;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.jms.TemporaryQueue;
+import javax.naming.Context;
+
+import org.jboss.test.jbossmessaging.JMSTestCase;
+
+/**
+ * Tests for temporaries and session/connection consumer construction
+ *
+ * @author <a href="mailto:richard.achmatowicz at jboss.com">Richard Achmatowicz</a>
+ * @author <a href="mailto:adrian at jboss.org>Adrian Brock</a>
+ * @version <tt>$Revision: 64130 $</tt>
+ */
+public class TemporarySessionConnectionUnitTestCase extends JMSTestCase
+{
+ static String QUEUE_FACTORY = "ConnectionFactory";
+
+ QueueConnection queueConnection;
+
+ public TemporarySessionConnectionUnitTestCase(String name) throws Exception
+ {
+ super(name);
+ }
+
+ public void testTemporaryDifferentSession() throws Exception
+ {
+ connect();
+ try
+ {
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ TemporaryQueue temp = session.createTemporaryQueue();
+ session.createConsumer(temp);
+ session.close();
+ session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ session.createConsumer(temp).close();
+ }
+ finally
+ {
+ disconnect();
+ }
+ }
+
+ public void testTemporaryDifferentConnection() throws Exception
+ {
+ connect();
+ try
+ {
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ TemporaryQueue temp = session.createTemporaryQueue();
+ session.createConsumer(temp);
+ disconnect();
+ connect();
+ session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ try
+ {
+ session.createConsumer(temp).close();
+ fail("Should not be able to consume a temporary on different connection");
+ }
+ catch (JMSException expected)
+ {
+ }
+ }
+ finally
+ {
+ disconnect();
+ }
+ }
+
+ protected void connect() throws Exception
+ {
+ Context context = getInitialContext();
+ QueueConnectionFactory queueFactory = (QueueConnectionFactory) context.lookup(QUEUE_FACTORY);
+ queueConnection = queueFactory.createQueueConnection();
+ queueConnection.start();
+
+ getLog().debug("Connection established.");
+ }
+
+ protected void disconnect()
+ {
+ try
+ {
+ if (queueConnection != null)
+ queueConnection.close();
+ }
+ catch (Exception ignored)
+ {
+ }
+
+ getLog().debug("Connection closed.");
+ }
+}
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/UnackedUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/UnackedUnitTestCase.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/UnackedUnitTestCase.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,749 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbossmessaging.test;
+
+import javax.jms.BytesMessage;
+import javax.jms.DeliveryMode;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+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.Session;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicPublisher;
+import javax.jms.TopicSession;
+import javax.jms.TopicSubscriber;
+import javax.naming.Context;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.log4j.Logger;
+import org.jboss.test.jbossmessaging.JMSTestCase;
+
+/**
+ * Rollback tests
+ *
+ * @author <a href="mailto:richard.achmatowicz at jboss.com">Richard Achmatowicz</a>
+ * @author
+ * @version $Revision: 64265 $
+ */
+public class UnackedUnitTestCase extends JMSTestCase
+{
+ // Provider specific
+ static String TOPIC_FACTORY = "ConnectionFactory";
+ static String QUEUE_FACTORY = "ConnectionFactory";
+
+ static String TEST_QUEUE = "queue/testQueue";
+ static String TEST_TOPIC = "topic/testTopic";
+ static String TEST_DURABLE_TOPIC = "topic/testDurableTopic";
+
+ static byte[] PAYLOAD = new byte[10];
+
+ static Context context;
+ static QueueConnection queueConnection;
+ static TopicConnection topicConnection;
+ static TopicConnection topicDurableConnection;
+
+ public static Test suite() throws Exception
+ {
+ // JBAS-3580, the execution order of tests in this test case is important
+ // so it must be defined explicitly when running under some JVMs
+ TestSuite suite = new TestSuite();
+ suite.addTest(new UnackedUnitTestCase("testUnackedQueue"));
+ suite.addTest(new UnackedUnitTestCase("testUnackedMultipleConnection"));
+ suite.addTest(new UnackedUnitTestCase("testUnackedMultipleSession"));
+ suite.addTest(new UnackedUnitTestCase("testUnackedTopic"));
+ suite.addTest(new UnackedUnitTestCase("testUnackedDurableTopic"));
+ suite.addTest(new UnackedUnitTestCase("testDummyLast"));
+
+ return suite;
+ }
+
+ /**
+ * Constructor the test
+ *
+ * @param name Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ public UnackedUnitTestCase(String name) throws Exception
+ {
+ super(name);
+ }
+
+ /**
+ * #Description of the Method
+ *
+ * @param persistence Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ public void runUnackedQueue(final int persistence) throws Exception
+ {
+ drainQueue();
+
+ final int iterationCount = getIterationCount();
+
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue)context.lookup(TEST_QUEUE);
+
+ QueueSender sender = session.createSender(queue);
+
+ Message message = session.createBytesMessage();
+ ((BytesMessage)message).writeBytes(PAYLOAD);
+
+ for (int i = 0; i < iterationCount; i++)
+ sender.send(message, persistence, 4, 0);
+
+ session.close();
+
+ session = queueConnection.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
+ queue = (Queue)context.lookup(TEST_QUEUE);
+ QueueReceiver receiver = session.createReceiver(queue);
+ queueConnection.start();
+ message = receiver.receive(50);
+ int c = 0;
+ while (message != null)
+ {
+ message = receiver.receive(50);
+ c++;
+ }
+ assertTrue("Should have received all data unacked", c == iterationCount);
+
+ queueConnection.close();
+ QueueConnectionFactory queueFactory = (QueueConnectionFactory)context.lookup(QUEUE_FACTORY);
+ queueConnection = queueFactory.createQueueConnection();
+
+ assertTrue("Queue should be full", drainQueue() == iterationCount);
+
+ }
+
+ /**
+ * #Description of the Method
+ *
+ * @param persistence Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ public void runUnackedMultipleSession(final int persistence) throws Exception
+ {
+ System.out.println("++ runUnackedMultipleSession");
+ drainQueue();
+
+ final int iterationCount = getIterationCount();
+
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue)context.lookup(TEST_QUEUE);
+
+ QueueSender sender = session.createSender(queue);
+
+ Message message = session.createBytesMessage();
+ ((BytesMessage)message).writeBytes(PAYLOAD);
+
+ for (int i = 0; i < iterationCount; i++)
+ sender.send(message, persistence, 4, 0);
+
+ session.close();
+
+ QueueSession session1 = queueConnection.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
+ QueueSession session2 = queueConnection.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
+ try
+ {
+ queue = (Queue)context.lookup(TEST_QUEUE);
+ QueueReceiver receiver1 = session1.createReceiver(queue);
+
+ QueueReceiver receiver2 = session2.createReceiver(queue);
+ queueConnection.start();
+
+ int c1=0, c2=0;
+
+ Message messageConsumer1=null, messageConsumer2=null;
+
+ Message lastMessageConsumer1 = null, lastMessageConsumer2=null;
+
+ do
+ {
+ messageConsumer1 = receiver1.receive(1000);
+ messageConsumer2 = receiver2.receive(1000);
+ if (messageConsumer1 != null)
+ {
+ c1 ++;
+ lastMessageConsumer1 = messageConsumer1;
+ }
+
+ if (messageConsumer2 != null)
+ {
+ c2 ++;
+ lastMessageConsumer2 = messageConsumer2;
+ }
+
+ System.out.println("messageConsumer1=" + messageConsumer1 + " messageConsumer2=" + messageConsumer2 + " c1=" + c1 + " c2 = " + c2);
+ }
+ while (messageConsumer1!=null || messageConsumer2!=null);
+
+ assertEquals(iterationCount, c1 + c2);
+
+ lastMessageConsumer1.acknowledge();
+ lastMessageConsumer2.acknowledge();
+
+ queueConnection.stop();
+ session1.close();
+ session2.close();
+ }
+ finally
+ {
+ try
+ {
+ session1.close();
+ }
+ catch (Throwable ignored)
+ {
+ }
+ try
+ {
+ session2.close();
+ }
+ catch (Throwable ignored)
+ {
+ }
+ }
+
+ System.out.println("-- runUnackedMultipleSession");
+ }
+
+ /**
+ * #Description of the Method
+ *
+ * @param persistence Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ public void runUnackedMultipleConnection(final int persistence) throws Exception
+ {
+ System.out.println("++runUnackedMultipleConnection");
+ drainQueue();
+
+ final int iterationCount = getIterationCount();
+
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue)context.lookup(TEST_QUEUE);
+
+ QueueSender sender = session.createSender(queue);
+
+ Message message = session.createBytesMessage();
+ ((BytesMessage)message).writeBytes(PAYLOAD);
+
+ for (int i = 0; i < iterationCount; i++)
+ sender.send(message, persistence, 4, 0);
+
+ session.close();
+
+ QueueConnectionFactory queueFactory = (QueueConnectionFactory)context.lookup(QUEUE_FACTORY);
+ QueueConnection queueConnection1 = queueFactory.createQueueConnection();
+ QueueConnection queueConnection2 = queueFactory.createQueueConnection();
+
+ try
+ {
+ QueueSession session1 = queueConnection1.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
+ queue = (Queue)context.lookup(TEST_QUEUE);
+ QueueReceiver receiver1 = session1.createReceiver(queue);
+
+ QueueSession session2 = queueConnection2.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
+ QueueReceiver receiver2 = session2.createReceiver(queue);
+
+ queueConnection1.start();
+ queueConnection2.start();
+
+ int c1=0, c2=0;
+
+ Message messageConsumer1=null, messageConsumer2=null;
+
+ Message lastMessageConsumer1 = null, lastMessageConsumer2=null;
+
+ do
+ {
+ messageConsumer1 = receiver1.receive(100);
+ messageConsumer2 = receiver2.receive(100);
+ if (messageConsumer1 != null)
+ {
+ c1 ++;
+ lastMessageConsumer1 = messageConsumer1;
+ }
+
+ if (messageConsumer2 != null)
+ {
+ c2 ++;
+ lastMessageConsumer2 = messageConsumer2;
+ }
+
+ System.out.println("messageConsumer1=" + messageConsumer1 + " messageConsumer2=" + messageConsumer2 + " c1=" + c1 + " c2 = " + c2);
+ }
+ while (messageConsumer1!=null || messageConsumer2!=null);
+
+ if (lastMessageConsumer1!=null) lastMessageConsumer1.acknowledge();
+ if (lastMessageConsumer2!=null) lastMessageConsumer2.acknowledge();
+
+ assertEquals(iterationCount, c1 + c2);
+
+ }
+ finally
+ {
+ try{queueConnection1.close();} catch (Throwable ignored){}
+ try{queueConnection2.close();} catch (Throwable ignored){}
+ }
+
+ System.out.println("--runUnackedMultipleConnection");
+ }
+
+ /**
+ * #Description of the Method
+ *
+ * @param persistence Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ public void runUnackedTopic(final int persistence) throws Exception
+ {
+ drainQueue();
+ drainTopic();
+
+ final int iterationCount = getIterationCount();
+ final Logger log = getLog();
+
+ Thread sendThread =
+ new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+
+ TopicSession session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic topic = (Topic)context.lookup(TEST_TOPIC);
+
+ TopicPublisher publisher = session.createPublisher(topic);
+
+ waitForSynchMessage();
+
+ BytesMessage message = session.createBytesMessage();
+ message.writeBytes(PAYLOAD);
+
+ for (int i = 0; i < iterationCount; i++)
+ {
+ publisher.publish(message, persistence, 4, 0);
+ }
+
+ session.close();
+ }
+ catch (Exception e)
+ {
+ log.error("error", e);
+ }
+ }
+ };
+
+ TopicSession session = topicConnection.createTopicSession(false, Session.CLIENT_ACKNOWLEDGE);
+ Topic topic = (Topic)context.lookup(TEST_TOPIC);
+ TopicSubscriber subscriber = session.createSubscriber(topic);
+
+
+ MyMessageListener listener = new MyMessageListener(iterationCount, log);
+
+ queueConnection.start();
+ sendThread.start();
+ subscriber.setMessageListener(listener);
+ topicConnection.start();
+ sendSynchMessage();
+ synchronized (listener)
+ {
+ if (listener.i < iterationCount)
+ listener.wait(5000);
+
+ assertEquals(iterationCount, listener.i);
+ }
+ sendThread.join();
+ topicConnection.close();
+ TopicConnectionFactory topicFactory = (TopicConnectionFactory)context.lookup(TOPIC_FACTORY);
+ topicConnection = topicFactory.createTopicConnection();
+ queueConnection.stop();
+ assertTrue("Topic should be empty", drainTopic() == 0);
+ }
+
+ /**
+ * #Description of the Method
+ *
+ * @param persistence Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ public void runUnackedDurableTopic(final int persistence) throws Exception
+ {
+ drainQueue();
+ drainDurableTopic();
+
+ final int iterationCount = getIterationCount();
+ final Logger log = getLog();
+
+ Thread sendThread =
+ new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+
+ TopicSession session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic topic = (Topic)context.lookup(TEST_DURABLE_TOPIC);
+
+ TopicPublisher publisher = session.createPublisher(topic);
+
+ waitForSynchMessage();
+
+ BytesMessage message = session.createBytesMessage();
+ message.writeBytes(PAYLOAD);
+
+ for (int i = 0; i < iterationCount; i++)
+ {
+ publisher.publish(message, persistence, 4, 0);
+ }
+
+ session.close();
+ }
+ catch (Exception e)
+ {
+ log.error("error", e);
+ }
+ }
+ };
+
+ TopicSession session = topicDurableConnection.createTopicSession(false, Session.CLIENT_ACKNOWLEDGE);
+ Topic topic = (Topic)context.lookup(TEST_DURABLE_TOPIC);
+ TopicSubscriber subscriber = session.createDurableSubscriber(topic, "test");
+
+ MyMessageListener listener = new MyMessageListener(iterationCount, log);
+
+ queueConnection.start();
+ sendThread.start();
+ subscriber.setMessageListener(listener);
+ topicDurableConnection.start();
+ sendSynchMessage();
+ synchronized (listener)
+ {
+ System.out.println("Hello");
+ if (listener.i < iterationCount)
+ {
+ listener.wait(5000);
+ }
+ assertEquals(iterationCount, listener.i);
+ }
+
+
+ sendThread.join();
+ topicDurableConnection.close();
+ TopicConnectionFactory topicFactory = (TopicConnectionFactory)context.lookup(TOPIC_FACTORY);
+ topicDurableConnection = topicFactory.createTopicConnection("john", "needle");
+ queueConnection.stop();
+ assertTrue("Topic should be full", drainDurableTopic() == iterationCount);
+ }
+
+ /**
+ * A unit test for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
+ public void testUnackedQueue() throws Exception
+ {
+
+ getLog().debug("Starting UnackedQueue test");
+
+ runUnackedQueue(DeliveryMode.NON_PERSISTENT);
+ runUnackedQueue(DeliveryMode.PERSISTENT);
+
+ getLog().debug("UnackedQueue passed");
+ }
+
+ /**
+ * A unit test for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
+ public void testUnackedMultipleSession() throws Exception
+ {
+
+ getLog().debug("Starting UnackedMultipleSession test");
+
+ runUnackedMultipleSession(DeliveryMode.NON_PERSISTENT);
+ runUnackedMultipleSession(DeliveryMode.PERSISTENT);
+
+ getLog().debug("UnackedMultipleSession passed");
+ }
+
+ /**
+ * A unit test for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
+ public void testUnackedMultipleConnection() throws Exception
+ {
+
+ getLog().debug("Starting UnackedMultipleConnection test");
+
+ runUnackedMultipleConnection(DeliveryMode.NON_PERSISTENT);
+ runUnackedMultipleConnection(DeliveryMode.PERSISTENT);
+
+ getLog().debug("UnackedMultipleConnection passed");
+ }
+
+ /**
+ * A unit test for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
+ public void testUnackedTopic() throws Exception
+ {
+
+ getLog().debug("Starting UnackedTopic test");
+
+ runUnackedTopic(DeliveryMode.NON_PERSISTENT);
+ runUnackedTopic(DeliveryMode.PERSISTENT);
+
+ getLog().debug("UnackedTopic passed");
+ }
+
+ /**
+ * A unit test for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
+ public void testUnackedDurableTopic() throws Exception
+ {
+
+ getLog().debug("Starting UnackedDurableTopic test");
+
+ runUnackedDurableTopic(DeliveryMode.NON_PERSISTENT);
+ runUnackedDurableTopic(DeliveryMode.PERSISTENT);
+
+ getLog().debug("UnackedDurableTopic passed");
+ }
+
+ /**
+ * A unit test for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
+ public void testDummyLast() throws Exception
+ {
+
+ TopicSession session = topicDurableConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ session.unsubscribe("test");
+
+ queueConnection.close();
+ topicConnection.close();
+ topicDurableConnection.close();
+ }
+
+ /**
+ * The JUnit setup method
+ *
+ * @exception Exception Description of Exception
+ */
+ protected void setUp() throws Exception
+ {
+ // call setUp() in superclass
+ super.setUp() ;
+
+ if (context == null)
+ {
+ context = getInitialContext();
+ }
+
+ QueueConnectionFactory queueFactory = (QueueConnectionFactory)context.lookup(QUEUE_FACTORY);
+ queueConnection = queueFactory.createQueueConnection();
+
+ TopicConnectionFactory topicFactory = (TopicConnectionFactory)context.lookup(TOPIC_FACTORY);
+ topicConnection = topicFactory.createTopicConnection();
+ topicDurableConnection = topicFactory.createTopicConnection("john", "needle");
+ }
+
+ protected void tearDown() throws Exception
+ {
+ if (queueConnection != null)
+ {
+ queueConnection.close();
+ queueConnection = null;
+ }
+
+ if (topicConnection != null)
+ {
+ topicConnection.close();
+ topicConnection = null;
+ }
+
+ if (topicDurableConnection != null)
+ {
+ topicDurableConnection.close();
+ topicDurableConnection = null;
+ }
+ }
+
+ // Emptys out all the messages in a queue
+ private int drainQueue() throws Exception
+ {
+ getLog().debug("Draining Queue");
+ queueConnection.start();
+
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue)context.lookup(TEST_QUEUE);
+
+ QueueReceiver receiver = session.createReceiver(queue);
+ Message message = receiver.receive(1000);
+ int c = 0;
+ while (message != null)
+ {
+ message = receiver.receive(1000);
+ c++;
+ }
+
+ getLog().debug(" Drained " + c + " messages from the queue");
+
+ session.close();
+
+ queueConnection.stop();
+
+ return c;
+ }
+
+ // Emptys out all the messages in a topic
+ private int drainTopic() throws Exception
+ {
+ getLog().debug("Draining Topic");
+ topicConnection.start();
+
+ final TopicSession session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic topic = (Topic)context.lookup(TEST_TOPIC);
+ TopicSubscriber subscriber = session.createSubscriber(topic);
+
+ Message message = subscriber.receive(1000);
+ int c = 0;
+ while (message != null)
+ {
+ message = subscriber.receive(1000);
+ c++;
+ }
+
+ getLog().debug(" Drained " + c + " messages from the topic");
+
+ session.close();
+
+ topicConnection.stop();
+
+ return c;
+ }
+
+ // Emptys out all the messages in a durable topic
+ private int drainDurableTopic() throws Exception
+ {
+ getLog().debug("Draining Durable Topic");
+ topicDurableConnection.start();
+
+ final TopicSession session = topicDurableConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic topic = (Topic)context.lookup(TEST_DURABLE_TOPIC);
+ TopicSubscriber subscriber = session.createDurableSubscriber(topic, "test");
+
+ Message message = subscriber.receive(1000);
+ int c = 0;
+ while (message != null)
+ {
+ message = subscriber.receive(1000);
+ c++;
+ }
+
+ getLog().debug(" Drained " + c + " messages from the durable topic");
+
+ session.close();
+
+ topicDurableConnection.stop();
+
+ return c;
+ }
+
+ private void waitForSynchMessage() throws Exception
+ {
+ getLog().debug("Waiting for Synch Message");
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue)context.lookup(TEST_QUEUE);
+
+ QueueReceiver receiver = session.createReceiver(queue);
+ receiver.receive();
+ session.close();
+ getLog().debug("Got Synch Message");
+ }
+
+ private void sendSynchMessage() throws Exception
+ {
+ getLog().debug("Sending Synch Message");
+ QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = (Queue)context.lookup(TEST_QUEUE);
+
+ QueueSender sender = session.createSender(queue);
+
+ Message message = session.createMessage();
+ sender.send(message);
+
+ session.close();
+ getLog().debug("Sent Synch Message");
+ }
+
+ public class MyMessageListener
+ implements MessageListener
+ {
+ public int i = 0;
+
+ public int iterationCount;
+
+ public Logger log;
+
+ public MyMessageListener(int iterationCount, Logger log)
+ {
+ this.iterationCount = iterationCount;
+ this.log = log;
+ }
+
+ public void onMessage(Message message)
+ {
+ synchronized (this)
+ {
+ System.out.println("Listener:: Got message " + i);
+ i++;
+ log.debug("Got message " + i);
+ if (i >= iterationCount)
+ this.notifyAll();
+ }
+ }
+ }
+
+ public int getIterationCount()
+ {
+ return 200;
+ }
+}
Added: branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/XAResourceUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/XAResourceUnitTestCase.java (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/main/org/jboss/test/jbossmessaging/test/XAResourceUnitTestCase.java 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,201 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbossmessaging.test;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.Message;
+import javax.jms.Topic;
+import javax.jms.TopicPublisher;
+import javax.jms.TopicSession;
+import javax.jms.TopicSubscriber;
+import javax.jms.XATopicConnection;
+import javax.jms.XATopicConnectionFactory;
+import javax.jms.XATopicSession;
+import javax.naming.InitialContext;
+import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
+
+import org.jboss.test.jbossmessaging.JMSTestCase;
+
+/**
+ * XAResource tests
+ *
+ * @author <a href="mailto:richard.achmatowicz at jboss.com">Richard Achmatowicz</a>
+ * @author
+ * @version
+ */
+public class XAResourceUnitTestCase extends JMSTestCase
+{
+ static String XA_TOPIC_FACTORY = "XAConnectionFactory";
+ static String FACTORY = "ConnectionFactory";
+
+ static String TEST_TOPIC = "topic/testTopic";
+
+ public XAResourceUnitTestCase(String name) throws Exception
+ {
+ super(name);
+ }
+
+ public void testXAResourceSuspendWorkCommit() throws Exception
+ {
+ InitialContext context = getInitialContext();
+ XATopicConnectionFactory factory = (XATopicConnectionFactory) context.lookup(XA_TOPIC_FACTORY);
+ Topic topic = (Topic) context.lookup(TEST_TOPIC);
+
+ XATopicConnection connection = factory.createXATopicConnection();
+ try
+ {
+ // Set up
+ XATopicSession xaSession = connection.createXATopicSession();
+ TopicSession session = xaSession.getTopicSession();
+ TopicPublisher publisher = session.createPublisher(topic);
+ Message message = session.createTextMessage();
+
+ // Add the xa resource to xid1
+ MyXid xid1 = new MyXid();
+ XAResource resource = xaSession.getXAResource();
+ resource.start(xid1, XAResource.TMNOFLAGS);
+
+ // Do some work
+ publisher.publish(message);
+
+ // Suspend the transaction
+ resource.end(xid1, XAResource.TMSUSPEND);
+
+ // Add the xa resource to xid2
+ MyXid xid2 = new MyXid();
+ resource.start(xid2, XAResource.TMNOFLAGS);
+
+ // Do some work in the new transaction
+ publisher.publish(message);
+
+ // Commit the first transaction and end the branch
+ resource.end(xid1, XAResource.TMSUCCESS);
+ resource.commit(xid1, true);
+
+ // Do some more work in the new transaction
+ publisher.publish(message);
+
+ // Commit the second transaction and end the branch
+ resource.end(xid2, XAResource.TMSUCCESS);
+ resource.commit(xid2, true);
+ }
+ finally
+ {
+ connection.close();
+ }
+ }
+
+ public void testXAResourceRollbackAfterPrepare() throws Exception
+ {
+ InitialContext context = getInitialContext();
+ XATopicConnectionFactory factory = (XATopicConnectionFactory) context.lookup(XA_TOPIC_FACTORY);
+
+ Topic topic = (Topic) context.lookup(TEST_TOPIC);
+
+ XATopicConnection connection = factory.createXATopicConnection();
+ try
+ {
+ // Set up
+ XATopicSession xaSession = connection.createXATopicSession();
+
+ // Add the xa resource to xid1
+ MyXid xid1 = new MyXid();
+ XAResource resource = xaSession.getXAResource();
+ resource.start(xid1, XAResource.TMNOFLAGS);
+
+ TopicSession session = xaSession.getTopicSession();
+ TopicSubscriber subscriber = session.createSubscriber(topic);
+ connection.start();
+ TopicPublisher publisher = session.createPublisher(topic);
+ Message message = session.createTextMessage();
+
+ // Publish a message using "AutoAcknowledge"
+ publisher.publish(message);
+
+ resource.end(xid1, XAResource.TMSUCCESS);
+ resource.prepare(xid1);
+ // JBossMessaging only sends the message when a commit is done, while JBossMQ would send messages to consumers on the same session,
+ // doing something differently on the transaction isolation.
+ // Because of that this commit is necessary to complete this testcase.
+ resource.commit(xid1, false);
+
+ xid1 = new MyXid();
+ resource.start(xid1, XAResource.TMNOFLAGS);
+
+ // Receive the message
+ message = subscriber.receive(1000);
+ if (message == null)
+ fail("No message?");
+
+ // Prepare the transaction
+ resource.end(xid1, XAResource.TMSUCCESS);
+ resource.prepare(xid1);
+
+ // Rollback
+ resource.rollback(xid1);
+
+ xid1 = new MyXid();
+ resource.start(xid1, XAResource.TMNOFLAGS);
+ // Receive the message using "AutoAcknowledge"
+ message = subscriber.receiveNoWait();
+ if (message == null)
+ fail("No message after rollback?");
+ resource.commit(xid1, true);
+
+ }
+ finally
+ {
+ connection.close();
+ }
+ }
+
+ public static class MyXid
+ implements Xid
+ {
+ static byte next = 0;
+
+ byte[] xid;
+ byte[] branch;
+
+ public MyXid()
+ {
+ xid = new byte[] { ++next };
+ branch = new byte[] { ++ next };
+ }
+
+ public int getFormatId()
+ {
+ return 314;
+ }
+
+ public byte[] getGlobalTransactionId()
+ {
+ return xid;
+ }
+
+ public byte[] getBranchQualifier()
+ {
+ return branch;
+ }
+ }
+}
Added: branches/JBPAPP_4_2/testsuite/src/resources/jbossmessaging/provider.properties
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/resources/jbossmessaging/provider.properties (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/resources/jbossmessaging/provider.properties 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,34 @@
+##
+# JORAM: Java(TM) Open Reliable Asynchronous Messaging
+# Copyright (C) 2002 INRIA
+# Contact: joram-team at objectweb.org
+#
+# This library 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 any later version.
+#
+# This library 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 library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA
+#
+# Initial developer(s): Jeff Mesnil (jmesnil at inrialpes.fr)
+# Contributor(s): ______________________________________.
+##
+
+##
+# This property is used to chose which provider is to be tested
+# Uncomment the chosen provider and comment the other ones
+##
+
+jms.provider.admin.class = org.jboss.test.jbossmessaging.JBossMessagingAdmin
+jms.provider.resources.dir = jbossmessaging
+#jms.provider.admin.class = org.jboss.test.jbossmq.JBossMQAdmin
+#jms.provider.resources.dir = jbossmq
+
Added: branches/JBPAPP_4_2/testsuite/src/resources/jbossmessaging/test-destinations-full-service.xml
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/resources/jbossmessaging/test-destinations-full-service.xml (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/resources/jbossmessaging/test-destinations-full-service.xml 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<server>
+
+ <mbean code="org.jboss.jms.server.destination.TopicService"
+ name="jboss.messaging.destination:service=Topic,name=testTopic"
+ xmbean-dd="xmdesc/Topic-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <attribute name="SecurityConfig">
+ <security>
+ <role name="guest" read="true" write="true"/>
+ <role name="publisher" read="true" write="true" create="false"/>
+ <role name="durpublisher" read="true" write="true" create="true"/>
+ </security>
+ </attribute>
+ </mbean>
+
+ <mbean code="org.jboss.jms.server.destination.TopicService"
+ name="jboss.messaging.destination:service=Topic,name=securedTopic"
+ xmbean-dd="xmdesc/Topic-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <attribute name="SecurityConfig">
+ <security>
+ <role name="publisher" read="true" write="true" create="false"/>
+ </security>
+ </attribute>
+ </mbean>
+
+ <mbean code="org.jboss.jms.server.destination.TopicService"
+ name="jboss.messaging.destination:service=Topic,name=testDurableTopic"
+ xmbean-dd="xmdesc/Topic-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <attribute name="SecurityConfig">
+ <security>
+ <role name="guest" read="true" write="true"/>
+ <role name="publisher" read="true" write="true" create="false"/>
+ <role name="durpublisher" read="true" write="true" create="true"/>
+ </security>
+ </attribute>
+ </mbean>
+
+
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.messaging.destination:service=Queue,name=testQueue"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <attribute name="SecurityConfig">
+ <security>
+ <role name="guest" read="true" write="true"/>
+ <role name="publisher" read="true" write="true" create="false"/>
+ <role name="noacc" read="false" write="false" create="false"/>
+ </security>
+ </attribute>
+ </mbean>
+
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.messaging.destination:service=Queue,name=A"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ </mbean>
+
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.messaging.destination:service=Queue,name=B"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ </mbean>
+
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.messaging.destination:service=Queue,name=C"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ </mbean>
+
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.messaging.destination:service=Queue,name=D"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ </mbean>
+
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.messaging.destination:service=Queue,name=ex"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ </mbean>
+
+</server>
Added: branches/JBPAPP_4_2/testsuite/src/resources/mdb4jbm/META-INF/ejb-jar.xml
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/resources/mdb4jbm/META-INF/ejb-jar.xml (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/resources/mdb4jbm/META-INF/ejb-jar.xml 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,203 @@
+<?xml version="1.0"?>
+
+<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/j2ee/dtds/ejb-jar_2_0.dtd">
+
+<ejb-jar>
+ <enterprise-beans>
+
+ <message-driven>
+ <ejb-name>ObjectMessageBean</ejb-name>
+ <ejb-class>org.jboss.test.mdb.bean.ObjectMessageBean</ejb-class>
+ <message-selector></message-selector>
+ <transaction-type>Bean</transaction-type>
+ <acknowledge-mode>AUTO_ACKNOWLEDGE</acknowledge-mode>
+ <message-driven-destination>
+ <destination-type>javax.jms.Queue</destination-type>
+ <subscription-durability>NonDurable</subscription-durability>
+ </message-driven-destination>
+ </message-driven>
+
+ <message-driven>
+ <ejb-name>BMTTXTimeOutBean</ejb-name>
+ <ejb-class>org.jboss.test.mdb.bean.TXTimeOutBean</ejb-class>
+ <message-selector></message-selector>
+ <transaction-type>Bean</transaction-type>
+ <acknowledge-mode>AUTO_ACKNOWLEDGE</acknowledge-mode>
+ <message-driven-destination>
+ <destination-type>javax.jms.Queue</destination-type>
+ <subscription-durability>NonDurable</subscription-durability>
+ </message-driven-destination>
+ </message-driven>
+
+ <message-driven>
+ <ejb-name>CMTTXTimeOutBean</ejb-name>
+ <ejb-class>org.jboss.test.mdb.bean.TXTimeOutBean</ejb-class>
+ <message-selector></message-selector>
+ <transaction-type>Container</transaction-type>
+ <acknowledge-mode>AUTO_ACKNOWLEDGE</acknowledge-mode>
+ <message-driven-destination>
+ <destination-type>javax.jms.Queue</destination-type>
+ <subscription-durability>NonDurable</subscription-durability>
+ </message-driven-destination>
+ </message-driven>
+
+
+ <message-driven>
+ <ejb-name>QueueBean</ejb-name>
+ <ejb-class>org.jboss.test.mdb.bean.QueueBean</ejb-class>
+<!--
+ <message-selector>JMSType='activityCompletion'</message-selector>
+-->
+ <message-selector></message-selector>
+ <!-- We also have the acknowledge-mode - AUTO_ACKNOWLEDGE | DUPS_OK_AKNOWLEDGE - for bean managed transactions, and the subscription-durability for topic destination types -->
+ <transaction-type>Bean</transaction-type>
+ <acknowledge-mode>AUTO_ACKNOWLEDGE</acknowledge-mode>
+
+ <message-driven-destination>
+ <destination-type>javax.jms.Queue</destination-type>
+<!--
+Only with topic
+ <subscription-durability>Durable</subscription-durability>
+-->
+<subscription-durability>NonDurable</subscription-durability>
+ </message-driven-destination>
+ </message-driven>
+ <message-driven>
+ <ejb-name>TopicBean</ejb-name>
+ <ejb-class>org.jboss.test.mdb.bean.TopicBean</ejb-class>
+<!--
+ <message-selector>JMSType='activityCompletion'</message-selector>
+-->
+ <message-selector></message-selector>
+ <!-- We also have the acknowledge-mode - AUTO_ACKNOWLEDGE | DUPS_OK_AKNOWLEDGE - for bean managed transactions, and the subscription-durability for topic destination types -->
+ <transaction-type>Container</transaction-type>
+ <!-- <acknowledge-mode>AUTO_ACKNOWLEDGE</acknowledge-mode> -->
+
+ <message-driven-destination>
+ <destination-type>javax.jms.Topic</destination-type>
+<!--
+Only with topic
+ <subscription-durability>Durable</subscription-durability>
+-->
+<subscription-durability>NonDurable</subscription-durability>
+ </message-driven-destination>
+ </message-driven>
+ <message-driven>
+ <ejb-name>DurableTopicBean</ejb-name>
+ <ejb-class>org.jboss.test.mdb.bean.TopicBean</ejb-class>
+<!--
+ <message-selector>JMSType='activityCompletion'</message-selector>
+-->
+ <message-selector></message-selector>
+ <!-- We also have the acknowledge-mode - AUTO_ACKNOWLEDGE | DUPS_OK_AKNOWLEDGE - for bean managed transactions, and the subscription-durability for topic destination types -->
+ <transaction-type>Container</transaction-type>
+ <!-- <acknowledge-mode>AUTO_ACKNOWLEDGE</acknowledge-mode> -->
+
+ <message-driven-destination>
+ <destination-type>javax.jms.Topic</destination-type>
+<!--
+Only with topic
+ <subscription-durability>Durable</subscription-durability>
+-->
+<subscription-durability>Durable</subscription-durability>
+ </message-driven-destination>
+ </message-driven>
+ <message-driven>
+ <ejb-name>ExQueueBean</ejb-name>
+ <ejb-class>org.jboss.test.mdb.bean.ExQueueBean</ejb-class>
+ <message-selector></message-selector>
+ <transaction-type>Container</transaction-type>
+
+ <message-driven-destination>
+ <destination-type>javax.jms.Queue</destination-type>
+ <subscription-durability>NonDurable</subscription-durability>
+ </message-driven-destination>
+ </message-driven>
+
+ <message-driven>
+ <ejb-name>QueueInADifferentContext</ejb-name>
+ <ejb-class>org.jboss.test.mdb.bean.ObjectMessageBean</ejb-class>
+ <message-selector></message-selector>
+ <transaction-type>Bean</transaction-type>
+ <acknowledge-mode>AUTO_ACKNOWLEDGE</acknowledge-mode>
+ <message-driven-destination>
+ <destination-type>javax.jms.Queue</destination-type>
+ <subscription-durability>NonDurable</subscription-durability>
+ </message-driven-destination>
+ </message-driven>
+
+ <message-driven>
+ <ejb-name>TopicInADifferentContext</ejb-name>
+ <ejb-class>org.jboss.test.mdb.bean.TopicBean</ejb-class>
+ <message-selector></message-selector>
+ <transaction-type>Container</transaction-type>
+ <message-driven-destination>
+ <destination-type>javax.jms.Topic</destination-type>
+ <subscription-durability>NonDurable</subscription-durability>
+ </message-driven-destination>
+ </message-driven>
+
+ </enterprise-beans>
+
+
+ <assembly-descriptor>
+ <container-transaction>
+
+ <method>
+
+ <ejb-name>TopicBean</ejb-name>
+
+ <method-name>onMessage</method-name>
+ <method-params>
+ <method-param>javax.jms.Message</method-param>
+ </method-params>
+
+ </method>
+ <!-- May also be NotSupported -->
+ <trans-attribute>Required</trans-attribute>
+
+ </container-transaction>
+ <container-transaction>
+
+ <method>
+
+ <ejb-name>DurableTopicBean</ejb-name>
+
+ <method-name>onMessage</method-name>
+
+ </method>
+ <!-- May also be NotSupported -->
+ <trans-attribute>Required</trans-attribute>
+
+ </container-transaction>
+
+ <container-transaction>
+ <method>
+ <ejb-name>BMTTXTimeOutBean</ejb-name>
+ <method-name>*</method-name>
+ </method>
+ <trans-attribute>Required</trans-attribute>
+ </container-transaction>
+
+ <container-transaction>
+ <method>
+ <ejb-name>CMTTXTimeOutBean</ejb-name>
+ <method-name>*</method-name>
+ </method>
+ <trans-attribute>NotSupported</trans-attribute>
+ </container-transaction>
+
+ <container-transaction>
+ <method>
+
+ <ejb-name>ExQueueBean</ejb-name>
+
+ <method-name>*</method-name>
+
+ </method>
+ <!-- May also be NotSupported -->
+ <trans-attribute>Required</trans-attribute>
+
+ </container-transaction>
+ </assembly-descriptor>
+ </ejb-jar>
Added: branches/JBPAPP_4_2/testsuite/src/resources/mdb4jbm/META-INF/jboss.xml
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/resources/mdb4jbm/META-INF/jboss.xml (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/resources/mdb4jbm/META-INF/jboss.xml 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE jboss PUBLIC
+ "-//JBoss//DTD JBOSS 4.2//EN"
+ "http://www.jboss.org/j2ee/dtd/jboss_4_2.dtd">
+<jboss>
+ <invoker-proxy-bindings>
+ <invoker-proxy-binding>
+ <name>my-message-driven-bean</name>
+ <invoker-mbean>default</invoker-mbean>
+ <proxy-factory>org.jboss.ejb.plugins.jms.JMSContainerInvoker</proxy-factory>
+ <proxy-factory-config>
+ <JMSProviderAdapterJNDI>DefaultJMSProvider</JMSProviderAdapterJNDI>
+ <ServerSessionPoolFactoryJNDI>StdJMSPool</ServerSessionPoolFactoryJNDI>
+ <CreateDestination>true</CreateDestination>
+ <DestinationManager>jboss.messaging:service=ServerPeer</DestinationManager>
+ <CreateTopicMethod>deployTopic</CreateTopicMethod>
+ <CreateQueueMethod>deployQueue</CreateQueueMethod>
+ <MaximumSize>15</MaximumSize>
+ <MaxMessages>1</MaxMessages>
+ <MDBConfig>
+ <ReconnectIntervalSec>10</ReconnectIntervalSec>
+ <DLQConfig>
+ <DestinationQueue>queue/DLQ</DestinationQueue>
+ <MaxTimesRedelivered>10</MaxTimesRedelivered>
+ <TimeToLive>0</TimeToLive>
+ </DLQConfig>
+ </MDBConfig>
+ </proxy-factory-config>
+ </invoker-proxy-binding>
+ </invoker-proxy-bindings>
+
+ <enterprise-beans>
+ <message-driven>
+ <ejb-name>ObjectMessageBean</ejb-name>
+ <configuration-name>Standard Message Driven Bean</configuration-name>
+ <destination-jndi-name>queue/testObjectMessage</destination-jndi-name>
+ <invoker-bindings>
+ <invoker>
+ <invoker-proxy-binding-name>my-message-driven-bean</invoker-proxy-binding-name>
+ </invoker>
+ </invoker-bindings>
+ </message-driven>
+ <message-driven>
+ <ejb-name>BMTTXTimeOutBean</ejb-name>
+ <configuration-name>Standard Message Driven Bean</configuration-name>
+ <destination-jndi-name>queue/A</destination-jndi-name>
+ </message-driven>
+ <message-driven>
+ <ejb-name>CMTTXTimeOutBean</ejb-name>
+ <configuration-name>Standard Message Driven Bean</configuration-name>
+ <destination-jndi-name>queue/B</destination-jndi-name>
+ </message-driven>
+ <message-driven>
+ <ejb-name>QueueBean</ejb-name>
+ <configuration-name>Standard Message Driven Bean</configuration-name>
+ <destination-jndi-name>queue/testQueue</destination-jndi-name>
+ </message-driven>
+ <message-driven>
+ <ejb-name>TopicBean</ejb-name>
+ <configuration-name>Standard Message Driven Bean</configuration-name>
+ <destination-jndi-name>topic/testTopic</destination-jndi-name>
+ </message-driven>
+ <message-driven>
+ <ejb-name>DurableTopicBean</ejb-name>
+ <configuration-name>Standard Message Driven Bean</configuration-name>
+ <destination-jndi-name>topic/testDurableTopic</destination-jndi-name>
+ <mdb-user>john</mdb-user>
+ <mdb-passwd>needle</mdb-passwd>
+ <mdb-subscription-id>DurableSubscriberExample</mdb-subscription-id>
+ </message-driven>
+ <message-driven>
+ <ejb-name>ExQueueBean</ejb-name>
+ <configuration-name>Standard Message Driven Bean</configuration-name>
+ <destination-jndi-name>queue/ex</destination-jndi-name>
+ </message-driven>
+
+ <message-driven>
+ <ejb-name>QueueInADifferentContext</ejb-name>
+ <configuration-name>Standard Message Driven Bean</configuration-name>
+ <destination-jndi-name>anotherContext/QueueInADifferentContext</destination-jndi-name>
+ </message-driven>
+ <message-driven>
+ <ejb-name>TopicInADifferentContext</ejb-name>
+ <configuration-name>Standard Message Driven Bean</configuration-name>
+ <destination-jndi-name>anotherContext/TopicInADifferentContext</destination-jndi-name>
+ </message-driven>
+ </enterprise-beans>
+</jboss>
Added: branches/JBPAPP_4_2/testsuite/src/resources/mdb4jbm/client.policy
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/resources/mdb4jbm/client.policy (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/resources/mdb4jbm/client.policy 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,4 @@
+grant {
+ // Allow everything for now
+ permission java.security.AllPermission;
+};
Added: branches/JBPAPP_4_2/testsuite/src/resources/mdb4jbm/jboss-service.xml
===================================================================
--- branches/JBPAPP_4_2/testsuite/src/resources/mdb4jbm/jboss-service.xml (rev 0)
+++ branches/JBPAPP_4_2/testsuite/src/resources/mdb4jbm/jboss-service.xml 2007-08-16 21:42:11 UTC (rev 64641)
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE server>
+
+<server>
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.messaging.destination:service=Queue,name=myMDBQueue"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ <attribute name="SecurityConfig">
+ <security>
+ <role name="guest" read="true" write="true"/>
+ <role name="publisher" read="true" write="true" create="false"/>
+ <role name="noacc" read="false" write="false" create="false"/>
+ </security>
+ </attribute>
+ </mbean>
+
+ <mbean code="org.jboss.jms.server.destination.TopicService"
+ name="jboss.messaging.destination:service=Topic,name=myMDBTopic"
+ xmbean-dd="xmdesc/Topic-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ <attribute name="SecurityConfig">
+ <security>
+ <role name="guest" read="true" write="true"/>
+ <role name="publisher" read="true" write="true" create="false"/>
+ <role name="durpublisher" read="true" write="true" create="true"/>
+ </security>
+ </attribute>
+ </mbean>
+
+ <mbean code="org.jboss.naming.NamingAlias"
+ name="jboss.test:test=mdb,alias=anotherContext/QueueInADifferentContext">
+ <attribute name="FromName">anotherContext/QueueInADifferentContext</attribute>
+ <attribute name="ToName">queue/myMDBQueue</attribute>
+ </mbean>
+ <mbean code="org.jboss.naming.NamingAlias"
+ name="jboss.test:test=mdb,alias=anotherContext/TopicInADifferentContext">
+ <attribute name="FromName">anotherContext/TopicInADifferentContext</attribute>
+ <attribute name="ToName">topic/myMDBTopic</attribute>
+ </mbean>
+</server>
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list