[jboss-cvs] JBoss Messaging SVN: r2925 - in trunk: src/main/org/jboss/jms/client/container and 23 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jul 25 06:43:59 EDT 2007
Author: timfox
Date: 2007-07-25 06:43:58 -0400 (Wed, 25 Jul 2007)
New Revision: 2925
Added:
trunk/tests/src/org/jboss/test/messaging/jms/JMSTestCase.java
trunk/tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTestBase.java
Removed:
trunk/src/main/org/jboss/messaging/util/prioritylinkedlist/PriorityLinkedListIterator.java
trunk/tests/src/org/jboss/test/messaging/jms/LongRunningInvocationTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/MessageTest.java
Modified:
trunk/src/etc/xmdesc/Queue-xmbean.xml
trunk/src/main/org/jboss/jms/client/container/ClientConsumer.java
trunk/src/main/org/jboss/jms/server/destination/ManagedQueue.java
trunk/src/main/org/jboss/jms/server/destination/ManagedTopic.java
trunk/src/main/org/jboss/jms/server/destination/QueueMBean.java
trunk/src/main/org/jboss/jms/server/destination/QueueService.java
trunk/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java
trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java
trunk/src/main/org/jboss/jms/server/security/SecurityMetadataStore.java
trunk/src/main/org/jboss/messaging/core/contract/Delivery.java
trunk/src/main/org/jboss/messaging/core/impl/ChannelSupport.java
trunk/src/main/org/jboss/messaging/core/impl/FirstReceiverDistributor.java
trunk/src/main/org/jboss/messaging/core/impl/MessagingQueue.java
trunk/src/main/org/jboss/messaging/core/impl/RoundRobinDistributor.java
trunk/src/main/org/jboss/messaging/core/impl/SimpleDelivery.java
trunk/src/main/org/jboss/messaging/core/impl/tx/TransactionRepository.java
trunk/src/main/org/jboss/messaging/util/prioritylinkedlist/BasicPriorityLinkedList.java
trunk/src/main/org/jboss/messaging/util/prioritylinkedlist/PriorityLinkedList.java
trunk/tests/build.xml
trunk/tests/etc/container.xml
trunk/tests/etc/jbossjta-properties.xml
trunk/tests/src/org/jboss/test/messaging/MessagingTestCase.java
trunk/tests/src/org/jboss/test/messaging/core/BrokenReceiver.java
trunk/tests/src/org/jboss/test/messaging/core/JDBCPersistenceManagerTest.java
trunk/tests/src/org/jboss/test/messaging/core/RoundRobinDistributorTest.java
trunk/tests/src/org/jboss/test/messaging/core/SimpleReceiver.java
trunk/tests/src/org/jboss/test/messaging/jms/AcknowledgementTest.java
trunk/tests/src/org/jboss/test/messaging/jms/BrowserTest.java
trunk/tests/src/org/jboss/test/messaging/jms/CTSMiscellaneousTest.java
trunk/tests/src/org/jboss/test/messaging/jms/ClientInRestrictedSecurityEnvironmentTest.java
trunk/tests/src/org/jboss/test/messaging/jms/ConnectionClosedTest.java
trunk/tests/src/org/jboss/test/messaging/jms/ConnectionConsumerTest.java
trunk/tests/src/org/jboss/test/messaging/jms/ConnectionFactoryTest.java
trunk/tests/src/org/jboss/test/messaging/jms/ConnectionTest.java
trunk/tests/src/org/jboss/test/messaging/jms/ConsumerClosedTest.java
trunk/tests/src/org/jboss/test/messaging/jms/DLQTest.java
trunk/tests/src/org/jboss/test/messaging/jms/DurableSubscriptionTest.java
trunk/tests/src/org/jboss/test/messaging/jms/ExpiryQueueTest.java
trunk/tests/src/org/jboss/test/messaging/jms/HTTPTransportTest.java
trunk/tests/src/org/jboss/test/messaging/jms/JCAWrapperTest.java
trunk/tests/src/org/jboss/test/messaging/jms/JMSTest.java
trunk/tests/src/org/jboss/test/messaging/jms/ManifestTest.java
trunk/tests/src/org/jboss/test/messaging/jms/MessageCleanupTest.java
trunk/tests/src/org/jboss/test/messaging/jms/MessageConsumerTest.java
trunk/tests/src/org/jboss/test/messaging/jms/MessageProducerTest.java
trunk/tests/src/org/jboss/test/messaging/jms/MessageProxyTest.java
trunk/tests/src/org/jboss/test/messaging/jms/MessageWithReadResolveTest.java
trunk/tests/src/org/jboss/test/messaging/jms/MiscellaneousTest.java
trunk/tests/src/org/jboss/test/messaging/jms/NonDurableSubscriberTest.java
trunk/tests/src/org/jboss/test/messaging/jms/PersistenceTest.java
trunk/tests/src/org/jboss/test/messaging/jms/QueueRequestorTest.java
trunk/tests/src/org/jboss/test/messaging/jms/QueueTest.java
trunk/tests/src/org/jboss/test/messaging/jms/ReferenceableTest.java
trunk/tests/src/org/jboss/test/messaging/jms/ReferencingTest.java
trunk/tests/src/org/jboss/test/messaging/jms/RemotingConnectionConfigurationTest.java
trunk/tests/src/org/jboss/test/messaging/jms/ScheduledDeliveryTest.java
trunk/tests/src/org/jboss/test/messaging/jms/SecurityTest.java
trunk/tests/src/org/jboss/test/messaging/jms/SessionTest.java
trunk/tests/src/org/jboss/test/messaging/jms/String64KLimitTest.java
trunk/tests/src/org/jboss/test/messaging/jms/TemporaryDestinationTest.java
trunk/tests/src/org/jboss/test/messaging/jms/TopicTest.java
trunk/tests/src/org/jboss/test/messaging/jms/TransactedSessionTest.java
trunk/tests/src/org/jboss/test/messaging/jms/WireFormatTest.java
trunk/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java
trunk/tests/src/org/jboss/test/messaging/jms/XAResourceRecoveryTest.java
trunk/tests/src/org/jboss/test/messaging/jms/XATestBase.java
trunk/tests/src/org/jboss/test/messaging/jms/bridge/BridgeTest.java
trunk/tests/src/org/jboss/test/messaging/jms/clustering/DistributedRequestResponseTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/ExpiredMessageTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/JMSCorrelationIDHeaderTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/JMSDeliveryModeHeaderTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/JMSDestinationHeaderTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/JMSExpirationHeaderTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/JMSMessageIDHeaderTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/JMSPriorityHeaderTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/JMSReplyToHeaderTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/JMSTimestampHeaderTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/JMSTypeHeaderTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/JMSXDeliveryCountTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/MapMessageTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/MessageBodyTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/MessagePropertyConversionTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/MessageTestBase.java
trunk/tests/src/org/jboss/test/messaging/jms/message/ObjectMessageDeliveryTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/foreign/ForeignBytesMessageTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/foreign/ForeignMapMessageTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/foreign/ForeignStreamMessageTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/foreign/ForeignTextMessageTest.java
trunk/tests/src/org/jboss/test/messaging/jms/selector/SelectorTest.java
trunk/tests/src/org/jboss/test/messaging/tools/ServerManagement.java
trunk/tests/src/org/jboss/test/messaging/tools/ant/JUnitTestSuiteListener.java
trunk/tests/src/org/jboss/test/messaging/tools/jmx/ServiceContainer.java
trunk/tests/src/org/jboss/test/messaging/tools/misc/ConfigurableSecurityManager.java
trunk/tests/src/org/jboss/test/messaging/util/prioritylinkedlist/PriorityLinkedListTest.java
trunk/tests/src/org/jboss/test/thirdparty/jbosssx/SecurityAssociationTest.java
Log:
Speeded up remote tests
Modified: trunk/src/etc/xmdesc/Queue-xmbean.xml
===================================================================
--- trunk/src/etc/xmdesc/Queue-xmbean.xml 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/src/etc/xmdesc/Queue-xmbean.xml 2007-07-25 10:43:58 UTC (rev 2925)
@@ -87,6 +87,12 @@
<type>int</type>
</attribute>
+ <attribute access="read-only" getMethod="getDeliveringCount">
+ <description>The number of messages currently being delivered</description>
+ <name>DeliveringCount</name>
+ <type>int</type>
+ </attribute>
+
<attribute access="read-only" getMethod="getScheduledMessageCount">
<description>The number of scheduled messages in the queue</description>
<name>ScheduledMessageCount</name>
Modified: trunk/src/main/org/jboss/jms/client/container/ClientConsumer.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/container/ClientConsumer.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/src/main/org/jboss/jms/client/container/ClientConsumer.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -639,7 +639,7 @@
lastDeliveryId = proxy.getDeliveryId();
- if (trace) { log.trace(this + " added message(s) to the buffer"); }
+ if (trace) { log.trace(this + " added message(s) to the buffer are now " + buffer.size() + " messages"); }
messageAdded();
Modified: trunk/src/main/org/jboss/jms/server/destination/ManagedQueue.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/destination/ManagedQueue.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/src/main/org/jboss/jms/server/destination/ManagedQueue.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -97,6 +97,15 @@
return count;
}
+ public int getDeliveringCount() throws Exception
+ {
+ int count = queue.getDeliveringCount();
+
+ if (trace) { log.trace(this + " returning DeliveringCount = " + count); }
+
+ return count;
+ }
+
public int getScheduledMessageCount() throws Exception
{
int count = queue.getScheduledCount();
Modified: trunk/src/main/org/jboss/jms/server/destination/ManagedTopic.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/destination/ManagedTopic.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/src/main/org/jboss/jms/server/destination/ManagedTopic.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -29,6 +29,7 @@
import org.jboss.jms.server.JMSCondition;
import org.jboss.jms.server.messagecounter.MessageCounter;
import org.jboss.jms.server.selector.Selector;
+import org.jboss.logging.Logger;
import org.jboss.messaging.core.contract.Binding;
import org.jboss.messaging.core.contract.Message;
import org.jboss.messaging.core.contract.Queue;
@@ -47,6 +48,8 @@
*/
public class ManagedTopic extends ManagedDestination
{
+ private static final Logger log = Logger.getLogger(ManagedTopic.class);
+
public ManagedTopic()
{
}
@@ -286,6 +289,8 @@
int count = 0;
+ log.info("Getting message count for " + this.name);
+
while (iter.hasNext())
{
Queue queue = (Queue)iter.next();
@@ -294,6 +299,8 @@
|| (type == NON_DURABLE && !queue.isRecoverable()))
{
count += queue.getMessageCount();
+
+ log.info("Count for " + queue.getName() + " is " + queue.getMessageCount());
}
}
Modified: trunk/src/main/org/jboss/jms/server/destination/QueueMBean.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/destination/QueueMBean.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/src/main/org/jboss/jms/server/destination/QueueMBean.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -41,6 +41,8 @@
int getMessageCount() throws Exception;
+ int getDeliveringCount() throws Exception;
+
int getScheduledMessageCount() throws Exception;
MessageCounter getMessageCounter();
Modified: trunk/src/main/org/jboss/jms/server/destination/QueueService.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/destination/QueueService.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/src/main/org/jboss/jms/server/destination/QueueService.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -198,6 +198,24 @@
}
}
+ public int getDeliveringCount() throws Exception
+ {
+ try
+ {
+ if (!started)
+ {
+ log.warn("Queue is stopped");
+ return 0;
+ }
+
+ return ((ManagedQueue)destination).getDeliveringCount();
+ }
+ catch (Throwable t)
+ {
+ throw ExceptionUtil.handleJMXInvocation(t, this + " getDeliveringCount");
+ }
+ }
+
public int getScheduledMessageCount() throws Exception
{
try
Modified: trunk/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -210,7 +210,7 @@
if (ref.getMessage().isExpired())
{
- SimpleDelivery delivery = new SimpleDelivery(observer, ref, true);
+ SimpleDelivery delivery = new SimpleDelivery(observer, ref, true, false);
try
{
@@ -253,7 +253,7 @@
boolean selectorRejected = !this.accept(message);
- SimpleDelivery delivery = new SimpleDelivery(observer, ref, !selectorRejected);
+ SimpleDelivery delivery = new SimpleDelivery(observer, ref, !selectorRejected, false);
if (selectorRejected)
{
Modified: trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -1131,6 +1131,8 @@
else
{
log.warn("No expiry queue has been configured so removing expired " + del.getReference());
+
+ del.acknowledge(null);
}
}
@@ -1714,7 +1716,7 @@
{
Transaction tx = tr.createTransaction();
- MessageReference ref = ms.reference(msg);
+ MessageReference ref = ms.reference(msg);
try
{
Modified: trunk/src/main/org/jboss/jms/server/security/SecurityMetadataStore.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/security/SecurityMetadataStore.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/src/main/org/jboss/jms/server/security/SecurityMetadataStore.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -120,16 +120,23 @@
public void setSecurityConfig(boolean isQueue, String destName, Element conf) throws Exception
{
if (trace) { log.trace("adding security configuration for " + (isQueue ? "queue " : "topic ") + destName); }
-
- SecurityMetadata m = new SecurityMetadata(conf);
-
- if (isQueue)
+
+ if (conf == null)
{
- queueSecurityConf.put(destName, m);
+ clearSecurityConfig(isQueue, destName);
}
else
- {
- topicSecurityConf.put(destName, m);
+ {
+ SecurityMetadata m = new SecurityMetadata(conf);
+
+ if (isQueue)
+ {
+ queueSecurityConf.put(destName, m);
+ }
+ else
+ {
+ topicSecurityConf.put(destName, m);
+ }
}
}
Modified: trunk/src/main/org/jboss/messaging/core/contract/Delivery.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/contract/Delivery.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/src/main/org/jboss/messaging/core/contract/Delivery.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -46,4 +46,6 @@
void acknowledge(Transaction tx) throws Throwable;
void cancel() throws Throwable;
+
+ boolean isRecovered();
}
Modified: trunk/src/main/org/jboss/messaging/core/impl/ChannelSupport.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/ChannelSupport.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/src/main/org/jboss/messaging/core/impl/ChannelSupport.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -168,8 +168,11 @@
pm.updateDeliveryCount(this.channelID, ref);
}
- deliveringCount.decrement();
-
+ if (!del.isRecovered())
+ {
+ deliveringCount.decrement();
+ }
+
if (!checkAndSchedule(ref))
{
cancelInternal(ref);
@@ -253,9 +256,7 @@
*
*/
public void removeAllReferences() throws Throwable
- {
- log.debug(this + " removing all references");
-
+ {
synchronized (lock)
{
if (deliveringCount.get() > 0)
@@ -264,6 +265,8 @@
deliveringCount.get());
}
+ log.trace(this + " removing all references, there are " + this.messageRefs.size());
+
//Now we consume the rest of the messages
//This may take a while if we have a lot of messages including perhaps millions
//paged in the database - but there's no obvious other way to do it.
@@ -277,17 +280,19 @@
MessageReference ref;
while ((ref = removeFirstInMemory()) != null)
{
+ log.trace("Removing ref " + ref);
+
SimpleDelivery del = new SimpleDelivery(this, ref);
del.acknowledge(null);
-
- // Delivery#acknowledge decrements the deliveringCount without incrementing it first (because
- // deliver has actually never been called), so increment it here to be accurate.
- deliveringCount.increment();
}
+
+ deliveringCount.set(0);
+
+ log.trace(this + " done removing all references, there are " + this.messageRefs.size());
}
- clearAllScheduledDeliveries();
+ clearAllScheduledDeliveries();
}
public List undelivered(Filter filter)
@@ -326,7 +331,7 @@
public int getMessageCount()
{
synchronized (lock)
- {
+ {
return messageRefs.size() + getDeliveringCount() + getScheduledCount();
}
}
@@ -655,7 +660,7 @@
return null;
}
- return new SimpleDelivery(this, ref, true);
+ return new SimpleDelivery(this, ref, true, false);
}
@@ -694,8 +699,11 @@
}
d.getReference().releaseMemoryReference();
-
- deliveringCount.decrement();
+
+ if (!d.isRecovered())
+ {
+ deliveringCount.decrement();
+ }
}
else
{
@@ -870,7 +878,10 @@
del.getReference().releaseMemoryReference();
- deliveringCount.decrement();
+ if (!del.isRecovered())
+ {
+ deliveringCount.decrement();
+ }
}
// prompt delivery
Modified: trunk/src/main/org/jboss/messaging/core/impl/FirstReceiverDistributor.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/FirstReceiverDistributor.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/src/main/org/jboss/messaging/core/impl/FirstReceiverDistributor.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -127,7 +127,7 @@
if (del == null && selectorRejected)
{
- del = new SimpleDelivery(null, null, false);
+ del = new SimpleDelivery(null, null, false, false);
}
return del;
Modified: trunk/src/main/org/jboss/messaging/core/impl/MessagingQueue.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/MessagingQueue.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/src/main/org/jboss/messaging/core/impl/MessagingQueue.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -531,7 +531,7 @@
public String toString()
{
- return "Queue[" + nodeID + "/" + channelID + "-" + name + "]";
+ return "Queue[" + System.identityHashCode(this) + "/" + nodeID + "/" + channelID + "-" + name + "]";
}
public boolean equals(Object other)
Modified: trunk/src/main/org/jboss/messaging/core/impl/RoundRobinDistributor.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/RoundRobinDistributor.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/src/main/org/jboss/messaging/core/impl/RoundRobinDistributor.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -154,7 +154,7 @@
if (del == null && selectorRejected)
{
- del = new SimpleDelivery(null, null, false);
+ del = new SimpleDelivery(null, null, false, false);
}
return del;
Modified: trunk/src/main/org/jboss/messaging/core/impl/SimpleDelivery.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/SimpleDelivery.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/src/main/org/jboss/messaging/core/impl/SimpleDelivery.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -48,7 +48,8 @@
private boolean selectorAccepted;
private DeliveryObserver observer;
- private MessageReference reference;
+ private MessageReference reference;
+ private boolean recovered;
private boolean trace = log.isTraceEnabled();
@@ -61,16 +62,17 @@
public SimpleDelivery(DeliveryObserver observer, MessageReference reference)
{
- this(observer, reference, true);
+ this(observer, reference, true, false);
}
-
+
public SimpleDelivery(DeliveryObserver observer, MessageReference reference,
- boolean selectorAccepted)
+ boolean selectorAccepted, boolean recovered)
{
this.reference = reference;
this.observer = observer;
this.selectorAccepted = selectorAccepted;
+ this.recovered = recovered;
}
// Delivery implementation ----------------------------------------------------------------------
@@ -104,6 +106,11 @@
observer.cancel(this);
}
+ public boolean isRecovered()
+ {
+ return recovered;
+ }
+
// Public ---------------------------------------------------------------------------------------
public String toString()
Modified: trunk/src/main/org/jboss/messaging/core/impl/tx/TransactionRepository.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/tx/TransactionRepository.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/src/main/org/jboss/messaging/core/impl/tx/TransactionRepository.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -391,7 +391,7 @@
if (trace) log.trace("Destination for message[ID=" + ref.getMessage().getMessageID() + "] is: " + queue);
//Create a new delivery - note that it must have a delivery observer otherwise acknowledge will fail
- Delivery del = new SimpleDelivery(queue, ref);
+ Delivery del = new SimpleDelivery(queue, ref, true, true);
if (trace) log.trace("Acknowledging..");
Modified: trunk/src/main/org/jboss/messaging/util/prioritylinkedlist/BasicPriorityLinkedList.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/prioritylinkedlist/BasicPriorityLinkedList.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/src/main/org/jboss/messaging/util/prioritylinkedlist/BasicPriorityLinkedList.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -22,10 +22,14 @@
package org.jboss.messaging.util.prioritylinkedlist;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
+import java.util.NoSuchElementException;
+import org.jboss.logging.Logger;
+
/**
* A basic priority linked list
*
@@ -39,12 +43,34 @@
*/
public class BasicPriorityLinkedList implements PriorityLinkedList
{
+ private static final Logger log = Logger.getLogger(BasicPriorityLinkedList.class);
+
protected LinkedList[] linkedLists;
protected int priorities;
protected int size;
+ public void dump()
+ {
+ log.trace("Dumping " + this);
+ log.trace("Size:" + size);
+ log.trace("===============");
+
+ for (int i = 0; i < linkedLists.length; i++)
+ {
+ log.trace("Priority:" + i);
+ log.trace("----------------");
+
+ Iterator iter = linkedLists[i].iterator();
+
+ while (iter.hasNext())
+ {
+ log.info("Ref: "+ iter.next());
+ }
+ }
+ }
+
public BasicPriorityLinkedList(int priorities)
{
this.priorities = priorities;
@@ -56,7 +82,7 @@
{
linkedLists[priority].addFirst(obj);
- size++;
+ size++;
}
public void addLast(Object obj, int priority)
@@ -69,8 +95,7 @@
public Object removeFirst()
{
Object obj = null;
-
-
+
//Initially we are just using a simple prioritization algorithm:
//Highest priority refs always get returned first.
//This could cause starvation of lower priority refs.
@@ -121,7 +146,7 @@
if (obj != null)
{
- size--;
+ size--;
}
return obj;
@@ -195,4 +220,87 @@
size = 0;
}
+
+ class PriorityLinkedListIterator implements ListIterator
+ {
+ private LinkedList[] lists;
+
+ private int index;
+
+ private ListIterator currentIter;
+
+ PriorityLinkedListIterator(LinkedList[] lists)
+ {
+ this.lists = lists;
+
+ index = lists.length - 1;
+
+ currentIter = lists[index].listIterator();
+ }
+
+ public void add(Object arg0)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean hasNext()
+ {
+ if (currentIter.hasNext())
+ {
+ return true;
+ }
+ while (index >= 0)
+ {
+ if (index == 0 || currentIter.hasNext())
+ {
+ break;
+ }
+ index--;
+ currentIter = lists[index].listIterator();
+ }
+ return currentIter.hasNext();
+ }
+
+ public boolean hasPrevious()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object next()
+ {
+ if (!hasNext())
+ {
+ throw new NoSuchElementException();
+ }
+ return currentIter.next();
+ }
+
+ public int nextIndex()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object previous()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public int previousIndex()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void remove()
+ {
+ currentIter.remove();
+
+ size--;
+ }
+
+ public void set(Object obj)
+ {
+ throw new UnsupportedOperationException();
+ }
+ }
+
}
Modified: trunk/src/main/org/jboss/messaging/util/prioritylinkedlist/PriorityLinkedList.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/prioritylinkedlist/PriorityLinkedList.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/src/main/org/jboss/messaging/util/prioritylinkedlist/PriorityLinkedList.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -54,4 +54,6 @@
ListIterator iterator();
boolean isEmpty();
+
+ void dump();
}
Deleted: trunk/src/main/org/jboss/messaging/util/prioritylinkedlist/PriorityLinkedListIterator.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/prioritylinkedlist/PriorityLinkedListIterator.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/src/main/org/jboss/messaging/util/prioritylinkedlist/PriorityLinkedListIterator.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -1,117 +0,0 @@
-/*
- * 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.messaging.util.prioritylinkedlist;
-
-import java.util.LinkedList;
-import java.util.ListIterator;
-import java.util.NoSuchElementException;
-
-/**
- *
- * A PriorityLinkedListIterator
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 1.1 $</tt>
- *
- * $Id$
- *
- */
-class PriorityLinkedListIterator implements ListIterator
-{
- private LinkedList[] lists;
-
- private int index;
-
- private ListIterator currentIter;
-
- PriorityLinkedListIterator(LinkedList[] lists)
- {
- this.lists = lists;
-
- index = lists.length - 1;
-
- currentIter = lists[index].listIterator();
- }
-
- public void add(Object arg0)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean hasNext()
- {
- if (currentIter.hasNext())
- {
- return true;
- }
- while (index >= 0)
- {
- if (index == 0 || currentIter.hasNext())
- {
- break;
- }
- index--;
- currentIter = lists[index].listIterator();
- }
- return currentIter.hasNext();
- }
-
- public boolean hasPrevious()
- {
- throw new UnsupportedOperationException();
- }
-
- public Object next()
- {
- if (!hasNext())
- {
- throw new NoSuchElementException();
- }
- return currentIter.next();
- }
-
- public int nextIndex()
- {
- throw new UnsupportedOperationException();
- }
-
- public Object previous()
- {
- throw new UnsupportedOperationException();
- }
-
- public int previousIndex()
- {
- throw new UnsupportedOperationException();
- }
-
- public void remove()
- {
- currentIter.remove();
- }
-
- public void set(Object obj)
- {
- throw new UnsupportedOperationException();
- }
-
-}
Modified: trunk/tests/build.xml
===================================================================
--- trunk/tests/build.xml 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/build.xml 2007-07-25 10:43:58 UTC (rev 2925)
@@ -57,7 +57,7 @@
Functional tests.
-->
- <property name="functional.tests.database" value="mysql"/>
+ <property name="functional.tests.database" value="oracle"/>
<!--
Stress tests.
@@ -66,7 +66,7 @@
<property name="stress.tests.database" value="mysql"/>
<!-- Clustering tests -->
- <property name="clustering.tests.database" value="mysql"/>
+ <property name="clustering.tests.database" value="oracle"/>
<property name ="test-mask" value="*Test"/>
<!--
@@ -325,6 +325,10 @@
<antcall target="bridge-tests"/>
+ <antcall target="invm-thirdparty-tests"/>
+
+ <antcall target="remote-thirdparty-tests"/>
+
</target>
<target name="http-tests" depends="tests-jar, prepare-testdirs, clear-test-logs">
@@ -368,23 +372,64 @@
haltonerror="${junit.batchtest.haltonerror}">
<formatter type="plain" usefile="${junit.formatter.usefile}"/>
<fileset dir="${build.tests.classes}">
- <include name="**/*Test.class"/>
- <exclude name="**/messaging/graveyard/**/*Test.class"/>
- <exclude name="**/jms/stress/**"/>
- <exclude name="**/jms/crash/*Test.class"/>
- <exclude name="**/*LeakTest.class"/>
- <exclude name="**/jms/bridge/**/*Test.class"/>
- <exclude name="**/jms/manual/**/*Test.class"/>
- <exclude name="**/jms/clustering/*Test.class"/>
+ <include name="**/${test-mask}.class"/>
+ <exclude name="**/jms/MemLeakTest.class"/>
<exclude name="**/jms/LongRunningInvocationTest.class"/>
<exclude name="**/jms/RemotingConnectionConfigurationTest.class"/>
+ <exclude name="**/jms/XAResourceRecoveryTest.class"/>
+ <exclude name="**/jms/stress/**"/>
+ <exclude name="**/jms/crash/**"/>
+ <exclude name="**/jms/bridge/**"/>
+ <exclude name="**/jms/manual/**"/>
+ <exclude name="**/jms/clustering/**"/>
+ <exclude name="**/thirdparty/**"/>
+ </fileset>
+ </batchtest>
+ </junit>
+ </target>
+
+ <target name="invm-thirdparty-tests" depends="tests-jar, prepare-testdirs, clear-test-logs"
+ description="Runs all available thirdparty tests an in-VM configuration">
+
+ <echo message=""/>
+ <echo message="Running invm tests, fork=${junit.fork}, junit.batchtest.fork=${junit.batchtest.fork}"/>
+ <echo message=""/>
+
+ <junit printsummary="${junit.printsummary}"
+ fork="${junit.fork}"
+ includeantruntime="${junit.includeantruntime}"
+ haltonerror="${junit.haltonerror}"
+ haltonfailure="${junit.haltonfailure}"
+ showoutput="${junit.showoutput}"
+ timeout="${junit.timeout}">
+
+ <sysproperty key="remote" value="false"/>
+ <sysproperty key="module.output" value="${tests.output}"/>
+ <sysproperty key="test.bind.address" value="${test.bind.address}"/>
+ <sysproperty key="jgroups.bind_addr" value="${test.bind.address}"/>
+ <sysproperty key="test.database" value="${functional.tests.database}"/>
+ <sysproperty key="test.logfile.suffix" value="invm"/>
+ <sysproperty key="build.lib" value="${build.lib}"/>
+ <sysproperty key="objectstore.dir" value="${objectstore.dir}"/>
+ <jvmarg value="-Xmx512M"/>
+ <!--
+ <jvmarg line="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_shmem,server=y,suspend=y,address=antjunit"/>
+ -->
+ <classpath refid="test.execution.classpath"/>
+ <formatter type="xml" usefile="${junit.formatter.usefile}"/>
+ <batchtest fork="${junit.batchtest.fork}"
+ todir="${junit.batchtest.todir}"
+ haltonfailure="${junit.batchtest.haltonfailure}"
+ haltonerror="${junit.batchtest.haltonerror}">
+ <formatter type="plain" usefile="${junit.formatter.usefile}"/>
+ <fileset dir="${build.tests.classes}">
+ <include name="**/thirdparty/**/*Test.class"/>
<exclude name="**/thirdparty/remoting/ManualConnectionValidatorTest.class"/>
<exclude name="**/thirdparty/remoting/PureAsynchronousCallTest.class"/>
<exclude name="**/thirdparty/remoting/RemotingConnectionFailureTest.class"/>
<exclude name="**/thirdparty/remoting/CallbackServerTimeoutTest.class"/>
<exclude name="**/thirdparty/remoting/ClientInvokerTimeoutTest.class"/>
<exclude name="**/thirdparty/remoting/SocketTransportCausalityTest.class"/>
- <exclude name="**/jms/XAResourceRecoveryTest.class"/>
</fileset>
</batchtest>
</junit>
@@ -403,7 +448,8 @@
<echo message=""/>
<junit printsummary="${junit.printsummary}"
- fork="${junit.fork}"
+ fork="on"
+ forkMode="once"
includeantruntime="yes"
haltonerror="${junit.haltonerror}"
haltonfailure="${junit.haltonfailure}"
@@ -430,8 +476,7 @@
<formatter classname="org.jboss.ant.taskdefs.XMLJUnitMultipleResultFormatter"
usefile="${junit.formatter.usefile}" extension="-Remote-${test.remoting}.xml"/>
- <batchtest fork="${junit.batchtest.fork}"
- todir="${junit.batchtest.todir}"
+ <batchtest todir="${junit.batchtest.todir}"
haltonfailure="${junit.batchtest.haltonfailure}"
haltonerror="${junit.batchtest.haltonerror}">
<formatter type="plain" usefile="${junit.formatter.usefile}"/>
@@ -443,22 +488,81 @@
<formatter classname="org.jboss.test.messaging.tools.ant.JUnitTestSuiteListener"/>
<fileset dir="${build.tests.classes}">
- <include name="**/jms/**/${test-mask}.class"/>
- <include name="**/thirdparty/**/${test-mask}.class"/>
- <exclude name="**/jms/bridge/**/*Test.class"/>
- <exclude name="**/messaging/graveyard/**/*Test.class"/>
- <exclude name="**/jms/WireFormatTest.class"/>
- <exclude name="**/jms/stress/**"/>
- <exclude name="**/jms/server/**"/>
- <exclude name="**/jms/persistence/**"/>
- <exclude name="**/jms/ReferencingTest.class"/>
- <exclude name="**/jms/PersistenceTest.class"/>
- <exclude name="**/jms/crash/*Test.class"/>
- <exclude name="**/*LeakTest.class"/>
+
+ <include name="**/jms/${test-mask}.class"/>
+ <include name="**/jms/message/**/*Test.class"/>
+ <include name="**/jms/selector/*Test.class"/>
+
+ <exclude name="**/jms/WireFormatTest.class"/>
+ <exclude name="**/jms/ReferencingTest.class"/>
+ <exclude name="**/jms/PersistenceTest.class"/>
+ <exclude name="**/jms/MemLeakTest.class"/>
<exclude name="**/jms/ManifestTest.class"/>
- <exclude name="**/jms/JCAWrapperTest.class"/>
- <exclude name="**/jms/manual/**/*Test.class"/>
- <exclude name="**/jms/clustering/*Test.class"/>
+ <exclude name="**/jms/JCAWrapperTest.class"/>
+
+ </fileset>
+ </batchtest>
+ </junit>
+
+ <antcall target="stop-rmi-server"/>
+
+ </target>
+
+
+ <target name="remote-thirdparty-tests" depends="tests-jar, prepare-testdirs, clear-test-logs"
+ description="Runs remotely all thirdparty tests for which it makes sense to run remotely">
+
+ <antcall target="stop-rmi-server"/>
+ <antcall target="start-rmi-server"/>
+
+ <mkdir dir="${build.tests.reports}"/>
+
+ <echo message=""/>
+ <echo message="Running remote tests, fork=${junit.fork}, junit.batchtest.fork=${junit.batchtest.fork}, remoting=${test.remoting}"/>
+ <echo message=""/>
+
+ <junit printsummary="${junit.printsummary}"
+ fork="on"
+ forkMode="once"
+ includeantruntime="yes"
+ haltonerror="${junit.haltonerror}"
+ haltonfailure="${junit.haltonfailure}"
+ showoutput="${junit.showoutput}"
+ timeout="${junit.timeout}">
+
+ <sysproperty key="remote" value="true"/>
+ <sysproperty key="module.output" value="${tests.output}"/>
+ <sysproperty key="test.bind.address" value="${test.bind.address}"/>
+ <sysproperty key="jgroups.bind_addr" value="${test.bind.address}"/>
+ <sysproperty key="test.database" value="${functional.tests.database}"/>
+ <sysproperty key="test.remoting" value="${test.remoting}"/>
+ <sysproperty key="test.logfile.suffix" value="remote-client"/>
+ <sysproperty key="objectstore.dir" value="${objectstore.dir}"/>
+ <jvmarg value="-Xmx512M"/>
+ <!--
+ <jvmarg line="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_shmem,server=n,suspend=n,address=antjunit"/>
+ -->
+ <classpath>
+ <path refid="test.execution.classpath"/>
+ </classpath>
+
+ <sysproperty key="jboss-junit-configuration" value="Remote-${test.remoting}"/>
+ <formatter classname="org.jboss.ant.taskdefs.XMLJUnitMultipleResultFormatter"
+ usefile="${junit.formatter.usefile}" extension="-Remote-${test.remoting}.xml"/>
+
+ <batchtest todir="${junit.batchtest.todir}"
+ haltonfailure="${junit.batchtest.haltonfailure}"
+ haltonerror="${junit.batchtest.haltonerror}">
+ <formatter type="plain" usefile="${junit.formatter.usefile}"/>
+ <!--
+ I needed a way to intercept the end of a forked ant JUnit test run, in order to
+ perform clean-up, and this is it: register a JUnitTestSuiteListener as a JUnit
+ batchtest formatter, and it will get notified on a endTestSuite() event.
+ -->
+ <formatter classname="org.jboss.test.messaging.tools.ant.JUnitTestSuiteListener"/>
+
+ <fileset dir="${build.tests.classes}">
+ <include name="**/thirdparty/**/${test-mask}.class"/>
<exclude name="**/thirdparty/remoting/ServerAddressTest.class"/>
<exclude name="**/thirdparty/jbosssx/SecurityAssociationTest.class"/>
</fileset>
Modified: trunk/tests/etc/container.xml
===================================================================
--- trunk/tests/etc/container.xml 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/etc/container.xml 2007-07-25 10:43:58 UTC (rev 2925)
@@ -34,7 +34,7 @@
<database-configuration name="oracle">
- <url>jdbc:oracle:thin:@dev01-priv:1521/qadb01</url>
+ <url>jdbc:oracle:thin:@localhost:1521/XE</url>
<driver>oracle.jdbc.driver.OracleDriver</driver>
<isolation>TRANSACTION_READ_COMMITTED</isolation>
<username>messaging</username>
Modified: trunk/tests/etc/jbossjta-properties.xml
===================================================================
--- trunk/tests/etc/jbossjta-properties.xml 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/etc/jbossjta-properties.xml 2007-07-25 10:43:58 UTC (rev 2925)
@@ -175,13 +175,13 @@
Default is 120 seconds.
-->
<property
- name="com.arjuna.ats.arjuna.recovery.periodicRecoveryPeriod" value="20"/>
+ name="com.arjuna.ats.arjuna.recovery.periodicRecoveryPeriod" value="5"/>
<!--
Interval in seconds between first and second pass of periodic recovery.
Default is 10 seconds.
-->
<property
- name="com.arjuna.ats.arjuna.recovery.recoveryBackoffPeriod" value="10"/>
+ name="com.arjuna.ats.arjuna.recovery.recoveryBackoffPeriod" value="2"/>
<!--
Periodic recovery modules to use. Invoked in sort-order of names.
-->
Modified: trunk/tests/src/org/jboss/test/messaging/MessagingTestCase.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/MessagingTestCase.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/MessagingTestCase.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -23,16 +23,20 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
+import java.util.ArrayList;
+import java.util.List;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.Message;
import javax.jms.MessageConsumer;
+import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.Topic;
import javax.jms.XAConnection;
import javax.jms.XAConnectionFactory;
+import javax.management.ObjectName;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import javax.transaction.TransactionManager;
@@ -114,7 +118,73 @@
ServerManagement.log(ServerManagement.INFO, banner);
}
}
+
+ protected void removeAllMessages(String destName, boolean isQueue, int server) throws Exception
+ {
+ String on = "jboss.messaging.destination:service=" + (isQueue ? "Queue" : "Topic") + ",name=" + destName;
+
+ ServerManagement.getServer(server).invoke(new ObjectName(on), "removeAllMessages", null, null);
+ }
+ protected void checkEmpty2(Queue queue) throws Exception
+ {
+ ObjectName destObjectName = new ObjectName("jboss.messaging.destination:service=Queue,name=" + queue.getQueueName());
+
+ Integer messageCount = (Integer)ServerManagement.getAttribute(destObjectName, "MessageCount");
+
+ Integer deliveringCount = (Integer)ServerManagement.getAttribute(destObjectName, "DeliveringCount");
+
+ assertEquals(0, messageCount.intValue() - deliveringCount.intValue());
+ }
+
+ protected void checkEmpty(Queue queue) throws Exception
+ {
+ ObjectName destObjectName = new ObjectName("jboss.messaging.destination:service=Queue,name=" + queue.getQueueName());
+
+ Integer messageCount = (Integer)ServerManagement.getAttribute(destObjectName, "MessageCount");
+
+ assertEquals(0, messageCount.intValue());
+ }
+
+ protected void checkEmpty(Topic topic) throws Exception
+ {
+ ObjectName destObjectName = new ObjectName("jboss.messaging.destination:service=Topic,name=" + topic.getTopicName());
+
+ Integer messageCount = (Integer)ServerManagement.getAttribute(destObjectName, "AllMessageCount");
+
+ assertEquals(0, messageCount.intValue());
+ }
+
+ protected void checkEmpty(Topic topic, String subName) throws Exception
+ {
+ ObjectName destObjectName = new ObjectName("jboss.messaging.destination:service=Topic,name=" + topic.getTopicName());
+
+ List msgs = (List)ServerManagement.invoke(destObjectName, "listAllMessages", new Object[] { subName }, new String[] { "java.lang.String" });
+
+ assertEquals(0, msgs.size());
+ }
+
+ protected void checkNoSubscriptions(Topic topic) throws Exception
+ {
+ ObjectName destObjectName = new ObjectName("jboss.messaging.destination:service=Topic,name=" + topic.getTopicName());
+
+ Integer messageCount = (Integer)ServerManagement.getAttribute(destObjectName, "AllSubscriptionsCount");
+
+ assertEquals(0, messageCount.intValue());
+ }
+
+ protected boolean assertRemainingMessages(int expected) throws Exception
+ {
+ ObjectName destObjectName =
+ new ObjectName("jboss.messaging.destination:service=Queue,name=Queue1");
+ Integer messageCount = (Integer)ServerManagement.getAttribute(destObjectName, "MessageCount");
+
+ log.trace("There are " + messageCount + " messages");
+
+ assertEquals(expected, messageCount.intValue());
+ return expected == messageCount.intValue();
+ }
+
protected void drainDestination(ConnectionFactory cf, Destination dest) throws Exception
{
Connection conn = null;
@@ -273,8 +343,126 @@
}
}
+
+ protected List getReferenceIds() throws Exception
+ {
+ InitialContext ctx = new InitialContext();
+ TransactionManager mgr = (TransactionManager)ctx.lookup(TransactionManagerService.JNDI_NAME);
+ DataSource ds = (DataSource)ctx.lookup("java:/DefaultDS");
+
+ javax.transaction.Transaction txOld = mgr.suspend();
+ mgr.begin();
+ java.sql.Connection conn = ds.getConnection();
+ String sql = "SELECT MESSAGE_ID, ORD FROM JBM_MSG_REF";
+ PreparedStatement ps = conn.prepareStatement(sql);
+
+ ResultSet rs = ps.executeQuery();
+
+ List msgIds = new ArrayList();
+
+ while (rs.next())
+ {
+ long msgId = rs.getLong(1);
+ msgIds.add(new Long(msgId));
+ }
+ rs.close();
+ ps.close();
+ conn.close();
+
+ mgr.commit();
+
+ if (txOld != null)
+ {
+ mgr.resume(txOld);
+ }
+
+ return msgIds;
+ }
+
+ protected List getReferenceIds(long channelId) throws Throwable
+ {
+ InitialContext ctx = new InitialContext();
+
+ TransactionManager mgr = (TransactionManager)ctx.lookup(TransactionManagerService.JNDI_NAME);
+ DataSource ds = (DataSource)ctx.lookup("java:/DefaultDS");
+
+ javax.transaction.Transaction txOld = mgr.suspend();
+ mgr.begin();
+
+ java.sql.Connection conn = ds.getConnection();
+ String sql = "SELECT MESSAGE_ID FROM JBM_MSG_REF WHERE CHANNEL_ID=? ORDER BY ORD";
+ PreparedStatement ps = conn.prepareStatement(sql);
+ ps.setLong(1, channelId);
+
+ ResultSet rs = ps.executeQuery();
+
+ List msgIds = new ArrayList();
+
+ while (rs.next())
+ {
+ long msgId = rs.getLong(1);
+ msgIds.add(new Long(msgId));
+ }
+ rs.close();
+ ps.close();
+ conn.close();
+
+ mgr.commit();
+
+ if (txOld != null)
+ {
+ mgr.resume(txOld);
+ }
+
+ return msgIds;
+ }
+
+ protected List getMessageIds() throws Exception
+ {
+ InitialContext ctx = new InitialContext();
+
+ TransactionManager mgr = (TransactionManager)ctx.lookup(TransactionManagerService.JNDI_NAME);
+ DataSource ds = (DataSource)ctx.lookup("java:/DefaultDS");
+
+ javax.transaction.Transaction txOld = mgr.suspend();
+ mgr.begin();
+
+ java.sql.Connection conn = ds.getConnection();
+ String sql = "SELECT MESSAGE_ID FROM JBM_MSG ORDER BY MESSAGE_ID";
+ PreparedStatement ps = conn.prepareStatement(sql);
+
+ ResultSet rs = ps.executeQuery();
+
+ List msgIds = new ArrayList();
+
+ while (rs.next())
+ {
+ long msgId = rs.getLong(1);
+ msgIds.add(new Long(msgId));
+ }
+ rs.close();
+ ps.close();
+ conn.close();
+
+ mgr.commit();
+
+ if (txOld != null)
+ {
+ mgr.resume(txOld);
+ }
+
+ return msgIds;
+ }
+
+
+
+
+
+
+
+
/**
* @return true if this test is ran in "remote" mode, i.e. the server side of the test runs in a
* different VM than this one (that is running the client side)
Modified: trunk/tests/src/org/jboss/test/messaging/core/BrokenReceiver.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/BrokenReceiver.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/core/BrokenReceiver.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -75,7 +75,7 @@
}
refs.add(ref);
- return new SimpleDelivery(observer, ref, true);
+ return new SimpleDelivery(observer, ref, true, false);
}
// Public --------------------------------------------------------
Modified: trunk/tests/src/org/jboss/test/messaging/core/JDBCPersistenceManagerTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/JDBCPersistenceManagerTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/core/JDBCPersistenceManagerTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -22,18 +22,12 @@
package org.jboss.test.messaging.core;
import java.io.Serializable;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import javax.naming.InitialContext;
-import javax.sql.DataSource;
-import javax.transaction.TransactionManager;
import javax.transaction.xa.Xid;
import org.jboss.messaging.core.contract.Channel;
@@ -50,7 +44,6 @@
import org.jboss.test.messaging.tools.ServerManagement;
import org.jboss.test.messaging.tools.jmx.ServiceContainer;
import org.jboss.test.messaging.util.CoreMessageFactory;
-import org.jboss.tm.TransactionManagerService;
import org.jboss.util.id.GUID;
@@ -1507,81 +1500,7 @@
}
- protected List getReferenceIds(long channelId) throws Throwable
- {
- InitialContext ctx = new InitialContext();
-
- TransactionManager mgr = (TransactionManager)ctx.lookup(TransactionManagerService.JNDI_NAME);
- DataSource ds = (DataSource)ctx.lookup("java:/DefaultDS");
-
- javax.transaction.Transaction txOld = mgr.suspend();
- mgr.begin();
-
- Connection conn = ds.getConnection();
- String sql = "SELECT MESSAGE_ID FROM JBM_MSG_REF WHERE CHANNEL_ID=? ORDER BY ORD";
- PreparedStatement ps = conn.prepareStatement(sql);
- ps.setLong(1, channelId);
-
- ResultSet rs = ps.executeQuery();
-
- List msgIds = new ArrayList();
-
- while (rs.next())
- {
- long msgId = rs.getLong(1);
- msgIds.add(new Long(msgId));
- }
- rs.close();
- ps.close();
- conn.close();
-
- mgr.commit();
-
- if (txOld != null)
- {
- mgr.resume(txOld);
- }
-
- return msgIds;
- }
-
- protected List getMessageIds() throws Throwable
- {
- InitialContext ctx = new InitialContext();
-
- TransactionManager mgr = (TransactionManager)ctx.lookup(TransactionManagerService.JNDI_NAME);
- DataSource ds = (DataSource)ctx.lookup("java:/DefaultDS");
-
- javax.transaction.Transaction txOld = mgr.suspend();
- mgr.begin();
-
- Connection conn = ds.getConnection();
- String sql = "SELECT MESSAGE_ID FROM JBM_MSG ORDER BY MESSAGE_ID";
- PreparedStatement ps = conn.prepareStatement(sql);
-
- ResultSet rs = ps.executeQuery();
-
- List msgIds = new ArrayList();
-
- while (rs.next())
- {
- long msgId = rs.getLong(1);
- msgIds.add(new Long(msgId));
- }
- rs.close();
- ps.close();
- conn.close();
-
- mgr.commit();
-
- if (txOld != null)
- {
- mgr.resume(txOld);
- }
-
- return msgIds;
- }
-
+
}
Modified: trunk/tests/src/org/jboss/test/messaging/core/RoundRobinDistributorTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/RoundRobinDistributorTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/core/RoundRobinDistributorTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -518,7 +518,7 @@
synchronized(lock)
{
- return new SimpleDelivery(null, null, true);
+ return new SimpleDelivery(null, null, true, false);
}
}
@@ -543,7 +543,7 @@
return null;
}
- Delivery del = new SimpleDelivery(null, null, selectorMatches);
+ Delivery del = new SimpleDelivery(null, null, selectorMatches, false);
if (selectorMatches)
{
Modified: trunk/tests/src/org/jboss/test/messaging/core/SimpleReceiver.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/SimpleReceiver.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/core/SimpleReceiver.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -134,7 +134,7 @@
if (SELECTOR_REJECTING.equals(state))
{
log.trace(this + " is rejecting message since doesn't match selector");
- return new SimpleDelivery(null, null, false);
+ return new SimpleDelivery(null, null, false, false);
}
if (REJECTING.equals(state))
@@ -168,7 +168,7 @@
Message m = ref.getMessage();
- SimpleDelivery delivery = new SimpleDelivery(observer, ref, true);
+ SimpleDelivery delivery = new SimpleDelivery(observer, ref, true, false);
messages.add(new Object[] {m, done ? null : delivery});
if (immediateAsynchronousAcknowledgment)
Modified: trunk/tests/src/org/jboss/test/messaging/jms/AcknowledgementTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/AcknowledgementTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/AcknowledgementTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -24,25 +24,20 @@
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
-import javax.jms.Destination;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
-import javax.jms.Topic;
import javax.jms.TopicConnection;
import javax.jms.TopicPublisher;
import javax.jms.TopicSession;
import javax.jms.TopicSubscriber;
import javax.management.ObjectName;
-import javax.naming.InitialContext;
-import org.jboss.jms.client.JBossConnectionFactory;
import org.jboss.jms.client.JBossSession;
import org.jboss.jms.client.delegate.ClientSessionDelegate;
-import org.jboss.test.messaging.MessagingTestCase;
import org.jboss.test.messaging.tools.ServerManagement;
import EDU.oswego.cs.dl.util.concurrent.Latch;
@@ -52,7 +47,7 @@
*
* $Id$
*/
-public class AcknowledgementTest extends MessagingTestCase
+public class AcknowledgementTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -60,12 +55,6 @@
// Attributes ----------------------------------------------------
- protected InitialContext initialContext;
-
- protected JBossConnectionFactory cf;
- protected Destination queue;
- protected Topic topic;
-
// Constructors --------------------------------------------------
public AcknowledgementTest(String name)
@@ -75,38 +64,8 @@
// TestCase overrides -------------------------------------------
- public void setUp() throws Exception
- {
- super.setUp();
- ServerManagement.start("all");
-
- initialContext = new InitialContext(ServerManagement.getJNDIEnvironment());
- cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
- ServerManagement.undeployQueue("Queue");
- ServerManagement.deployQueue("Queue");
- ServerManagement.undeployTopic("Topic");
- ServerManagement.deployTopic("Topic");
- queue = (Destination)initialContext.lookup("/queue/Queue");
- topic = (Topic)initialContext.lookup("/topic/Topic");
+ // Public --------------------------------------------------------
- drainDestination(cf, queue);
-
- log.debug("setup done");
- }
-
- public void tearDown() throws Exception
- {
- ServerManagement.undeployQueue("Queue");
- ServerManagement.undeployTopic("Topic");
-
- super.tearDown();
- }
-
-
- // Public --------------------------------------------------------
-
-
/* Topics shouldn't hold on to messages if there are no subscribers */
public void testPersistentMessagesForTopicDropped() throws Exception
{
@@ -116,7 +75,7 @@
{
conn = cf.createTopicConnection();
TopicSession sess = conn.createTopicSession(true, 0);
- TopicPublisher pub = sess.createPublisher(topic);
+ TopicPublisher pub = sess.createPublisher(topic1);
pub.setDeliveryMode(DeliveryMode.PERSISTENT);
Message m = sess.createTextMessage("testing123");
@@ -124,14 +83,8 @@
sess.commit();
conn.close();
- conn = cf.createTopicConnection();
- conn.start();
- TopicSession newsess = conn.createTopicSession(true, 0);
- TopicSubscriber newcons = newsess.createSubscriber(topic);
-
- Message m2 = (Message)newcons.receive(200);
- assertNull(m2);
+ checkEmpty(topic1);
}
finally
{
@@ -152,8 +105,8 @@
conn = cf.createTopicConnection();
conn.start();
TopicSession sess = conn.createTopicSession(true, 0);
- TopicPublisher pub = sess.createPublisher(topic);
- TopicSubscriber sub = sess.createSubscriber(topic);
+ TopicPublisher pub = sess.createPublisher(topic1);
+ TopicSubscriber sub = sess.createSubscriber(topic1);
pub.setDeliveryMode(DeliveryMode.PERSISTENT);
Message m = sess.createTextMessage("testing123");
@@ -169,14 +122,8 @@
sess.rollback();
conn.close();
- conn = cf.createTopicConnection();
- conn.start();
- TopicSession newsess = conn.createTopicSession(true, 0);
- TopicSubscriber newcons = newsess.createSubscriber(topic);
-
- Message m3 = (Message)newcons.receive(200);
- assertNull(m3);
+ checkEmpty(topic1);
}
finally
{
@@ -195,8 +142,8 @@
{
conn = cf.createTopicConnection();
TopicSession sess = conn.createTopicSession(true, 0);
- TopicPublisher pub = sess.createPublisher(topic);
- TopicSubscriber cons = sess.createSubscriber(topic);
+ TopicPublisher pub = sess.createPublisher(topic1);
+ TopicSubscriber cons = sess.createSubscriber(topic1);
conn.start();
Message m = sess.createTextMessage("testing123");
@@ -221,8 +168,8 @@
//test 2
TopicSession newsess = conn.createTopicSession(true, 0);
- TopicPublisher newpub = newsess.createPublisher(topic);
- TopicSubscriber newcons = newsess.createSubscriber(topic);
+ TopicPublisher newpub = newsess.createPublisher(topic1);
+ TopicSubscriber newcons = newsess.createSubscriber(topic1);
Message m3 = newsess.createTextMessage("testing456");
newpub.publish(m3);
@@ -247,8 +194,7 @@
assertNotNull(m6);
assertEquals("testing456", m6.getText());
- newsess.commit();
-
+ newsess.commit();
}
finally
{
@@ -261,90 +207,93 @@
public void testTransactionalAcknowledgement() throws Exception
{
-
- Connection conn = cf.createConnection();
-
- Session producerSess = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageProducer producer = producerSess.createProducer(queue);
-
- Session consumerSess = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageConsumer consumer = consumerSess.createConsumer(queue);
- conn.start();
-
- final int NUM_MESSAGES = 20;
-
- //Send some messages
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- Message m = producerSess.createMessage();
- producer.send(m);
- }
-
- assertRemainingMessages(0);
+ Connection conn = null;
- producerSess.rollback();
-
- //Send some messages
- for (int i = 0; i < NUM_MESSAGES; i++)
+ try
{
- Message m = producerSess.createMessage();
- producer.send(m);
+
+ conn = cf.createConnection();
+
+ Session producerSess = conn.createSession(true, Session.SESSION_TRANSACTED);
+ MessageProducer producer = producerSess.createProducer(queue1);
+
+ Session consumerSess = conn.createSession(true, Session.SESSION_TRANSACTED);
+ MessageConsumer consumer = consumerSess.createConsumer(queue1);
+ conn.start();
+
+ final int NUM_MESSAGES = 20;
+
+ //Send some messages
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ Message m = producerSess.createMessage();
+ producer.send(m);
+ }
+
+ assertRemainingMessages(0);
+
+ producerSess.rollback();
+
+ //Send some messages
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ Message m = producerSess.createMessage();
+ producer.send(m);
+ }
+ assertRemainingMessages(0);
+
+ producerSess.commit();
+
+ assertRemainingMessages(NUM_MESSAGES);
+
+ log.trace("Sent messages");
+
+ int count = 0;
+ while (true)
+ {
+ Message m = consumer.receive(200);
+ if (m == null) break;
+ count++;
+ }
+
+ assertRemainingMessages(NUM_MESSAGES);
+
+ log.trace("Received " + count + " messages");
+
+ assertEquals(count, NUM_MESSAGES);
+
+ consumerSess.rollback();
+
+ assertRemainingMessages(NUM_MESSAGES);
+
+ log.trace("Session rollback called");
+
+ int i = 0;
+ for(; i < NUM_MESSAGES; i++)
+ {
+ consumer.receive();
+ log.trace("Received message " + i);
+ }
+
+ assertRemainingMessages(NUM_MESSAGES);
+
+ // if I don't receive enough messages, the test will timeout
+
+ log.trace("Received " + i + " messages after recover");
+
+ consumerSess.commit();
+
+ assertRemainingMessages(0);
+
+ checkEmpty(queue1);
}
- assertRemainingMessages(0);
-
- producerSess.commit();
-
- assertRemainingMessages(NUM_MESSAGES);
-
- log.trace("Sent messages");
-
- int count = 0;
- while (true)
+ finally
{
- Message m = consumer.receive(200);
- if (m == null) break;
- count++;
+ if (conn != null)
+ {
+ conn.close();
+ }
}
-
- assertRemainingMessages(NUM_MESSAGES);
-
- log.trace("Received " + count + " messages");
-
- assertEquals(count, NUM_MESSAGES);
-
- consumerSess.rollback();
-
- assertRemainingMessages(NUM_MESSAGES);
-
- log.trace("Session rollback called");
-
- Message m = null;
-
- int i = 0;
- for(; i < NUM_MESSAGES; i++)
- {
- m = consumer.receive();
- log.trace("Received message " + i);
-
- }
-
- assertRemainingMessages(NUM_MESSAGES);
-
- // if I don't receive enough messages, the test will timeout
-
- log.trace("Received " + i + " messages after recover");
-
- consumerSess.commit();
-
- assertRemainingMessages(0);
-
- // make sure I don't receive anything else
-
- m = consumer.receive(200);
- assertNull(m);
-
- conn.close();
-
}
/**
@@ -352,75 +301,85 @@
*/
public void testClientAcknowledgeNoAcknowledgement() throws Exception
{
- Connection conn = cf.createConnection();
-
- Session producerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageProducer producer = producerSess.createProducer(queue);
-
- Session consumerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageConsumer consumer = consumerSess.createConsumer(queue);
- conn.start();
-
- final int NUM_MESSAGES = 20;
-
- //Send some messages
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- Message m = producerSess.createMessage();
- producer.send(m);
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+
+ Session producerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+ MessageProducer producer = producerSess.createProducer(queue1);
+
+ Session consumerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+ MessageConsumer consumer = consumerSess.createConsumer(queue1);
+ conn.start();
+
+ final int NUM_MESSAGES = 20;
+
+ //Send some messages
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ Message m = producerSess.createMessage();
+ producer.send(m);
+ }
+
+ assertRemainingMessages(NUM_MESSAGES);
+
+ log.trace("Sent messages");
+
+ int count = 0;
+ while (true)
+ {
+ Message m = consumer.receive(200);
+ if (m == null) break;
+ count++;
+ }
+
+ assertRemainingMessages(NUM_MESSAGES);
+
+ log.trace("Received " + count + " messages");
+
+ assertEquals(count, NUM_MESSAGES);
+
+ consumerSess.recover();
+
+ assertRemainingMessages(NUM_MESSAGES);
+
+ log.trace("Session recover called");
+
+ Message m = null;
+
+ int i = 0;
+ for(; i < NUM_MESSAGES; i++)
+ {
+ m = consumer.receive();
+ log.trace("Received message " + i);
+
+ }
+
+ assertRemainingMessages(NUM_MESSAGES);
+
+ // if I don't receive enough messages, the test will timeout
+
+ log.trace("Received " + i + " messages after recover");
+
+ m.acknowledge();
+
+ assertRemainingMessages(0);
+
+ // make sure I don't receive anything else
+
+ checkEmpty(queue1);
+
+ conn.close();
}
-
- assertRemainingMessages(NUM_MESSAGES);
-
- log.trace("Sent messages");
-
- int count = 0;
- while (true)
+ finally
{
- Message m = consumer.receive(200);
- if (m == null) break;
- count++;
+ if (conn != null)
+ {
+ conn.close();
+ }
}
-
- assertRemainingMessages(NUM_MESSAGES);
-
- log.trace("Received " + count + " messages");
-
- assertEquals(count, NUM_MESSAGES);
-
- consumerSess.recover();
-
- assertRemainingMessages(NUM_MESSAGES);
-
- log.trace("Session recover called");
-
- Message m = null;
-
- int i = 0;
- for(; i < NUM_MESSAGES; i++)
- {
- m = consumer.receive();
- log.trace("Received message " + i);
-
- }
-
- assertRemainingMessages(NUM_MESSAGES);
-
- // if I don't receive enough messages, the test will timeout
-
- log.trace("Received " + i + " messages after recover");
-
- m.acknowledge();
-
- assertRemainingMessages(0);
-
- // make sure I don't receive anything else
-
- m = consumer.receive(200);
- assertNull(m);
-
- conn.close();
-
}
@@ -431,65 +390,57 @@
*/
public void testIndividualClientAcknowledge() throws Exception
{
- Connection conn = cf.createConnection();
-
- Session producerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageProducer producer = producerSess.createProducer(queue);
+ Connection conn = null;
- Session consumerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageConsumer consumer = consumerSess.createConsumer(queue);
- conn.start();
-
- final int NUM_MESSAGES = 20;
-
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- Message m = producerSess.createMessage();
- producer.send(m);
- }
+ try
+ {
+ conn = cf.createConnection();
+
+ Session producerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+ MessageProducer producer = producerSess.createProducer(queue1);
+
+ Session consumerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+ MessageConsumer consumer = consumerSess.createConsumer(queue1);
+ conn.start();
+
+ final int NUM_MESSAGES = 20;
+
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ Message m = producerSess.createMessage();
+ producer.send(m);
+ }
+
+ assertRemainingMessages(NUM_MESSAGES);
+
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ Message m = consumer.receive(200);
+
+ assertNotNull(m);
- assertRemainingMessages(NUM_MESSAGES);
-
- log.trace("Sent " + NUM_MESSAGES + " messages");
-
- int count = 0;
- while (true)
- {
+ assertRemainingMessages(NUM_MESSAGES - i);
+
+ m.acknowledge();
+
+ assertRemainingMessages(NUM_MESSAGES - (i + 1));
+ }
+
+ assertRemainingMessages(0);
+
+ consumerSess.recover();
+
Message m = consumer.receive(200);
- log.trace("Received message " + m);
- if (m == null)
- {
- break;
- }
- log.trace("Acking session");
-
- assertRemainingMessages(NUM_MESSAGES - count);
-
- m.acknowledge();
-
- assertRemainingMessages(NUM_MESSAGES - (count + 1));
- count++;
+ assertNull(m);
}
-
- assertRemainingMessages(0);
-
- assertEquals(NUM_MESSAGES, count);
- log.trace("received and acknowledged " + count + " messages");
-
- Message m = consumer.receive(200);
- assertNull(m);
-
- log.trace("mesage is " + m);
-
- log.trace("calling session recover()");
- consumerSess.recover();
- log.trace("recover called");
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
- m = consumer.receive(200);
- assertNull(m);
-
- conn.close();
-
}
@@ -499,62 +450,70 @@
*/
public void testBulkClientAcknowledge() throws Exception
{
-
- Connection conn = cf.createConnection();
-
- Session producerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageProducer producer = producerSess.createProducer(queue);
-
- Session consumerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageConsumer consumer = consumerSess.createConsumer(queue);
- conn.start();
-
- final int NUM_MESSAGES = 20;
-
- //Send some messages
- for (int i = 0; i < NUM_MESSAGES; i++)
+ Connection conn = null;
+
+ try
{
- Message m = producerSess.createMessage();
- producer.send(m);
+ conn = cf.createConnection();
+
+ Session producerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+ MessageProducer producer = producerSess.createProducer(queue1);
+
+ Session consumerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+ MessageConsumer consumer = consumerSess.createConsumer(queue1);
+ conn.start();
+
+ final int NUM_MESSAGES = 20;
+
+ //Send some messages
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ Message m = producerSess.createMessage();
+ producer.send(m);
+ }
+
+ assertRemainingMessages(NUM_MESSAGES);
+
+ log.trace("Sent messages");
+
+ Message m = null;
+ int count = 0;
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ m = consumer.receive(200);
+ if (m == null) break;
+ count++;
+ }
+
+ assertRemainingMessages(NUM_MESSAGES);
+
+ assertNotNull(m);
+
+ m.acknowledge();
+
+ assertRemainingMessages(0);
+
+ log.trace("Received " + count + " messages");
+
+ assertEquals(count, NUM_MESSAGES);
+
+ consumerSess.recover();
+
+ log.trace("Session recover called");
+
+ m = consumer.receive(200);
+
+ log.trace("Message is:" + m);
+
+ assertNull(m);
}
-
- assertRemainingMessages(NUM_MESSAGES);
-
- log.trace("Sent messages");
-
- Message m = null;
- int count = 0;
- for (int i = 0; i < NUM_MESSAGES; i++)
+ finally
{
- m = consumer.receive(200);
- if (m == null) break;
- count++;
+ if (conn != null)
+ {
+ conn.close();
+ }
}
-
- assertRemainingMessages(NUM_MESSAGES);
-
- assertNotNull(m);
-
- m.acknowledge();
-
- assertRemainingMessages(0);
-
- log.trace("Received " + count + " messages");
-
- assertEquals(count, NUM_MESSAGES);
-
- consumerSess.recover();
-
- log.trace("Session recover called");
-
- m = consumer.receive(200);
-
- log.trace("Message is:" + m);
-
- assertNull(m);
-
- conn.close();
-
}
@@ -564,71 +523,82 @@
*/
public void testPartialClientAcknowledge() throws Exception
{
-
- Connection conn = cf.createConnection();
-
- Session producerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageProducer producer = producerSess.createProducer(queue);
-
- Session consumerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageConsumer consumer = consumerSess.createConsumer(queue);
- conn.start();
-
- final int NUM_MESSAGES = 20;
- final int ACKED_MESSAGES = 11;
-
- //Send some messages
- for (int i = 0; i < NUM_MESSAGES; i++)
+ Connection conn = null;
+
+ try
{
- Message m = producerSess.createMessage();
- producer.send(m);
+
+ conn = cf.createConnection();
+
+ Session producerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+ MessageProducer producer = producerSess.createProducer(queue1);
+
+ Session consumerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+ MessageConsumer consumer = consumerSess.createConsumer(queue1);
+ conn.start();
+
+ final int NUM_MESSAGES = 20;
+ final int ACKED_MESSAGES = 11;
+
+ //Send some messages
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ Message m = producerSess.createMessage();
+ producer.send(m);
+ }
+
+ assertRemainingMessages(NUM_MESSAGES);
+
+ log.trace("Sent messages");
+
+ int count = 0;
+
+ Message m = null;
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ m = consumer.receive(200);
+ if (m == null)
+ {
+ break;
+ }
+ if (count == ACKED_MESSAGES -1)
+ {
+ m.acknowledge();
+ }
+ count++;
+ }
+
+ assertRemainingMessages(NUM_MESSAGES - ACKED_MESSAGES);
+
+ assertNotNull(m);
+
+ log.trace("Received " + count + " messages");
+
+ assertEquals(count, NUM_MESSAGES);
+
+ consumerSess.recover();
+
+ log.trace("Session recover called");
+
+ count = 0;
+ while (true)
+ {
+ m = consumer.receive(200);
+ if (m == null) break;
+ count++;
+ }
+
+ assertEquals(NUM_MESSAGES - ACKED_MESSAGES, count);
}
-
- assertRemainingMessages(NUM_MESSAGES);
-
- log.trace("Sent messages");
-
- int count = 0;
-
- Message m = null;
- for (int i = 0; i < NUM_MESSAGES; i++)
+ finally
{
- m = consumer.receive(200);
- if (m == null)
- {
- break;
- }
- if (count == ACKED_MESSAGES -1)
- {
- m.acknowledge();
- }
- count++;
+ if (conn != null)
+ {
+ conn.close();
+ }
+
+ removeAllMessages(queue1.getQueueName(), true, 0);
}
-
- assertRemainingMessages(NUM_MESSAGES - ACKED_MESSAGES);
-
- assertNotNull(m);
-
- log.trace("Received " + count + " messages");
-
- assertEquals(count, NUM_MESSAGES);
-
- consumerSess.recover();
-
- log.trace("Session recover called");
-
- count = 0;
- while (true)
- {
- m = consumer.receive(200);
- if (m == null) break;
- count++;
- }
-
- assertEquals(NUM_MESSAGES - ACKED_MESSAGES, count);
-
- conn.close();
-
}
@@ -639,78 +609,98 @@
*/
public void testAutoAcknowledge() throws Exception
{
-
- Connection conn = cf.createConnection();
-
- Session producerSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer producer = producerSess.createProducer(queue);
-
- Session consumerSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer consumer = consumerSess.createConsumer(queue);
- conn.start();
-
- final int NUM_MESSAGES = 20;
-
- //Send some messages
- for (int i = 0; i < NUM_MESSAGES; i++)
+ Connection conn = null;
+
+ try
{
- Message m = producerSess.createMessage();
- producer.send(m);
+
+ conn = cf.createConnection();
+
+ Session producerSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer producer = producerSess.createProducer(queue1);
+
+ Session consumerSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer consumer = consumerSess.createConsumer(queue1);
+ conn.start();
+
+ final int NUM_MESSAGES = 20;
+
+ //Send some messages
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ Message m = producerSess.createMessage();
+ producer.send(m);
+ }
+
+ assertRemainingMessages(NUM_MESSAGES);
+
+ log.trace("Sent messages");
+
+ int count = 0;
+
+ Message m = null;
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ assertRemainingMessages(NUM_MESSAGES - i);
+
+ m = consumer.receive(200);
+
+ assertRemainingMessages(NUM_MESSAGES - (i + 1));
+
+ if (m == null) break;
+ count++;
+ }
+
+ assertRemainingMessages(0);
+
+ assertNotNull(m);
+
+ log.trace("Received " + count + " messages");
+
+ assertEquals(count, NUM_MESSAGES);
+
+ consumerSess.recover();
+
+ log.trace("Session recover called");
+
+ m = consumer.receive(200);
+
+ log.trace("Message is:" + m);
+
+ assertNull(m);
}
-
- assertRemainingMessages(NUM_MESSAGES);
-
- log.trace("Sent messages");
-
- int count = 0;
-
- Message m = null;
- for (int i = 0; i < NUM_MESSAGES; i++)
+ finally
{
- assertRemainingMessages(NUM_MESSAGES - i);
-
- m = consumer.receive(200);
-
- assertRemainingMessages(NUM_MESSAGES - (i + 1));
-
- if (m == null) break;
- count++;
+ if (conn != null)
+ {
+ conn.close();
+ }
}
-
- assertRemainingMessages(0);
- assertNotNull(m);
-
- log.trace("Received " + count + " messages");
-
- assertEquals(count, NUM_MESSAGES);
-
- consumerSess.recover();
-
- log.trace("Session recover called");
-
- m = consumer.receive(200);
-
- log.trace("Message is:" + m);
-
- assertNull(m);
-
- conn.close();
-
}
public void testDupsOKBatchDefault() throws Exception
{
//test default
- Connection conn = cf.createConnection();
+ Connection conn = null;
- JBossSession sess = (JBossSession)conn.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
-
- ClientSessionDelegate del = (ClientSessionDelegate)sess.getDelegate();
-
- assertEquals(1000, del.getDupsOKBatchSize());
-
- conn.close();
+ try
+ {
+ conn = cf.createConnection();
+
+ JBossSession sess = (JBossSession)conn.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
+
+ ClientSessionDelegate del = (ClientSessionDelegate)sess.getDelegate();
+
+ assertEquals(1000, del.getDupsOKBatchSize());
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void testDupsOKAcknowledgeQueue() throws Exception
@@ -740,15 +730,15 @@
try
{
- ConnectionFactory myCF = (ConnectionFactory)initialContext.lookup("/mycf");
+ ConnectionFactory myCF = (ConnectionFactory)ic.lookup("/mycf");
conn = myCF.createConnection();
Session producerSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer producer = producerSess.createProducer(queue);
+ MessageProducer producer = producerSess.createProducer(queue1);
Session consumerSess = conn.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
- MessageConsumer consumer = consumerSess.createConsumer(queue);
+ MessageConsumer consumer = consumerSess.createConsumer(queue1);
conn.start();
//Send some messages
@@ -837,15 +827,15 @@
try
{
- ConnectionFactory myCF = (ConnectionFactory)initialContext.lookup("/mycf");
+ ConnectionFactory myCF = (ConnectionFactory)ic.lookup("/mycf");
conn = myCF.createConnection();
Session producerSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer producer = producerSess.createProducer(topic);
+ MessageProducer producer = producerSess.createProducer(topic1);
Session consumerSess = conn.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
- MessageConsumer consumer = consumerSess.createConsumer(topic);
+ MessageConsumer consumer = consumerSess.createConsumer(topic1);
conn.start();
//Send some messages
@@ -890,109 +880,130 @@
*/
public void testLazyAcknowledge() throws Exception
{
-
- Connection conn = cf.createConnection();
-
- Session producerSess = conn.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
- MessageProducer producer = producerSess.createProducer(queue);
-
- Session consumerSess = conn.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
- MessageConsumer consumer = consumerSess.createConsumer(queue);
- conn.start();
-
- final int NUM_MESSAGES = 20;
-
- //Send some messages
- for (int i = 0; i < NUM_MESSAGES; i++)
+ Connection conn = null;
+
+ try
{
- Message m = producerSess.createMessage();
- producer.send(m);
+
+ conn = cf.createConnection();
+
+ Session producerSess = conn.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
+ MessageProducer producer = producerSess.createProducer(queue1);
+
+ Session consumerSess = conn.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
+ MessageConsumer consumer = consumerSess.createConsumer(queue1);
+ conn.start();
+
+ final int NUM_MESSAGES = 20;
+
+ //Send some messages
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ Message m = producerSess.createMessage();
+ producer.send(m);
+ }
+
+ assertRemainingMessages(NUM_MESSAGES);
+
+ log.trace("Sent messages");
+
+ int count = 0;
+
+ Message m = null;
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ m = consumer.receive(200);
+ if (m == null) break;
+ count++;
+ }
+
+ assertNotNull(m);
+
+ assertRemainingMessages(NUM_MESSAGES);
+
+ log.trace("Received " + count + " messages");
+
+ assertEquals(count, NUM_MESSAGES);
+
+ consumerSess.recover();
+
+ log.trace("Session recover called");
+
+ m = consumer.receive(200);
+
+ log.trace("Message is:" + m);
+
+ assertNull(m);
}
-
- assertRemainingMessages(NUM_MESSAGES);
-
- log.trace("Sent messages");
-
- int count = 0;
-
- Message m = null;
- for (int i = 0; i < NUM_MESSAGES; i++)
+ finally
{
- m = consumer.receive(200);
- if (m == null) break;
- count++;
+ if (conn != null)
+ {
+ conn.close();
+ }
}
-
- assertNotNull(m);
-
- assertRemainingMessages(NUM_MESSAGES);
- log.trace("Received " + count + " messages");
-
- assertEquals(count, NUM_MESSAGES);
-
- consumerSess.recover();
-
- log.trace("Session recover called");
-
- m = consumer.receive(200);
-
- log.trace("Message is:" + m);
-
- assertNull(m);
-
- conn.close();
-
}
public void testMessageListenerAutoAck() throws Exception
{
- Connection conn = cf.createConnection();
- Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessSend.createProducer(queue);
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ Connection conn = null;
- log.trace("Sending messages");
-
- TextMessage tm1 = sessSend.createTextMessage("a");
- TextMessage tm2 = sessSend.createTextMessage("b");
- TextMessage tm3 = sessSend.createTextMessage("c");
- prod.send(tm1);
- prod.send(tm2);
- prod.send(tm3);
-
- log.trace("Sent messages");
-
- sessSend.close();
-
- assertRemainingMessages(3);
-
- conn.start();
-
- Session sessReceive = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- log.trace("Creating consumer");
-
- MessageConsumer cons = sessReceive.createConsumer(queue);
-
- log.trace("Created consumer");
-
- MessageListenerAutoAck listener = new MessageListenerAutoAck(sessReceive);
-
- log.trace("Setting message listener");
-
- cons.setMessageListener(listener);
-
- log.trace("Set message listener");
-
- listener.waitForMessages();
-
- Thread.sleep(500);
-
- assertRemainingMessages(0);
-
- conn.close();
- assertFalse(listener.failed);
+ try
+ {
+ conn = cf.createConnection();
+ Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer prod = sessSend.createProducer(queue1);
+ prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ log.trace("Sending messages");
+
+ TextMessage tm1 = sessSend.createTextMessage("a");
+ TextMessage tm2 = sessSend.createTextMessage("b");
+ TextMessage tm3 = sessSend.createTextMessage("c");
+ prod.send(tm1);
+ prod.send(tm2);
+ prod.send(tm3);
+
+ log.trace("Sent messages");
+
+ sessSend.close();
+
+ assertRemainingMessages(3);
+
+ conn.start();
+
+ Session sessReceive = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ log.trace("Creating consumer");
+
+ MessageConsumer cons = sessReceive.createConsumer(queue1);
+
+ log.trace("Created consumer");
+
+ MessageListenerAutoAck listener = new MessageListenerAutoAck(sessReceive);
+
+ log.trace("Setting message listener");
+
+ cons.setMessageListener(listener);
+
+ log.trace("Set message listener");
+
+ listener.waitForMessages();
+
+ Thread.sleep(500);
+
+ assertRemainingMessages(0);
+
+ assertFalse(listener.failed);
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
/*
@@ -1012,7 +1023,7 @@
{
conn = cf.createConnection();
Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = s.createProducer(queue);
+ MessageProducer p = s.createProducer(queue1);
p.setDeliveryMode(DeliveryMode.PERSISTENT);
Message m = s.createTextMessage("one");
p.send(m);
@@ -1030,7 +1041,7 @@
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer consumer = session.createConsumer(queue);
+ MessageConsumer consumer = session.createConsumer(queue1);
TextMessage messageReceived = (TextMessage)consumer.receive(1000);
@@ -1067,120 +1078,157 @@
public void testMessageListenerDupsOK() throws Exception
{
- Connection conn = cf.createConnection();
- Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessSend.createProducer(queue);
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ Connection conn = null;
- log.trace("Sending messages");
-
- TextMessage tm1 = sessSend.createTextMessage("a");
- TextMessage tm2 = sessSend.createTextMessage("b");
- TextMessage tm3 = sessSend.createTextMessage("c");
- prod.send(tm1);
- prod.send(tm2);
- prod.send(tm3);
-
- log.trace("Sent messages");
-
- sessSend.close();
-
- assertRemainingMessages(3);
-
- conn.start();
-
- Session sessReceive = conn.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
-
- log.trace("Creating consumer");
-
- MessageConsumer cons = sessReceive.createConsumer(queue);
-
- log.trace("Created consumer");
-
- MessageListenerDupsOK listener = new MessageListenerDupsOK(sessReceive);
-
- log.trace("Setting message listener");
-
- cons.setMessageListener(listener);
-
- log.trace("Set message listener");
-
- listener.waitForMessages();
-
- assertRemainingMessages(3);
-
- conn.close();
-
- Thread.sleep(500);
-
- assertRemainingMessages(0);
- assertFalse(listener.failed);
+ try
+ {
+
+ conn = cf.createConnection();
+ Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer prod = sessSend.createProducer(queue1);
+ prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ log.trace("Sending messages");
+
+ TextMessage tm1 = sessSend.createTextMessage("a");
+ TextMessage tm2 = sessSend.createTextMessage("b");
+ TextMessage tm3 = sessSend.createTextMessage("c");
+ prod.send(tm1);
+ prod.send(tm2);
+ prod.send(tm3);
+
+ log.trace("Sent messages");
+
+ sessSend.close();
+
+ assertRemainingMessages(3);
+
+ conn.start();
+
+ Session sessReceive = conn.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
+
+ log.trace("Creating consumer");
+
+ MessageConsumer cons = sessReceive.createConsumer(queue1);
+
+ log.trace("Created consumer");
+
+ MessageListenerDupsOK listener = new MessageListenerDupsOK(sessReceive);
+
+ log.trace("Setting message listener");
+
+ cons.setMessageListener(listener);
+
+ log.trace("Set message listener");
+
+ listener.waitForMessages();
+
+ assertRemainingMessages(3);
+
+ conn.close();
+
+ Thread.sleep(500);
+
+ assertRemainingMessages(0);
+ assertFalse(listener.failed);
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void testMessageListenerClientAck() throws Exception
{
- Connection conn = cf.createConnection();
- Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessSend.createProducer(queue);
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- TextMessage tm1 = sessSend.createTextMessage("a");
- TextMessage tm2 = sessSend.createTextMessage("b");
- TextMessage tm3 = sessSend.createTextMessage("c");
- prod.send(tm1);
- prod.send(tm2);
- prod.send(tm3);
- sessSend.close();
+ Connection conn = null;
- assertRemainingMessages(3);
-
- conn.start();
- Session sessReceive = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageConsumer cons = sessReceive.createConsumer(queue);
- MessageListenerClientAck listener = new MessageListenerClientAck(sessReceive);
- cons.setMessageListener(listener);
-
- listener.waitForMessages();
-
- Thread.sleep(500);
-
- assertRemainingMessages(0);
-
- conn.close();
-
- assertFalse(listener.failed);
+ try
+ {
+ conn = cf.createConnection();
+ Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer prod = sessSend.createProducer(queue1);
+ prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ TextMessage tm1 = sessSend.createTextMessage("a");
+ TextMessage tm2 = sessSend.createTextMessage("b");
+ TextMessage tm3 = sessSend.createTextMessage("c");
+ prod.send(tm1);
+ prod.send(tm2);
+ prod.send(tm3);
+ sessSend.close();
+
+ assertRemainingMessages(3);
+
+ conn.start();
+ Session sessReceive = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+ MessageConsumer cons = sessReceive.createConsumer(queue1);
+ MessageListenerClientAck listener = new MessageListenerClientAck(sessReceive);
+ cons.setMessageListener(listener);
+
+ listener.waitForMessages();
+
+ Thread.sleep(500);
+
+ assertRemainingMessages(0);
+
+ conn.close();
+
+ assertFalse(listener.failed);
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void testMessageListenerTransactionalAck() throws Exception
{
- Connection conn = cf.createConnection();
- Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessSend.createProducer(queue);
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- TextMessage tm1 = sessSend.createTextMessage("a");
- TextMessage tm2 = sessSend.createTextMessage("b");
- TextMessage tm3 = sessSend.createTextMessage("c");
- prod.send(tm1);
- prod.send(tm2);
- prod.send(tm3);
- sessSend.close();
+ Connection conn = null;
- assertRemainingMessages(3);
-
- conn.start();
- Session sessReceive = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageConsumer cons = sessReceive.createConsumer(queue);
- MessageListenerTransactionalAck listener = new MessageListenerTransactionalAck(sessReceive);
- cons.setMessageListener(listener);
- listener.waitForMessages();
-
- Thread.sleep(500);
-
- assertRemainingMessages(0);
-
- conn.close();
-
- assertFalse(listener.failed);
+ try
+ {
+ conn = cf.createConnection();
+ Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer prod = sessSend.createProducer(queue1);
+ prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ TextMessage tm1 = sessSend.createTextMessage("a");
+ TextMessage tm2 = sessSend.createTextMessage("b");
+ TextMessage tm3 = sessSend.createTextMessage("c");
+ prod.send(tm1);
+ prod.send(tm2);
+ prod.send(tm3);
+ sessSend.close();
+
+ assertRemainingMessages(3);
+
+ conn.start();
+ Session sessReceive = conn.createSession(true, Session.SESSION_TRANSACTED);
+ MessageConsumer cons = sessReceive.createConsumer(queue1);
+ MessageListenerTransactionalAck listener = new MessageListenerTransactionalAck(sessReceive);
+ cons.setMessageListener(listener);
+ listener.waitForMessages();
+
+ Thread.sleep(500);
+
+ assertRemainingMessages(0);
+
+ conn.close();
+
+ assertFalse(listener.failed);
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
// Package protected ---------------------------------------------
@@ -1569,22 +1617,6 @@
}
}
-
- private boolean assertRemainingMessages(int expected) throws Exception
- {
- //Need to pause since delivery may still be in progress
- // Thread.sleep(500);
- ObjectName destObjectName =
- new ObjectName("jboss.messaging.destination:service=Queue,name=Queue");
- Integer messageCount = (Integer)ServerManagement.getAttribute(destObjectName, "MessageCount");
-
- log.trace("There are " + messageCount + " messages");
-
- assertEquals(expected, messageCount.intValue());
- return expected == messageCount.intValue();
- }
-
-
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/BrowserTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/BrowserTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/BrowserTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -28,17 +28,11 @@
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
-import javax.jms.Queue;
import javax.jms.QueueBrowser;
import javax.jms.Session;
-import javax.jms.Topic;
import javax.jms.TextMessage;
-import javax.naming.InitialContext;
-import org.jboss.jms.client.JBossConnectionFactory;
import org.jboss.jms.destination.JBossQueue;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
/**
@@ -48,7 +42,7 @@
*
* $Id$
*/
-public class BrowserTest extends MessagingTestCase
+public class BrowserTest extends JMSTestCase
{
// Constants -----------------------------------------------------------------------------------
@@ -57,15 +51,6 @@
// Attributes -----------------------------------------------------------------------------------
- protected InitialContext initialContext;
-
- protected JBossConnectionFactory cf;
- protected Queue queue;
- protected Topic topic;
- protected Connection connection;
- protected Session session;
- protected MessageProducer producer;
-
// Constructors ---------------------------------------------------------------------------------
public BrowserTest(String name)
@@ -77,15 +62,31 @@
public void testCreateBrowserOnNullDestination() throws Exception
{
- try
- {
- session.createBrowser(null);
- fail("should throw exception");
- }
- catch(InvalidDestinationException e)
- {
- // OK
- }
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ try
+ {
+ session.createBrowser(null);
+ fail("should throw exception");
+ }
+ catch(InvalidDestinationException e)
+ {
+ // OK
+ }
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void testCreateBrowserOnNonExistentQueue() throws Exception
@@ -108,167 +109,194 @@
}
finally
{
- pconn.close();
+ if (pconn != null)
+ {
+ pconn.close();
+ }
}
}
public void testBrowse() throws Exception
{
- log.trace("Starting testBrowse()");
-
- final int numMessages = 10;
-
- for (int i = 0; i < numMessages; i++)
- {
- Message m = session.createMessage();
- m.setIntProperty("cnt", i);
- producer.send(m);
- }
-
- log.trace("Sent messages");
-
- QueueBrowser browser = session.createBrowser(queue);
-
- assertEquals(browser.getQueue(), queue);
-
- assertNull(browser.getMessageSelector());
-
- Enumeration en = browser.getEnumeration();
-
- int count = 0;
- while (en.hasMoreElements())
- {
- en.nextElement();
- count++;
- }
-
- assertEquals(numMessages, count);
-
- MessageConsumer mc = session.createConsumer(queue);
-
- connection.start();
-
- for (int i = 0; i < numMessages; i++)
- {
- Message m = mc.receive();
- assertNotNull(m);
- }
-
- browser = session.createBrowser(queue);
- en = browser.getEnumeration();
-
- count = 0;
- while (en.hasMoreElements())
- {
- Message mess = (Message)en.nextElement();
- log.trace("message:" + mess);
- count++;
- }
-
- log.trace("Received " + count + " messages");
-
- assertEquals(0, count);
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer producer = session.createProducer(queue1);
+
+ final int numMessages = 10;
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ Message m = session.createMessage();
+ m.setIntProperty("cnt", i);
+ producer.send(m);
+ }
+
+ log.trace("Sent messages");
+
+ QueueBrowser browser = session.createBrowser(queue1);
+
+ assertEquals(browser.getQueue(), queue1);
+
+ assertNull(browser.getMessageSelector());
+
+ Enumeration en = browser.getEnumeration();
+
+ int count = 0;
+ while (en.hasMoreElements())
+ {
+ en.nextElement();
+ count++;
+ }
+
+ assertEquals(numMessages, count);
+
+ MessageConsumer mc = session.createConsumer(queue1);
+
+ conn.start();
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ Message m = mc.receive();
+ assertNotNull(m);
+ }
+
+ browser = session.createBrowser(queue1);
+ en = browser.getEnumeration();
+
+ count = 0;
+ while (en.hasMoreElements())
+ {
+ Message mess = (Message)en.nextElement();
+ log.trace("message:" + mess);
+ count++;
+ }
+
+ log.trace("Received " + count + " messages");
+
+ assertEquals(0, count);
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void testBrowseWithSelector() throws Exception
{
-
- final int numMessages = 100;
-
- for (int i = 0; i < numMessages; i++)
- {
- Message m = session.createMessage();
- m.setIntProperty("test_counter", i+1);
- producer.send(m);
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer producer = session.createProducer(queue1);
+
+ final int numMessages = 100;
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ Message m = session.createMessage();
+ m.setIntProperty("test_counter", i+1);
+ producer.send(m);
+ }
+
+ log.trace("Sent messages");
+
+ QueueBrowser browser = session.createBrowser(queue1, "test_counter > 30");
+
+ Enumeration en = browser.getEnumeration();
+ int count = 0;
+ while (en.hasMoreElements())
+ {
+ Message m = (Message)en.nextElement();
+ int testCounter = m.getIntProperty("test_counter");
+ assertTrue(testCounter > 30);
+ count++;
+ }
+ assertEquals(70, count);
}
-
- log.trace("Sent messages");
-
- QueueBrowser browser = session.createBrowser(queue, "test_counter > 30");
-
- Enumeration en = browser.getEnumeration();
- int count = 0;
- while (en.hasMoreElements())
+ finally
{
- Message m = (Message)en.nextElement();
- int testCounter = m.getIntProperty("test_counter");
- assertTrue(testCounter > 30);
- count++;
+ if (conn != null)
+ {
+ conn.close();
+ }
+
+ removeAllMessages(queue1.getQueueName(), true, 0);
}
- assertEquals(70, count);
}
public void testGetEnumeration() throws Exception
{
- // send a message to the queue
-
- Message m = session.createTextMessage("A");
- producer.send(m);
-
- // make sure we can browse it
-
- QueueBrowser browser = session.createBrowser(queue);
-
- Enumeration en = browser.getEnumeration();
-
- assertTrue(en.hasMoreElements());
-
- TextMessage rm = (TextMessage)en.nextElement();
-
- assertNotNull(rm);
- assertEquals("A", rm.getText());
-
- assertFalse(en.hasMoreElements());
-
- // create a *new* enumeration, that should reset it
-
- en = browser.getEnumeration();
-
- assertTrue(en.hasMoreElements());
-
- rm = (TextMessage)en.nextElement();
-
- assertNotNull(rm);
- assertEquals("A", rm.getText());
-
- assertFalse(en.hasMoreElements());
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer producer = session.createProducer(queue1);
+
+ // send a message to the queue
+
+ Message m = session.createTextMessage("A");
+ producer.send(m);
+
+ // make sure we can browse it
+
+ QueueBrowser browser = session.createBrowser(queue1);
+
+ Enumeration en = browser.getEnumeration();
+
+ assertTrue(en.hasMoreElements());
+
+ TextMessage rm = (TextMessage)en.nextElement();
+
+ assertNotNull(rm);
+ assertEquals("A", rm.getText());
+
+ assertFalse(en.hasMoreElements());
+
+ // create a *new* enumeration, that should reset it
+
+ en = browser.getEnumeration();
+
+ assertTrue(en.hasMoreElements());
+
+ rm = (TextMessage)en.nextElement();
+
+ assertNotNull(rm);
+ assertEquals("A", rm.getText());
+
+ assertFalse(en.hasMoreElements());
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+
+ removeAllMessages(queue1.getQueueName(), true, 0);
+ }
}
// Package protected ----------------------------------------------------------------------------
// Protected ------------------------------------------------------------------------------------
- protected void setUp() throws Exception
- {
-
- super.setUp();
- ServerManagement.start("all");
-
- initialContext = new InitialContext(ServerManagement.getJNDIEnvironment());
- cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
- ServerManagement.undeployQueue("Queue");
-
- ServerManagement.deployQueue("Queue");
- queue = (Queue)initialContext.lookup("/queue/Queue");
-
- drainDestination(cf, queue);
-
- connection = cf.createConnection();
- session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- producer = session.createProducer(queue);
-
- }
-
- protected void tearDown() throws Exception
- {
- ServerManagement.undeployQueue("Queue");
-
- connection.close();
-
- super.tearDown();
- }
-
// Private --------------------------------------------------------------------------------------
// Inner classes --------------------------------------------------------------------------------
Modified: trunk/tests/src/org/jboss/test/messaging/jms/CTSMiscellaneousTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/CTSMiscellaneousTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/CTSMiscellaneousTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -23,40 +23,33 @@
import javax.jms.BytesMessage;
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
import javax.jms.InvalidSelectorException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
-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.Topic;
import javax.jms.TopicConnection;
-import javax.jms.TopicConnectionFactory;
import javax.jms.TopicSession;
import javax.naming.InitialContext;
-import org.jboss.jms.client.JBossConnectionFactory;
-import org.jboss.test.messaging.MessagingTestCase;
import org.jboss.test.messaging.jms.message.SimpleJMSBytesMessage;
import org.jboss.test.messaging.jms.message.SimpleJMSMessage;
-import org.jboss.test.messaging.tools.ServerManagement;
/**
* Safeguards for previously detected TCK failures.
*
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @author <a href="mailto:tim.fox at jboss.org">Tim Fox</a>
* @version <tt>$Revision$</tt>
*
* $Id$
*/
-public class CTSMiscellaneousTest extends MessagingTestCase
+public class CTSMiscellaneousTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -77,47 +70,66 @@
public void testForeignByteMessage() throws Exception
{
- ConnectionFactory cf = (JBossConnectionFactory)ic.lookup("/ConnectionFactory");
-
- Connection c = cf.createConnection();
- Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Queue queue = (Queue)ic.lookup("/queue/Queue");
+ Connection c = null;
- drainDestination(cf, queue);
-
- MessageProducer p = s.createProducer(queue);
-
- // create a Bytes foreign message
- SimpleJMSBytesMessage bfm = new SimpleJMSBytesMessage();
-
- p.send(bfm);
-
- MessageConsumer cons = s.createConsumer(queue);
- c.start();
-
- BytesMessage bm = (BytesMessage)cons.receive();
- assertNotNull(bm);
-
- c.close();
+ try
+ {
+ c = cf.createConnection();
+ Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer p = s.createProducer(queue1);
+
+ // create a Bytes foreign message
+ SimpleJMSBytesMessage bfm = new SimpleJMSBytesMessage();
+
+ p.send(bfm);
+
+ MessageConsumer cons = s.createConsumer(queue1);
+ c.start();
+
+ BytesMessage bm = (BytesMessage)cons.receive();
+ assertNotNull(bm);
+ }
+ finally
+ {
+ if (c != null)
+ {
+ c.close();
+ }
+ }
+
}
public void testJMSMessageIDChanged() throws Exception
{
- ConnectionFactory cf = (JBossConnectionFactory)ic.lookup("/ConnectionFactory");
-
- Connection c = cf.createConnection();
- Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Queue queue = (Queue)ic.lookup("/queue/Queue");
- MessageProducer p = s.createProducer(queue);
-
- Message m = new SimpleJMSMessage();
- m.setJMSMessageID("something");
-
- p.send(m);
-
- assertFalse("something".equals(m.getJMSMessageID()));
-
- c.close();
+ Connection c = null;
+
+ try
+ {
+
+ c= cf.createConnection();
+ Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer p = s.createProducer(queue1);
+
+ Message m = new SimpleJMSMessage();
+ m.setJMSMessageID("something");
+
+ p.send(m);
+
+ assertFalse("something".equals(m.getJMSMessageID()));
+
+ c.close();
+ }
+ finally
+ {
+ if (c != null)
+ {
+ c.close();
+ }
+
+ removeAllMessages(queue1.getQueueName(), true, 0);
+ }
}
/**
@@ -125,49 +137,61 @@
*/
public void test_1() throws Exception
{
- QueueConnectionFactory qcf = (QueueConnectionFactory)ic.lookup("/ConnectionFactory");
- Queue queue = (Queue)ic.lookup("/queue/Queue");
-
- QueueConnection qc = qcf.createQueueConnection();
- QueueSession qs = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
-
- QueueReceiver qreceiver = qs.createReceiver(queue, "targetMessage = TRUE");
-
- qc.start();
-
- TextMessage m = qs.createTextMessage();
- m.setText("one");
- m.setBooleanProperty("targetMessage", false);
-
- QueueSender qsender = qs.createSender(queue);
-
- qsender.send(m);
-
- m.setText("two");
- m.setBooleanProperty("targetMessage", true);
-
- qsender.send(m);
-
- TextMessage rm = (TextMessage)qreceiver.receive(1000);
-
- assertEquals("two", rm.getText());
-
- qc.close();
+ QueueConnection qc = null;
+
+ try
+ {
+ qc = cf.createQueueConnection();
+ QueueSession qs = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ QueueReceiver qreceiver = qs.createReceiver(queue1, "targetMessage = TRUE");
+
+ qc.start();
+
+ TextMessage m = qs.createTextMessage();
+ m.setText("one");
+ m.setBooleanProperty("targetMessage", false);
+
+ QueueSender qsender = qs.createSender(queue1);
+
+ qsender.send(m);
+
+ m.setText("two");
+ m.setBooleanProperty("targetMessage", true);
+
+ qsender.send(m);
+
+ TextMessage rm = (TextMessage)qreceiver.receive(1000);
+
+ assertEquals("two", rm.getText());
+ }
+ finally
+ {
+ if (qc != null)
+ {
+ qc.close();
+ }
+ Thread.sleep(2000);
+ log.info("****** removing merssages");
+ removeAllMessages(queue1.getQueueName(), true, 0);
+ checkEmpty(queue1);
+ }
}
public void testInvalidSelectorOnDurableSubscription() throws Exception
{
- ConnectionFactory cf = (JBossConnectionFactory)ic.lookup("/ConnectionFactory");
- Connection c = cf.createConnection();
- c.setClientID("something");
+ Connection c = null;
+
try
- {
+ {
+ c = cf.createConnection();
+ c.setClientID("something");
+
Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Topic topic = (Topic)ic.lookup("/topic/Topic");
try
{
- s.createDurableSubscriber(topic, "somename", "=TEST 'test'", false);
+ s.createDurableSubscriber(topic1, "somename", "=TEST 'test'", false);
fail("this should fail");
}
catch(InvalidSelectorException e)
@@ -183,17 +207,17 @@
public void testInvalidSelectorOnSubscription() throws Exception
{
- TopicConnectionFactory cf = (TopicConnectionFactory)ic.lookup("/ConnectionFactory");
- TopicConnection c = cf.createTopicConnection();
- c.setClientID("something");
+ TopicConnection c = null;
try
{
+ c = cf.createTopicConnection();
+ c.setClientID("something");
+
TopicSession s = c.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
- Topic topic = (Topic)ic.lookup("/topic/Topic");
try
{
- s.createSubscriber(topic, "=TEST 'test'", false);
+ s.createSubscriber(topic1, "=TEST 'test'", false);
fail("this should fail");
}
catch(InvalidSelectorException e)
@@ -211,38 +235,7 @@
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
-
- protected void setUp() throws Exception
- {
- super.setUp();
-
- ServerManagement.start("all");
-
- ic = new InitialContext(ServerManagement.getJNDIEnvironment());
-
- ServerManagement.undeployQueue("Queue");
- ServerManagement.undeployTopic("Topic");
- ServerManagement.deployQueue("Queue");
- ServerManagement.deployTopic("Topic");
-
- ConnectionFactory cf = (JBossConnectionFactory)ic.lookup("/ConnectionFactory");
- Queue queue = (Queue)ic.lookup("/queue/Queue");
-
- drainDestination(cf, queue);
-
- log.debug("setup done");
- }
-
- public void tearDown() throws Exception
- {
- ServerManagement.undeployQueue("Queue");
- ServerManagement.undeployTopic("Topic");
-
- ic.close();
-
- super.tearDown();
- }
-
+
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
Modified: trunk/tests/src/org/jboss/test/messaging/jms/ClientInRestrictedSecurityEnvironmentTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/ClientInRestrictedSecurityEnvironmentTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/ClientInRestrictedSecurityEnvironmentTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -24,16 +24,11 @@
import java.net.SocketPermission;
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
-import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
-import javax.naming.InitialContext;
-import org.jboss.jms.client.JBossConnectionFactory;
-import org.jboss.test.messaging.MessagingTestCase;
import org.jboss.test.messaging.tools.ServerManagement;
import org.jboss.test.messaging.tools.misc.ConfigurableSecurityManager;
@@ -46,7 +41,7 @@
*
* $Id$
*/
-public class ClientInRestrictedSecurityEnvironmentTest extends MessagingTestCase
+public class ClientInRestrictedSecurityEnvironmentTest extends JMSTestCase
{
// Constants ------------------------------------------------------------------------------------
@@ -54,7 +49,6 @@
// Attributes -----------------------------------------------------------------------------------
- private InitialContext ic;
private SecurityManager oldSM;
private ConfigurableSecurityManager configurableSecurityManager;
@@ -129,12 +123,9 @@
}
// make sure our security manager disallows "listen" and "accept" on a socket
- configurableSecurityManager.dissalow(SocketPermission.class, "listen");
- configurableSecurityManager.dissalow(SocketPermission.class, "accept");
+ configurableSecurityManager.disallow(SocketPermission.class, "listen");
+ configurableSecurityManager.disallow(SocketPermission.class, "accept");
- ConnectionFactory cf = (JBossConnectionFactory)ic.lookup("/ConnectionFactory");
- Queue queue = (Queue)ic.lookup("/queue/TestQueue");
-
Connection conn = null;
try
@@ -143,8 +134,8 @@
Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = s.createProducer(queue);
- MessageConsumer c = s.createConsumer(queue);
+ MessageProducer p = s.createProducer(queue1);
+ MessageConsumer c = s.createConsumer(queue1);
conn.start();
@@ -153,7 +144,6 @@
TextMessage m = (TextMessage)c.receive();
assertEquals("payload", m.getText());
-
}
finally
{
@@ -171,13 +161,7 @@
protected void setUp() throws Exception
{
super.setUp();
- ServerManagement.start("all");
-
- ServerManagement.undeployQueue("TestQueue");
- ServerManagement.deployQueue("TestQueue");
-
- ic = new InitialContext(ServerManagement.getJNDIEnvironment());
-
+
// install our own security manager
configurableSecurityManager = new ConfigurableSecurityManager();
@@ -191,19 +175,13 @@
protected void tearDown() throws Exception
{
+ super.tearDown();
+
configurableSecurityManager.clear();
configurableSecurityManager = null;
System.setSecurityManager(oldSM);
- if (ic != null)
- {
- ic.close();
- }
-
- ServerManagement.undeployQueue("TestQueue");
-
- ServerManagement.stop();
super.tearDown();
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/ConnectionClosedTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/ConnectionClosedTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/ConnectionClosedTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -22,25 +22,18 @@
package org.jboss.test.messaging.jms;
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
-import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
-import javax.jms.Topic;
import javax.jms.TopicConnection;
import javax.jms.TopicConnectionFactory;
import javax.jms.TopicSession;
import javax.jms.TopicSubscriber;
-import javax.naming.InitialContext;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
-
/**
* All tests related to closing a Connection.
*
@@ -50,7 +43,7 @@
*
* $Id$
*/
-public class ConnectionClosedTest extends MessagingTestCase
+public class ConnectionClosedTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -58,12 +51,6 @@
// Attributes ----------------------------------------------------
- protected InitialContext initialContext;
-
- protected ConnectionFactory cf;
- protected Topic topic;
- protected Queue queue;
-
// Constructors --------------------------------------------------
public ConnectionClosedTest(String name)
@@ -73,32 +60,6 @@
// TestCase overrides -------------------------------------------
- public void setUp() throws Exception
- {
- super.setUp();
- ServerManagement.start("all");
-
-
- initialContext = new InitialContext(ServerManagement.getJNDIEnvironment());
- cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
- ServerManagement.undeployTopic("Topic");
- ServerManagement.deployTopic("Topic");
- topic = (Topic)initialContext.lookup("/topic/Topic");
-
- ServerManagement.undeployQueue("Queue");
- ServerManagement.deployQueue("Queue");
- queue = (Queue)initialContext.lookup("/queue/Queue");
- }
-
- public void tearDown() throws Exception
- {
- ServerManagement.undeployQueue("Queue");
- ServerManagement.undeployTopic("Topic");
-
- super.tearDown();
- }
-
-
// Public --------------------------------------------------------
public void testCloseOnce() throws Exception
@@ -123,15 +84,15 @@
TopicSession sess1 = conn1.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
TopicSession sess2 = conn2.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
- TopicSubscriber sub1 = sess1.createSubscriber(topic);
- TopicSubscriber sub2 = sess2.createSubscriber(topic);
+ TopicSubscriber sub1 = sess1.createSubscriber(topic1);
+ TopicSubscriber sub2 = sess2.createSubscriber(topic1);
conn1.start();
Connection conn3 = cf.createConnection();
Session sess3 = conn3.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess3.createProducer(topic);
+ MessageProducer prod = sess3.createProducer(topic1);
prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
final int NUM_MESSAGES = 10;
@@ -142,8 +103,6 @@
prod.send(tm);
}
- log.debug("all messages sent");
-
int count = 0;
while (true)
{
@@ -157,8 +116,6 @@
}
assertEquals(NUM_MESSAGES, count);
- log.debug("all messages received by sub1");
-
Message m = sub2.receive(200);
assertNull(m);
@@ -202,7 +159,7 @@
conn.start();
- final MessageConsumer consumer = session.createConsumer(topic);
+ final MessageConsumer consumer = session.createConsumer(topic1);
class TestRunnable implements Runnable
{
@@ -256,12 +213,8 @@
{
Connection connection = cf.createConnection();
- log.info("Closing connection");
-
connection.close();
- log.info("Closed connection");
-
try
{
connection.getMetaData();
@@ -296,9 +249,9 @@
{
Connection conn = cf.createConnection();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer consumer = sess.createConsumer(topic);
- MessageProducer producer = sess.createProducer(topic);
- sess.createBrowser(queue);
+ MessageConsumer consumer = sess.createConsumer(topic1);
+ MessageProducer producer = sess.createProducer(topic1);
+ sess.createBrowser(queue1);
Message m = sess.createMessage();
conn.close();
@@ -349,7 +302,7 @@
try
{
- sess.createProducer(queue);
+ sess.createProducer(queue1);
fail("should throw IllegalStateException");
}
catch(javax.jms.IllegalStateException e)
@@ -359,7 +312,7 @@
try
{
- sess.createConsumer(queue);
+ sess.createConsumer(queue1);
fail("should throw IllegalStateException");
}
catch(javax.jms.IllegalStateException e)
Modified: trunk/tests/src/org/jboss/test/messaging/jms/ConnectionConsumerTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/ConnectionConsumerTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/ConnectionConsumerTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -22,8 +22,6 @@
package org.jboss.test.messaging.jms;
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
@@ -32,10 +30,8 @@
import javax.jms.ServerSessionPool;
import javax.jms.Session;
import javax.jms.TextMessage;
-import javax.naming.InitialContext;
import org.jboss.jms.client.JBossConnectionConsumer;
-import org.jboss.test.messaging.MessagingTestCase;
import org.jboss.test.messaging.tools.ServerManagement;
import EDU.oswego.cs.dl.util.concurrent.Latch;
@@ -49,7 +45,7 @@
*
* $Id$
*/
-public class ConnectionConsumerTest extends MessagingTestCase
+public class ConnectionConsumerTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -57,9 +53,6 @@
// Attributes ----------------------------------------------------
- protected ConnectionFactory cf;
- protected Destination queue;
-
// Constructors --------------------------------------------------
public ConnectionConsumerTest(String name)
@@ -69,32 +62,6 @@
// TestCase overrides -------------------------------------------
- public void setUp() throws Exception
- {
- super.setUp();
- ServerManagement.start("all");
-
-
- ServerManagement.undeployQueue("Queue");
- ServerManagement.deployQueue("Queue");
-
- InitialContext ic = new InitialContext(ServerManagement.getJNDIEnvironment());
- cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
- queue = (Destination)ic.lookup("/queue/Queue");
-
- this.drainDestination(cf, queue);
-
- log.debug("setup done");
- }
-
- public void tearDown() throws Exception
- {
- ServerManagement.undeployQueue("Queue");
-
- super.tearDown();
- }
-
-
// Public --------------------------------------------------------
public void testSimple() throws Exception
@@ -121,12 +88,12 @@
ServerSessionPool pool = new MockServerSessionPool(sessCons);
- JBossConnectionConsumer cc = (JBossConnectionConsumer)connConsumer.createConnectionConsumer(queue, null, pool, 1);
+ JBossConnectionConsumer cc = (JBossConnectionConsumer)connConsumer.createConnectionConsumer(queue1, null, pool, 1);
connProducer = cf.createConnection();
Session sessProd = connProducer.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProd.createProducer(queue);
+ MessageProducer prod = sessProd.createProducer(queue1);
for (int i = 0; i < NUM_MESSAGES; i++)
{
@@ -148,20 +115,12 @@
fail ("Didn't receive correct messages");
}
- log.trace("Received all messages");
-
- log.trace("closing connection consumer ...");
-
cc.close();
- log.trace("closing connections ...");
-
connProducer.close();
connProducer = null;
connConsumer.close();
connConsumer = null;
-
-
}
finally
{
@@ -194,14 +153,12 @@
ServerSessionPool pool = new MockServerSessionPool(sessCons);
- JBossConnectionConsumer cc = (JBossConnectionConsumer)connConsumer.createConnectionConsumer(queue, null, pool, 1);
+ JBossConnectionConsumer cc = (JBossConnectionConsumer)connConsumer.createConnectionConsumer(queue1, null, pool, 1);
- log.trace("Started connection consumer");
-
connProducer = cf.createConnection();
Session sessProd = connProducer.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProd.createProducer(queue);
+ MessageProducer prod = sessProd.createProducer(queue1);
TextMessage m1 = sessProd.createTextMessage("a");
TextMessage m2 = sessProd.createTextMessage("b");
@@ -209,10 +166,7 @@
prod.send(m1);
prod.send(m2);
prod.send(m3);
-
-
- log.trace("Sent messages");
-
+
//Wait for messages
listener.waitForLatch(10000);
@@ -224,14 +178,10 @@
cc.close();
- log.trace("Closed connection consumer");
-
connProducer.close();
connProducer = null;
connConsumer.close();
- connConsumer = null;
-
-
+ connConsumer = null;
}
finally
{
@@ -239,9 +189,8 @@
if (connConsumer != null) connProducer.close();
}
}
+
-
-
public void testRedeliveryTransactedDifferentConnection() throws Exception
{
if (ServerManagement.isRemote()) return;
@@ -270,14 +219,12 @@
connConnectionConsumer.start();
- JBossConnectionConsumer cc = (JBossConnectionConsumer)connConnectionConsumer.createConnectionConsumer(queue, null, pool, 1);
+ JBossConnectionConsumer cc = (JBossConnectionConsumer)connConnectionConsumer.createConnectionConsumer(queue1, null, pool, 1);
- log.trace("Started connection consumer");
-
connProducer = cf.createConnection();
Session sessProd = connProducer.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProd.createProducer(queue);
+ MessageProducer prod = sessProd.createProducer(queue1);
TextMessage m1 = sessProd.createTextMessage("a");
TextMessage m2 = sessProd.createTextMessage("b");
@@ -285,10 +232,7 @@
prod.send(m1);
prod.send(m2);
prod.send(m3);
-
-
- log.trace("Sent messages");
-
+
//Wait for messages
listener.waitForLatch(10000);
@@ -299,16 +243,13 @@
}
cc.close();
-
- log.trace("Closed connection consumer");
-
+
connProducer.close();
connProducer = null;
connConsumer.close();
connConsumer = null;
connConnectionConsumer.close();
- connConnectionConsumer = null;
-
+ connConnectionConsumer = null;
}
finally
{
@@ -342,14 +283,12 @@
ServerSessionPool pool = new MockServerSessionPool(sessCons);
- JBossConnectionConsumer cc = (JBossConnectionConsumer)connConsumer.createConnectionConsumer(queue, null, pool, 1);
+ JBossConnectionConsumer cc = (JBossConnectionConsumer)connConsumer.createConnectionConsumer(queue1, null, pool, 1);
- log.trace("Started connection consumer");
-
connProducer = cf.createConnection();
Session sessProd = connProducer.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProd.createProducer(queue);
+ MessageProducer prod = sessProd.createProducer(queue1);
for (int i = 0; i < NUM_MESSAGES; i++)
{
@@ -357,9 +296,6 @@
prod.send(m);
}
- log.trace("Sent messages");
-
-
cc.close();
connProducer.close();
@@ -572,10 +508,8 @@
{
log.error(e);
failed = true;
- }
-
- }
-
+ }
+ }
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/ConnectionFactoryTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/ConnectionFactoryTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/ConnectionFactoryTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -31,11 +31,9 @@
import javax.jms.TopicConnection;
import javax.jms.TopicConnectionFactory;
import javax.management.ObjectName;
-import javax.naming.InitialContext;
import org.jboss.jms.client.JBossConnectionFactory;
import org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate;
-import org.jboss.test.messaging.MessagingTestCase;
import org.jboss.test.messaging.tools.ServerManagement;
import org.jboss.test.messaging.tools.jmx.ServiceContainer;
@@ -46,7 +44,7 @@
*
* $Id$
*/
-public class ConnectionFactoryTest extends MessagingTestCase
+public class ConnectionFactoryTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -54,8 +52,6 @@
// Attributes ----------------------------------------------------
- protected InitialContext initialContext;
-
// Constructors --------------------------------------------------
public ConnectionFactoryTest(String name)
@@ -72,7 +68,7 @@
public void testQueueConnectionFactory() throws Exception
{
QueueConnectionFactory qcf =
- (QueueConnectionFactory)initialContext.lookup("/ConnectionFactory");
+ (QueueConnectionFactory)ic.lookup("/ConnectionFactory");
QueueConnection qc = qcf.createQueueConnection();
qc.close();
}
@@ -84,7 +80,7 @@
public void testTopicConnectionFactory() throws Exception
{
TopicConnectionFactory qcf =
- (TopicConnectionFactory)initialContext.lookup("/ConnectionFactory");
+ (TopicConnectionFactory)ic.lookup("/ConnectionFactory");
TopicConnection tc = qcf.createTopicConnection();
tc.close();
}
@@ -113,7 +109,7 @@
ServerManagement.invoke(on, "create", new Object[0], new String[0]);
ServerManagement.invoke(on, "start", new Object[0], new String[0]);
- ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/TestConnectionFactory");
+ ConnectionFactory cf = (ConnectionFactory)ic.lookup("/TestConnectionFactory");
Connection c = cf.createConnection();
assertEquals("sofiavergara", c.getClientID());
@@ -156,7 +152,7 @@
ServerManagement.invoke(on2, "destroy", new Object[0], new String[0]);
ServerManagement.undeploy(on2);
- cf = (ConnectionFactory)initialContext.lookup("/TestConnectionFactory");
+ cf = (ConnectionFactory)ic.lookup("/TestConnectionFactory");
Connection c2 = null;
try
{
@@ -174,7 +170,6 @@
ServerManagement.invoke(on, "stop", new Object[0], new String[0]);
ServerManagement.invoke(on, "destroy", new Object[0], new String[0]);
ServerManagement.undeploy(on);
-
}
public void testAdministrativelyConfiguredConnectors() throws Exception
@@ -197,20 +192,20 @@
ObjectName cf4 = deployConnectionFactory("jboss.messaging.destination:service=TestConnectionFactory4", name3, "/TestConnectionFactory4", "clientid4");
- JBossConnectionFactory f1 = (JBossConnectionFactory)initialContext.lookup("/TestConnectionFactory1");
+ JBossConnectionFactory f1 = (JBossConnectionFactory)ic.lookup("/TestConnectionFactory1");
ClientConnectionFactoryDelegate del1 = (ClientConnectionFactoryDelegate)f1.getDelegate();
assertTrue(del1.getServerLocatorURI().startsWith("bisocket://localhost:1234"));
- JBossConnectionFactory f2 = (JBossConnectionFactory)initialContext.lookup("/TestConnectionFactory2");
+ JBossConnectionFactory f2 = (JBossConnectionFactory)ic.lookup("/TestConnectionFactory2");
ClientConnectionFactoryDelegate del2 = (ClientConnectionFactoryDelegate)f2.getDelegate();
assertTrue(del2.getServerLocatorURI().startsWith("bisocket://localhost:1235"));
- JBossConnectionFactory f3 = (JBossConnectionFactory)initialContext.lookup("/TestConnectionFactory3");
+ JBossConnectionFactory f3 = (JBossConnectionFactory)ic.lookup("/TestConnectionFactory3");
ClientConnectionFactoryDelegate del3 = (ClientConnectionFactoryDelegate)f3.getDelegate();
assertTrue(del3.getServerLocatorURI().startsWith("bisocket://localhost:1236"));
- JBossConnectionFactory f4 = (JBossConnectionFactory)initialContext.lookup("/TestConnectionFactory4");
+ JBossConnectionFactory f4 = (JBossConnectionFactory)ic.lookup("/TestConnectionFactory4");
ClientConnectionFactoryDelegate del4 = (ClientConnectionFactoryDelegate)f4.getDelegate();
assertTrue(del4.getServerLocatorURI().startsWith("bisocket://localhost:1236"));
@@ -243,7 +238,7 @@
// the ConnectionFactories that ship with Messaging do not have their clientID
// administratively configured.
- ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
+ ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
Connection c = cf.createConnection();
assertNull(c.getClientID());
@@ -256,7 +251,7 @@
// the ConnectionFactories that ship with Messaging do not have their clientID
// administratively configured.
- ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
+ ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
Connection c = cf.createConnection();
// set the client id immediately after the connection is created
@@ -278,8 +273,8 @@
try
{
- Topic topic = (Topic) initialContext.lookup("/topic/TestSubscriber");
- ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/TestDurableCF");
+ Topic topic = (Topic) ic.lookup("/topic/TestSubscriber");
+ ConnectionFactory cf = (ConnectionFactory) ic.lookup("/TestDurableCF");
conn = cf.createConnection();
// I have to remove this asertion, as the test would work if doing this assertion
@@ -333,20 +328,6 @@
// Protected -----------------------------------------------------
- protected void setUp() throws Exception
- {
- super.setUp();
- ServerManagement.start("all");
-
-
- initialContext = new InitialContext(ServerManagement.getJNDIEnvironment());
- }
-
- protected void tearDown() throws Exception
- {
- super.tearDown();
- }
-
// Private -------------------------------------------------------
private ObjectName deployConnector(int port, String name) throws Exception
Modified: trunk/tests/src/org/jboss/test/messaging/jms/ConnectionTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/ConnectionTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/ConnectionTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -22,19 +22,16 @@
package org.jboss.test.messaging.jms;
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
import javax.jms.ConnectionMetaData;
-import javax.jms.Destination;
import javax.jms.ExceptionListener;
import javax.jms.JMSException;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
+import javax.jms.ServerSessionPool;
import javax.jms.Session;
+import javax.jms.Topic;
import javax.jms.TopicConnection;
import javax.jms.TopicConnectionFactory;
-import javax.jms.ServerSessionPool;
-import javax.jms.Topic;
-import javax.naming.InitialContext;
import org.jboss.jms.client.JBossConnection;
import org.jboss.jms.client.delegate.ClientConnectionDelegate;
@@ -44,8 +41,6 @@
import org.jboss.jms.tx.ResourceManager;
import org.jboss.jms.tx.ResourceManagerFactory;
import org.jboss.logging.Logger;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
/**
@@ -58,23 +53,16 @@
*
* $Id$
*/
-public class ConnectionTest extends MessagingTestCase
+public class ConnectionTest extends JMSTestCase
{
// Constants -----------------------------------------------------
private static final Logger log = Logger.getLogger(ConnectionTest.class);
-
// Static --------------------------------------------------------
// Attributes ----------------------------------------------------
- protected InitialContext initialContext;
-
- protected ConnectionFactory cf;
-
- protected Destination topic;
-
// Constructors --------------------------------------------------
public ConnectionTest(String name)
@@ -84,31 +72,6 @@
// TestCase overrides -------------------------------------------
- public void setUp() throws Exception
- {
- super.setUp();
-
- ServerManagement.start("all");
-
- initialContext = new InitialContext(ServerManagement.getJNDIEnvironment());
-
- cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
- ServerManagement.undeployTopic("Topic");
-
- ServerManagement.deployTopic("Topic");
-
- topic = (Destination)initialContext.lookup("/topic/Topic");
- }
-
- public void tearDown() throws Exception
- {
- ServerManagement.undeployTopic("Topic");
-
- super.tearDown();
- }
-
-
// Public --------------------------------------------------------
public void testResourceManagersForSameServer() throws Exception
@@ -195,7 +158,7 @@
public void testManyConnections() throws Exception
{
- for (int i = 0; i < 1000; i++)
+ for (int i = 0; i < 100; i++)
{
Connection conn = cf.createConnection();
conn.close();
@@ -371,36 +334,7 @@
}
- // TODO why is this test commented out?
-// public void testStartStop() throws Exception
-// {
-//
-// if (ServerManagement.isRemote())
-// {
-// //This test doesn't make sense remotely
-// return;
-// }
-//
-// Connection connection = cf.createConnection();
-// Serializable connectionID = ((JBossConnection)connection).getConnectionID();
-//
-// ServerConnectionDelegate d = ServerManagement.getServerPeer().
-// getClientManager().getConnectionDelegate(connectionID);
-//
-// assertFalse(d.isStarted());
-//
-// connection.start();
-//
-// assertTrue(d.isStarted());
-//
-// connection.stop();
-//
-// assertFalse(d.isStarted());
-//
-// connection.close();
-// }
-
/**
* Test creation of QueueSession
*/
@@ -413,7 +347,6 @@
qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
qc.close();
-
}
/**
@@ -459,7 +392,7 @@
*/
public void testConnectionListenerBug() throws Exception
{
- for (int i = 0; i < 500; i++)
+ for (int i = 0; i < 100; i++)
{
Connection conn = cf.createConnection();
@@ -470,8 +403,7 @@
conn.close();
//The problem with this test is I would need to capture the output and search
- //for NullPointerException!!!
-
+ //for NullPointerException!!!
}
}
@@ -487,7 +419,7 @@
try
{
- queueConnection.createDurableConnectionConsumer((Topic)topic, "subscriptionName", "",
+ queueConnection.createDurableConnectionConsumer((Topic)topic1, "subscriptionName", "",
(ServerSessionPool) null, 1);
fail("Should throw a javax.jms.IllegalStateException");
}
@@ -506,9 +438,7 @@
{
queueConnection.close();
}
- }
-
-
+ }
// Package protected ---------------------------------------------
@@ -528,7 +458,4 @@
log.trace("Received exception");
}
}
-
-
-
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/ConsumerClosedTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/ConsumerClosedTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/ConsumerClosedTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -6,17 +6,11 @@
*/
package org.jboss.test.messaging.jms;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
-
-import javax.naming.InitialContext;
-import javax.jms.ConnectionFactory;
-import javax.jms.Queue;
import javax.jms.Connection;
-import javax.jms.Session;
-import javax.jms.MessageProducer;
import javax.jms.MessageConsumer;
-import javax.management.ObjectName;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.naming.InitialContext;
/**
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
@@ -24,7 +18,7 @@
*
* $Id$
*/
-public class ConsumerClosedTest extends MessagingTestCase
+public class ConsumerClosedTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -47,61 +41,48 @@
public void testMessagesSentDuringClose() throws Exception
- {
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
- Queue queue = (Queue)ic.lookup("/queue/ConsumerClosedTestQueue");
-
- Connection c = cf.createConnection();
- c.start();
-
- Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = s.createProducer(queue);
-
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
+ {
+ Connection c = null;
+
+ try
{
- p.send(s.createTextMessage("message" + i));
+ c = cf.createConnection();
+ c.start();
+
+ Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer p = s.createProducer(queue1);
+
+ for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
+ {
+ p.send(s.createTextMessage("message" + i));
+ }
+
+ log.debug("all messages sent");
+
+ MessageConsumer cons = s.createConsumer(queue1);
+ cons.close();
+
+ log.debug("consumer closed");
+
+ // make sure that all messages are in queue
+
+ assertRemainingMessages(NUMBER_OF_MESSAGES);
}
-
- log.debug("all messages sent");
-
- MessageConsumer cons = s.createConsumer(queue);
- cons.close();
-
- log.debug("consumer closed");
-
- // make sure that all messages are in queue
- ObjectName on =
- new ObjectName("jboss.messaging.destination:service=Queue,name=ConsumerClosedTestQueue");
- Integer count = (Integer)ServerManagement.getAttribute(on, "MessageCount");
- assertEquals(NUMBER_OF_MESSAGES, count.intValue());
+ finally
+ {
+ if (c != null)
+ {
+ c.close();
+ }
+
+ removeAllMessages(queue1.getQueueName(), true, 0);
+ }
}
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
- protected void setUp() throws Exception
- {
- super.setUp();
-
- ServerManagement.start("all");
-
- ic = new InitialContext(ServerManagement.getJNDIEnvironment());
-
- ServerManagement.deployQueue("ConsumerClosedTestQueue");
-
- log.debug("setup done");
- }
-
- protected void tearDown() throws Exception
- {
- ServerManagement.undeployQueue("ConsumerClosedTestQueue");
-
- ic.close();
-
- super.tearDown();
- }
-
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
Modified: trunk/tests/src/org/jboss/test/messaging/jms/DLQTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/DLQTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/DLQTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -25,24 +25,20 @@
import java.util.Map;
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
-import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;
import javax.management.ObjectName;
-import javax.naming.InitialContext;
import javax.naming.NameNotFoundException;
import org.jboss.jms.destination.JBossQueue;
import org.jboss.jms.message.JBossMessage;
-import org.jboss.test.messaging.MessagingTestCase;
import org.jboss.test.messaging.tools.ServerManagement;
/**
@@ -54,7 +50,7 @@
* $Id$
*
*/
-public class DLQTest extends MessagingTestCase
+public class DLQTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -62,10 +58,6 @@
// Attributes ----------------------------------------------------
- protected InitialContext ic;
- protected ConnectionFactory cf;
- protected Queue queue;
-
// Constructors --------------------------------------------------
public DLQTest(String name)
@@ -82,36 +74,32 @@
return;
}
- ServerManagement.deployQueue("DLQ");
-
- ObjectName serverPeerObjectName = ServerManagement.getServerPeerObjectName();
-
- ObjectName dlqObjectName = (ObjectName)ServerManagement.getAttribute(serverPeerObjectName, "DefaultDLQ");
-
- assertNotNull(dlqObjectName);
-
- String name = (String)ServerManagement.getAttribute(dlqObjectName, "Name");
-
- assertNotNull(name);
-
- assertEquals("DLQ", name);
-
- String jndiName = (String)ServerManagement.getAttribute(dlqObjectName, "JNDIName");
-
- assertNotNull(jndiName);
-
- assertEquals("/queue/DLQ", jndiName);
-
- org.jboss.messaging.core.contract.Queue dlq = ServerManagement.getServer().getServerPeer().getDefaultDLQInstance();
-
- assertNotNull(dlq);
-
- InitialContext ic = null;
-
try
{
- ic = new InitialContext(ServerManagement.getJNDIEnvironment());
+ ServerManagement.deployQueue("DLQ");
+
+ ObjectName serverPeerObjectName = ServerManagement.getServerPeerObjectName();
+
+ ObjectName dlqObjectName = (ObjectName)ServerManagement.getAttribute(serverPeerObjectName, "DefaultDLQ");
+
+ assertNotNull(dlqObjectName);
+
+ String name = (String)ServerManagement.getAttribute(dlqObjectName, "Name");
+
+ assertNotNull(name);
+
+ assertEquals("DLQ", name);
+ String jndiName = (String)ServerManagement.getAttribute(dlqObjectName, "JNDIName");
+
+ assertNotNull(jndiName);
+
+ assertEquals("/queue/DLQ", jndiName);
+
+ org.jboss.messaging.core.contract.Queue dlq = ServerManagement.getServer().getServerPeer().getDefaultDLQInstance();
+
+ assertNotNull(dlq);
+
JBossQueue q = (JBossQueue)ic.lookup("/queue/DLQ");
assertNotNull(q);
@@ -120,10 +108,7 @@
}
finally
{
- if (ic != null) ic.close();
-
ServerManagement.undeployQueue("DLQ");
-
}
}
@@ -138,26 +123,15 @@
assertNull(dlq);
- InitialContext ic = null;
-
try
{
- ic = new InitialContext(ServerManagement.getJNDIEnvironment());
+ ic.lookup("/queue/DLQ");
- try
- {
- ic.lookup("/queue/DLQ");
-
- fail();
- }
- catch (NameNotFoundException e)
- {
- //Ok
- }
+ fail();
}
- finally
+ catch (NameNotFoundException e)
{
- if (ic != null) ic.close();
+ //Ok
}
}
@@ -172,48 +146,30 @@
final int MAX_DELIVERIES = 8;
- ServerManagement.deployQueue("DefaultDLQ");
+ ObjectName serverPeerObjectName = ServerManagement.getServerPeerObjectName();
- ServerManagement.deployQueue("OverrideDLQ");
+ String testQueueObjectName = "jboss.messaging.destination:service=Queue,name=Queue1";
- ServerManagement.deployQueue("TestQueue");
+ Connection conn = null;
- String defaultDLQObjectName = "jboss.messaging.destination:service=Queue,name=DefaultDLQ";
-
- String overrideDLQObjectName = "jboss.messaging.destination:service=Queue,name=OverrideDLQ";
-
- String testQueueObjectName = "jboss.messaging.destination:service=Queue,name=TestQueue";
-
- ObjectName serverPeerObjectName = ServerManagement.getServerPeerObjectName();
-
- ServerManagement.setAttribute(serverPeerObjectName, "DefaultMaxDeliveryAttempts", String.valueOf(MAX_DELIVERIES));
-
- ServerManagement.setAttribute(serverPeerObjectName, "DefaultDLQ", defaultDLQObjectName);
-
- ServerManagement.setAttribute(new ObjectName(testQueueObjectName), "DLQ", "");
-
- Queue testQueue = (Queue)ic.lookup("/queue/TestQueue");
-
- Queue defaultDLQ = (Queue)ic.lookup("/queue/DefaultDLQ");
-
- Queue overrideDLQ = (Queue)ic.lookup("/queue/OverrideDLQ");
-
- drainDestination(cf, testQueue);
-
- drainDestination(cf, defaultDLQ);
-
- drainDestination(cf, overrideDLQ);
-
- Connection conn = null;
-
try
- {
+ {
+ String defaultDLQObjectName = "jboss.messaging.destination:service=Queue,name=Queue2";
+
+ String overrideDLQObjectName = "jboss.messaging.destination:service=Queue,name=Queue3";
+
+ ServerManagement.setAttribute(serverPeerObjectName, "DefaultMaxDeliveryAttempts", String.valueOf(MAX_DELIVERIES));
+
+ ServerManagement.setAttribute(serverPeerObjectName, "DefaultDLQ", defaultDLQObjectName);
+
+ ServerManagement.setAttribute(new ObjectName(testQueueObjectName), "DLQ", "");
+
conn = cf.createConnection();
{
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(testQueue);
+ MessageProducer prod = sess.createProducer(queue1);
for (int i = 0; i < NUM_MESSAGES; i++)
{
@@ -224,7 +180,7 @@
Session sess2 = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageConsumer cons = sess2.createConsumer(testQueue);
+ MessageConsumer cons = sess2.createConsumer(queue1);
conn.start();
@@ -242,15 +198,16 @@
sess2.recover();
}
+ //Prompt them to go to DLQ
+ cons.receive(100);
+
//At this point all the messages have been delivered exactly MAX_DELIVERIES times
- Message m = cons.receive(1000);
+ checkEmpty(queue1);
- assertNull(m);
-
//Now should be in default dlq
- MessageConsumer cons3 = sess.createConsumer(defaultDLQ);
+ MessageConsumer cons3 = sess.createConsumer(queue2);
for (int i = 0; i < NUM_MESSAGES; i++)
{
@@ -274,7 +231,7 @@
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(testQueue);
+ MessageProducer prod = sess.createProducer(queue1);
for (int i = 0; i < NUM_MESSAGES; i++)
{
@@ -285,7 +242,7 @@
Session sess2 = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageConsumer cons = sess2.createConsumer(testQueue);
+ MessageConsumer cons = sess2.createConsumer(queue1);
conn.start();
@@ -303,15 +260,15 @@
sess2.recover();
}
+ cons.receive(100);
+
//At this point all the messages have been delivered exactly MAX_DELIVERIES times
- Message m = cons.receive(1000);
+ checkEmpty(queue1);
- assertNull(m);
-
//Now should be in override dlq
- MessageConsumer cons3 = sess.createConsumer(overrideDLQ);
+ MessageConsumer cons3 = sess.createConsumer(queue3);
for (int i = 0; i < NUM_MESSAGES; i++)
{
@@ -326,13 +283,9 @@
finally
{
ServerManagement.setAttribute(serverPeerObjectName, "DefaultDLQ", "jboss.messaging.destination:service=Queue,name=DLQ");
-
- ServerManagement.undeployQueue("DefaultDLQ");
- ServerManagement.undeployQueue("OverrideDLQ");
-
- ServerManagement.undeployQueue("TestQueue");
-
+ ServerManagement.setAttribute(new ObjectName(testQueueObjectName), "DLQ", "");
+
if (conn != null)
{
conn.close();
@@ -374,33 +327,29 @@
public void testHeadersSet() throws Exception
{
Connection conn = null;
-
- ServerManagement.deployQueue("DLQ");
-
- Queue dlq = (Queue)ic.lookup("/queue/DLQ");
- drainDestination(cf, dlq);
-
- ObjectName serverPeerObjectName = ServerManagement.getServerPeerObjectName();
-
- final int MAX_DELIVERIES = 16;
-
- final int NUM_MESSAGES = 5;
-
- ServerManagement.setAttribute(serverPeerObjectName, "DefaultMaxDeliveryAttempts", String.valueOf(MAX_DELIVERIES));
-
- int maxRedeliveryAttempts =
- ((Integer)ServerManagement.getAttribute(serverPeerObjectName, "DefaultMaxDeliveryAttempts")).intValue();
-
- assertEquals(MAX_DELIVERIES, maxRedeliveryAttempts);
-
try
- {
+ {
+ ObjectName serverPeerObjectName = ServerManagement.getServerPeerObjectName();
+
+ ServerManagement.setAttribute(serverPeerObjectName, "DefaultDLQ", "jboss.messaging.destination:service=Queue,name=Queue2");
+
+ final int MAX_DELIVERIES = 16;
+
+ final int NUM_MESSAGES = 5;
+
+ ServerManagement.setAttribute(serverPeerObjectName, "DefaultMaxDeliveryAttempts", String.valueOf(MAX_DELIVERIES));
+
+ int maxRedeliveryAttempts =
+ ((Integer)ServerManagement.getAttribute(serverPeerObjectName, "DefaultMaxDeliveryAttempts")).intValue();
+
+ assertEquals(MAX_DELIVERIES, maxRedeliveryAttempts);
+
conn = cf.createConnection();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
Map origIds = new HashMap();
@@ -415,7 +364,7 @@
Session sess2 = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageConsumer cons = sess2.createConsumer(queue);
+ MessageConsumer cons = sess2.createConsumer(queue1);
conn.start();
@@ -436,20 +385,18 @@
//At this point all the messages have been delivered exactly MAX_DELIVERIES times - this is ok
//they haven't exceeded max delivery attempts so shouldn't be in the DLQ - let's check
- MessageConsumer cons3 = sess.createConsumer(dlq);
+ checkEmpty(queue2);
- Message m = cons3.receive(1000);
-
- assertNull(m);
-
// So let's try and consume them - this should cause them to go to the DLQ - since they
// will then exceed max delivery attempts
- m = cons.receive(1000);
+ Message m = cons.receive(100);
assertNull(m);
//All the messages should now be in the DLQ
+ MessageConsumer cons3 = sess.createConsumer(queue2);
+
for (int i = 0; i < NUM_MESSAGES; i++)
{
TextMessage tm = (TextMessage)cons3.receive(1000);
@@ -465,116 +412,96 @@
String origMessageId =
tm.getStringProperty(JBossMessage.JBOSS_MESSAGING_ORIG_MESSAGE_ID);
- assertEquals(queue.toString(), origDest);
+ assertEquals(queue1.toString(), origDest);
String origId = (String)origIds.get(tm.getText());
assertEquals(origId, origMessageId);
}
-
- //No more should be available
-
- m = cons.receive(1000);
-
- assertNull(m);
-
- cons.close();
-
- MessageConsumer cons2 = sess2.createConsumer(queue);
-
- m = cons2.receive(1000);
-
- assertNull(m);
}
finally
{
- ServerManagement.undeployQueue("DLQ");
-
if (conn != null) conn.close();
}
}
public void testOverrideDefaultMaxDeliveryAttemptsForQueue() throws Exception
- {
- final String QUEUE_NAME = "MDA_Queue";
-
- ServerManagement.deployQueue(QUEUE_NAME);
-
- try
- {
- int maxDeliveryAttempts = getDefaultMaxDeliveryAttempts() - 5;
- setMaxDeliveryAttempts(
- new ObjectName("jboss.messaging.destination:service=Queue,name=" + QUEUE_NAME),
- maxDeliveryAttempts);
- testMaxDeliveryAttempts("/queue/" + QUEUE_NAME, maxDeliveryAttempts, true);
- }
- finally
- {
- ServerManagement.undeployQueue(QUEUE_NAME);
- }
+ {
+ int md = getDefaultMaxDeliveryAttempts();
+ try
+ {
+ int maxDeliveryAttempts = md - 5;
+ setMaxDeliveryAttempts(
+ new ObjectName("jboss.messaging.destination:service=Queue,name=Queue1"),
+ maxDeliveryAttempts);
+ testMaxDeliveryAttempts(queue1, maxDeliveryAttempts, true);
+ }
+ finally
+ {
+ setMaxDeliveryAttempts(
+ new ObjectName("jboss.messaging.destination:service=Queue,name=Queue1"),
+ md);
+ }
}
public void testOverrideDefaultMaxDeliveryAttemptsForTopic() throws Exception
{
- final String TOPIC_NAME = "Topic";
-
- ServerManagement.deployTopic(TOPIC_NAME);
-
- try
- {
- int maxDeliveryAttempts = getDefaultMaxDeliveryAttempts() - 5;
- setMaxDeliveryAttempts(
- new ObjectName("jboss.messaging.destination:service=Topic,name=" + TOPIC_NAME),
- maxDeliveryAttempts);
-
- testMaxDeliveryAttempts("/topic/" + TOPIC_NAME, maxDeliveryAttempts, false);
- }
- finally
- {
- ServerManagement.undeployTopic(TOPIC_NAME);
- }
+ int md = getDefaultMaxDeliveryAttempts();
+ try
+ {
+ int maxDeliveryAttempts = md - 5;
+ setMaxDeliveryAttempts(
+ new ObjectName("jboss.messaging.destination:service=Topic,name=Topic1"),
+ maxDeliveryAttempts);
+
+ testMaxDeliveryAttempts(topic1, maxDeliveryAttempts, false);
+ }
+ finally
+ {
+ setMaxDeliveryAttempts(
+ new ObjectName("jboss.messaging.destination:service=Queue,name=Queue1"),
+ md);
+ }
}
public void testUseDefaultMaxDeliveryAttemptsForQueue() throws Exception
{
- final String QUEUE_NAME = "MDA_Queue";
-
- ServerManagement.deployQueue(QUEUE_NAME);
-
- try
- {
- setMaxDeliveryAttempts(
- new ObjectName("jboss.messaging.destination:service=Queue,name=" + QUEUE_NAME),
- -1);
-
- // Check that defaultMaxDeliveryAttempts takes effect
- testMaxDeliveryAttempts("/queue/" + QUEUE_NAME, getDefaultMaxDeliveryAttempts(), true);
- }
- finally
- {
- ServerManagement.undeployQueue(QUEUE_NAME);
- }
+ int md = getDefaultMaxDeliveryAttempts();
+ try
+ {
+ setMaxDeliveryAttempts(
+ new ObjectName("jboss.messaging.destination:service=Queue,name=Queue1"),
+ -1);
+
+ // Check that defaultMaxDeliveryAttempts takes effect
+ testMaxDeliveryAttempts(queue1, getDefaultMaxDeliveryAttempts(), true);
+ }
+ finally
+ {
+ setMaxDeliveryAttempts(
+ new ObjectName("jboss.messaging.destination:service=Queue,name=Queue1"),
+ md);
+ }
}
public void testUseDefaultMaxDeliveryAttemptsForTopic() throws Exception
{
- final String TOPIC_NAME = "Topic";
-
- ServerManagement.deployTopic(TOPIC_NAME);
-
- try
- {
- setMaxDeliveryAttempts(
- new ObjectName("jboss.messaging.destination:service=Topic,name=" + TOPIC_NAME),
- -1);
-
- // Check that defaultMaxDeliveryAttempts takes effect
- testMaxDeliveryAttempts("/topic/" + TOPIC_NAME, getDefaultMaxDeliveryAttempts(), false);
- }
- finally
- {
- ServerManagement.undeployTopic(TOPIC_NAME);
- }
+ int md = getDefaultMaxDeliveryAttempts();
+ try
+ {
+ setMaxDeliveryAttempts(
+ new ObjectName("jboss.messaging.destination:service=Topic,name=Topic1"),
+ -1);
+
+ // Check that defaultMaxDeliveryAttempts takes effect
+ testMaxDeliveryAttempts(topic1, getDefaultMaxDeliveryAttempts(), false);
+ }
+ finally
+ {
+ setMaxDeliveryAttempts(
+ new ObjectName("jboss.messaging.destination:service=Queue,name=Queue1"),
+ md);
+ }
}
// Package protected ---------------------------------------------
@@ -585,32 +512,30 @@
{
Connection conn = null;
- ServerManagement.deployQueue("DLQ");
-
- Queue dlq = (Queue)ic.lookup("/queue/DLQ");
-
- drainDestination(cf, dlq);
-
- ObjectName serverPeerObjectName = ServerManagement.getServerPeerObjectName();
-
- final int MAX_DELIVERIES = 16;
-
- final int NUM_MESSAGES = 5;
-
- ServerManagement.setAttribute(serverPeerObjectName, "DefaultMaxDeliveryAttempts", String.valueOf(MAX_DELIVERIES));
-
- int maxRedeliveryAttempts =
- ((Integer)ServerManagement.getAttribute(serverPeerObjectName, "DefaultMaxDeliveryAttempts")).intValue();
-
- assertEquals(MAX_DELIVERIES, maxRedeliveryAttempts);
-
try
{
+ ObjectName serverPeerObjectName = ServerManagement.getServerPeerObjectName();
+
+ final int MAX_DELIVERIES = 16;
+
+ final int NUM_MESSAGES = 5;
+
+ ServerManagement.setAttribute(serverPeerObjectName, "DefaultMaxDeliveryAttempts", String.valueOf(MAX_DELIVERIES));
+
+ String defaultDLQObjectName = "jboss.messaging.destination:service=Queue,name=Queue2";
+
+ ServerManagement.setAttribute(serverPeerObjectName, "DefaultDLQ", defaultDLQObjectName);
+
+ int maxRedeliveryAttempts =
+ ((Integer)ServerManagement.getAttribute(serverPeerObjectName, "DefaultMaxDeliveryAttempts")).intValue();
+
+ assertEquals(MAX_DELIVERIES, maxRedeliveryAttempts);
+
conn = cf.createConnection();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
prod.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
@@ -621,42 +546,37 @@
prod.send(tm);
}
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
- FailingMessageListener listener = new FailingMessageListener();
+ FailingMessageListener listener = new FailingMessageListener(MAX_DELIVERIES * NUM_MESSAGES);
cons.setMessageListener(listener);
conn.start();
- Thread.sleep(4000);
+ listener.waitForMessages();
- cons.setMessageListener(null);
-
assertEquals(MAX_DELIVERIES * NUM_MESSAGES, listener.deliveryCount);
-
- Message m = cons.receive(1000);
-
- assertNull(m);
-
+
//Message should all be in the dlq - let's check
- MessageConsumer cons2 = sess.createConsumer(dlq);
+ MessageConsumer cons2 = sess.createConsumer(queue2);
for (int i = 0; i < NUM_MESSAGES; i++)
{
TextMessage tm = (TextMessage)cons2.receive(1000);
assertNotNull(tm);
+
+ log.info("Got mnessage" + tm);
assertEquals("Message:" + i, tm.getText());
}
-
+
+ checkEmpty(queue1);
}
finally
{
- ServerManagement.undeployQueue("DLQ");
-
if (conn != null) conn.close();
}
}
@@ -666,32 +586,30 @@
{
Connection conn = null;
- ServerManagement.deployQueue("DLQ");
-
- Queue dlq = (Queue)ic.lookup("/queue/DLQ");
-
- drainDestination(cf, dlq);
-
- ObjectName serverPeerObjectName = ServerManagement.getServerPeerObjectName();
-
- final int MAX_DELIVERIES = 16;
-
- final int NUM_MESSAGES = 5;
-
- ServerManagement.setAttribute(serverPeerObjectName, "DefaultMaxDeliveryAttempts", String.valueOf(MAX_DELIVERIES));
-
- int maxRedeliveryAttempts =
- ((Integer)ServerManagement.getAttribute(serverPeerObjectName, "DefaultMaxDeliveryAttempts")).intValue();
-
- assertEquals(MAX_DELIVERIES, maxRedeliveryAttempts);
-
try
{
+ ObjectName serverPeerObjectName = ServerManagement.getServerPeerObjectName();
+
+ final int MAX_DELIVERIES = 16;
+
+ final int NUM_MESSAGES = 5;
+
+ String defaultDLQObjectName = "jboss.messaging.destination:service=Queue,name=Queue2";
+
+ ServerManagement.setAttribute(serverPeerObjectName, "DefaultDLQ", defaultDLQObjectName);
+
+ ServerManagement.setAttribute(serverPeerObjectName, "DefaultMaxDeliveryAttempts", String.valueOf(MAX_DELIVERIES));
+
+ int maxRedeliveryAttempts =
+ ((Integer)ServerManagement.getAttribute(serverPeerObjectName, "DefaultMaxDeliveryAttempts")).intValue();
+
+ assertEquals(MAX_DELIVERIES, maxRedeliveryAttempts);
+
conn = cf.createConnection();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
prod.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
@@ -704,7 +622,7 @@
Session sess2 = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageConsumer cons = sess2.createConsumer(queue);
+ MessageConsumer cons = sess2.createConsumer(queue1);
conn.start();
@@ -725,21 +643,19 @@
//At this point all the messages have been delivered exactly MAX_DELIVERIES times - this is ok
//they haven't exceeded max delivery attempts so shouldn't be in the DLQ - let's check
- MessageConsumer cons3 = sess.createConsumer(dlq);
+ checkEmpty(queue2);
- Message m = cons3.receive(1000);
-
- assertNull(m);
-
//So let's try and consume them - this should cause them to go to the DLQ - since they will then exceed max
//delivery attempts
- m = cons.receive(1000);
+ Message m = cons.receive(100);
assertNull(m);
//Now, all the messages should now be in the DLQ
+ MessageConsumer cons3 = sess.createConsumer(queue2);
+
for (int i = 0; i < NUM_MESSAGES; i++)
{
TextMessage tm = (TextMessage)cons3.receive(1000);
@@ -750,18 +666,10 @@
}
//No more should be available
-
- m = cons.receive(1000);
-
- assertNull(m);
-
+
cons.close();
-
- MessageConsumer cons2 = sess2.createConsumer(queue);
-
- m = cons2.receive(1000);
-
- assertNull(m);
+
+ checkEmpty(queue1);
}
finally
{
@@ -775,32 +683,30 @@
{
Connection conn = null;
- ServerManagement.deployQueue("DLQ");
-
- Queue dlq = (Queue)ic.lookup("/queue/DLQ");
-
- drainDestination(cf, dlq);
-
- ObjectName serverPeerObjectName = ServerManagement.getServerPeerObjectName();
-
- final int MAX_DELIVERIES = 16;
-
- final int NUM_MESSAGES = 5;
-
- ServerManagement.setAttribute(serverPeerObjectName, "DefaultMaxDeliveryAttempts", String.valueOf(MAX_DELIVERIES));
-
- int maxRedeliveryAttempts =
- ((Integer)ServerManagement.getAttribute(serverPeerObjectName, "DefaultMaxDeliveryAttempts")).intValue();
-
- assertEquals(MAX_DELIVERIES, maxRedeliveryAttempts);
-
try
{
+ ObjectName serverPeerObjectName = ServerManagement.getServerPeerObjectName();
+
+ final int MAX_DELIVERIES = 16;
+
+ final int NUM_MESSAGES = 5;
+
+ ServerManagement.setAttribute(serverPeerObjectName, "DefaultMaxDeliveryAttempts", String.valueOf(MAX_DELIVERIES));
+
+ String defaultDLQObjectName = "jboss.messaging.destination:service=Queue,name=Queue2";
+
+ ServerManagement.setAttribute(serverPeerObjectName, "DefaultDLQ", defaultDLQObjectName);
+
+ int maxRedeliveryAttempts =
+ ((Integer)ServerManagement.getAttribute(serverPeerObjectName, "DefaultMaxDeliveryAttempts")).intValue();
+
+ assertEquals(MAX_DELIVERIES, maxRedeliveryAttempts);
+
conn = cf.createConnection();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
prod.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
@@ -813,7 +719,7 @@
Session sess2 = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageConsumer cons = sess2.createConsumer(queue);
+ MessageConsumer cons = sess2.createConsumer(queue1);
conn.start();
@@ -834,20 +740,18 @@
//At this point all the messages have been delivered exactly MAX_DELIVERIES times - this is ok
//they haven't exceeded max delivery attempts so shouldn't be in the DLQ - let's check
- MessageConsumer cons3 = sess.createConsumer(dlq);
+ checkEmpty(queue2);
- Message m = cons3.receive(1000);
-
- assertNull(m);
-
//So let's try and consume them - this should cause them to go to the DLQ - since they will then exceed max
//delivery attempts
- m = cons.receive(1000);
+ Message m = cons.receive(100);
assertNull(m);
//All the messages should now be in the DLQ
+ MessageConsumer cons3 = sess.createConsumer(queue2);
+
for (int i = 0; i < NUM_MESSAGES; i++)
{
TextMessage tm = (TextMessage)cons3.receive(1000);
@@ -859,17 +763,7 @@
//No more should be available
- m = cons.receive(1000);
-
- assertNull(m);
-
- cons.close();
-
- MessageConsumer cons2 = sess2.createConsumer(queue);
-
- m = cons2.receive(1000);
-
- assertNull(m);
+ checkEmpty(queue1);
}
finally
{
@@ -893,14 +787,8 @@
Integer.toString(maxDeliveryAttempts));
}
- protected void testMaxDeliveryAttempts(String destJndiName, int destMaxDeliveryAttempts, boolean queue) throws Exception
+ protected void testMaxDeliveryAttempts(Destination destination, int destMaxDeliveryAttempts, boolean queue) throws Exception
{
- ServerManagement.deployQueue("DLQ");
- Queue dlq = (Queue) ic.lookup("/queue/DLQ");
- drainDestination(cf, dlq);
-
- Destination destination = (Destination) ic.lookup(destJndiName);
-
Connection conn = cf.createConnection();
if (!queue)
@@ -910,6 +798,9 @@
try
{
+ ServerManagement.setAttribute(ServerManagement.getServerPeerObjectName(),
+ "DefaultDLQ", "jboss.messaging.destination:service=Queue,name=Queue2");
+
// Create the consumer before the producer so that the message we send doesn't
// get lost if the destination is a Topic.
Session consumingSession = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
@@ -944,21 +835,22 @@
}
// At this point the message should not yet be in the DLQ
- MessageConsumer dlqConsumer = consumingSession.createConsumer(dlq);
- Message m = dlqConsumer.receive(1000);
- assertNull(m);
+ checkEmpty(queue2);
// Now we try to consume the message again from the destination, which causes it
// to go to the DLQ instead.
- m = destinationConsumer.receive(1000);
+ Message m = destinationConsumer.receive(100);
assertNull(m);
// The message should be in the DLQ now
+ MessageConsumer dlqConsumer = consumingSession.createConsumer(queue2);
m = dlqConsumer.receive(1000);
assertNotNull(m);
assertTrue(m instanceof TextMessage);
assertEquals("Message", ((TextMessage) m).getText());
+ m.acknowledge();
+
if (!queue)
{
destinationConsumer.close();
@@ -972,37 +864,9 @@
{
conn.close();
}
-
- ServerManagement.undeployQueue("DLQ");
}
}
-
- protected void setUp() throws Exception
- {
- super.setUp();
-
- ServerManagement.start("all");
-
- ic = new InitialContext(ServerManagement.getJNDIEnvironment());
-
- cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
-
- ServerManagement.deployQueue("Queue");
-
- queue = (Queue)ic.lookup("/queue/Queue");
-
- }
-
- protected void tearDown() throws Exception
- {
- super.tearDown();
-
- ServerManagement.undeployQueue("Queue");
-
- if (ic != null) ic.close();
- }
-
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
@@ -1010,11 +874,28 @@
class FailingMessageListener implements MessageListener
{
volatile int deliveryCount;
-
- public void onMessage(Message msg)
+
+ int numMessages;
+
+ FailingMessageListener(int numMessages)
{
+ this.numMessages = numMessages;
+ }
+
+ synchronized void waitForMessages() throws Exception
+ {
+ while (deliveryCount != numMessages)
+ {
+ this.wait();
+ }
+ }
+
+ public synchronized void onMessage(Message msg)
+ {
deliveryCount++;
+ this.notify();
+
throw new RuntimeException("Your mum!");
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/DurableSubscriptionTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/DurableSubscriptionTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/DurableSubscriptionTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -24,7 +24,6 @@
import java.util.List;
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.IllegalStateException;
import javax.jms.InvalidDestinationException;
@@ -38,11 +37,9 @@
import javax.jms.Topic;
import javax.jms.TopicSubscriber;
import javax.management.ObjectName;
-import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.jms.server.destination.SubscriptionInfo;
-import org.jboss.test.messaging.MessagingTestCase;
import org.jboss.test.messaging.tools.ServerManagement;
@@ -55,7 +52,7 @@
*
* $Id: DurableSubscriberTest.java 1319 2006-09-19 17:17:53Z ovidiu.feodorov at jboss.com $
*/
-public class DurableSubscriptionTest extends MessagingTestCase
+public class DurableSubscriptionTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -63,8 +60,6 @@
// Attributes ----------------------------------------------------
- protected InitialContext ic;
-
// Constructors --------------------------------------------------
public DurableSubscriptionTest(String name)
@@ -74,85 +69,72 @@
// Public --------------------------------------------------------
- public void setUp() throws Exception
- {
- super.setUp();
-
- ServerManagement.start("all");
-
- ServerManagement.undeployTopic("Topic");
- ServerManagement.deployTopic("Topic");
-
- ic = new InitialContext(ServerManagement.getJNDIEnvironment());
-
- log.debug("setup done");
- }
-
- public void tearDown() throws Exception
- {
- log.debug("starting tear down");
-
- ic.close();
-
- ServerManagement.undeployTopic("Topic");
-
- super.tearDown();
- }
-
public void testSimplestDurableSubscription() throws Exception
{
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("ConnectionFactory");
- Topic topic = (Topic)ic.lookup("/topic/Topic");
- Connection conn = cf.createConnection();
-
- conn.setClientID("brookeburke");
-
- Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = s.createProducer(topic);
- prod.setDeliveryMode(DeliveryMode.PERSISTENT);
-
- s.createDurableSubscriber(topic, "monicabelucci");
-
- ObjectName destObjectName =
- new ObjectName("jboss.messaging.destination:service=Topic,name=Topic");
- List subs = (List)ServerManagement.invoke(destObjectName, "listAllSubscriptions", null, null);
+ Connection conn = null;
- assertNotNull(subs);
-
- assertEquals(1, subs.size());
-
- SubscriptionInfo info = (SubscriptionInfo)subs.get(0);
-
- assertEquals("monicabelucci", info.getName());
-
- prod.send(s.createTextMessage("k"));
-
- conn.close();
-
- subs = (List)ServerManagement.invoke(destObjectName, "listAllSubscriptions", null, null);
-
- assertEquals(1, subs.size());
-
- info = (SubscriptionInfo)subs.get(0);
-
- assertEquals("monicabelucci", info.getName());
-
- conn = cf.createConnection();
- conn.setClientID("brookeburke");
-
- s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer durable = s.createDurableSubscriber(topic, "monicabelucci");
-
- conn.start();
-
- TextMessage tm = (TextMessage)durable.receive(1000);
- assertEquals("k", tm.getText());
-
- Message m = durable.receive(1000);
- assertNull(m);
-
- conn.close();
+ try
+ {
+ conn = cf.createConnection();
+
+ conn.setClientID("brookeburke");
+
+ Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer prod = s.createProducer(topic1);
+ prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+
+ s.createDurableSubscriber(topic1, "monicabelucci");
+
+ ObjectName destObjectName =
+ new ObjectName("jboss.messaging.destination:service=Topic,name=Topic1");
+ List subs = (List)ServerManagement.invoke(destObjectName, "listAllSubscriptions", null, null);
+
+ assertNotNull(subs);
+
+ assertEquals(1, subs.size());
+
+ SubscriptionInfo info = (SubscriptionInfo)subs.get(0);
+
+ assertEquals("monicabelucci", info.getName());
+
+ prod.send(s.createTextMessage("k"));
+
+ conn.close();
+
+ subs = (List)ServerManagement.invoke(destObjectName, "listAllSubscriptions", null, null);
+
+ assertEquals(1, subs.size());
+
+ info = (SubscriptionInfo)subs.get(0);
+
+ assertEquals("monicabelucci", info.getName());
+
+ conn = cf.createConnection();
+ conn.setClientID("brookeburke");
+
+ s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer durable = s.createDurableSubscriber(topic1, "monicabelucci");
+
+ conn.start();
+
+ TextMessage tm = (TextMessage)durable.receive(1000);
+ assertEquals("k", tm.getText());
+
+ Message m = durable.receive(1000);
+ assertNull(m);
+
+ durable.close();
+
+ s.unsubscribe("monicabelucci");
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
@@ -164,44 +146,48 @@
* Test with a different topic (a redeployed topic is a different topic).
*/
public void testDurableSubscriptionOnNewTopic() throws Exception
- {
- ServerManagement.deployTopic("CompletelyNewTopic");
-
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("ConnectionFactory");
- Topic topic = (Topic)ic.lookup("/topic/CompletelyNewTopic");
- Connection conn = cf.createConnection();
-
- conn.setClientID("brookeburke");
-
- Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = s.createProducer(topic);
- prod.setDeliveryMode(DeliveryMode.PERSISTENT);
-
- s.createDurableSubscriber(topic, "monicabelucci");
-
- prod.send(s.createTextMessage("one"));
-
- conn.close();
-
- ServerManagement.deployTopic("CompletelyNewTopic2");
-
- Topic topic2 = (Topic)ic.lookup("/topic/CompletelyNewTopic2");
- conn = cf.createConnection();
-
- conn.setClientID("brookeburke");
-
- s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer durable = s.createDurableSubscriber(topic2, "monicabelucci");
-
- conn.start();
-
- Message m = durable.receive(1000);
- assertNull(m);
-
- ServerManagement.undeployTopic("CompletelyNewTopic");
- ServerManagement.undeployTopic("CompletelyNewTopic2");
+ {
+ Connection conn = null;
- conn.close();
+ try
+ {
+ conn = cf.createConnection();
+
+ conn.setClientID("brookeburke");
+
+ Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer prod = s.createProducer(topic1);
+ prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+
+ s.createDurableSubscriber(topic1, "monicabelucci");
+
+ prod.send(s.createTextMessage("one"));
+
+ conn.close();
+
+ conn = cf.createConnection();
+
+ conn.setClientID("brookeburke");
+
+ s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer durable = s.createDurableSubscriber(topic2, "monicabelucci");
+
+ conn.start();
+
+ Message m = durable.receive(1000);
+ assertNull(m);
+
+ durable.close();
+
+ s.unsubscribe("monicabelucci");
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
/**
@@ -213,95 +199,109 @@
*/
public void testDurableSubscriptionDifferentSelector() throws Exception
{
- ServerManagement.deployTopic("CompletelyNewTopic2");
+ Connection conn = null;
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("ConnectionFactory");
- Topic topic = (Topic)ic.lookup("/topic/Topic");
- Connection conn = cf.createConnection();
+ try
+ {
+ conn = cf.createConnection();
+
+ conn.setClientID("brookeburke");
+
+ Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer prod = s.createProducer(topic1);
+ prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+
+ MessageConsumer durable =
+ s.createDurableSubscriber(topic1,
+ "monicabelucci",
+ "color = 'red' AND shape = 'square'",
+ false);
+
+ TextMessage tm = s.createTextMessage("A red square message");
+ tm.setStringProperty("color", "red");
+ tm.setStringProperty("shape", "square");
+
+ prod.send(tm);
+
+ conn.start();
+
+ TextMessage rm = (TextMessage)durable.receive(5000);
+ assertEquals("A red square message", rm.getText());
+
+ tm = s.createTextMessage("Another red square message");
+ tm.setStringProperty("color", "red");
+ tm.setStringProperty("shape", "square");
+ prod.send(tm);
+
+ // TODO: when subscriptions/durable subscription will be registered as MBean, use the JMX
+ // interface to make sure the 'another red square message' is maintained by the
+ // durable subascription
+ // http://jira.jboss.org/jira/browse/JBMESSAGING-217
+
+ conn.close();
+
+ conn = cf.createConnection();
+
+ conn.setClientID("brookeburke");
+
+ s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ // modify the selector
+ durable = s.createDurableSubscriber(topic1,
+ "monicabelucci",
+ "color = 'red'",
+ false);
+
+ conn.start();
+
+ Message m = durable.receive(1000);
+
+ // the durable subscription is destroyed and re-created. The red square message stored by
+ // the previous durable subscription is lost and (hopefully) garbage collected.
+ assertNull(m);
+
+ durable.close();
+
+ s.unsubscribe("monicabelucci");
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
+ }
- conn.setClientID("brookeburke");
-
- Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = s.createProducer(topic);
- prod.setDeliveryMode(DeliveryMode.PERSISTENT);
-
+ public void testDurableSubscriptionOnTemporaryTopic() throws Exception
+ {
+ Connection conn = null;
- //fails here
- MessageConsumer durable =
- s.createDurableSubscriber(topic,
- "monicabelucci",
- "color = 'red' AND shape = 'square'",
- false);
-
- TextMessage tm = s.createTextMessage("A red square message");
- tm.setStringProperty("color", "red");
- tm.setStringProperty("shape", "square");
-
- log.info("**Sending the message");
-
- prod.send(tm);
-
- conn.start();
-
- TextMessage rm = (TextMessage)durable.receive(5000);
- assertEquals("A red square message", rm.getText());
-
- tm = s.createTextMessage("Another red square message");
- tm.setStringProperty("color", "red");
- tm.setStringProperty("shape", "square");
- prod.send(tm);
-
- // TODO: when subscriptions/durable subscription will be registered as MBean, use the JMX
- // interface to make sure the 'another red square message' is maintained by the
- // durable subascription
- // http://jira.jboss.org/jira/browse/JBMESSAGING-217
-
- conn.close();
-
conn = cf.createConnection();
-
- conn.setClientID("brookeburke");
-
- s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- // modify the selector
- durable = s.createDurableSubscriber(topic,
- "monicabelucci",
- "color = 'red'",
- false);
-
- conn.start();
-
- Message m = durable.receive(1000);
-
- // the durable subscription is destroyed and re-created. The red square message stored by
- // the previous durable subscription is lost and (hopefully) garbage collected.
- assertNull(m);
- ServerManagement.undeployTopic("CompletelyNewTopic2");
-
- conn.close();
- }
-
- public void testDurableSubscriptionOnTemporaryTopic() throws Exception
- {
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("ConnectionFactory");
- Connection conn = cf.createConnection();
- conn.setClientID("doesn't actually matter");
- Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Topic temporaryTopic = s.createTemporaryTopic();
-
try
{
- s.createDurableSubscriber(temporaryTopic, "mySubscription");
- fail("this should throw exception");
+ conn.setClientID("doesn't actually matter");
+ Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic temporaryTopic = s.createTemporaryTopic();
+
+ try
+ {
+ s.createDurableSubscriber(temporaryTopic, "mySubscription");
+ fail("this should throw exception");
+ }
+ catch(InvalidDestinationException e)
+ {
+ // OK
+ }
}
- catch(InvalidDestinationException e)
+ finally
{
- // OK
+ if (conn != null)
+ {
+ conn.close();
+ }
}
-
- conn.close();
}
/**
@@ -324,214 +324,263 @@
ServerManagement.deployTopic("TopicToBeRedeployed");
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("ConnectionFactory");
Topic topic = (Topic)ic.lookup("/topic/TopicToBeRedeployed");
- Connection conn = cf.createConnection();
- conn.setClientID("brookeburke");
-
- Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = s.createProducer(topic);
- prod.setDeliveryMode(DeliveryMode.PERSISTENT);
- MessageConsumer ds = s.createDurableSubscriber(topic, "monicabelucci");
- conn.start();
-
- prod.send(s.createTextMessage("one"));
- prod.send(s.createTextMessage("two"));
+ Connection conn = null;
- TextMessage tm = (TextMessage)ds.receive();
- assertEquals("one", tm.getText());
- conn.close();
-
- ServerManagement.undeployTopic("TopicToBeRedeployed");
- log.debug("topic undeployed");
-
try
{
- topic = (Topic)ic.lookup("/topic/TopicToBeRedeployed");
- fail("should throw exception");
+
+ conn = cf.createConnection();
+ conn.setClientID("brookeburke");
+
+ Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer prod = s.createProducer(topic);
+ prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+ MessageConsumer ds = s.createDurableSubscriber(topic, "monicabelucci");
+ conn.start();
+
+ prod.send(s.createTextMessage("one"));
+ prod.send(s.createTextMessage("two"));
+
+ TextMessage tm = (TextMessage)ds.receive();
+ assertEquals("one", tm.getText());
+ conn.close();
+
+ ServerManagement.undeployTopic("TopicToBeRedeployed");
+ log.debug("topic undeployed");
+
+ try
+ {
+ topic = (Topic)ic.lookup("/topic/TopicToBeRedeployed");
+ fail("should throw exception");
+ }
+ catch(NamingException e)
+ {
+ // OK
+ }
+
+ conn = cf.createConnection();
+ conn.setClientID("brookeburke");
+
+ s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ try
+ {
+ s.createDurableSubscriber(topic, "monicabelucci");
+ fail("should throw exception");
+ }
+ catch(JMSException e)
+ {
+ // OK
+ }
+
+ ServerManagement.deployTopic("TopicToBeRedeployed");
+ log.debug("topic redeployed");
+
+ // since redeployment has an activation semantic, I expect to find the messages there
+
+ topic = (Topic)ic.lookup("/topic/TopicToBeRedeployed");
+ ds = s.createDurableSubscriber(topic, "monicabelucci");
+ conn.start();
+
+ tm = (TextMessage)ds.receive(1000);
+ assertEquals("two", tm.getText());
+
+ ds.close();
+
+ s.unsubscribe("monicabelucci");
}
- catch(NamingException e)
+ finally
{
- // OK
+ if (conn != null)
+ {
+ conn.close();
+ }
+ ServerManagement.undeployTopic("TopicToBeRedeployed");
}
-
- conn = cf.createConnection();
- conn.setClientID("brookeburke");
-
- s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- try
- {
- s.createDurableSubscriber(topic, "monicabelucci");
- fail("should throw exception");
- }
- catch(JMSException e)
- {
- // OK
- }
-
- ServerManagement.deployTopic("TopicToBeRedeployed");
- log.debug("topic redeployed");
-
- // since redeployment has an activation semantic, I expect to find the messages there
-
- topic = (Topic)ic.lookup("/topic/TopicToBeRedeployed");
- ds = s.createDurableSubscriber(topic, "monicabelucci");
- conn.start();
-
- tm = (TextMessage)ds.receive(1000);
- assertEquals("two", tm.getText());
-
- conn.close();
- ServerManagement.undeployTopic("TopicToBeRedeployed");
}
public void testUnsubscribeDurableSubscription() throws Exception
{
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("ConnectionFactory");
- Topic topic = (Topic)ic.lookup("/topic/Topic");
-
- Connection conn = cf.createConnection();
- conn.setClientID("ak47");
-
- Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = s.createDurableSubscriber(topic, "uzzi");
- MessageProducer prod = s.createProducer(topic);
- prod.setDeliveryMode(DeliveryMode.PERSISTENT);
-
- prod.send(s.createTextMessage("one"));
-
- log.debug("unsubscribing ...");
-
- cons.close();
- s.unsubscribe("uzzi");
-
- log.debug("resubscribing ...");
-
- MessageConsumer ds = s.createDurableSubscriber(topic, "uzzi");
- conn.start();
-
- assertNull(ds.receive(1000));
+ Connection conn = null;
- ds.close();
-
- s.unsubscribe("uzzi");
+ try
+ {
+ conn = cf.createConnection();
+ conn.setClientID("ak47");
+
+ Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer cons = s.createDurableSubscriber(topic1, "uzzi");
+ MessageProducer prod = s.createProducer(topic1);
+ prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+
+ prod.send(s.createTextMessage("one"));
+
+ cons.close();
+ s.unsubscribe("uzzi");
- conn.close();
+ MessageConsumer ds = s.createDurableSubscriber(topic1, "uzzi");
+ conn.start();
+
+ assertNull(ds.receive(1000));
+
+ ds.close();
+
+ s.unsubscribe("uzzi");
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void testInvalidSelectorException() throws Exception
{
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("ConnectionFactory");
- Topic topic = (Topic)ic.lookup("/topic/Topic");
- Connection c = cf.createConnection();
- c.setClientID("sofiavergara");
- Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
+ Connection c = null;
+
try
{
- s.createDurableSubscriber(topic, "mysubscribption", "=TEST 'test'", true);
- fail("this should fail");
+
+ c = cf.createConnection();
+ c.setClientID("sofiavergara");
+ Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ try
+ {
+ s.createDurableSubscriber(topic1, "mysubscribption", "=TEST 'test'", true);
+ fail("this should fail");
+ }
+ catch(InvalidSelectorException e)
+ {
+ // OK
+ }
}
- catch(InvalidSelectorException e)
+ finally
{
- // OK
+ if (c != null)
+ {
+ c.close();
+ }
}
-
- c.close();
}
//See JMS 1.1. spec sec 6.11
public void testUnsubscribeWithActiveConsumer() throws Exception
{
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("ConnectionFactory");
- Topic topic = (Topic)ic.lookup("/topic/Topic");
-
- Connection conn = cf.createConnection();
- conn.setClientID("zeke");
-
- Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- TopicSubscriber dursub = s.createDurableSubscriber(topic, "dursub0");
-
+ Connection conn = null;
+
try
{
- s.unsubscribe("dursub0");
- fail();
+
+ conn = cf.createConnection();
+ conn.setClientID("zeke");
+
+ Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ TopicSubscriber dursub = s.createDurableSubscriber(topic1, "dursub0");
+
+ try
+ {
+ s.unsubscribe("dursub0");
+ fail();
+ }
+ catch (IllegalStateException e)
+ {
+ //Ok - it is illegal to ubscribe a subscription if it has active consumers
+ }
+
+ dursub.close();
+
+ s.unsubscribe("dursub0");
}
- catch (IllegalStateException e)
+ finally
{
- //Ok - it is illegal to ubscribe a subscription if it has active consumers
+ if (conn != null)
+ {
+ conn.close();
+ }
}
-
- dursub.close();
-
- s.unsubscribe("dursub0");
-
- conn.close();
}
public void testSubscribeWithActiveSubscription() throws Exception
{
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("ConnectionFactory");
- Topic topic = (Topic)ic.lookup("/topic/Topic");
-
- Connection conn = cf.createConnection();
- conn.setClientID("zeke");
-
- Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- TopicSubscriber dursub1 = s.createDurableSubscriber(topic, "dursub1");
-
+ Connection conn = null;
+
try
- {
- s.createDurableSubscriber(topic, "dursub1");
- fail();
+ {
+
+ conn = cf.createConnection();
+ conn.setClientID("zeke");
+
+ Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ TopicSubscriber dursub1 = s.createDurableSubscriber(topic1, "dursub1");
+
+ try
+ {
+ s.createDurableSubscriber(topic1, "dursub1");
+ fail();
+ }
+ catch (IllegalStateException e)
+ {
+ //Ok - it is illegal to have more than one active subscriber on a subscrtiption at any one time
+ }
+
+ dursub1.close();
+
+ s.unsubscribe("dursub1");
}
- catch (IllegalStateException e)
+ finally
{
- //Ok - it is illegal to have more than one active subscriber on a subscrtiption at any one time
+ if (conn != null)
+ {
+ conn.close();
+ }
}
-
- dursub1.close();
-
- s.unsubscribe("dursub1");
-
- conn.close();
}
public void testDurableSubscriptionWithPeriodsInName() throws Exception
{
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("ConnectionFactory");
- Topic topic = (Topic)ic.lookup("/topic/Topic");
-
- Connection conn = cf.createConnection();
- conn.setClientID(".client.id.with.periods.");
-
- Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- TopicSubscriber subscriber = s.createDurableSubscriber(topic, ".subscription.name.with.periods.");
+ Connection conn = null;
- ServerManagement.undeployTopic("Topic");
- ServerManagement.deployTopic("Topic");
-
- topic = (Topic)ic.lookup("/topic/Topic");
- s.createProducer(topic).send(s.createTextMessage("Subscription test"));
-
- conn.start();
-
- Message m = subscriber.receive(1000L);
-
- assertNotNull(m);
- assertTrue(m instanceof TextMessage);
-
- subscriber.close();
-
- s.unsubscribe(".subscription.name.with.periods.");
-
- conn.close();
+ try
+ {
+ conn = cf.createConnection();
+ conn.setClientID(".client.id.with.periods.");
+
+ Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ TopicSubscriber subscriber = s.createDurableSubscriber(topic1, ".subscription.name.with.periods.");
+
+ ServerManagement.undeployTopic("Topic1");
+ ServerManagement.deployTopic("Topic1");
+
+ topic1 = (Topic)ic.lookup("/topic/Topic1");
+ s.createProducer(topic1).send(s.createTextMessage("Subscription test"));
+
+ conn.start();
+
+ Message m = subscriber.receive(1000L);
+
+ assertNotNull(m);
+ assertTrue(m instanceof TextMessage);
+
+ subscriber.close();
+
+ s.unsubscribe(".subscription.name.with.periods.");
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
// Package protected ---------------------------------------------
Modified: trunk/tests/src/org/jboss/test/messaging/jms/ExpiryQueueTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/ExpiryQueueTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/ExpiryQueueTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -54,7 +54,7 @@
* $Id$
*
*/
-public class ExpiryQueueTest extends MessagingTestCase
+public class ExpiryQueueTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -62,11 +62,6 @@
// Attributes ----------------------------------------------------
- protected InitialContext ic;
- protected ConnectionFactory cf;
- protected Queue queue;
- protected Topic topic;
-
// Constructors --------------------------------------------------
public ExpiryQueueTest(String name)
@@ -84,8 +79,7 @@
}
try
- {
-
+ {
ServerManagement.deployQueue("ExpiryQueue");
ObjectName serverPeerObjectName = ServerManagement.getServerPeerObjectName();
@@ -348,17 +342,17 @@
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(topic);
+ MessageProducer prod = sess.createProducer(topic1);
conn.start();
//Create 3 durable subscriptions
- MessageConsumer sub1 = sess.createDurableSubscriber(topic, "sub1");
+ MessageConsumer sub1 = sess.createDurableSubscriber(topic1, "sub1");
- MessageConsumer sub2 = sess.createDurableSubscriber(topic, "sub2");
+ MessageConsumer sub2 = sess.createDurableSubscriber(topic1, "sub2");
- MessageConsumer sub3 = sess.createDurableSubscriber(topic, "sub3");
+ MessageConsumer sub3 = sess.createDurableSubscriber(topic1, "sub3");
Map origIds = new HashMap();
@@ -416,7 +410,7 @@
long actualExpiryTime =
tm.getLongProperty(JBossMessage.JBOSS_MESSAGING_ACTUAL_EXPIRY_TIME);
- assertEquals(topic.toString(), origDest);
+ assertEquals(topic1.toString(), origDest);
String origId = (String)origIds.get(tm.getText());
@@ -491,7 +485,7 @@
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
int deliveryMode = persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT;
@@ -504,7 +498,7 @@
prod.send(tm, deliveryMode, 4, 2000);
}
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
//The messages should now be sitting in the consumer buffer
@@ -574,7 +568,7 @@
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
int deliveryMode = persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT;
@@ -587,7 +581,7 @@
prod.send(tm, deliveryMode, 4, 2000);
}
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
//The messages should now be sitting in the consumer buffer
@@ -635,7 +629,6 @@
try
{
-
ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
conn = cf.createConnection();
@@ -644,7 +637,7 @@
conn.start();
- MessageProducer prod = session.createProducer(queue);
+ MessageProducer prod = session.createProducer(queue1);
prod.setTimeToLive(100);
Message m = session.createTextMessage("This message will die");
@@ -654,7 +647,7 @@
// wait for the message to die
Thread.sleep(2000);
- MessageConsumer cons = session.createConsumer(queue);
+ MessageConsumer cons = session.createConsumer(queue1);
assertNull(cons.receive(3000));
@@ -686,41 +679,6 @@
// Protected -----------------------------------------------------
- protected void setUp() throws Exception
- {
- super.setUp();
-
- ServerManagement.start("all");
-
- ic = new InitialContext(ServerManagement.getJNDIEnvironment());
-
- cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
-
- ServerManagement.undeployQueue("Queue");
-
- ServerManagement.undeployTopic("Topic");
-
- ServerManagement.deployQueue("Queue");
-
- ServerManagement.deployTopic("Topic");
-
- queue = (Queue)ic.lookup("/queue/Queue");
-
- topic = (Topic)ic.lookup("/topic/Topic");
-
- }
-
- protected void tearDown() throws Exception
- {
- super.tearDown();
-
- ServerManagement.undeployQueue("Queue");
-
- ServerManagement.undeployTopic("Topic");
-
- if (ic != null) ic.close();
- }
-
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
Modified: trunk/tests/src/org/jboss/test/messaging/jms/HTTPTransportTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/HTTPTransportTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/HTTPTransportTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -6,29 +6,25 @@
*/
package org.jboss.test.messaging.jms;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
-
-import javax.naming.InitialContext;
-import javax.jms.ConnectionFactory;
-import javax.jms.Queue;
import javax.jms.Connection;
-import javax.jms.Session;
-import javax.jms.MessageProducer;
import javax.jms.Message;
import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
import javax.jms.TextMessage;
-import javax.management.ObjectName;
+import org.jboss.test.messaging.tools.ServerManagement;
+
/**
* This class contain tests that only make sense for a HTTP transport. They will be ignored for
* any other kind of transport.
*
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
* @version <tt>$Revision$</tt>
* $Id$
*/
-public class HTTPTransportTest extends MessagingTestCase
+public class HTTPTransportTest extends JMSTestCase
{
// Constants ------------------------------------------------------------------------------------
@@ -36,11 +32,6 @@
// Attributes -----------------------------------------------------------------------------------
- private InitialContext ic;
- private ConnectionFactory cf;
- private Queue queue;
- private ObjectName queueObjectName;
-
// Constructors ---------------------------------------------------------------------------------
public HTTPTransportTest(String name)
@@ -62,7 +53,7 @@
// send a bunch of messages and let them accumulate in the queue
Connection conn = cf.createConnection();
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = session.createProducer(queue);
+ MessageProducer prod = session.createProducer(queue1);
int messageCount = 20;
@@ -75,17 +66,15 @@
conn.close();
// make sure messages made it to the queue
- Integer count = (Integer)ServerManagement.getAttribute(queueObjectName, "MessageCount");
- assertEquals(messageCount, count.intValue());
+ assertRemainingMessages(messageCount);
-
conn = cf.createConnection();
session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = session.createConsumer(queue);
+ MessageConsumer cons = session.createConsumer(queue1);
conn.start();
- // messages will be sent in bulk from server side, on the next HTTP client listner poll
+ // messages will be sent in bulk from server side, on the next HTTP client listener poll
for(int i = 0; i < messageCount; i++)
{
@@ -102,37 +91,6 @@
// Protected ------------------------------------------------------------------------------------
- protected void setUp() throws Exception
- {
- super.setUp();
-
- ServerManagement.start("all");
-
- ic = new InitialContext(ServerManagement.getJNDIEnvironment());
-
- ServerManagement.deployQueue("HTTPTestQueue");
-
- cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
-
- queue = (Queue)ic.lookup("/queue/HTTPTestQueue");
-
- queueObjectName =
- new ObjectName("jboss.messaging.destination:service=Queue,name=HTTPTestQueue");
-
- ServerManagement.invoke(queueObjectName, "removeAllMessages", new Object[0], new String[0]);
-
- log.debug("setup done");
- }
-
- public void tearDown() throws Exception
- {
- ServerManagement.undeployQueue("HTTPTestQueue");
-
- ic.close();
-
- super.tearDown();
- }
-
// Private --------------------------------------------------------------------------------------
// Inner classes --------------------------------------------------------------------------------
Modified: trunk/tests/src/org/jboss/test/messaging/jms/JCAWrapperTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/JCAWrapperTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/JCAWrapperTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -25,14 +25,11 @@
import javax.jms.ConnectionFactory;
import javax.jms.Message;
import javax.jms.MessageProducer;
-import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
-import javax.naming.InitialContext;
import javax.transaction.Transaction;
import javax.transaction.UserTransaction;
-import org.jboss.test.messaging.MessagingTestCase;
import org.jboss.test.messaging.tools.ServerManagement;
import org.jboss.tm.TransactionManagerLocator;
@@ -41,7 +38,7 @@
*
* $Id: JCAWrapperTest.java 1019 2006-07-17 17:15:04Z timfox $
*/
-public class JCAWrapperTest extends MessagingTestCase
+public class JCAWrapperTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -49,9 +46,6 @@
// Attributes ----------------------------------------------------
- protected InitialContext ic;
- protected Queue queue;
-
// Constructors --------------------------------------------------
public JCAWrapperTest(String name)
@@ -65,11 +59,13 @@
{
Transaction suspended = TransactionManagerLocator.getInstance().locate().suspend();
+ Connection conn = null;
+
try
{
ConnectionFactory mcf = (ConnectionFactory)ic.lookup("java:/JCAConnectionFactory");
- Connection conn = mcf.createConnection();
+ conn = mcf.createConnection();
conn.start();
UserTransaction ut = ServerManagement.getUserTransaction();
@@ -77,7 +73,7 @@
ut.begin();
Session s = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageProducer p = s.createProducer(queue);
+ MessageProducer p = s.createProducer(queue1);
Message m = s.createTextMessage("one");
p.send(m);
@@ -91,14 +87,18 @@
s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn.start();
- TextMessage rm = (TextMessage)s.createConsumer(queue).receive(500);
+ TextMessage rm = (TextMessage)s.createConsumer(queue1).receive(500);
assertEquals("one", rm.getText());
conn.close();
}
finally
- {
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
if (suspended != null)
{
@@ -114,12 +114,13 @@
public void testSimpleTransactedSend2() throws Exception
{
Transaction suspended = TransactionManagerLocator.getInstance().locate().suspend();
+
+ Connection conn = null;
try
{
-
ConnectionFactory mcf = (ConnectionFactory)ic.lookup("java:/JCAConnectionFactory");
- Connection conn = mcf.createConnection();
+ conn = mcf.createConnection();
conn.start();
UserTransaction ut = ServerManagement.getUserTransaction();
@@ -127,7 +128,7 @@
ut.begin();
Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = s.createProducer(queue);
+ MessageProducer p = s.createProducer(queue1);
Message m = s.createTextMessage("one");
p.send(m);
@@ -141,14 +142,16 @@
s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn.start();
- TextMessage rm = (TextMessage)s.createConsumer(queue).receive(500);
+ TextMessage rm = (TextMessage)s.createConsumer(queue1).receive(500);
assertEquals("one", rm.getText());
-
- conn.close();
}
finally
- {
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
if (suspended != null)
{
@@ -161,27 +164,6 @@
// Protected -----------------------------------------------------
- protected void setUp() throws Exception
- {
- super.setUp();
- ServerManagement.start("all");
-
- ic = new InitialContext(ServerManagement.getJNDIEnvironment());
-
- ServerManagement.deployQueue("UserTransactionTestQueue");
- queue = (Queue)ic.lookup("/queue/UserTransactionTestQueue");
- drainDestination((ConnectionFactory)ic.lookup("/ConnectionFactory"), queue);
-
- log.debug("setup done");
- }
-
- protected void tearDown() throws Exception
- {
- ServerManagement.undeployQueue("UserTransactionTestQueue");
- ic.close();
- super.tearDown();
- }
-
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
Modified: trunk/tests/src/org/jboss/test/messaging/jms/JMSTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/JMSTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/JMSTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -22,32 +22,27 @@
package org.jboss.test.messaging.jms;
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
-import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
-import javax.management.ObjectName;
import javax.naming.InitialContext;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
-
import EDU.oswego.cs.dl.util.concurrent.Slot;
/**
* The most comprehensive, yet simple, unit test.
*
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Foxv</a>
* @version <tt>$Revision$</tt>
*
* $Id$
*/
-public class JMSTest extends MessagingTestCase
+public class JMSTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -65,28 +60,6 @@
}
// Public --------------------------------------------------------
-
- public void setUp() throws Exception
- {
- super.setUp();
-
- ServerManagement.start("all");
-
- ic = new InitialContext(ServerManagement.getJNDIEnvironment());
-
- ServerManagement.deployQueue("JMSTestQueue");
-
- log.debug("setup done");
- }
-
- public void tearDown() throws Exception
- {
- ServerManagement.undeployQueue("JMSTestQueue");
-
- ic.close();
-
- super.tearDown();
- }
public void testNoop() throws Exception
{
@@ -95,352 +68,393 @@
public void test_NonPersistent_NonTransactional() throws Exception
{
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
-
- Queue queue = (Queue)ic.lookup("/queue/JMSTestQueue");
-
- Connection conn = cf.createConnection();
-
- Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageProducer prod = session.createProducer(queue);
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-
- TextMessage m = session.createTextMessage("message one");
-
- prod.send(m);
-
- conn.close();
-
- conn = cf.createConnection();
-
- session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer cons = session.createConsumer(queue);
-
- conn.start();
-
- TextMessage rm = (TextMessage)cons.receive();
-
- assertEquals("message one", rm.getText());
-
- conn.close();
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = session.createProducer(queue1);
+ prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ TextMessage m = session.createTextMessage("message one");
+
+ prod.send(m);
+
+ conn.close();
+
+ conn = cf.createConnection();
+
+ session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer cons = session.createConsumer(queue1);
+
+ conn.start();
+
+ TextMessage rm = (TextMessage)cons.receive();
+
+ assertEquals("message one", rm.getText());
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void test_CreateTextMessageNull() throws Exception
- {
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
-
- Queue queue = (Queue)ic.lookup("/queue/JMSTestQueue");
-
- Connection conn = cf.createConnection();
-
- Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageProducer prod = session.createProducer(queue);
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-
- TextMessage m = session.createTextMessage();
-
- m.setText("message one");
-
- prod.send(m);
-
- conn.close();
-
- conn = cf.createConnection();
-
- session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer cons = session.createConsumer(queue);
-
- conn.start();
-
- TextMessage rm = (TextMessage)cons.receive();
-
- assertEquals("message one", rm.getText());
-
- conn.close();
+ {
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = session.createProducer(queue1);
+ prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ TextMessage m = session.createTextMessage();
+
+ m.setText("message one");
+
+ prod.send(m);
+
+ conn.close();
+
+ conn = cf.createConnection();
+
+ session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer cons = session.createConsumer(queue1);
+
+ conn.start();
+
+ TextMessage rm = (TextMessage)cons.receive();
+
+ assertEquals("message one", rm.getText());
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void test_Persistent_NonTransactional() throws Exception
{
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
-
- Queue queue = (Queue)ic.lookup("/queue/JMSTestQueue");
-
- Connection conn = cf.createConnection();
-
- Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageProducer prod = session.createProducer(queue);
- prod.setDeliveryMode(DeliveryMode.PERSISTENT);
-
- TextMessage m = session.createTextMessage("message one");
-
- prod.send(m);
-
- conn.close();
-
- conn = cf.createConnection();
-
- session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer cons = session.createConsumer(queue);
-
- conn.start();
-
- TextMessage rm = (TextMessage)cons.receive();
-
- assertEquals("message one", rm.getText());
-
- conn.close();
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = session.createProducer(queue1);
+ prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+
+ TextMessage m = session.createTextMessage("message one");
+
+ prod.send(m);
+
+ conn.close();
+
+ conn = cf.createConnection();
+
+ session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer cons = session.createConsumer(queue1);
+
+ conn.start();
+
+ TextMessage rm = (TextMessage)cons.receive();
+
+ assertEquals("message one", rm.getText());
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void test_NonPersistent_Transactional_Send() throws Exception
{
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
-
- Queue queue = (Queue)ic.lookup("/queue/JMSTestQueue");
-
- Connection conn = cf.createConnection();
-
- Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
-
- MessageProducer prod = session.createProducer(queue);
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-
- TextMessage m = session.createTextMessage("message one");
- prod.send(m);
- m = session.createTextMessage("message two");
- prod.send(m);
-
- session.commit();
-
- conn.close();
-
- conn = cf.createConnection();
-
- session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer cons = session.createConsumer(queue);
-
- conn.start();
-
- TextMessage rm = (TextMessage)cons.receive();
- assertEquals("message one", rm.getText());
- rm = (TextMessage)cons.receive();
- assertEquals("message two", rm.getText());
-
- conn.close();
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+
+ Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
+
+ MessageProducer prod = session.createProducer(queue1);
+ prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ TextMessage m = session.createTextMessage("message one");
+ prod.send(m);
+ m = session.createTextMessage("message two");
+ prod.send(m);
+
+ session.commit();
+
+ conn.close();
+
+ conn = cf.createConnection();
+
+ session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer cons = session.createConsumer(queue1);
+
+ conn.start();
+
+ TextMessage rm = (TextMessage)cons.receive();
+ assertEquals("message one", rm.getText());
+ rm = (TextMessage)cons.receive();
+ assertEquals("message two", rm.getText());
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void test_Persistent_Transactional_Send() throws Exception
- {
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
-
- Queue queue = (Queue)ic.lookup("/queue/JMSTestQueue");
-
- Connection conn = cf.createConnection();
-
- Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
-
- MessageProducer prod = session.createProducer(queue);
- prod.setDeliveryMode(DeliveryMode.PERSISTENT);
-
- TextMessage m = session.createTextMessage("message one");
- prod.send(m);
- m = session.createTextMessage("message two");
- prod.send(m);
-
- session.commit();
-
- conn.close();
-
- conn = cf.createConnection();
-
- session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer cons = session.createConsumer(queue);
-
- conn.start();
-
- TextMessage rm = (TextMessage)cons.receive();
- assertEquals("message one", rm.getText());
- rm = (TextMessage)cons.receive();
- assertEquals("message two", rm.getText());
-
- conn.close();
+ {
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+
+ Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
+
+ MessageProducer prod = session.createProducer(queue1);
+ prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+
+ TextMessage m = session.createTextMessage("message one");
+ prod.send(m);
+ m = session.createTextMessage("message two");
+ prod.send(m);
+
+ session.commit();
+
+ conn.close();
+
+ conn = cf.createConnection();
+
+ session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer cons = session.createConsumer(queue1);
+
+ conn.start();
+
+ TextMessage rm = (TextMessage)cons.receive();
+ assertEquals("message one", rm.getText());
+ rm = (TextMessage)cons.receive();
+ assertEquals("message two", rm.getText());
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void test_NonPersistent_Transactional_Acknowledgment() throws Exception
- {
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
-
- Queue queue = (Queue)ic.lookup("/queue/JMSTestQueue");
-
- Connection conn = cf.createConnection();
-
- Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageProducer prod = session.createProducer(queue);
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- TextMessage m = session.createTextMessage("one");
- prod.send(m);
-
- conn.close();
-
- conn = cf.createConnection();
-
- session = conn.createSession(true, Session.SESSION_TRANSACTED);
-
- MessageConsumer cons = session.createConsumer(queue);
-
- conn.start();
-
- TextMessage rm = (TextMessage)cons.receive();
- assertEquals("one", rm.getText());
-
- session.commit();
-
- conn.close();
+ {
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = session.createProducer(queue1);
+ prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ TextMessage m = session.createTextMessage("one");
+ prod.send(m);
+
+ conn.close();
+
+ conn = cf.createConnection();
+
+ session = conn.createSession(true, Session.SESSION_TRANSACTED);
+
+ MessageConsumer cons = session.createConsumer(queue1);
+
+ conn.start();
+
+ TextMessage rm = (TextMessage)cons.receive();
+ assertEquals("one", rm.getText());
+
+ session.commit();
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void test_Asynchronous_to_Client() throws Exception
{
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
-
- Queue queue = (Queue)ic.lookup("/queue/JMSTestQueue");
-
- Connection conn = cf.createConnection();
-
- Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- final MessageConsumer cons = session.createConsumer(queue);
-
- conn.start();
-
- final Slot slot = new Slot();
-
- new Thread(new Runnable()
- {
- public void run()
- {
- try
- {
- Message m = cons.receive(5000);
- if (m != null)
- {
- slot.put(m);
- }
- }
- catch(Exception e)
- {
- log.error("receive failed", e);
- }
-
- }
- }, "Receiving Thread").start();
-
-
- Thread.sleep(500);
-
- MessageProducer prod = session.createProducer(queue);
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-
- TextMessage m = session.createTextMessage("message one");
-
- prod.send(m);
-
- TextMessage rm = (TextMessage)slot.poll(5000);
-
- assertEquals("message one", rm.getText());
-
- conn.close();
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ final MessageConsumer cons = session.createConsumer(queue1);
+
+ conn.start();
+
+ final Slot slot = new Slot();
+
+ new Thread(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ Message m = cons.receive(5000);
+ if (m != null)
+ {
+ slot.put(m);
+ }
+ }
+ catch(Exception e)
+ {
+ log.error("receive failed", e);
+ }
+
+ }
+ }, "Receiving Thread").start();
+
+ MessageProducer prod = session.createProducer(queue1);
+ prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ TextMessage m = session.createTextMessage("message one");
+
+ prod.send(m);
+
+ TextMessage rm = (TextMessage)slot.poll(5000);
+
+ assertEquals("message one", rm.getText());
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void test_MessageListener() throws Exception
- {
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
-
- Queue queue = (Queue)ic.lookup("/queue/JMSTestQueue");
-
- Connection conn = cf.createConnection();
-
- Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer cons = session.createConsumer(queue);
-
- final Slot slot = new Slot();
-
- cons.setMessageListener(new MessageListener()
- {
- public void onMessage(Message m)
- {
- try
- {
- slot.put(m);
- }
- catch(InterruptedException e)
- {
- log.warn("got InterruptedException", e);
- }
- }
- });
-
- conn.start();
-
- MessageProducer prod = session.createProducer(queue);
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- TextMessage m = session.createTextMessage("one");
- prod.send(m);
-
- TextMessage rm = (TextMessage)slot.poll(5000);
-
- assertEquals("one", rm.getText());
-
- conn.close();
+ {
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer cons = session.createConsumer(queue1);
+
+ final Slot slot = new Slot();
+
+ cons.setMessageListener(new MessageListener()
+ {
+ public void onMessage(Message m)
+ {
+ try
+ {
+ slot.put(m);
+ }
+ catch(InterruptedException e)
+ {
+ log.warn("got InterruptedException", e);
+ }
+ }
+ });
+
+ conn.start();
+
+ MessageProducer prod = session.createProducer(queue1);
+ prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ TextMessage m = session.createTextMessage("one");
+ prod.send(m);
+
+ TextMessage rm = (TextMessage)slot.poll(5000);
+
+ assertEquals("one", rm.getText());
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void test_ClientAcknowledge() throws Exception
{
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
-
- Queue queue = (Queue)ic.lookup("/queue/JMSTestQueue");
-
- Connection conn = cf.createConnection();
-
- Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageProducer p = session.createProducer(queue);
- p.send(session.createTextMessage("CLACK"));
-
- MessageConsumer cons = session.createConsumer(queue);
-
- conn.start();
-
- TextMessage m = (TextMessage)cons.receive(1000);
-
- assertEquals("CLACK", m.getText());
-
- // make sure there's no other message in queue
- Message m2 = cons.receive(1000);
- assertNull(m2);
-
- // make sure the message is still in "delivering" state
- ObjectName on = new ObjectName("jboss.messaging.destination:service=Queue,name=JMSTestQueue");
- Integer mc = (Integer)ServerManagement.getAttribute(on, "MessageCount");
-
- assertEquals(1, mc.intValue());
-
- m.acknowledge();
-
- // make sure there's nothing in queue anymore
- mc = (Integer)ServerManagement.getAttribute(on, "MessageCount");
-
- assertEquals(0, mc.intValue());
-
- conn.close();
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+
+ Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+ MessageProducer p = session.createProducer(queue1);
+ p.send(session.createTextMessage("CLACK"));
+
+ MessageConsumer cons = session.createConsumer(queue1);
+
+ conn.start();
+
+ TextMessage m = (TextMessage)cons.receive(1000);
+
+ assertEquals("CLACK", m.getText());
+
+ // make sure the message is still in "delivering" state
+ assertRemainingMessages(1);
+
+ m.acknowledge();
+
+ assertRemainingMessages(0);
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
Added: trunk/tests/src/org/jboss/test/messaging/jms/JMSTestCase.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/JMSTestCase.java (rev 0)
+++ trunk/tests/src/org/jboss/test/messaging/jms/JMSTestCase.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -0,0 +1,124 @@
+package org.jboss.test.messaging.jms;
+
+import javax.jms.Queue;
+import javax.jms.Topic;
+import javax.naming.InitialContext;
+
+import org.jboss.jms.client.JBossConnectionFactory;
+import org.jboss.test.messaging.MessagingTestCase;
+import org.jboss.test.messaging.tools.ServerManagement;
+import org.jboss.test.messaging.tools.jmx.ServiceAttributeOverrides;
+
+/**
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @version <tt>$Revision: $</tt>23 Jul 2007
+ *
+ * $Id: $
+ *
+ */
+public class JMSTestCase extends MessagingTestCase
+{
+ protected static Topic topic1;
+
+ protected static Topic topic2;
+
+ protected static Topic topic3;
+
+ protected static Queue queue1;
+
+ protected static Queue queue2;
+
+ protected static Queue queue3;
+
+ protected static Queue queue4;
+
+ protected static JBossConnectionFactory cf;
+
+ protected static InitialContext ic;
+
+ protected static final String defaultConf = "all";
+
+ protected static String conf;
+
+ protected String overrideConf;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ boolean changeServer = false;
+
+ String newConf = null;
+
+ if (overrideConf == null && !defaultConf.equals(conf))
+ {
+ //Going back to default
+ changeServer = true;
+
+ newConf = defaultConf;
+ }
+
+ if (overrideConf != null && !overrideConf.equals(conf))
+ {
+ //Applying new config
+ changeServer = true;
+
+ newConf = overrideConf;
+ }
+
+ if (changeServer)
+ {
+ log.info("Config has changed so stopping server with " + conf + " config and starting new one with " + newConf);
+
+ ServerManagement.stop();
+
+ conf = newConf;
+
+ ServerManagement.start(0, conf);
+
+ deployAndLookupAdministeredObjects();
+ }
+ else
+ {
+ log.info("Server does not need to be changed");
+ }
+
+ checkEmpty(queue1);
+ checkEmpty(queue2);
+ checkEmpty(queue3);
+ checkEmpty(queue4);
+
+ // Check no subscriptions left lying around
+
+ checkNoSubscriptions(topic1);
+ checkNoSubscriptions(topic2);
+ checkNoSubscriptions(topic3);
+ }
+
+ public JMSTestCase(String name)
+ {
+ super(name);
+ }
+
+ protected void deployAndLookupAdministeredObjects() throws Exception
+ {
+ ServerManagement.deployTopic("Topic1");
+ ServerManagement.deployTopic("Topic2");
+ ServerManagement.deployTopic("Topic3");
+ ServerManagement.deployQueue("Queue1");
+ ServerManagement.deployQueue("Queue2");
+ ServerManagement.deployQueue("Queue3");
+ ServerManagement.deployQueue("Queue4");
+
+ ic = new InitialContext(ServerManagement.getJNDIEnvironment());
+ cf = (JBossConnectionFactory)ic.lookup("/ConnectionFactory");
+ topic1 = (Topic)ic.lookup("/topic/Topic1");
+ topic2 = (Topic)ic.lookup("/topic/Topic2");
+ topic3 = (Topic)ic.lookup("/topic/Topic3");
+ queue1 = (Queue)ic.lookup("/queue/Queue1");
+ queue2 = (Queue)ic.lookup("/queue/Queue2");
+ queue3 = (Queue)ic.lookup("/queue/Queue3");
+ queue4 = (Queue)ic.lookup("/queue/Queue4");
+ }
+}
Deleted: trunk/tests/src/org/jboss/test/messaging/jms/LongRunningInvocationTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/LongRunningInvocationTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/LongRunningInvocationTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -1,192 +0,0 @@
-/*
- * 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.messaging.jms;
-
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.DeliveryMode;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.Queue;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.naming.InitialContext;
-
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
-import org.jboss.test.messaging.tools.aop.PoisonInterceptor;
-
-/**
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 1.1 $</tt>
- *
- * $Id$
- *
- */
-public class LongRunningInvocationTest extends MessagingTestCase
-{
- // Constants -----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- InitialContext ic;
-
- // Constructors --------------------------------------------------
-
- public LongRunningInvocationTest(String name)
- {
- super(name);
- }
-
- // Public --------------------------------------------------------
-
- public void setUp() throws Exception
- {
- if (!ServerManagement.isRemote())
- {
- throw new IllegalStateException("Test should only be run in remote mode");
- }
-
- super.setUp();
-
- ServerManagement.start("all");
-
- ic = new InitialContext(ServerManagement.getJNDIEnvironment());
-
- ServerManagement.undeployQueue("JMSTestQueue");
- ServerManagement.deployQueue("JMSTestQueue");
-
- log.debug("setup done");
- }
-
- public void tearDown() throws Exception
- {
- if (ServerManagement.isStarted(0))
- {
- ServerManagement.undeployQueue("JMSTestQueue");
- }
-
- ic.close();
-
- super.tearDown();
- }
-
- public void testLongRunningInvocationPingFirst() throws Exception
- {
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
-
- Queue queue = (Queue)ic.lookup("/queue/JMSTestQueue");
-
- Connection conn = null;
-
- try
- {
- conn = cf.createConnection();
-
- Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageProducer prod = session.createProducer(queue);
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-
- MessageConsumer cons = session.createConsumer(queue);
-
- TextMessage m = session.createTextMessage("message one");
-
- // Pause a bit to let a least one ping through
- Thread.sleep(5000);
-
- //Poison the server so the invocation takes 2 minutes - longer than the ping period
-
- ServerManagement.poisonTheServer(0, PoisonInterceptor.LONG_SEND);
-
- log.info("This will pause for 1 minutes on send");
- prod.send(m);
-
- conn.start();
-
- TextMessage m2 = (TextMessage)cons.receive(1000);
-
- assertEquals(m.getText(), m2.getText());
- }
- finally
- {
- conn.close();
-
- ServerManagement.kill(0);
- }
-
- }
-
- public void testLongRunningInvocation() throws Exception
- {
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
-
- Queue queue = (Queue)ic.lookup("/queue/JMSTestQueue");
-
- Connection conn = null;
-
- try
- {
- conn = cf.createConnection();
-
- Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageProducer prod = session.createProducer(queue);
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-
- MessageConsumer cons = session.createConsumer(queue);
-
- TextMessage m = session.createTextMessage("message one");
-
- //Poison the server so the invocation takes 2 minutes - longer than the ping period
-
- ServerManagement.poisonTheServer(0, PoisonInterceptor.LONG_SEND);
-
- log.info("This will pause for 1 minutes on send");
- prod.send(m);
-
- conn.start();
-
- TextMessage m2 = (TextMessage)cons.receive(1000);
-
- assertEquals(m.getText(), m2.getText());
- }
- finally
- {
- conn.close();
-
- ServerManagement.kill(0);
- }
-
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
-}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/ManifestTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/ManifestTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/ManifestTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -29,13 +29,8 @@
import java.util.jar.Manifest;
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
import javax.jms.ConnectionMetaData;
-import javax.naming.InitialContext;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
-
/**
* Tests MANIFEST.MF content of the output jar.
*
@@ -44,7 +39,7 @@
*
* $Id$
*/
-public class ManifestTest extends MessagingTestCase
+public class ManifestTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -60,11 +55,6 @@
}
// Public --------------------------------------------------------
- public void setUp() throws Exception
- {
- super.setUp();
- ServerManagement.start("all");
- }
public void testManifestEntries() throws Exception
{
@@ -82,32 +72,42 @@
Manifest manifest = jar.getManifest();
// Open a connection and get ConnectionMetaData
- InitialContext ic = new InitialContext(ServerManagement.getJNDIEnvironment());
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
- Connection conn = cf.createConnection();
- assertNotNull(conn);
- ConnectionMetaData meta = conn.getMetaData();
+ Connection conn = null;
- // Compare the value from ConnectionMetaData and MANIFEST.MF
- Attributes attrs = manifest.getMainAttributes();
-
- log.info("META--> " + meta.getJMSMajorVersion());
- log.info("META--> " + meta.getJMSMinorVersion());
- log.info("META--> " + meta.getJMSProviderName());
- log.info("META--> " + meta.getJMSVersion());
- log.info("META--> " + meta.getProviderMajorVersion());
- log.info("META--> " + meta.getProviderMinorVersion());
- log.info("META--> " + meta.getProviderVersion());
-
- Iterator itr = attrs.entrySet().iterator();
- while (itr.hasNext()) {
- Object item = itr.next();
- log.trace("MANIFEST--> " + item + " : " + attrs.get(item));
+ try
+ {
+ conn = cf.createConnection();
+ assertNotNull(conn);
+ ConnectionMetaData meta = conn.getMetaData();
+
+ // Compare the value from ConnectionMetaData and MANIFEST.MF
+ Attributes attrs = manifest.getMainAttributes();
+
+ log.info("META--> " + meta.getJMSMajorVersion());
+ log.info("META--> " + meta.getJMSMinorVersion());
+ log.info("META--> " + meta.getJMSProviderName());
+ log.info("META--> " + meta.getJMSVersion());
+ log.info("META--> " + meta.getProviderMajorVersion());
+ log.info("META--> " + meta.getProviderMinorVersion());
+ log.info("META--> " + meta.getProviderVersion());
+
+ Iterator itr = attrs.entrySet().iterator();
+ while (itr.hasNext()) {
+ Object item = itr.next();
+ log.trace("MANIFEST--> " + item + " : " + attrs.get(item));
+ }
+
+ assertEquals(attrs.getValue("Implementation-Title"), meta.getJMSProviderName());
+ String ver = attrs.getValue("Implementation-Version");
+ assertTrue(-1 != ver.indexOf(meta.getProviderVersion()));
}
-
- assertEquals(attrs.getValue("Implementation-Title"), meta.getJMSProviderName());
- String ver = attrs.getValue("Implementation-Version");
- assertTrue(-1 != ver.indexOf(meta.getProviderVersion()));
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
// Package protected ---------------------------------------------
Modified: trunk/tests/src/org/jboss/test/messaging/jms/MessageCleanupTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/MessageCleanupTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/MessageCleanupTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -21,11 +21,6 @@
*/
package org.jboss.test.messaging.jms;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.util.ArrayList;
-import java.util.List;
-
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
@@ -34,16 +29,9 @@
import javax.jms.Session;
import javax.jms.TemporaryQueue;
import javax.jms.TemporaryTopic;
-import javax.jms.Topic;
-import javax.naming.InitialContext;
-import javax.sql.DataSource;
-import javax.transaction.TransactionManager;
-import org.jboss.jms.client.JBossConnectionFactory;
import org.jboss.messaging.core.impl.message.SimpleMessageStore;
-import org.jboss.test.messaging.MessagingTestCase;
import org.jboss.test.messaging.tools.ServerManagement;
-import org.jboss.tm.TransactionManagerService;
/**
*
@@ -55,7 +43,7 @@
* $Id$
*
*/
-public class MessageCleanupTest extends MessagingTestCase
+public class MessageCleanupTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -63,11 +51,6 @@
// Attributes ----------------------------------------------------
- protected InitialContext ic;
- protected ConnectionFactory cf;
-
- protected Topic topic;
-
// Constructors --------------------------------------------------
public MessageCleanupTest(String name)
@@ -77,33 +60,6 @@
// TestCase overrides -------------------------------------------
- public void setUp() throws Exception
- {
- super.setUp();
-
- ServerManagement.start("all");
-
-
- ic = new InitialContext(ServerManagement.getJNDIEnvironment());
- cf = (JBossConnectionFactory)ic.lookup("/ConnectionFactory");
-
- ServerManagement.undeployTopic("TestTopic");
- ServerManagement.deployTopic("TestTopic", 100, 10, 10);
-
- topic = (Topic)ic.lookup("/topic/TestTopic");
-
- log.debug("setup done");
- }
-
- public void tearDown() throws Exception
- {
- ServerManagement.undeployTopic("TestTopic");
-
- super.tearDown();
-
- log.debug("tear down done");
- }
-
/*
* Test that all messages on a non durable sub are removed on close
*/
@@ -111,100 +67,119 @@
{
if (ServerManagement.isRemote()) return;
- Connection conn = cf.createConnection();
+ Connection conn = null;
- Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageProducer prod = sess.createProducer(topic);
-
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-
- MessageConsumer cons = sess.createConsumer(topic);
-
- for (int i = 0; i < 150; i++)
+ try
{
- prod.send(sess.createMessage());
+
+ conn = cf.createConnection();
+
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = sess.createProducer(topic1);
+
+ prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ MessageConsumer cons = sess.createConsumer(topic1);
+
+ for (int i = 0; i < 150; i++)
+ {
+ prod.send(sess.createMessage());
+ }
+
+ SimpleMessageStore ms = (SimpleMessageStore)ServerManagement.getMessageStore();
+
+ assertEquals(100, ms.messageIds().size());
+
+ //50 Should be paged onto disk
+
+ assertEquals(50, getReferenceIds().size());
+
+ assertEquals(50, getMessageIds().size());
+
+ //Now we close the consumer
+
+ cons.close();
+
+ assertEquals(0, ms.messageIds().size());
+
+ assertEquals(0, getReferenceIds().size());
+
+ assertEquals(0, getMessageIds().size());
}
-
- SimpleMessageStore ms = (SimpleMessageStore)ServerManagement.getMessageStore();
-
- assertEquals(100, ms.messageIds().size());
-
- //50 Should be paged onto disk
-
- assertEquals(50, getReferenceIds().size());
-
- assertEquals(50, getMessageIds().size());
-
- //Now we close the consumer
-
- cons.close();
-
- assertEquals(0, ms.messageIds().size());
-
- assertEquals(0, getReferenceIds().size());
-
- assertEquals(0, getMessageIds().size());
-
- conn.close();
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void testNonDurableClose2() throws Exception
{
if (ServerManagement.isRemote()) return;
- Connection conn = cf.createConnection();
+ Connection conn = null;
- conn.setClientID("wibble12345");
-
- Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageProducer prod = sess.createProducer(topic);
-
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-
- MessageConsumer cons1 = sess.createConsumer(topic);
-
- MessageConsumer cons2 = sess.createDurableSubscriber(topic, "sub1");
-
- for (int i = 0; i < 150; i++)
+ try
+ {
+ conn = cf.createConnection();
+
+ conn.setClientID("wibble12345");
+
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = sess.createProducer(topic1);
+
+ prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ MessageConsumer cons1 = sess.createConsumer(topic1);
+
+ MessageConsumer cons2 = sess.createDurableSubscriber(topic1, "sub1");
+
+ for (int i = 0; i < 150; i++)
+ {
+ prod.send(sess.createMessage());
+ }
+
+ SimpleMessageStore ms = (SimpleMessageStore)ServerManagement.getMessageStore();
+
+ assertEquals(100, ms.messageIds().size());
+
+ assertEquals(100, getReferenceIds().size());
+
+ assertEquals(50, getMessageIds().size());
+
+ //Now we close the consumers
+
+ cons1.close();
+ cons2.close();
+
+ assertEquals(100, ms.messageIds().size());
+
+ assertEquals(50, getReferenceIds().size());
+
+ assertEquals(50, getMessageIds().size());
+
+ sess.unsubscribe("sub1");
+
+ assertEquals(0, ms.messageIds().size());
+
+ assertEquals(0, getReferenceIds().size());
+
+ assertEquals(0, getMessageIds().size());
+ }
+ finally
{
- prod.send(sess.createMessage());
+ if (conn != null)
+ {
+ conn.close();
+ }
}
-
- SimpleMessageStore ms = (SimpleMessageStore)ServerManagement.getMessageStore();
-
- assertEquals(100, ms.messageIds().size());
-
- assertEquals(100, getReferenceIds().size());
-
- assertEquals(50, getMessageIds().size());
-
- //Now we close the consumers
-
- cons1.close();
- cons2.close();
-
- assertEquals(100, ms.messageIds().size());
-
- assertEquals(50, getReferenceIds().size());
-
- assertEquals(50, getMessageIds().size());
-
- sess.unsubscribe("sub1");
-
- assertEquals(0, ms.messageIds().size());
-
- assertEquals(0, getReferenceIds().size());
-
- assertEquals(0, getMessageIds().size());
-
-
- conn.close();
}
-
/*
* Test that all messages on a temporary queue are removed on close
*/
@@ -219,41 +194,52 @@
ConnectionFactory cf2 = (ConnectionFactory)ic.lookup("/TempQueueConnectionFactory");
- Connection conn = cf2.createConnection();
+ Connection conn = null;
- Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- TemporaryQueue queue = sess.createTemporaryQueue();
-
- MessageProducer prod = sess.createProducer(queue);
-
- prod.setDeliveryMode(DeliveryMode.PERSISTENT);
-
- conn.start();
-
- for (int i = 0; i < 150; i++)
- {
- prod.send(sess.createMessage());
+ try
+ {
+ conn = cf2.createConnection();
+
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ TemporaryQueue queue = sess.createTemporaryQueue();
+
+ MessageProducer prod = sess.createProducer(queue);
+
+ prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+
+ conn.start();
+
+ for (int i = 0; i < 150; i++)
+ {
+ prod.send(sess.createMessage());
+ }
+
+ SimpleMessageStore ms = (SimpleMessageStore)ServerManagement.getMessageStore();
+
+ assertEquals(100, ms.messageIds().size());
+
+ assertEquals(50, getReferenceIds().size());
+
+ assertEquals(50, getMessageIds().size());
+
+ //Now we close the connection
+
+ conn.close();
+
+ assertEquals(0, ms.messageIds().size());
+
+ assertEquals(0, getReferenceIds().size());
+
+ assertEquals(0, getMessageIds().size());
}
-
- SimpleMessageStore ms = (SimpleMessageStore)ServerManagement.getMessageStore();
-
- assertEquals(100, ms.messageIds().size());
-
- assertEquals(50, getReferenceIds().size());
-
- assertEquals(50, getMessageIds().size());
-
- //Now we close the connection
-
- conn.close();
-
- assertEquals(0, ms.messageIds().size());
-
- assertEquals(0, getReferenceIds().size());
-
- assertEquals(0, getMessageIds().size());
-
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
/*
@@ -270,45 +256,56 @@
ConnectionFactory cf2 = (ConnectionFactory)ic.lookup("/TempTopicConnectionFactory");
- Connection conn = cf2.createConnection();
+ Connection conn = null;
- Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- TemporaryTopic topic = sess.createTemporaryTopic();
-
- MessageProducer prod = sess.createProducer(topic);
-
- prod.setDeliveryMode(DeliveryMode.PERSISTENT);
-
- sess.createConsumer(topic);
-
- sess.createConsumer(topic);
-
- //Don't start the connection
-
- for (int i = 0; i < 150; i++)
- {
- prod.send(sess.createMessage());
+ try
+ {
+ conn = cf2.createConnection();
+
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ TemporaryTopic topic = sess.createTemporaryTopic();
+
+ MessageProducer prod = sess.createProducer(topic);
+
+ prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+
+ sess.createConsumer(topic);
+
+ sess.createConsumer(topic);
+
+ //Don't start the connection
+
+ for (int i = 0; i < 150; i++)
+ {
+ prod.send(sess.createMessage());
+ }
+
+ SimpleMessageStore ms = (SimpleMessageStore)ServerManagement.getMessageStore();
+
+ assertEquals(100, ms.messageIds().size());
+
+ assertEquals(100, getReferenceIds().size());
+
+ assertEquals(50, getMessageIds().size());
+
+ //Now we close the connection
+
+ conn.close();
+
+ assertEquals(0, ms.messageIds().size());
+
+ assertEquals(0, getReferenceIds().size());
+
+ assertEquals(0, getMessageIds().size());
}
-
- SimpleMessageStore ms = (SimpleMessageStore)ServerManagement.getMessageStore();
-
- assertEquals(100, ms.messageIds().size());
-
- assertEquals(100, getReferenceIds().size());
-
- assertEquals(50, getMessageIds().size());
-
- //Now we close the connection
-
- conn.close();
-
- assertEquals(0, ms.messageIds().size());
-
- assertEquals(0, getReferenceIds().size());
-
- assertEquals(0, getMessageIds().size());
-
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
// Public --------------------------------------------------------
@@ -317,86 +314,10 @@
// Protected -----------------------------------------------------
- // Private -------------------------------------------------------
-
- protected List getReferenceIds() throws Exception
- {
- InitialContext ctx = new InitialContext();
+ // Private -------------------------------------------------------
- TransactionManager mgr = (TransactionManager)ctx.lookup(TransactionManagerService.JNDI_NAME);
- DataSource ds = (DataSource)ctx.lookup("java:/DefaultDS");
-
- javax.transaction.Transaction txOld = mgr.suspend();
- mgr.begin();
-
- java.sql.Connection conn = ds.getConnection();
- String sql = "SELECT MESSAGE_ID, ORD FROM JBM_MSG_REF";
- PreparedStatement ps = conn.prepareStatement(sql);
-
- ResultSet rs = ps.executeQuery();
-
- List msgIds = new ArrayList();
-
- while (rs.next())
- {
- long msgId = rs.getLong(1);
- msgIds.add(new Long(msgId));
- }
- rs.close();
- ps.close();
- conn.close();
-
- mgr.commit();
-
- if (txOld != null)
- {
- mgr.resume(txOld);
- }
-
- return msgIds;
- }
-
-
- protected List getMessageIds() throws Exception
- {
- InitialContext ctx = new InitialContext();
-
- TransactionManager mgr = (TransactionManager)ctx.lookup(TransactionManagerService.JNDI_NAME);
- DataSource ds = (DataSource)ctx.lookup("java:/DefaultDS");
-
- javax.transaction.Transaction txOld = mgr.suspend();
- mgr.begin();
-
- java.sql.Connection conn = ds.getConnection();
- String sql = "SELECT MESSAGE_ID FROM JBM_MSG ORDER BY MESSAGE_ID";
- PreparedStatement ps = conn.prepareStatement(sql);
-
- ResultSet rs = ps.executeQuery();
-
- List msgIds = new ArrayList();
-
- while (rs.next())
- {
- long msgId = rs.getLong(1);
- msgIds.add(new Long(msgId));
- }
- rs.close();
- ps.close();
- conn.close();
-
- mgr.commit();
-
- if (txOld != null)
- {
- mgr.resume(txOld);
- }
-
- return msgIds;
- }
-
- // Inner classes -------------------------------------------------
-
-
+ // Inner classes -------------------------------------------------
+
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/MessageConsumerTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/MessageConsumerTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/MessageConsumerTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -28,7 +28,6 @@
import javax.jms.BytesMessage;
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.InvalidDestinationException;
import javax.jms.JMSException;
@@ -45,11 +44,8 @@
import javax.jms.TextMessage;
import javax.jms.Topic;
import javax.jms.TopicSubscriber;
-import javax.naming.InitialContext;
import org.jboss.jms.destination.JBossTopic;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
import EDU.oswego.cs.dl.util.concurrent.Latch;
@@ -61,92 +57,23 @@
*
* $Id$
*/
-public class MessageConsumerTest extends MessagingTestCase
+public class MessageConsumerTest extends JMSTestCase
{
// Constants -----------------------------------------------------
// Static --------------------------------------------------------
-
+
// Attributes ----------------------------------------------------
- protected Connection producerConnection, consumerConnection;
- protected Session producerSession, consumerSession;
- protected MessageProducer topicProducer, queueProducer;
- protected MessageConsumer topicConsumer, queueConsumer;
- protected Topic topic;
- protected Queue queue;
- protected Queue queue2;
- protected ConnectionFactory cf;
-
- protected Thread worker1;
-
// Constructors --------------------------------------------------
public MessageConsumerTest(String name)
{
super(name);
}
-
+
// Public --------------------------------------------------------
- public void setUp() throws Exception
- {
- super.setUp();
-
- ServerManagement.start("all");
-
- ServerManagement.undeployTopic("Topic");
- ServerManagement.undeployQueue("Queue");
- ServerManagement.undeployQueue("Queue2");
-
- ServerManagement.deployTopic("Topic");
- ServerManagement.deployQueue("Queue");
- ServerManagement.deployQueue("Queue2");
-
- InitialContext ic = new InitialContext(ServerManagement.getJNDIEnvironment());
- cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
- topic = (Topic)ic.lookup("/topic/Topic");
- queue = (Queue)ic.lookup("/queue/Queue");
- queue2 = (Queue)ic.lookup("/queue/Queue2");
-
- producerConnection = cf.createConnection();
- consumerConnection = cf.createConnection();
-
- producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- topicProducer = producerSession.createProducer(topic);
- topicProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- topicConsumer = consumerSession.createConsumer(topic);
-
- queueProducer = producerSession.createProducer(queue);
- queueProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- queueConsumer = consumerSession.createConsumer(queue);
-
- this.drainDestination(cf, queue);
- this.drainDestination(cf, queue2);
-
- log.debug("setup done");
- }
-
- public void tearDown() throws Exception
- {
- producerConnection.close();
- consumerConnection.close();
-
- if (worker1 != null)
- {
- worker1.interrupt();
- }
-
- ServerManagement.undeployTopic("Topic");
- ServerManagement.undeployQueue("Queue");
- ServerManagement.undeployQueue("Queue2");
-
- super.tearDown();
- }
-
-
public void testReceiveWithClientAckThenCloseSession() throws Exception
{
Connection conn = null;
@@ -157,7 +84,7 @@
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
final int NUM_MESSAGES = 5;
@@ -170,7 +97,7 @@
Session sess2 = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageConsumer cons = sess2.createConsumer(queue);
+ MessageConsumer cons = sess2.createConsumer(queue1);
conn.start();
@@ -185,8 +112,7 @@
// Now close the session
- sess2.close();
-
+ sess2.close();
}
finally
{
@@ -194,77 +120,90 @@
{
conn.close();
}
- }
-
+
+ removeAllMessages(queue1.getQueueName(), true, 0);
+ }
}
public void testRelayMessage() throws Exception
{
- Connection conn = cf.createConnection();
-
- conn.start();
-
- final Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer cons = sess.createConsumer(queue);
-
- final Object lock = new Object();
-
- final int numMessages = 100;
-
-
- class MyListener implements MessageListener
- {
- boolean failed;
-
- int count;
-
- public void onMessage(Message m)
- {
- try
- {
- MessageProducer prod = sess.createProducer(queue2);
-
- prod.send(m);
-
- count++;
-
- if (count == numMessages)
- {
- synchronized (lock)
- {
- lock.notify();
- }
-
- }
- }
- catch (JMSException e)
- {
- failed = true;
- }
- }
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+
+ conn.start();
+
+ final Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer cons = sess.createConsumer(queue1);
+
+ final int numMessages = 100;
+
+ class MyListener implements MessageListener
+ {
+ boolean failed;
+
+ int count;
+
+ public synchronized void onMessage(Message m)
+ {
+ try
+ {
+ MessageProducer prod = sess.createProducer(queue2);
+
+ prod.send(m);
+
+ count++;
+
+ if (count == numMessages)
+ {
+ this.notify();
+ }
+ }
+ catch (JMSException e)
+ {
+ failed = true;
+ }
+ }
+
+ synchronized void waitForMessages() throws Exception
+ {
+ while (count < numMessages)
+ {
+ this.wait();
+ }
+ }
+ }
+
+ MyListener listener = new MyListener();
+
+ cons.setMessageListener(listener);
+
+ MessageProducer prod = sess.createProducer(queue1);
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ prod.send(sess.createMessage());
+ }
+
+ listener.waitForMessages();
+
+ conn.close();
+
+ assertFalse(listener.failed);
}
-
- MyListener listener = new MyListener();
-
- cons.setMessageListener(listener);
-
- MessageProducer prod = sess.createProducer(queue);
-
- for (int i = 0; i < numMessages; i++)
+ finally
{
- prod.send(sess.createMessage());
+ if (conn != null)
+ {
+ conn.close();
+ }
+
+ removeAllMessages(queue2.getQueueName(), true, 0);
}
-
- synchronized (lock)
- {
- lock.wait();
- }
-
- conn.close();
-
- assertFalse(listener.failed);
}
@@ -289,13 +228,13 @@
Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessSend.createProducer(queue);
+ MessageProducer prod = sessSend.createProducer(queue1);
conn.start();
Session sessConsume1 = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageConsumer cons1 = sessConsume1.createConsumer(queue);
+ MessageConsumer cons1 = sessConsume1.createConsumer(queue1);
TextMessage tm = sessSend.createTextMessage();
@@ -315,11 +254,10 @@
Session sessConsume2 = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageConsumer cons2 = sessConsume2.createConsumer(queue);
+ MessageConsumer cons2 = sessConsume2.createConsumer(queue1);
// this should cancel message and cause delivery to other consumer
- log.trace("Closed session 1");
sessConsume1.close();
TextMessage tm3 = (TextMessage)cons2.receive(1000);
@@ -332,13 +270,11 @@
}
finally
{
-
if (conn != null)
{
conn.close();
}
}
-
}
@@ -347,31 +283,95 @@
*/
public void testReceive() throws Exception
{
- // start consumer connection before the message is submitted
- consumerConnection.start();
+ Connection producerConnection = null;
+
+ Connection consumerConnection = null;
+
+ try
+ {
+ producerConnection = cf.createConnection();
+
+ consumerConnection = cf.createConnection();
+
+ Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer queueProducer = producerSession.createProducer(queue1);
+
+ MessageConsumer queueConsumer = consumerSession.createConsumer(queue1);
+
+ // start consumer connection before the message is submitted
+ consumerConnection.start();
+
+ TextMessage tm = producerSession.createTextMessage("someText");
+
+ queueProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ queueProducer.send(tm);
+
+ TextMessage m = (TextMessage)queueConsumer.receive();
+
+ assertEquals(tm.getText(), m.getText());
+ }
+ finally
+ {
+ if (producerConnection != null)
+ {
+ producerConnection.close();
+ }
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
- TextMessage tm = producerSession.createTextMessage("someText");
- queueProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-
- queueProducer.send(tm);
-
- TextMessage m = (TextMessage)queueConsumer.receive();
- assertEquals(tm.getText(), m.getText());
-
}
public void testReceivePersistent() throws Exception
{
- // start consumer connection before the message is submitted
- consumerConnection.start();
-
- TextMessage tm = producerSession.createTextMessage("someText");
- assertEquals(DeliveryMode.PERSISTENT, tm.getJMSDeliveryMode());
-
- queueProducer.send(tm);
-
- TextMessage m = (TextMessage)queueConsumer.receive();
- assertEquals(tm.getText(), m.getText());
+ Connection producerConnection = null;
+
+ Connection consumerConnection = null;
+
+ try
+ {
+ producerConnection = cf.createConnection();
+
+ consumerConnection = cf.createConnection();
+
+ Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer queueProducer = producerSession.createProducer(queue1);
+
+ MessageConsumer queueConsumer = consumerSession.createConsumer(queue1);
+
+ // start consumer connection before the message is submitted
+ consumerConnection.start();
+
+ TextMessage tm = producerSession.createTextMessage("someText");
+
+ assertEquals(DeliveryMode.PERSISTENT, tm.getJMSDeliveryMode());
+
+ queueProducer.send(tm);
+
+ TextMessage m = (TextMessage)queueConsumer.receive();
+
+ assertEquals(tm.getText(), m.getText());
+ }
+ finally
+ {
+ if (producerConnection != null)
+ {
+ producerConnection.close();
+ }
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
}
@@ -380,14 +380,46 @@
*/
public void testReceiveTimeout() throws Exception
{
- TextMessage tm = producerSession.createTextMessage("someText");
- queueProducer.send(tm);
-
- // start consumer connection after the message is submitted
- consumerConnection.start();
-
- TextMessage m = (TextMessage)queueConsumer.receive(2000);
- assertEquals(tm.getText(), m.getText());
+ Connection producerConnection = null;
+
+ Connection consumerConnection = null;
+
+ try
+ {
+ producerConnection = cf.createConnection();
+
+ consumerConnection = cf.createConnection();
+
+ Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer queueProducer = producerSession.createProducer(queue1);
+
+ MessageConsumer queueConsumer = consumerSession.createConsumer(queue1);
+
+ TextMessage tm = producerSession.createTextMessage("someText");
+
+ queueProducer.send(tm);
+
+ // start consumer connection after the message is submitted
+ consumerConnection.start();
+
+ TextMessage m = (TextMessage)queueConsumer.receive(2000);
+
+ assertEquals(tm.getText(), m.getText());
+ }
+ finally
+ {
+ if (producerConnection != null)
+ {
+ producerConnection.close();
+ }
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
}
/**
@@ -395,23 +427,55 @@
*/
public void testReceiveNoWait() throws Exception
{
- TextMessage tm = producerSession.createTextMessage("someText");
- queueProducer.send(tm);
-
- // start consumer connection after the message is submitted
- consumerConnection.start();
-
- //NOTE! There 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, ActiveMQ implement it this way
-
- Thread.sleep(500);
-
- TextMessage m = (TextMessage)queueConsumer.receiveNoWait();
- assertEquals(tm.getText(), m.getText());
+ Connection producerConnection = null;
+
+ Connection consumerConnection = null;
+
+ try
+ {
+ producerConnection = cf.createConnection();
+
+ consumerConnection = cf.createConnection();
+
+ Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer queueProducer = producerSession.createProducer(queue1);
+
+ MessageConsumer queueConsumer = consumerSession.createConsumer(queue1);
+
+ TextMessage tm = producerSession.createTextMessage("someText");
+
+ queueProducer.send(tm);
+
+ // start consumer connection after the message is submitted
+ consumerConnection.start();
+
+ //NOTE! There 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, ActiveMQ implement it this way
+
+ Thread.sleep(500);
+
+ TextMessage m = (TextMessage)queueConsumer.receiveNoWait();
+
+ assertEquals(tm.getText(), m.getText());
+ }
+ finally
+ {
+ if (producerConnection != null)
+ {
+ producerConnection.close();
+ }
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
}
/**
@@ -419,20 +483,53 @@
*/
public void testReceiveOnListener() throws Exception
{
- TextMessage tm = producerSession.createTextMessage("someText");
- queueProducer.send(tm);
-
- MessageListenerImpl l = new MessageListenerImpl();
- queueConsumer.setMessageListener(l);
-
- // start consumer connection after the message is submitted
- consumerConnection.start();
-
- // wait for the listener to receive the message
- l.waitForMessages();
-
- TextMessage m = (TextMessage)l.getNextMessage();
- assertEquals(tm.getText(), m.getText());
+ Connection producerConnection = null;
+
+ Connection consumerConnection = null;
+
+ try
+ {
+ producerConnection = cf.createConnection();
+
+ consumerConnection = cf.createConnection();
+
+ Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer queueProducer = producerSession.createProducer(queue1);
+
+ MessageConsumer queueConsumer = consumerSession.createConsumer(queue1);
+
+ TextMessage tm = producerSession.createTextMessage("someText");
+
+ queueProducer.send(tm);
+
+ MessageListenerImpl l = new MessageListenerImpl();
+
+ queueConsumer.setMessageListener(l);
+
+ // start consumer connection after the message is submitted
+ consumerConnection.start();
+
+ // wait for the listener to receive the message
+ l.waitForMessages();
+
+ TextMessage m = (TextMessage)l.getNextMessage();
+
+ assertEquals(tm.getText(), m.getText());
+ }
+ finally
+ {
+ if (producerConnection != null)
+ {
+ producerConnection.close();
+ }
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
}
//
@@ -441,10 +538,12 @@
public void testCreateConsumerOnInexistentDestination() throws Exception
{
- Connection pconn = cf.createConnection();
-
+ Connection pconn = null;
+
try
{
+ pconn = cf.createConnection();
+
Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
try
@@ -459,7 +558,10 @@
}
finally
{
- pconn.close();
+ if (pconn != null)
+ {
+ pconn.close();
+ }
}
}
@@ -477,14 +579,13 @@
try
{
-
connSend = cf.createConnection();
connSend.start();
Session sessSend = connSend.createSession(true, Session.SESSION_TRANSACTED);
- MessageProducer prod = sessSend.createProducer(queue2);
+ MessageProducer prod = sessSend.createProducer(queue1);
prod.setDeliveryMode(DeliveryMode.PERSISTENT);
@@ -500,7 +601,7 @@
Session sessReceive = connReceive.createSession(true, Session.SESSION_TRANSACTED);
- MessageConsumer cons = sessReceive.createConsumer(queue2);
+ MessageConsumer cons = sessReceive.createConsumer(queue1);
TextMessage m2 = (TextMessage)cons.receive(1500);
@@ -527,61 +628,115 @@
}
- public void testClientAcknowledgmentOnClosedConsumer() throws Exception
- {
- // create my consumer from scratch
- consumerConnection.close();
+ public void testClientAcknowledgmentOnClosedConsumer() throws Exception
+ {
+ Connection producerConnection = null;
- TextMessage tm = producerSession.createTextMessage();
+ Connection consumerConnection = null;
- tm.setText("One");
- queueProducer.send(tm);
+ try
+ {
+ producerConnection = cf.createConnection();
+ consumerConnection = cf.createConnection();
- consumerConnection = cf.createConnection();
- consumerSession = consumerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- queueConsumer = consumerSession.createConsumer(queue);
+ Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- consumerConnection.start();
+ Session consumerSession = consumerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- TextMessage m = (TextMessage)queueConsumer.receive(1500);
- assertEquals(m.getText(), "One");
+ MessageProducer queueProducer = producerSession.createProducer(queue1);
- queueConsumer.close();
+ MessageConsumer queueConsumer = consumerSession.createConsumer(queue1);
- m.acknowledge();
+ TextMessage tm = producerSession.createTextMessage();
- try
- {
- queueConsumer.receive(2000);
- fail("should throw exception");
- }
- catch(javax.jms.IllegalStateException e)
- {
- // OK
- }
- }
+ tm.setText("One");
+ queueProducer.send(tm);
+ consumerConnection.start();
+ TextMessage m = (TextMessage)queueConsumer.receive(1500);
+ assertEquals(m.getText(), "One");
+
+ queueConsumer.close();
+
+ m.acknowledge();
+
+ try
+ {
+ queueConsumer.receive(2000);
+ fail("should throw exception");
+ }
+ catch(javax.jms.IllegalStateException e)
+ {
+ // OK
+ }
+ }
+ finally
+ {
+ if (producerConnection != null)
+ {
+ producerConnection.close();
+ }
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
+ }
+
+
public void testSendMessageAndCloseConsumer1() throws Exception
{
- // setUp() created a consumer already
+ Connection producerConnection = null;
- Message m = producerSession.createMessage();
- queueProducer.send(m);
+ Connection consumerConnection = null;
- queueConsumer.close();
+ try
+ {
+ producerConnection = cf.createConnection();
- // since no message was received, we expect the message back in the queue
+ consumerConnection = cf.createConnection();
- queueConsumer = consumerSession.createConsumer(queue);
+ Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- consumerConnection.start();
+ Session consumerSession = consumerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- Message r = queueConsumer.receive(2000);
- assertEquals(m.getJMSMessageID(), r.getJMSMessageID());
+ MessageProducer queueProducer = producerSession.createProducer(queue1);
+
+ MessageConsumer queueConsumer = consumerSession.createConsumer(queue1);
+
+ Message m = producerSession.createMessage();
+
+ queueProducer.send(m);
+
+ queueConsumer.close();
+
+ // since no message was received, we expect the message back in the queue
+
+ queueConsumer = consumerSession.createConsumer(queue1);
+
+ consumerConnection.start();
+
+ Message r = queueConsumer.receive(2000);
+
+ assertEquals(m.getJMSMessageID(), r.getJMSMessageID());
+ }
+ finally
+ {
+ if (producerConnection != null)
+ {
+ producerConnection.close();
+ }
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
+
+ removeAllMessages(queue1.getQueueName(), true, 0);
}
@@ -591,39 +746,67 @@
*/
public void testSendMessageAndCloseConsumer2() throws Exception
{
- // create my consumer from scratch
- consumerConnection.close();
+ Connection producerConnection = null;
- TextMessage tm = producerSession.createTextMessage();
+ Connection consumerConnection = null;
- tm.setText("One");
- queueProducer.send(tm);
+ try
+ {
+ producerConnection = cf.createConnection();
- tm.setText("Two");
- queueProducer.send(tm);
+ consumerConnection = cf.createConnection();
- consumerConnection = cf.createConnection();
- consumerSession = consumerConnection.createSession(true, 0);
- queueConsumer = consumerSession.createConsumer(queue);
+ Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- consumerConnection.start();
+ Session consumerSession = consumerConnection.createSession(true, 0);
- TextMessage m = (TextMessage)queueConsumer.receive(1500);
- assertEquals("One", m.getText());
+ MessageProducer queueProducer = producerSession.createProducer(queue1);
- queueConsumer.close();
- consumerSession.commit();
-
- // I expect that "Two" is still in the queue
-
- MessageConsumer queueConsumer2 = consumerSession.createConsumer(queue);
- m = (TextMessage)queueConsumer2.receive(1500);
- assertNotNull(m);
- assertEquals(m.getText(), "Two");
-
- consumerSession.commit();
-
- consumerConnection.close();
+ MessageConsumer queueConsumer = consumerSession.createConsumer(queue1);
+
+ TextMessage tm = producerSession.createTextMessage();
+
+ tm.setText("One");
+
+ queueProducer.send(tm);
+
+ tm.setText("Two");
+
+ queueProducer.send(tm);
+
+ consumerConnection.start();
+
+ TextMessage m = (TextMessage)queueConsumer.receive(1500);
+
+ assertEquals("One", m.getText());
+
+ queueConsumer.close();
+
+ consumerSession.commit();
+
+ // I expect that "Two" is still in the queue
+
+ MessageConsumer queueConsumer2 = consumerSession.createConsumer(queue1);
+
+ m = (TextMessage)queueConsumer2.receive(1500);
+
+ assertNotNull(m);
+
+ assertEquals(m.getText(), "Two");
+
+ consumerSession.commit();
+ }
+ finally
+ {
+ if (producerConnection != null)
+ {
+ producerConnection.close();
+ }
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
}
public void testRedel0() throws Exception
@@ -636,7 +819,7 @@
conn.start();
Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
TextMessage tm1 = sess.createTextMessage("a");
TextMessage tm2 = sess.createTextMessage("b");
TextMessage tm3 = sess.createTextMessage("c");
@@ -645,7 +828,7 @@
prod.send(tm3);
sess.commit();
- MessageConsumer cons1 = sess.createConsumer(queue);
+ MessageConsumer cons1 = sess.createConsumer(queue1);
TextMessage rm1 = (TextMessage)cons1.receive();
assertNotNull(rm1);
@@ -653,7 +836,7 @@
cons1.close();
- MessageConsumer cons2 = sess.createConsumer(queue);
+ MessageConsumer cons2 = sess.createConsumer(queue1);
sess.commit();
@@ -664,11 +847,8 @@
TextMessage rm3 = (TextMessage)cons2.receive(1500);
assertNotNull(rm3);
assertEquals("c", rm3.getText());
-
- TextMessage rm4 = (TextMessage)cons2.receive(1500);
- assertNull(rm4);
-
-
+
+ sess.commit();
}
finally
{
@@ -676,8 +856,11 @@
{
conn.close();
}
+
+ checkEmpty(queue1);
+
+ removeAllMessages(queue1.getQueueName(), true, 0);
}
-
}
@@ -691,7 +874,7 @@
conn.start();
Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
TextMessage tm1 = sess.createTextMessage("hello1");
TextMessage tm2 = sess.createTextMessage("hello2");
TextMessage tm3 = sess.createTextMessage("hello3");
@@ -700,7 +883,7 @@
prod.send(tm3);
sess.commit();
- MessageConsumer cons1 = sess.createConsumer(queue);
+ MessageConsumer cons1 = sess.createConsumer(queue1);
TextMessage rm1 = (TextMessage)cons1.receive(1500);
assertNotNull(rm1);
@@ -708,7 +891,7 @@
cons1.close();
- MessageConsumer cons2 = sess.createConsumer(queue);
+ MessageConsumer cons2 = sess.createConsumer(queue1);
sess.commit();
@@ -719,11 +902,8 @@
TextMessage rm3 = (TextMessage)cons2.receive(1500);
assertNotNull(rm3);
assertEquals("hello3", rm3.getText());
-
- TextMessage rm4 = (TextMessage)cons2.receive(1500);
- assertNull(rm4);
-
-
+
+ sess.commit();
}
finally
{
@@ -731,8 +911,11 @@
{
conn.close();
}
+
+ checkEmpty(queue1);
+
+ removeAllMessages(queue1.getQueueName(), true, 0);
}
-
}
public void testRedel2() throws Exception
@@ -745,7 +928,7 @@
conn.start();
Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
TextMessage tm1 = sess.createTextMessage("hello1");
TextMessage tm2 = sess.createTextMessage("hello2");
TextMessage tm3 = sess.createTextMessage("hello3");
@@ -754,7 +937,7 @@
prod.send(tm3);
sess.commit();
- MessageConsumer cons1 = sess.createConsumer(queue);
+ MessageConsumer cons1 = sess.createConsumer(queue1);
TextMessage rm1 = (TextMessage)cons1.receive(1500);
assertNotNull(rm1);
@@ -764,7 +947,7 @@
sess.commit();
- MessageConsumer cons2 = sess.createConsumer(queue);
+ MessageConsumer cons2 = sess.createConsumer(queue1);
TextMessage rm2 = (TextMessage)cons2.receive(1500);
assertNotNull(rm2);
@@ -773,11 +956,8 @@
TextMessage rm3 = (TextMessage)cons2.receive(1500);
assertNotNull(rm3);
assertEquals("hello3", rm3.getText());
-
- TextMessage rm4 = (TextMessage)cons2.receive(1500);
- assertNull(rm4);
-
-
+
+ sess.commit();
}
finally
{
@@ -785,8 +965,11 @@
{
conn.close();
}
+
+ checkEmpty(queue1);
+
+ removeAllMessages(queue1.getQueueName(), true, 0);
}
-
}
public void testRedel3() throws Exception
@@ -799,7 +982,7 @@
conn.start();
Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
TextMessage tm1 = sess.createTextMessage("hello1");
log.trace(tm1.getJMSMessageID());
TextMessage tm2 = sess.createTextMessage("hello2");
@@ -809,7 +992,7 @@
prod.send(tm3);
sess.commit();
- MessageConsumer cons1 = sess.createConsumer(queue);
+ MessageConsumer cons1 = sess.createConsumer(queue1);
TextMessage rm1 = (TextMessage)cons1.receive(1500);
assertNotNull(rm1);
@@ -830,11 +1013,8 @@
TextMessage rm4 = (TextMessage)cons1.receive(1500);
assertEquals("hello3", rm4.getText());
-
- //This last step is important - there shouldn't be any more messages to receive
- TextMessage rm5 = (TextMessage)cons1.receive(1500);
- assertNull(rm5);
-
+
+ sess.commit();
}
finally
{
@@ -842,8 +1022,12 @@
{
conn.close();
}
+
+ //This last step is important - there shouldn't be any more messages to receive
+ checkEmpty(queue1);
+
+ removeAllMessages(queue1.getQueueName(), true, 0);
}
-
}
public void testRedel4() throws Exception
@@ -856,7 +1040,7 @@
conn.start();
Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
TextMessage tm1 = sess.createTextMessage("hello1");
TextMessage tm2 = sess.createTextMessage("hello2");
TextMessage tm3 = sess.createTextMessage("hello3");
@@ -865,7 +1049,7 @@
prod.send(tm3);
sess.commit();
- MessageConsumer cons1 = sess.createConsumer(queue);
+ MessageConsumer cons1 = sess.createConsumer(queue1);
TextMessage rm1 = (TextMessage)cons1.receive(1500);
assertNotNull(rm1);
@@ -879,7 +1063,7 @@
sess.rollback();
- MessageConsumer cons2 = sess.createConsumer(queue);
+ MessageConsumer cons2 = sess.createConsumer(queue1);
TextMessage rm2 = (TextMessage)cons2.receive(1500);
assertNotNull(rm2);
@@ -892,12 +1076,8 @@
TextMessage rm4 = (TextMessage)cons2.receive(1500);
assertNotNull(rm4);
assertEquals("hello3", rm4.getText());
-
- //This last step is important - there shouldn't be any more messages to receive
- TextMessage rm5 = (TextMessage)cons2.receive(1500);
- assertNull(rm5);
-
-
+
+ sess.commit();
}
finally
{
@@ -905,6 +1085,11 @@
{
conn.close();
}
+
+ //This last step is important - there shouldn't be any more messages to receive
+ checkEmpty(queue1);
+
+ removeAllMessages(queue1.getQueueName(), true, 0);
}
}
@@ -919,7 +1104,7 @@
conn.start();
Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
TextMessage tm1 = sess.createTextMessage("hello1");
TextMessage tm2 = sess.createTextMessage("hello2");
TextMessage tm3 = sess.createTextMessage("hello3");
@@ -927,7 +1112,7 @@
prod.send(tm2);
prod.send(tm3);
- MessageConsumer cons1 = sess.createConsumer(queue);
+ MessageConsumer cons1 = sess.createConsumer(queue1);
TextMessage rm1 = (TextMessage)cons1.receive(1500);
assertNotNull(rm1);
@@ -947,11 +1132,8 @@
TextMessage rm4 = (TextMessage)cons1.receive(1500);
assertNotNull(rm4);
assertEquals("hello3", rm4.getText());
-
-
- //This last step is important - there shouldn't be any more messages to receive
- TextMessage rm5 = (TextMessage)cons1.receive(1500);
- assertNull(rm5);
+
+ rm4.acknowledge();
}
finally
{
@@ -959,6 +1141,11 @@
{
conn.close();
}
+
+ //This last step is important - there shouldn't be any more messages to receive
+ checkEmpty(queue1);
+
+ removeAllMessages(queue1.getQueueName(), true, 0);
}
}
@@ -972,7 +1159,7 @@
conn.start();
Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
TextMessage tm1 = sess.createTextMessage("hello1");
TextMessage tm2 = sess.createTextMessage("hello2");
TextMessage tm3 = sess.createTextMessage("hello3");
@@ -980,7 +1167,7 @@
prod.send(tm2);
prod.send(tm3);
- MessageConsumer cons1 = sess.createConsumer(queue);
+ MessageConsumer cons1 = sess.createConsumer(queue1);
TextMessage rm1 = (TextMessage)cons1.receive(1500);
assertNotNull(rm1);
@@ -993,7 +1180,7 @@
//redeliver
sess.recover();
- MessageConsumer cons2 = sess.createConsumer(queue);
+ MessageConsumer cons2 = sess.createConsumer(queue1);
log.debug("receiving ...");
@@ -1008,13 +1195,8 @@
TextMessage rm4 = (TextMessage)cons2.receive(1500);
assertNotNull(rm4);
assertEquals("hello3", rm4.getText());
-
-
- //This last step is important - there shouldn't be any more messages to receive
- TextMessage rm5 = (TextMessage)cons2.receive(1500);
- assertNull(rm5);
-
-
+
+ rm4.acknowledge();
}
finally
{
@@ -1022,77 +1204,73 @@
{
conn.close();
}
+
+ //This last step is important - there shouldn't be any more messages to receive
+ checkEmpty(queue1);
+
+ removeAllMessages(queue1.getQueueName(), true, 0);
}
-
}
/**
* http://www.jboss.org/index.html?module=bb&op=viewtopic&t=71350
*/
- public void testRedel7() throws Exception
- {
- Connection conn = null;
+ public void testRedel7() throws Exception
+ {
+ Connection conn = null;
- try
- {
- conn = cf.createConnection();
- conn.start();
+ try
+ {
+ conn = cf.createConnection();
+ conn.start();
- Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+ Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
-
- TextMessage tm1 = sess.createTextMessage("1");
-
- TextMessage tm2 = sess.createTextMessage("2");
-
- TextMessage tm3 = sess.createTextMessage("3");
-
- prod.send(tm1);
- prod.send(tm2);
- prod.send(tm3);
+ MessageProducer prod = sess.createProducer(queue1);
- log.trace("Creating consumer");
- MessageConsumer cons1 = sess.createConsumer(queue);
+ TextMessage tm1 = sess.createTextMessage("1");
- log.trace("Waiting for message");
-
- TextMessage r1 = (TextMessage)cons1.receive();
-
- assertEquals(tm1.getText(), r1.getText());
+ TextMessage tm2 = sess.createTextMessage("2");
- log.trace("Got first message");
+ TextMessage tm3 = sess.createTextMessage("3");
- cons1.close();
+ prod.send(tm1);
+ prod.send(tm2);
+ prod.send(tm3);
- log.trace("Closed consumer");
+ MessageConsumer cons1 = sess.createConsumer(queue1);
- MessageConsumer cons2 = sess.createConsumer(queue);
+ TextMessage r1 = (TextMessage)cons1.receive();
- log.trace("Waiting for second message");
- TextMessage r2 = (TextMessage)cons2.receive();
-
- assertEquals(tm2.getText(), r2.getText());
+ assertEquals(tm1.getText(), r1.getText());
- log.trace("got second message");
+ cons1.close();
- TextMessage r3 = (TextMessage)cons2.receive();
-
- assertEquals(tm3.getText(), r3.getText());
- r1.acknowledge();
- r2.acknowledge();
- r3.acknowledge();
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- }
- }
+ MessageConsumer cons2 = sess.createConsumer(queue1);
+ TextMessage r2 = (TextMessage)cons2.receive();
+
+ assertEquals(tm2.getText(), r2.getText());
+
+ TextMessage r3 = (TextMessage)cons2.receive();
+
+ assertEquals(tm3.getText(), r3.getText());
+
+ r1.acknowledge();
+ r2.acknowledge();
+ r3.acknowledge();
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ removeAllMessages(queue1.getQueueName(), true, 0);
+ }
+ }
+
/**
* http://www.jboss.org/index.html?module=bb&op=viewtopic&t=71350
*/
@@ -1106,7 +1284,7 @@
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
//Send 3 messages
@@ -1114,22 +1292,14 @@
prod.send(sess.createTextMessage("2"));
prod.send(sess.createTextMessage("3"));
- log.trace("Sent messages");
-
conn.start();
- MessageConsumer cons1 = sess.createConsumer(queue);
+ MessageConsumer cons1 = sess.createConsumer(queue1);
- log.trace("closing cons1");
-
cons1.close();
- log.trace("cons1 closed");
+ MessageConsumer cons2 = sess.createConsumer(queue1);
- MessageConsumer cons2 = sess.createConsumer(queue);
-
- log.trace("cons2 created");
-
Message r1 = cons2.receive();
Message r2 = cons2.receive();
Message r3 = cons2.receive();
@@ -1148,8 +1318,6 @@
}
}
-
-
public void testSendAndReceivePersistentDifferentConnections() throws Exception
{
Connection connSend = null;
@@ -1157,9 +1325,6 @@
try
{
-
- log.trace("Running testSendAndReceivePersistentDifferentConnections");
-
connSend = cf.createConnection();
connSend.start();
@@ -1172,7 +1337,7 @@
Message m = sessSend.createTextMessage("hello");
- prod.send(queue2, m);
+ prod.send(queue1, m);
sessSend.commit();
@@ -1182,7 +1347,7 @@
Session sessReceive = connReceive.createSession(true, Session.SESSION_TRANSACTED);
- MessageConsumer cons = sessReceive.createConsumer(queue2);
+ MessageConsumer cons = sessReceive.createConsumer(queue1);
TextMessage m2 = (TextMessage)cons.receive(1500);
@@ -1201,432 +1366,737 @@
sessReceive = connReceive.createSession(true, Session.SESSION_TRANSACTED);
- cons = sessReceive.createConsumer(queue2);
-
- TextMessage m3 = (TextMessage)cons.receive(1500);
-
- assertNull(m3);
-
-
- log.trace("Done test");
-
+ cons = sessReceive.createConsumer(queue1);
}
finally
{
if (connSend != null) connSend.close();
if (connReceive != null) connReceive.close();
+
+ checkEmpty(queue1);
}
}
public void testMultipleConcurrentConsumers() throws Exception
- {
- consumerConnection.start();
- Session sess1 = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Session sess2 = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Session sess3 = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer cons1 = sess1.createConsumer(topic);
- MessageConsumer cons2 = sess2.createConsumer(topic);
- MessageConsumer cons3 = sess3.createConsumer(topic);
-
- final int NUM_MESSAGES = 100;
-
- class Receiver implements Runnable
- {
- Receiver(MessageConsumer c1)
- {
- cons = c1;
- }
- MessageConsumer cons;
- boolean failed;
- public void run()
- {
- try
- {
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- TextMessage m = (TextMessage)cons.receive(5000);
- if (m == null)
- {
- log.error("Didn't receive all the messages");
- failed = true;
- break;
- }
- log.trace("received message");
- if (!m.getText().equals("testing"))
- {
- failed = true;
- }
- }
-
- }
- catch (Exception e)
- {
- log.error("Failed in receiving messages", e);
- failed = true;
- }
- }
- }
-
-
- Receiver rec1 = new Receiver(cons1);
- Receiver rec2 = new Receiver(cons2);
- Receiver rec3 = new Receiver(cons3);
-
- Thread t1 = new Thread(rec1);
- Thread t2 = new Thread(rec2);
- Thread t3 = new Thread(rec3);
-
- log.trace("Starting threads");
-
- t1.start();
- t2.start();
- t3.start();
-
- log.trace("Sending messages to topic");
-
- producerConnection.start();
- Session prodSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = prodSession.createProducer(topic);
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- Message m = prodSession.createTextMessage("testing");
- prod.send(m);
- log.trace("Sent message to topic");
- }
-
- t1.join();
- t2.join();
- t3.join();
-
- sess1.close();
- sess2.close();
- sess3.close();
- prodSession.close();
-
- assertTrue(!rec1.failed);
- assertTrue(!rec2.failed);
- assertTrue(!rec3.failed);
+ {
+ Connection producerConnection = null;
+
+ Connection consumerConnection = null;
+
+ try
+ {
+ producerConnection = cf.createConnection();
+
+ consumerConnection = cf.createConnection();
+
+ consumerConnection.start();
+ Session sess1 = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Session sess2 = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Session sess3 = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer cons1 = sess1.createConsumer(topic1);
+ MessageConsumer cons2 = sess2.createConsumer(topic1);
+ MessageConsumer cons3 = sess3.createConsumer(topic1);
+
+ final int NUM_MESSAGES = 100;
+
+ class Receiver implements Runnable
+ {
+ Receiver(MessageConsumer c1)
+ {
+ cons = c1;
+ }
+ MessageConsumer cons;
+ boolean failed;
+ public void run()
+ {
+ try
+ {
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ TextMessage m = (TextMessage)cons.receive(5000);
+ if (m == null)
+ {
+ log.error("Didn't receive all the messages");
+ failed = true;
+ break;
+ }
+ log.trace("received message");
+ if (!m.getText().equals("testing"))
+ {
+ failed = true;
+ }
+ }
+
+ }
+ catch (Exception e)
+ {
+ log.error("Failed in receiving messages", e);
+ failed = true;
+ }
+ }
+ }
+
+
+ Receiver rec1 = new Receiver(cons1);
+ Receiver rec2 = new Receiver(cons2);
+ Receiver rec3 = new Receiver(cons3);
+
+ Thread t1 = new Thread(rec1);
+ Thread t2 = new Thread(rec2);
+ Thread t3 = new Thread(rec3);
+
+ log.trace("Starting threads");
+
+ t1.start();
+ t2.start();
+ t3.start();
+
+ log.trace("Sending messages to topic");
+
+ producerConnection.start();
+ Session prodSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer prod = prodSession.createProducer(topic1);
+ prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ Message m = prodSession.createTextMessage("testing");
+ prod.send(m);
+ log.trace("Sent message to topic");
+ }
+
+ t1.join();
+ t2.join();
+ t3.join();
+
+ sess1.close();
+ sess2.close();
+ sess3.close();
+ prodSession.close();
+
+ assertTrue(!rec1.failed);
+ assertTrue(!rec2.failed);
+ assertTrue(!rec3.failed);
+ }
+ finally
+ {
+ if (producerConnection != null)
+ {
+ producerConnection.close();
+ }
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
}
public void testGetSelector() throws Exception
{
- String selector = "JMSType = 'something'";
- topicConsumer = consumerSession.createConsumer(topic, selector);
- assertEquals(selector, topicConsumer.getMessageSelector());
+ Connection consumerConnection = null;
+
+ try
+ {
+ consumerConnection = cf.createConnection();
+
+ Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ String selector = "JMSType = 'something'";
+
+ MessageConsumer topicConsumer = consumerSession.createConsumer(topic1, selector);
+
+ assertEquals(selector, topicConsumer.getMessageSelector());
+ }
+ finally
+ {
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
}
public void testGetSelectorOnClosedConsumer() throws Exception
{
- topicConsumer.close();
-
- try
- {
- topicConsumer.getMessageSelector();
- }
- catch(javax.jms.IllegalStateException e)
- {
- // OK
- }
+ Connection consumerConnection = null;
+
+ try
+ {
+ consumerConnection = cf.createConnection();
+
+ Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer topicConsumer = consumerSession.createConsumer(topic1);
+
+ topicConsumer.close();
+
+ try
+ {
+ topicConsumer.getMessageSelector();
+ }
+ catch(javax.jms.IllegalStateException e)
+ {
+ // OK
+ }
+ }
+ finally
+ {
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
}
public void testGetTopic() throws Exception
{
- Topic t = ((TopicSubscriber)topicConsumer).getTopic();
- assertEquals(topic, t);
+ Connection consumerConnection = null;
+
+ try
+ {
+ consumerConnection = cf.createConnection();
+
+ Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer topicConsumer = consumerSession.createConsumer(topic1);
+
+ Topic t = ((TopicSubscriber)topicConsumer).getTopic();
+
+ assertEquals(topic1, t);
+ }
+ finally
+ {
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
}
public void testGetTopicOnClosedConsumer() throws Exception
{
- topicConsumer.close();
-
- try
- {
- ((TopicSubscriber)topicConsumer).getTopic();
- }
- catch(javax.jms.IllegalStateException e)
- {
- // OK
- }
+ Connection consumerConnection = null;
+
+ try
+ {
+ consumerConnection = cf.createConnection();
+
+ Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer topicConsumer = consumerSession.createConsumer(topic1);
+
+ topicConsumer.close();
+
+ try
+ {
+ ((TopicSubscriber)topicConsumer).getTopic();
+ }
+ catch(javax.jms.IllegalStateException e)
+ {
+ // OK
+ }
+ }
+ finally
+ {
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
}
public void testGetQueue() throws Exception
{
- Queue q = ((QueueReceiver)queueConsumer).getQueue();
- assertEquals(queue, q);
+ Connection consumerConnection = null;
+
+ try
+ {
+ consumerConnection = cf.createConnection();
+
+ Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer queueConsumer = consumerSession.createConsumer(queue1);
+
+ Queue q = ((QueueReceiver)queueConsumer).getQueue();
+
+ assertEquals(queue1, q);
+ }
+ finally
+ {
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
}
public void testGetQueueOnClosedConsumer() throws Exception
{
- queueConsumer.close();
-
- try
- {
- ((QueueReceiver)queueConsumer).getQueue();
- }
- catch(javax.jms.IllegalStateException e)
- {
- // OK
- }
+ Connection consumerConnection = null;
+
+ try
+ {
+ consumerConnection = cf.createConnection();
+
+ Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer queueConsumer = consumerSession.createConsumer(queue1);
+
+ queueConsumer.close();
+
+ try
+ {
+ ((QueueReceiver)queueConsumer).getQueue();
+ }
+ catch(javax.jms.IllegalStateException e)
+ {
+ // OK
+ }
+ }
+ finally
+ {
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
}
public void testReceiveOnTopicTimeoutNoMessage() throws Exception
{
- if (log.isTraceEnabled()) log.trace("testReceiveOnTopicTimeoutNoMessage");
- Message m = topicConsumer.receive(1000);
- assertNull(m);
+ Connection consumerConnection = null;
+
+ try
+ {
+ consumerConnection = cf.createConnection();
+
+ Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer topicConsumer = consumerSession.createConsumer(topic1);
+
+ Message m = topicConsumer.receive(1000);
+
+ assertNull(m);
+ }
+ finally
+ {
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
}
public void testReceiveOnTopicConnectionStopped() throws Exception
{
- if (log.isTraceEnabled()) log.trace("testReceiveOnTopicConnectionStopped");
- consumerConnection.stop();
-
- final Message m = producerSession.createMessage();
- new Thread(new Runnable()
- {
- public void run()
- {
- try
- {
- // this is needed to make sure the main thread has enough time to block
- Thread.sleep(1000);
- topicProducer.send(m);
- }
- catch(Exception e)
- {
- log.error(e);
- }
- }
- }, "Producer").start();
-
- assertNull(topicConsumer.receive(1500));
+ Connection producerConnection = null;
+
+ Connection consumerConnection = null;
+
+ try
+ {
+ producerConnection = cf.createConnection();
+
+ consumerConnection = cf.createConnection();
+
+ Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ final MessageProducer topicProducer = producerSession.createProducer(topic1);
+
+ MessageConsumer topicConsumer = consumerSession.createConsumer(topic1);
+
+ final Message m = producerSession.createMessage();
+ new Thread(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ // this is needed to make sure the main thread has enough time to block
+ Thread.sleep(1000);
+ topicProducer.send(m);
+ }
+ catch(Exception e)
+ {
+ log.error(e);
+ }
+ }
+ }, "Producer").start();
+
+ assertNull(topicConsumer.receive(1500));
+ }
+ finally
+ {
+ if (producerConnection != null)
+ {
+ producerConnection.close();
+ }
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
}
public void testReceiveOnTopicTimeout() throws Exception
{
- if (log.isTraceEnabled()) log.trace("testReceiveOnTopicTimeout");
- consumerConnection.start();
-
- final Message m1 = producerSession.createMessage();
- new Thread(new Runnable()
- {
- public void run()
- {
- try
- {
- // this is needed to make sure the main thread has enough time to block
- Thread.sleep(1000);
- topicProducer.send(m1);
- }
- catch(Exception e)
- {
- log.error(e);
- }
- }
- }, "Producer").start();
-
- Message m2 = topicConsumer.receive(1500);
- assertEquals(m1.getJMSMessageID(), m2.getJMSMessageID());
+ Connection producerConnection = null;
+
+ Connection consumerConnection = null;
+
+ try
+ {
+ producerConnection = cf.createConnection();
+
+ consumerConnection = cf.createConnection();
+
+ Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ final MessageProducer topicProducer = producerSession.createProducer(topic1);
+
+ MessageConsumer topicConsumer = consumerSession.createConsumer(topic1);
+
+ consumerConnection.start();
+
+ final Message m1 = producerSession.createMessage();
+ new Thread(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ // this is needed to make sure the main thread has enough time to block
+ Thread.sleep(1000);
+ topicProducer.send(m1);
+ }
+ catch(Exception e)
+ {
+ log.error(e);
+ }
+ }
+ }, "Producer").start();
+
+ Message m2 = topicConsumer.receive(1500);
+ assertEquals(m1.getJMSMessageID(), m2.getJMSMessageID());
+ }
+ finally
+ {
+ if (producerConnection != null)
+ {
+ producerConnection.close();
+ }
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
}
public void testReceiveOnTopic() throws Exception
{
- if (log.isTraceEnabled()) log.trace("testReceiveOnTopic");
- consumerConnection.start();
+ Connection producerConnection = null;
+
+ Connection consumerConnection = null;
+
+ try
+ {
+ producerConnection = cf.createConnection();
+
+ consumerConnection = cf.createConnection();
+
+ Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ final MessageProducer topicProducer = producerSession.createProducer(topic1);
+
+ MessageConsumer topicConsumer = consumerSession.createConsumer(topic1);
+
+ consumerConnection.start();
+
+ final Message m1 = producerSession.createMessage();
+ new Thread(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ // this is needed to make sure the main thread has enough time to block
+ Thread.sleep(1000);
+ topicProducer.send(m1);
+ }
+ catch(Exception e)
+ {
+ log.error(e);
+ }
+ }
+ }, "Producer").start();
+
+ Message m2 = topicConsumer.receive(3000);
- final Message m1 = producerSession.createMessage();
- new Thread(new Runnable()
- {
- public void run()
- {
- try
- {
- // this is needed to make sure the main thread has enough time to block
- Thread.sleep(1000);
- topicProducer.send(m1);
- }
- catch(Exception e)
- {
- log.error(e);
- }
- }
- }, "Producer").start();
-
- Message m2 = topicConsumer.receive(3000);
-
- if (log.isTraceEnabled()) log.trace("m1:" + m1 + ", m2:" + m2) ;
-
- assertEquals(m1.getJMSMessageID(), m2.getJMSMessageID());
+ assertEquals(m1.getJMSMessageID(), m2.getJMSMessageID());
+ }
+ finally
+ {
+ if (producerConnection != null)
+ {
+ producerConnection.close();
+ }
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
}
-
-
public void testReceiveNoWaitOnTopic() throws Exception
{
- consumerConnection.start();
-
- Message m = topicConsumer.receiveNoWait();
-
- assertNull(m);
-
- Message m1 = producerSession.createMessage();
- topicProducer.send(m1);
-
- // block this thread for a while to allow ServerConsumerDelegate's delivery thread to kick in
- Thread.sleep(500);
-
- m = topicConsumer.receiveNoWait();
-
- assertEquals(m1.getJMSMessageID(), m.getJMSMessageID());
+ Connection producerConnection = null;
+
+ Connection consumerConnection = null;
+
+ try
+ {
+ producerConnection = cf.createConnection();
+
+ consumerConnection = cf.createConnection();
+
+ Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ final MessageProducer topicProducer = producerSession.createProducer(topic1);
+
+ MessageConsumer topicConsumer = consumerSession.createConsumer(topic1);
+
+ consumerConnection.start();
+
+ Message m = topicConsumer.receiveNoWait();
+
+ assertNull(m);
+
+ Message m1 = producerSession.createMessage();
+ topicProducer.send(m1);
+
+ // block this thread for a while to allow ServerConsumerDelegate's delivery thread to kick in
+ Thread.sleep(500);
+
+ m = topicConsumer.receiveNoWait();
+
+ assertEquals(m1.getJMSMessageID(), m.getJMSMessageID());
+ }
+ finally
+ {
+ if (producerConnection != null)
+ {
+ producerConnection.close();
+ }
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
}
-
-
-
/**
* The test sends a burst of messages and verifies if the consumer receives all of them.
*/
-
-
public void testStressReceiveOnQueue() throws Exception
{
- if (log.isTraceEnabled()) log.trace("testStressReceiveOnQueue");
- final int count = 100;
-
- consumerConnection.start();
-
- new Thread(new Runnable()
- {
- public void run()
- {
- try
- {
- // this is needed to make sure the main thread has enough time to block
- Thread.sleep(1000);
-
- for (int i = 0; i < count; i++)
- {
- Message m = producerSession.createMessage();
- queueProducer.send(m);
- }
- }
- catch(Exception e)
- {
- log.error(e);
- }
- }
- }, "ProducerTestThread").start();
-
- int received = 0;
- while(true)
- {
- Message m = queueConsumer.receive(1500);
- if (m == null)
- {
- break;
- }
- received++;
- }
-
- assertEquals(count, received);
+ Connection producerConnection = null;
+
+ Connection consumerConnection = null;
+
+ try
+ {
+ producerConnection = cf.createConnection();
+
+ consumerConnection = cf.createConnection();
+
+ final Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ final MessageProducer queueProducer = producerSession.createProducer(queue1);
+
+ MessageConsumer queueConsumer = consumerSession.createConsumer(queue1);
+
+ final int count = 100;
+
+ consumerConnection.start();
+
+ new Thread(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ for (int i = 0; i < count; i++)
+ {
+ Message m = producerSession.createMessage();
+ queueProducer.send(m);
+ }
+ }
+ catch(Exception e)
+ {
+ log.error(e);
+ }
+ }
+ }, "ProducerTestThread").start();
+
+ for (int i = 0; i < count; i++)
+ {
+ Message m = queueConsumer.receive(1500);
+ assertNotNull(m);
+ }
+ }
+ finally
+ {
+ if (producerConnection != null)
+ {
+ producerConnection.close();
+ }
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+
+ checkEmpty(queue1);
+ }
}
/**
* The test sends a burst of messages and verifies if the consumer receives all of them.
*/
-
-
-
-
public void testStressReceiveOnTopic() throws Exception
{
- if (log.isTraceEnabled()) log.trace("testStressReceiveOnTopic");
- final int count = 1000;
-
- consumerConnection.start();
-
- new Thread(new Runnable()
- {
- public void run()
- {
- try
- {
- // this is needed to make sure the main thread has enough time to block
- Thread.sleep(1000);
-
- for (int i = 0; i < count; i++)
- {
- Message m = producerSession.createMessage();
- topicProducer.send(m);
- }
- }
- catch(Exception e)
- {
- log.error(e);
- }
- }
- }, "ProducerTestThread").start();
-
- int received = 0;
- while(true)
- {
- Message m = topicConsumer.receive(1500);
- if (m == null)
- {
- break;
- }
- received++;
- }
-
- assertEquals(count, received);
-
+ Connection producerConnection = null;
+
+ Connection consumerConnection = null;
+
+ try
+ {
+ producerConnection = cf.createConnection();
+
+ consumerConnection = cf.createConnection();
+
+ final Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ final MessageProducer topicProducer = producerSession.createProducer(topic1);
+
+ MessageConsumer topicConsumer = consumerSession.createConsumer(topic1);
+
+ final int count = 1000;
+
+ consumerConnection.start();
+
+ new Thread(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ // this is needed to make sure the main thread has enough time to block
+ Thread.sleep(1000);
+
+ for (int i = 0; i < count; i++)
+ {
+ Message m = producerSession.createMessage();
+ topicProducer.send(m);
+ }
+ }
+ catch(Exception e)
+ {
+ log.error(e);
+ }
+ }
+ }, "ProducerTestThread").start();
+
+ for (int i = 0; i < count; i++)
+ {
+ Message m = topicConsumer.receive(1500);
+ assertNotNull(m);
+ }
+
+ checkEmpty(topic1);
+ }
+ finally
+ {
+ if (producerConnection != null)
+ {
+ producerConnection.close();
+ }
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
}
-
-
public void testReceiveOnClose() throws Exception
{
- if (log.isTraceEnabled()) log.trace("testReceiveOnClose");
- consumerConnection.start();
- final Latch latch = new Latch();
- Thread closerThread = new Thread(new Runnable()
- {
- public void run()
- {
- try
- {
- // this is needed to make sure the main thread has enough time to block
- Thread.sleep(1000);
- topicConsumer.close();
- }
- catch(Exception e)
- {
- log.error(e);
- }
- finally
- {
- latch.release();
- }
- }
- }, "closing thread");
- closerThread.start();
-
- assertNull(topicConsumer.receive(3000));
-
- // wait for the closing thread to finish
- latch.acquire();
+ Connection consumerConnection = null;
+
+ try
+ {
+ consumerConnection = cf.createConnection();
+
+ Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ final MessageConsumer topicConsumer = consumerSession.createConsumer(topic1);
+
+ consumerConnection.start();
+ final Latch latch = new Latch();
+ Thread closerThread = new Thread(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ // this is needed to make sure the main thread has enough time to block
+ Thread.sleep(1000);
+ topicConsumer.close();
+ }
+ catch(Exception e)
+ {
+ log.error(e);
+ }
+ finally
+ {
+ latch.release();
+ }
+ }
+ }, "closing thread");
+ closerThread.start();
+
+ assertNull(topicConsumer.receive(1500));
+
+ // wait for the closing thread to finish
+ latch.acquire();
+ }
+ finally
+ {
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
}
/** to be used by testTimeoutReceiveOnClose */
@@ -1635,11 +2105,13 @@
Object waitMonitor;
long timeToSleep;
+ MessageConsumer topicConsumer;
- public ThreadCloser( Object waitMonitor, long timeToSleep)
+ public ThreadCloser( Object waitMonitor, long timeToSleep, MessageConsumer topicConsumer)
{
this.waitMonitor=waitMonitor;
this.timeToSleep=timeToSleep;
+ this.topicConsumer = topicConsumer;
}
@@ -1674,11 +2146,13 @@
long t1;
long t2;
Object receivedObject;
+ MessageConsumer topicConsumer;
- public ThreadReceiver(Object waitMonitor, long timeToWait)
+ public ThreadReceiver(Object waitMonitor, long timeToWait, MessageConsumer topicConsumer)
{
this.waitMonitor=waitMonitor;
this.timeToWait=timeToWait;
+ this.topicConsumer = topicConsumer;
}
public void run()
@@ -1706,33 +2180,52 @@
public void testTimeoutReceiveOnClose() throws Exception
{
- System.gc(); /// If A GC need to be executed, it' s better to be executed now
- Thread.sleep(1000);
- if (log.isTraceEnabled()) log.trace("testTimeoutReceiveOnClose");
+ Connection consumerConnection = null;
- Object monitor = new Object();
- ThreadCloser closer = null;
- ThreadReceiver receiver = new ThreadReceiver(monitor,2000);
+ try
+ {
+ consumerConnection = cf.createConnection();
- closer = new ThreadCloser(monitor,1000);
- receiver= new ThreadReceiver(monitor,2000);
- closer.start();
- receiver.start();
- Thread.sleep(2000);
- synchronized (monitor)
- {
- monitor.notifyAll();
- }
- closer.join();
- receiver.join();
+ Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer topicConsumer = consumerSession.createConsumer(topic1);
+
+ //This is a really weird test - the received object is always going to be null since no message is sent!!
- assertNull(receiver.receivedObject);
+ System.gc(); /// If A GC need to be executed, it' s better to be executed now
+ Thread.sleep(1000);
+ if (log.isTraceEnabled()) log.trace("testTimeoutReceiveOnClose");
- log.info("Elapsed time was " + (receiver.t2-receiver.t1));
+ Object monitor = new Object();
+ ThreadCloser closer = null;
+ ThreadReceiver receiver = null;
- // We need to make sure the
- assertTrue("Receive was supposed to receive a notification before 2 seconds",receiver.t2-receiver.t1<=1500);
+ closer = new ThreadCloser(monitor,1000, topicConsumer);
+ receiver= new ThreadReceiver(monitor,2000, topicConsumer);
+ closer.start();
+ receiver.start();
+ Thread.sleep(2000);
+ synchronized (monitor)
+ {
+ monitor.notifyAll();
+ }
+ closer.join();
+ receiver.join();
+
+ assertNull(receiver.receivedObject);
+
+ log.info("Elapsed time was " + (receiver.t2-receiver.t1));
+
+ // We need to make sure the
+ assertTrue("Receive was supposed to receive a notification before 2 seconds",receiver.t2-receiver.t1<=1500);
+ }
+ finally
+ {
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
}
//
@@ -1741,21 +2234,49 @@
public void testMessageListenerOnTopic() throws Exception
{
- if (log.isTraceEnabled()) log.trace("testMessageListenerOnTopic");
+ Connection producerConnection = null;
+
+ Connection consumerConnection = null;
+
+ try
+ {
+ producerConnection = cf.createConnection();
+
+ consumerConnection = cf.createConnection();
+
+ Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer topicProducer = producerSession.createProducer(topic1);
+
+ MessageConsumer topicConsumer = consumerSession.createConsumer(topic1);
- MessageListenerImpl l = new MessageListenerImpl();
- topicConsumer.setMessageListener(l);
-
- consumerConnection.start();
-
- Message m1 = producerSession.createMessage();
- topicProducer.send(m1);
-
- // block the current thread until the listener gets something; this is to avoid closing
- // the connection too early
- l.waitForMessages();
-
- assertEquals(m1.getJMSMessageID(), l.getNextMessage().getJMSMessageID());
+ MessageListenerImpl l = new MessageListenerImpl();
+ topicConsumer.setMessageListener(l);
+
+ consumerConnection.start();
+
+ Message m1 = producerSession.createMessage();
+ topicProducer.send(m1);
+
+ // block the current thread until the listener gets something; this is to avoid closing
+ // the connection too early
+ l.waitForMessages();
+
+ assertEquals(m1.getJMSMessageID(), l.getNextMessage().getJMSMessageID());
+ }
+ finally
+ {
+ if (producerConnection != null)
+ {
+ producerConnection.close();
+ }
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
}
@@ -1830,64 +2351,107 @@
public void testSetMessageListenerTwice() throws Exception
{
- if (log.isTraceEnabled()) log.trace("testSetMessageListenerTwice");
- MessageListenerImpl listener1 = new MessageListenerImpl();
+ Connection producerConnection = null;
+
+ Connection consumerConnection = null;
+
+ try
+ {
+ producerConnection = cf.createConnection();
+
+ consumerConnection = cf.createConnection();
+
+ Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer topicProducer = producerSession.createProducer(topic1);
+
+ MessageConsumer topicConsumer = consumerSession.createConsumer(topic1);
+
+ MessageListenerImpl listener1 = new MessageListenerImpl();
+
+ topicConsumer.setMessageListener(listener1);
- topicConsumer.setMessageListener(listener1);
- log.trace("Set message listener1");
+ MessageListenerImpl listener2 = new MessageListenerImpl();
+
+ topicConsumer.setMessageListener(listener2);
- MessageListenerImpl listener2 = new MessageListenerImpl();
+ consumerConnection.start();
+
+ Message m1 = producerSession.createMessage();
+ topicProducer.send(m1);
+
+ // block the current thread until the listener gets something; this is to avoid closing
+ // connection too early
- topicConsumer.setMessageListener(listener2);
- log.trace("Set message listener2");
-
- consumerConnection.start();
-
- Message m1 = producerSession.createMessage();
- topicProducer.send(m1);
-
- // block the current thread until the listener gets something; this is to avoid closing
- // connection too early
- //log.trace("Waiting for messages....");
-
- listener2.waitForMessages();
-
- assertEquals(m1.getJMSMessageID(), listener2.getNextMessage().getJMSMessageID());
- assertEquals(0, listener1.size());
+ listener2.waitForMessages();
+
+ assertEquals(m1.getJMSMessageID(), listener2.getNextMessage().getJMSMessageID());
+ assertEquals(0, listener1.size());
+ }
+ finally
+ {
+ if (producerConnection != null)
+ {
+ producerConnection.close();
+ }
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
}
public void testSetMessageListenerWhileReceiving() throws Exception
{
- if (log.isTraceEnabled()) log.trace("testSetMessageListenerWhileReceiving");
- consumerConnection.start();
- worker1= new Thread(new Runnable()
- {
- public void run()
- {
- try
- {
- topicConsumer.receive(3000);
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }}, "Receiver");
-
- worker1.start();
-
- Thread.sleep(1000);
-
- try
- {
- topicConsumer.setMessageListener(new MessageListenerImpl());
- fail("should have thrown JMSException");
- }
- catch(JMSException e)
- {
- // ok
- log.trace(e.getMessage());
- }
+ Connection consumerConnection = null;
+
+ try
+ {
+ consumerConnection = cf.createConnection();
+
+ Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ final MessageConsumer topicConsumer = consumerSession.createConsumer(topic1);
+
+ consumerConnection.start();
+ Thread worker1= new Thread(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ topicConsumer.receive(3000);
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ }
+ }}, "Receiver");
+
+ worker1.start();
+
+ Thread.sleep(1000);
+
+ try
+ {
+ topicConsumer.setMessageListener(new MessageListenerImpl());
+ fail("should have thrown JMSException");
+ }
+ catch(JMSException e)
+ {
+ // ok
+ log.trace(e.getMessage());
+ }
+ }
+ finally
+ {
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
}
// This is commented out until http://jira.jboss.com/jira/browse/JBMESSAGING-983 is complete
@@ -1956,31 +2520,65 @@
// Test that stop doesn't in any way break subsequent close
public void testCloseAfterStop() throws Exception
{
- MessageListener myListener = new MessageListener() {
- public void onMessage(Message message)
- {
- try
- {
- Thread.sleep(100);
- }
- catch (InterruptedException e)
- {
- // Ignore
- }
- }
- };
-
- queueConsumer.setMessageListener(myListener);
-
- consumerConnection.start();
-
- for (int i = 0; i < 100; i++)
- {
- queueProducer.send(producerSession.createTextMessage("Message #" + Integer.toString(i)));
- }
-
- consumerConnection.stop();
- consumerConnection.close();
+ Connection producerConnection = null;
+
+ Connection consumerConnection = null;
+
+ try
+ {
+ producerConnection = cf.createConnection();
+
+ consumerConnection = cf.createConnection();
+
+ Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer queueProducer = producerSession.createProducer(queue1);
+
+ MessageConsumer queueConsumer = consumerSession.createConsumer(queue1);
+
+ MessageListener myListener = new MessageListener() {
+ public void onMessage(Message message)
+ {
+ try
+ {
+ Thread.sleep(100);
+ }
+ catch (InterruptedException e)
+ {
+ // Ignore
+ }
+ }
+ };
+
+ queueConsumer.setMessageListener(myListener);
+
+ consumerConnection.start();
+
+ for (int i = 0; i < 100; i++)
+ {
+ queueProducer.send(producerSession.createTextMessage("Message #" + Integer.toString(i)));
+ }
+
+ consumerConnection.stop();
+
+ consumerConnection.close();
+
+ consumerConnection = null;
+ }
+ finally
+ {
+ if (producerConnection != null)
+ {
+ producerConnection.close();
+ }
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ removeAllMessages(queue1.getQueueName(), true, 0);
+ }
}
//
@@ -1989,71 +2587,112 @@
public void testTwoConsumersNonTransacted() throws Exception
{
+ Connection producerConnection = null;
+
+ Connection consumerConnection = null;
+
+ try
+ {
+ producerConnection = cf.createConnection();
+
+ Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer queueProducer = producerSession.createProducer(queue1);
+
+ TextMessage tm = producerSession.createTextMessage();
+ tm.setText("One");
+ queueProducer.send(tm);
+ tm.setText("Two");
+ queueProducer.send(tm);
- consumerSession.close();
-
- TextMessage tm = producerSession.createTextMessage();
- tm.setText("One");
- queueProducer.send(tm);
- tm.setText("Two");
- queueProducer.send(tm);
-
- // recreate the connection and receive the first message
- consumerConnection = cf.createConnection();
- consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- queueConsumer = consumerSession.createConsumer(queue);
- consumerConnection.start();
-
- TextMessage m = (TextMessage)queueConsumer.receive(1500);
- assertEquals("One", m.getText());
-
- consumerConnection.close();
-
- // recreate the connection and receive the second message
- consumerConnection = cf.createConnection();
- consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- queueConsumer = consumerSession.createConsumer(queue);
- consumerConnection.start();
-
- m = (TextMessage)queueConsumer.receive(1500);
- assertEquals("Two", m.getText());
-
- consumerConnection.close();
+ // recreate the connection and receive the first message
+ consumerConnection = cf.createConnection();
+ Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer queueConsumer = consumerSession.createConsumer(queue1);
+ consumerConnection.start();
+
+ TextMessage m = (TextMessage)queueConsumer.receive(1500);
+ assertEquals("One", m.getText());
+
+ consumerConnection.close();
+ consumerConnection = null;
+
+ // recreate the connection and receive the second message
+ consumerConnection = cf.createConnection();
+ consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ queueConsumer = consumerSession.createConsumer(queue1);
+ consumerConnection.start();
+
+ m = (TextMessage)queueConsumer.receive(1500);
+ assertEquals("Two", m.getText());
+ }
+ finally
+ {
+ if (producerConnection != null)
+ {
+ producerConnection.close();
+ }
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ }
}
public void testTwoConsumersTransacted() throws Exception
{
+ Connection producerConnection = null;
+
+ Connection consumerConnection = null;
+
+ try
+ {
+ producerConnection = cf.createConnection();
+
+ Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer queueProducer = producerSession.createProducer(queue1);
- consumerSession.close();
-
- TextMessage tm = producerSession.createTextMessage();
- tm.setText("One");
- queueProducer.send(tm);
- tm.setText("Two");
- queueProducer.send(tm);
-
- // recreate the connection and receive the first message
- consumerConnection = cf.createConnection();
- consumerSession = consumerConnection.createSession(true, -1);
- queueConsumer = consumerSession.createConsumer(queue);
- consumerConnection.start();
-
- TextMessage m = (TextMessage)queueConsumer.receive(1500);
- assertEquals("One", m.getText());
-
- consumerSession.commit();
- consumerConnection.close();
-
- // recreate the connection and receive the second message
- consumerConnection = cf.createConnection();
- consumerSession = consumerConnection.createSession(true, -1);
- queueConsumer = consumerSession.createConsumer(queue);
- consumerConnection.start();
-
- m = (TextMessage)queueConsumer.receive(1500);
- assertEquals("Two", m.getText());
-
- consumerConnection.close();
+ TextMessage tm = producerSession.createTextMessage();
+ tm.setText("One");
+ queueProducer.send(tm);
+ tm.setText("Two");
+ queueProducer.send(tm);
+
+ // recreate the connection and receive the first message
+ consumerConnection = cf.createConnection();
+ Session consumerSession = consumerConnection.createSession(true, -1);
+ MessageConsumer queueConsumer = consumerSession.createConsumer(queue1);
+ consumerConnection.start();
+
+ TextMessage m = (TextMessage)queueConsumer.receive(1500);
+ assertEquals("One", m.getText());
+
+ consumerSession.commit();
+ consumerConnection.close();
+ consumerConnection = null;
+
+ // recreate the connection and receive the second message
+ consumerConnection = cf.createConnection();
+ consumerSession = consumerConnection.createSession(true, -1);
+ queueConsumer = consumerSession.createConsumer(queue1);
+ consumerConnection.start();
+
+ m = (TextMessage)queueConsumer.receive(1500);
+ assertEquals("Two", m.getText());
+ }
+ finally
+ {
+ if (producerConnection != null)
+ {
+ producerConnection.close();
+ }
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ removeAllMessages(queue1.getQueueName(), true, 0);
+ }
}
//
@@ -2069,25 +2708,24 @@
try
{
-
conn1 = cf.createConnection();
Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer producer1 = sess1.createProducer(topic);
+ MessageProducer producer1 = sess1.createProducer(topic1);
producer1.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- MessageConsumer consumer1 = sess1.createConsumer(topic, null, true);
+ MessageConsumer consumer1 = sess1.createConsumer(topic1, null, true);
conn2 = cf.createConnection();
Session sess2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
assertEquals(Session.AUTO_ACKNOWLEDGE, sess2.getAcknowledgeMode());
- MessageConsumer consumer2 = sess2.createConsumer(topic, null, true);
+ MessageConsumer consumer2 = sess2.createConsumer(topic1, null, true);
// we need different session because we cannot access the same session from different
// threads
Session sess3 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
assertEquals(Session.AUTO_ACKNOWLEDGE, sess3.getAcknowledgeMode());
- MessageConsumer consumer3 = sess3.createConsumer(topic, null, true);
+ MessageConsumer consumer3 = sess3.createConsumer(topic1, null, true);
//Consumer 1 should not get the message but consumers 2 and 3 should
@@ -2141,10 +2779,8 @@
assertTrue(!tr3.exceptionThrown);
assertNull(tr1.m);
-
assertNotNull(tr2.m);
assertNotNull(tr3.m);
-
}
finally
{
@@ -2157,14 +2793,8 @@
conn2.close();
}
}
-
}
-
-
-
-
-
/*
*
* Also see JMS 1.1 Spec. 6.12
@@ -2175,7 +2805,6 @@
try
{
-
conn1 = cf.createConnection();
conn1.start();
@@ -2184,21 +2813,14 @@
Session sess1 = conn1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
Session sess2 = conn1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+ MessageConsumer cons1 = sess1.createConsumer(topic1);
- log.trace("careting consumer1");
- MessageConsumer cons1 = sess1.createConsumer(topic);
+ MessageConsumer cons2 = sess2.createConsumer(topic1);
- log.trace("creating consumer2");
- MessageConsumer cons2 = sess2.createConsumer(topic);
-
- log.trace("starting connection");
-
conn1.start();
- log.trace("started connection");
-
Session sess3 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess3.createProducer(topic);
+ MessageProducer prod = sess3.createProducer(topic1);
prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
TextMessage tm = sess3.createTextMessage("nurse!");
@@ -2224,7 +2846,6 @@
assertNotNull(tm2);
assertEquals("nurse!", tm2.getText());
-
//but tm1 should not be redelivered
tm1 = (TextMessage)cons1.receive(1500);
assertNull(tm1);
@@ -2237,7 +2858,6 @@
conn1.close();
}
}
-
}
@@ -2259,17 +2879,17 @@
conn1.start();
Session sess1 = conn1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageProducer prod = sess1.createProducer(topic);
+ MessageProducer prod = sess1.createProducer(topic1);
prod.setDeliveryMode(DeliveryMode.PERSISTENT);
final int NUM_MESSAGES = 1;
- MessageConsumer cons = sess1.createConsumer(topic);
+ MessageConsumer cons = sess1.createConsumer(topic1);
for (int i = 0; i < NUM_MESSAGES; i++)
{
TextMessage tm = sess1.createTextMessage("helloxyz");
- prod.send(topic, tm);
+ prod.send(topic1, tm);
}
//receive but don't ack
@@ -2285,17 +2905,10 @@
assertEquals(NUM_MESSAGES, count);
conn1.close();
-
- conn2 = cf.createConnection();
- conn2.start();
-
- Session sess2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer cons2 = sess2.createConsumer(topic);
- Message m = cons2.receive(1500);
- assertNull(m);
-
- conn2.close();
+
+ conn1 = null;
+
+ checkEmpty(topic1);
}
finally
{
@@ -2308,8 +2921,6 @@
conn2.close();
}
}
-
-
}
//Check messages have correct type after being resurrected from persistent storage
@@ -2326,7 +2937,7 @@
//Send some persistent messages to a queue with no receivers
Session sessSend = theConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer theProducer = sessSend.createProducer(queue2);
+ MessageProducer theProducer = sessSend.createProducer(queue1);
theProducer.setDeliveryMode(DeliveryMode.PERSISTENT);
Message m = sessSend.createMessage();
@@ -2360,7 +2971,7 @@
Session sessReceive = theOtherConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer theConsumer = sessReceive.createConsumer(queue2);
+ MessageConsumer theConsumer = sessReceive.createConsumer(queue1);
Message m2 = theConsumer.receive(1500);
@@ -2381,6 +2992,9 @@
StreamMessage sm2 = (StreamMessage)theConsumer.receive(1500);
assertEquals("aardvark", sm2.readString());
+
+ TextMessage tm2 = (TextMessage)theConsumer.receive(1500);
+ assertEquals("aardvark", tm2.getText());
}
finally
{
@@ -2393,13 +3007,8 @@
theOtherConn.close();
}
}
-
-
}
-
-
-
public void testDurableSubscriptionSimple() throws Exception
{
final String CLIENT_ID1 = "test-client-id1";
@@ -2413,10 +3022,10 @@
conn1.setClientID(CLIENT_ID1);
Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess1.createProducer(topic);
+ MessageProducer prod = sess1.createProducer(topic1);
prod.setDeliveryMode(DeliveryMode.PERSISTENT);
- MessageConsumer durable = sess1.createDurableSubscriber(topic, "mySubscription");
+ MessageConsumer durable = sess1.createDurableSubscriber(topic1, "mySubscription");
conn1.start();
@@ -2425,7 +3034,7 @@
for (int i = 0; i < NUM_MESSAGES; i++)
{
TextMessage tm = sess1.createTextMessage("hello");
- prod.send(topic, tm);
+ prod.send(topic1, tm);
}
int count = 0;
@@ -2452,7 +3061,6 @@
conn1.close();
}
}
-
}
@@ -2462,55 +3070,46 @@
Connection conn1 = null;
Connection conn2 = null;
+ Connection conn3 = null;
try
{
-
conn1 = cf.createConnection();
conn1.setClientID(CLIENT_ID1);
Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
- log.debug("creating first durable subscription");
- sess1.createDurableSubscriber(topic, "mySubscription1");
+ sess1.createDurableSubscriber(topic1, "mySubscription1");
- log.debug("creating the second durable subscription");
- sess1.createDurableSubscriber(topic, "mySubscription2");
+ sess1.createDurableSubscriber(topic1, "mySubscription2");
- log.debug("closing conn1");
conn1.close();
conn2 = cf.createConnection();
conn2.setClientID(CLIENT_ID1);
Session sess2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer producer = sess2.createProducer(topic);
+ MessageProducer producer = sess2.createProducer(topic1);
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
final int NUM_MESSAGES = 50;
- log.debug("sending messages");
-
for (int i = 0; i < NUM_MESSAGES; i++)
{
TextMessage tm = sess2.createTextMessage("hello");
producer.send(tm);
}
- log.debug("all " + NUM_MESSAGES + " messages sent");
-
sess2.unsubscribe("mySubscription1");
- log.debug("unsubscribed 'mySubscription1'");
-
conn2.close();
- Connection conn3 = cf.createConnection();
+ conn3 = cf.createConnection();
conn3.setClientID(CLIENT_ID1);
conn3.start();
Session sess3 = conn3.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer durable3 = sess3.createDurableSubscriber(topic, "mySubscription2");
+ MessageConsumer durable3 = sess3.createDurableSubscriber(topic1, "mySubscription2");
int count = 0;
while (true)
@@ -2528,13 +3127,18 @@
log.debug("received " + NUM_MESSAGES + " messages");
- MessageConsumer durable4 = sess3.createDurableSubscriber(topic, "mySubscription1");
+ MessageConsumer durable4 = sess3.createDurableSubscriber(topic1, "mySubscription1");
Message m = durable4.receive(1000);
assertNull(m);
- conn3.close();
-
+ durable3.close();
+
+ sess3.unsubscribe("mySubscription2");
+
+ durable4.close();
+
+ sess3.unsubscribe("mySubscription1");
}
finally
{
@@ -2546,12 +3150,13 @@
{
conn2.close();
}
+ if (conn3 != null)
+ {
+ conn3.close();
+ }
}
-
}
-
-
public void testDurableSubscriptionDataRemaining() throws Exception
{
final String CLIENT_ID1 = "test-client-id1";
@@ -2570,26 +3175,24 @@
try
{
-
// Create a durable subscriber on one connection and close it
conn1 = cf.createConnection();
conn1.setClientID(CLIENT_ID1);
sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer durable = sess1.createDurableSubscriber(topic, "mySubscription");
+ MessageConsumer durable = sess1.createDurableSubscriber(topic1, "mySubscription");
conn1.close();
-
// Send some messages on another connection and close it
conn2 = cf.createConnection();
conn2.setClientID(CLIENT_ID1);
Session sess2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod2 = sess2.createProducer(topic);
+ MessageProducer prod2 = sess2.createProducer(topic1);
prod2.setDeliveryMode(DeliveryMode.PERSISTENT);
final int NUM_MESSAGES = 10;
for (int i = 0; i < NUM_MESSAGES; i++)
{
TextMessage tm = sess2.createTextMessage("hello");
- prod2.send(topic, tm);
+ prod2.send(topic1, tm);
}
conn2.close();
@@ -2598,7 +3201,7 @@
conn3.setClientID(CLIENT_ID1);
conn3.start();
sess3 = conn3.createSession(false, Session.AUTO_ACKNOWLEDGE);
- durable = sess3.createDurableSubscriber(topic, "mySubscription");
+ durable = sess3.createDurableSubscriber(topic1, "mySubscription");
int count = 0;
while (true)
{
@@ -2618,7 +3221,7 @@
conn4.setClientID(CLIENT_ID1);
conn4.start();
sess4 = conn4.createSession(false, Session.AUTO_ACKNOWLEDGE);
- durable = sess4.createDurableSubscriber(topic, "mySubscription");
+ durable = sess4.createDurableSubscriber(topic1, "mySubscription");
TextMessage tm = (TextMessage)durable.receive(1000);
assertNull(tm);
@@ -2629,14 +3232,14 @@
conn5.setClientID(CLIENT_ID1);
conn5.start();
Session sess5 = conn5.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod5 = sess5.createProducer(topic);
+ MessageProducer prod5 = sess5.createProducer(topic1);
prod5.setDeliveryMode(DeliveryMode.PERSISTENT);
log.debug("sending.1 " + NUM_MESSAGES + " messages");
for (int i = 0; i < NUM_MESSAGES; i++)
{
TextMessage tm2 = sess5.createTextMessage("hello");
- prod5.send(topic, tm2);
+ prod5.send(topic1, tm2);
}
log.debug("unsubscribing mySubscription");
@@ -2651,7 +3254,7 @@
conn6.setClientID(CLIENT_ID1);
conn6.start();
sess6 = conn6.createSession(false, Session.AUTO_ACKNOWLEDGE);
- durable = sess6.createDurableSubscriber(topic, "mySubscription");
+ durable = sess6.createDurableSubscriber(topic1, "mySubscription");
TextMessage tm3 = (TextMessage)durable.receive(1000);
assertNull(tm3);
@@ -2689,10 +3292,8 @@
conn6.close();
}
}
-
}
-
public void testDurableSubscriptionReconnect() throws Exception
{
final String CLIENT_ID1 = "test-client-id1";
@@ -2706,30 +3307,23 @@
conn1.setClientID(CLIENT_ID1);
Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess1.createProducer(topic);
+ MessageProducer prod = sess1.createProducer(topic1);
prod.setDeliveryMode(DeliveryMode.PERSISTENT);
- log.debug("creating durable subscription");
- MessageConsumer durable = sess1.createDurableSubscriber(topic, "mySubscription");
- log.debug("durable subscription created");
+ MessageConsumer durable = sess1.createDurableSubscriber(topic1, "mySubscription");
conn1.start();
final int NUM_MESSAGES = 2;
-
- log.debug("sending messages ...");
-
for (int i = 0; i < NUM_MESSAGES; i++)
{
TextMessage tm = sess1.createTextMessage("hello");
- prod.send(topic, tm);
+ prod.send(topic1, tm);
}
final int NUM_TO_RECEIVE = NUM_MESSAGES - 1;
- log.debug("receiving messages ...");
-
for (int i = 0; i < NUM_TO_RECEIVE; i++)
{
TextMessage tm = (TextMessage)durable.receive(3000);
@@ -2748,10 +3342,8 @@
// Re-subscribe to the subscription
- log.trace("resubscribing");
+ MessageConsumer durable2 = sess2.createDurableSubscriber(topic1, "mySubscription");
- MessageConsumer durable2 = sess2.createDurableSubscriber(topic, "mySubscription");
-
conn2.start();
int count = 0;
@@ -2765,8 +3357,6 @@
count++;
}
- log.trace("Received " + count + " messages");
-
assertEquals(NUM_MESSAGES - NUM_TO_RECEIVE, count);
durable2.close();
@@ -2784,8 +3374,6 @@
conn2.close();
}
}
-
-
}
public void testDurableSubscriptionReconnectDifferentClientID() throws Exception
@@ -2803,10 +3391,10 @@
conn1.setClientID(CLIENT_ID1);
Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess1.createProducer(topic);
+ MessageProducer prod = sess1.createProducer(topic1);
prod.setDeliveryMode(DeliveryMode.PERSISTENT);
- MessageConsumer durable = sess1.createDurableSubscriber(topic, "mySubscription");
+ MessageConsumer durable = sess1.createDurableSubscriber(topic1, "mySubscription");
conn1.start();
@@ -2816,7 +3404,7 @@
for (int i = 0; i < NUM_MESSAGES; i++)
{
TextMessage tm = sess1.createTextMessage("hello");
- prod.send(topic, tm);
+ prod.send(topic1, tm);
}
final int NUM_TO_RECEIVE1 = 22;
@@ -2841,26 +3429,26 @@
Session sess2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
//Re-subscribe to the subscription
- MessageConsumer durable2 = sess2.createDurableSubscriber(topic, "mySubscription");
+ MessageConsumer durable2 = sess2.createDurableSubscriber(topic1, "mySubscription");
conn2.start();
- int count = 0;
- while (true)
- {
- TextMessage tm = (TextMessage)durable2.receive(1500);
- if (tm == null)
- {
- break;
- }
- count++;
- }
+ TextMessage tm = (TextMessage)durable2.receive(1500);
+ assertNull(tm);
+
+ durable2.close();
- assertEquals(0, count);
+ sess2.unsubscribe("mySubscription");
+
+ //Now need to remove the original subscription
+
+ conn1 = cf.createConnection();
- durable2.close();
+ conn1.setClientID(CLIENT_ID1);
- sess2.unsubscribe("mySubscription");
+ sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ sess1.unsubscribe("mySubscription");
}
finally
{
@@ -2873,11 +3461,8 @@
conn2.close();
}
}
-
}
-
-
public void testDurableSubscriptionInvalidUnsubscribe() throws Exception
{
final String CLIENT_ID1 = "test-client-id1";
@@ -2888,7 +3473,6 @@
{
conn1 = cf.createConnection();
-
conn1.setClientID(CLIENT_ID1);
Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -2911,9 +3495,6 @@
}
}
-
-
-
public void testDurableSubscriptionClientIDNotSet() throws Exception
{
//Client id must be set before creating a durable subscription
@@ -2933,7 +3514,7 @@
try
{
- sess1.createDurableSubscriber(topic, "mySubscription");
+ sess1.createDurableSubscriber(topic1, "mySubscription");
fail();
}
catch (JMSException e)
@@ -2951,239 +3532,337 @@
public void testRedeliveredDifferentSessions() throws Exception
{
- producerSession.close();
- consumerSession.close();
-
- Session sessProducer = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue);
- TextMessage tm = sessProducer.createTextMessage("testRedeliveredDifferentSessions");
- prod.send(tm);
-
- consumerConnection.start();
-
- Session sess1 = consumerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageConsumer cons1 = sess1.createConsumer(queue);
- TextMessage tm2 = (TextMessage)cons1.receive(3000);
+ Connection producerConnection = null;
- assertNotNull(tm2);
- assertEquals("testRedeliveredDifferentSessions", tm2.getText());
-
- //don't acknowledge it
- sess1.close();
-
- Session sess2 = consumerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageConsumer cons2 = sess2.createConsumer(queue);
- TextMessage tm3 = (TextMessage)cons2.receive(3000);
+ Connection consumerConnection = null;
- assertNotNull(tm3);
- assertEquals("testRedeliveredDifferentSessions", tm3.getText());
-
- assertTrue(tm3.getJMSRedelivered());
+ try
+ {
+ producerConnection = cf.createConnection();
+
+ consumerConnection = cf.createConnection();
+
+ Session sessProducer = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer prod = sessProducer.createProducer(queue1);
+ TextMessage tm = sessProducer.createTextMessage("testRedeliveredDifferentSessions");
+ prod.send(tm);
+
+ consumerConnection.start();
+
+ Session sess1 = consumerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+ MessageConsumer cons1 = sess1.createConsumer(queue1);
+ TextMessage tm2 = (TextMessage)cons1.receive(3000);
+
+ assertNotNull(tm2);
+ assertEquals("testRedeliveredDifferentSessions", tm2.getText());
+
+ //don't acknowledge it
+ sess1.close();
+
+ Session sess2 = consumerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+ MessageConsumer cons2 = sess2.createConsumer(queue1);
+ TextMessage tm3 = (TextMessage)cons2.receive(3000);
+
+ assertNotNull(tm3);
+ assertEquals("testRedeliveredDifferentSessions", tm3.getText());
+
+ assertTrue(tm3.getJMSRedelivered());
+ }
+ finally
+ {
+ if (producerConnection != null)
+ {
+ producerConnection.close();
+ }
+ if (consumerConnection != null)
+ {
+ consumerConnection.close();
+ }
+ removeAllMessages(queue1.getQueueName(), true, 0);
+ }
}
-
-
public void testRedelMessageListener1() throws Exception
{
- Connection conn = cf.createConnection();
-
- conn.start();
-
- Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
-
- MessageConsumer cons = sess.createConsumer(queue2);
-
- RedelMessageListenerImpl listener = new RedelMessageListenerImpl(false);
- listener.sess = sess;
-
- cons.setMessageListener(listener);
-
- MessageProducer prod = sess.createProducer(queue2);
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- TextMessage m1 = sess.createTextMessage("a");
- TextMessage m2 = sess.createTextMessage("b");
- TextMessage m3 = sess.createTextMessage("c");
-
- prod.send(m1);
- prod.send(m2);
- prod.send(m3);
-
-
- listener.waitForMessages();
-
- conn.close();
-
- assertFalse(listener.failed);
-
-
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+
+ conn.start();
+
+ Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+
+ MessageConsumer cons = sess.createConsumer(queue1);
+
+ RedelMessageListenerImpl listener = new RedelMessageListenerImpl(false);
+ listener.sess = sess;
+
+ cons.setMessageListener(listener);
+
+ MessageProducer prod = sess.createProducer(queue1);
+ prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ TextMessage m1 = sess.createTextMessage("a");
+ TextMessage m2 = sess.createTextMessage("b");
+ TextMessage m3 = sess.createTextMessage("c");
+
+ prod.send(m1);
+ prod.send(m2);
+ prod.send(m3);
+
+ listener.waitForMessages();
+
+ conn.close();
+ conn = null;
+
+ assertFalse(listener.failed);
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void testRedelMessageListener2() throws Exception
{
- Connection conn = cf.createConnection();
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
- conn.start();
-
- Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
-
- MessageConsumer cons = sess.createConsumer(queue2);
-
- RedelMessageListenerImpl listener = new RedelMessageListenerImpl(true);
- listener.sess = sess;
-
- cons.setMessageListener(listener);
-
- MessageProducer prod = sessSend.createProducer(queue2);
- TextMessage m1 = sess.createTextMessage("a");
- TextMessage m2 = sess.createTextMessage("b");
- TextMessage m3 = sess.createTextMessage("c");
-
- prod.send(m1);
- prod.send(m2);
- prod.send(m3);
-
- listener.waitForMessages();
-
- assertFalse(listener.failed);
-
- conn.close();
-
+ conn.start();
+
+ Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
+
+ MessageConsumer cons = sess.createConsumer(queue1);
+
+ RedelMessageListenerImpl listener = new RedelMessageListenerImpl(true);
+ listener.sess = sess;
+
+ cons.setMessageListener(listener);
+
+ MessageProducer prod = sessSend.createProducer(queue1);
+ TextMessage m1 = sess.createTextMessage("a");
+ TextMessage m2 = sess.createTextMessage("b");
+ TextMessage m3 = sess.createTextMessage("c");
+
+ prod.send(m1);
+ prod.send(m2);
+ prod.send(m3);
+
+ listener.waitForMessages();
+
+ assertFalse(listener.failed);
+
+ conn.close();
+
+ conn = null;
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void testExceptionMessageListener1() throws Exception
{
- Connection conn = cf.createConnection();
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
- conn.start();
-
- Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer cons = sess.createConsumer(queue2);
-
- ExceptionRedelMessageListenerImpl listener = new ExceptionRedelMessageListenerImpl(sess);
-
- cons.setMessageListener(listener);
-
- MessageProducer prod = sessSend.createProducer(queue2);
- TextMessage m1 = sess.createTextMessage("a");
- TextMessage m2 = sess.createTextMessage("b");
- TextMessage m3 = sess.createTextMessage("c");
-
- prod.send(m1);
- prod.send(m2);
- prod.send(m3);
-
- listener.waitForMessages();
-
- assertFalse(listener.failed);
-
- conn.close();
-
+ conn.start();
+
+ Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer cons = sess.createConsumer(queue1);
+
+ ExceptionRedelMessageListenerImpl listener = new ExceptionRedelMessageListenerImpl(sess);
+
+ cons.setMessageListener(listener);
+
+ MessageProducer prod = sessSend.createProducer(queue1);
+ TextMessage m1 = sess.createTextMessage("a");
+ TextMessage m2 = sess.createTextMessage("b");
+ TextMessage m3 = sess.createTextMessage("c");
+
+ prod.send(m1);
+ prod.send(m2);
+ prod.send(m3);
+
+ listener.waitForMessages();
+
+ assertFalse(listener.failed);
+
+ conn.close();
+
+ conn = null;
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void testExceptionMessageListener2() throws Exception
{
- Connection conn = cf.createConnection();
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
- conn.start();
-
- Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- Session sess = conn.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
-
- MessageConsumer cons = sess.createConsumer(queue2);
-
- ExceptionRedelMessageListenerImpl listener = new ExceptionRedelMessageListenerImpl(sess);
-
- cons.setMessageListener(listener);
-
- MessageProducer prod = sessSend.createProducer(queue2);
- TextMessage m1 = sess.createTextMessage("a");
- TextMessage m2 = sess.createTextMessage("b");
- TextMessage m3 = sess.createTextMessage("c");
-
- prod.send(m1);
- prod.send(m2);
- prod.send(m3);
-
- listener.waitForMessages();
-
- assertFalse(listener.failed);
-
- conn.close();
-
+ conn.start();
+
+ Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Session sess = conn.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
+
+ MessageConsumer cons = sess.createConsumer(queue1);
+
+ ExceptionRedelMessageListenerImpl listener = new ExceptionRedelMessageListenerImpl(sess);
+
+ cons.setMessageListener(listener);
+
+ MessageProducer prod = sessSend.createProducer(queue1);
+ TextMessage m1 = sess.createTextMessage("a");
+ TextMessage m2 = sess.createTextMessage("b");
+ TextMessage m3 = sess.createTextMessage("c");
+
+ prod.send(m1);
+ prod.send(m2);
+ prod.send(m3);
+
+ listener.waitForMessages();
+
+ assertFalse(listener.failed);
+
+ conn.close();
+
+ conn = null;
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void testExceptionMessageListener3() throws Exception
{
- Connection conn = cf.createConnection();
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
- conn.start();
-
- Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
-
- MessageConsumer cons = sess.createConsumer(queue2);
-
- ExceptionRedelMessageListenerImpl listener = new ExceptionRedelMessageListenerImpl(sess);
-
- cons.setMessageListener(listener);
-
- MessageProducer prod = sessSend.createProducer(queue2);
- TextMessage m1 = sess.createTextMessage("a");
- TextMessage m2 = sess.createTextMessage("b");
- TextMessage m3 = sess.createTextMessage("c");
-
- prod.send(m1);
- prod.send(m2);
- prod.send(m3);
-
- listener.waitForMessages();
-
- assertFalse(listener.failed);
-
- conn.close();
-
+ conn.start();
+
+ Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
+
+ MessageConsumer cons = sess.createConsumer(queue1);
+
+ ExceptionRedelMessageListenerImpl listener = new ExceptionRedelMessageListenerImpl(sess);
+
+ cons.setMessageListener(listener);
+
+ MessageProducer prod = sessSend.createProducer(queue1);
+ TextMessage m1 = sess.createTextMessage("a");
+ TextMessage m2 = sess.createTextMessage("b");
+ TextMessage m3 = sess.createTextMessage("c");
+
+ prod.send(m1);
+ prod.send(m2);
+ prod.send(m3);
+
+ listener.waitForMessages();
+
+ assertFalse(listener.failed);
+
+ conn.close();
+
+ conn = null;
+
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ removeAllMessages(queue1.getQueueName(), true, 0);
+ }
}
public void testExceptionMessageListener4() throws Exception
{
- Connection conn = cf.createConnection();
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
- conn.start();
-
- Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
-
- MessageConsumer cons = sess.createConsumer(queue2);
-
- ExceptionRedelMessageListenerImpl listener = new ExceptionRedelMessageListenerImpl(sess);
-
- cons.setMessageListener(listener);
-
- MessageProducer prod = sessSend.createProducer(queue2);
- TextMessage m1 = sess.createTextMessage("a");
- TextMessage m2 = sess.createTextMessage("b");
- TextMessage m3 = sess.createTextMessage("c");
-
- prod.send(m1);
- prod.send(m2);
- prod.send(m3);
-
- listener.waitForMessages();
-
- assertFalse(listener.failed);
-
- conn.close();
-
+ conn.start();
+
+ Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+
+ MessageConsumer cons = sess.createConsumer(queue1);
+
+ ExceptionRedelMessageListenerImpl listener = new ExceptionRedelMessageListenerImpl(sess);
+
+ cons.setMessageListener(listener);
+
+ MessageProducer prod = sessSend.createProducer(queue1);
+ TextMessage m1 = sess.createTextMessage("a");
+ TextMessage m2 = sess.createTextMessage("b");
+ TextMessage m3 = sess.createTextMessage("c");
+
+ prod.send(m1);
+ prod.send(m2);
+ prod.send(m3);
+
+ listener.waitForMessages();
+
+ assertFalse(listener.failed);
+
+ conn.close();
+
+ conn = null;
+
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+
+ removeAllMessages(queue1.getQueueName(), true, 0);
+ }
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/MessageProducerTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/MessageProducerTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/MessageProducerTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -22,19 +22,15 @@
package org.jboss.test.messaging.jms;
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
-import javax.jms.DeliveryMode;
import javax.jms.TextMessage;
-import javax.naming.InitialContext;
-import org.jboss.test.messaging.MessagingTestCase;
import org.jboss.test.messaging.jms.message.SimpleJMSTextMessage;
-import org.jboss.test.messaging.tools.ServerManagement;
/**
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
@@ -43,7 +39,7 @@
*
* $Id$
*/
-public class MessageProducerTest extends MessagingTestCase
+public class MessageProducerTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -51,12 +47,6 @@
// Attributes ----------------------------------------------------
- protected ConnectionFactory cf;
-
- protected Destination topic;
- protected Destination topic2;
- protected Destination queue;
-
// Constructors --------------------------------------------------
public MessageProducerTest(String name)
@@ -66,55 +56,23 @@
// Public --------------------------------------------------------
- public void setUp() throws Exception
- {
- super.setUp();
-
- ServerManagement.start("all");
-
-
-
- ServerManagement.undeployTopic("Topic");
- ServerManagement.undeployTopic("Topic2");
- ServerManagement.undeployQueue("Queue");
- ServerManagement.deployTopic("Topic");
- ServerManagement.deployTopic("Topic2");
- ServerManagement.deployQueue("Queue");
-
- InitialContext ic = new InitialContext(ServerManagement.getJNDIEnvironment());
- cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
- topic = (Destination)ic.lookup("/topic/Topic");
- topic2 = (Destination)ic.lookup("/topic/Topic2");
- queue = (Destination)ic.lookup("/queue/Queue");
-
- this.drainDestination(cf, queue);
-
- log.debug("setup done");
- }
-
- public void tearDown() throws Exception
- {
- ServerManagement.undeployTopic("Topic");
- ServerManagement.undeployTopic("Topic2");
- ServerManagement.undeployQueue("Queue");
-
- super.tearDown();
- }
-
/**
* The simplest possible non-transacted test.
*/
public void testSimpleSend() throws Exception
{
- Connection pconn = cf.createConnection();
- Connection cconn = cf.createConnection();
-
+ Connection pconn = null;
+ Connection cconn = null;
+
try
{
+ pconn = cf.createConnection();
+ cconn = cf.createConnection();
+
Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session cs = cconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = ps.createProducer(queue);
- MessageConsumer c = cs.createConsumer(queue);
+ MessageProducer p = ps.createProducer(queue1);
+ MessageConsumer c = cs.createConsumer(queue1);
cconn.start();
@@ -138,17 +96,20 @@
*/
public void testTransactedSend() throws Exception
{
- Connection pconn = cf.createConnection();
- Connection cconn = cf.createConnection();
+ Connection pconn = null;
+ Connection cconn = null;
try
{
+ pconn = cf.createConnection();
+ cconn = cf.createConnection();
+
cconn.start();
Session ts = pconn.createSession(true, -1);
Session cs = cconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = ts.createProducer(queue);
- MessageConsumer c = cs.createConsumer(queue);
+ MessageProducer p = ts.createProducer(queue1);
+ MessageConsumer c = cs.createConsumer(queue1);
TextMessage m = ts.createTextMessage("test");
p.send(m);
@@ -186,12 +147,10 @@
this.m = m;
}
- public void run()
+ public synchronized void run()
{
try
{
- // this is needed to make sure the main thread has enough time to block
- Thread.sleep(3000);
prod.send(m);
}
catch(Exception e)
@@ -213,8 +172,8 @@
{
Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session cs = cconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- final MessageProducer p = ps.createProducer(topic);
- MessageConsumer c = cs.createConsumer(topic);
+ final MessageProducer p = ps.createProducer(topic1);
+ MessageConsumer c = cs.createConsumer(topic1);
cconn.start();
@@ -226,7 +185,7 @@
t.start();
- TextMessage m2 = (TextMessage)c.receive(8000);
+ TextMessage m2 = (TextMessage)c.receive(5000);
if (sender.ex != null)
{
@@ -271,8 +230,6 @@
{
try
{
- // this is needed to make sure the main thread has enough time to block
- Thread.sleep(1000);
anonProducer.send(topic2, m1);
}
catch(Exception e)
@@ -303,8 +260,8 @@
{
Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session cs = cconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = ps.createProducer(queue);
- MessageConsumer c = cs.createConsumer(queue);
+ MessageProducer p = ps.createProducer(queue1);
+ MessageConsumer c = cs.createConsumer(queue1);
// send a message that is not created by the session
@@ -332,9 +289,9 @@
try
{
Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = ps.createProducer(topic);
+ MessageProducer p = ps.createProducer(topic1);
Destination dest = p.getDestination();
- assertEquals(dest, topic);
+ assertEquals(dest, topic1);
}
finally
{
@@ -349,7 +306,7 @@
try
{
Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = ps.createProducer(topic);
+ MessageProducer p = ps.createProducer(topic1);
p.close();
try
@@ -408,7 +365,7 @@
try
{
Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = ps.createProducer(topic);
+ MessageProducer p = ps.createProducer(topic1);
assertFalse(p.getDisableMessageID());
}
@@ -425,7 +382,7 @@
try
{
Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = ps.createProducer(topic);
+ MessageProducer p = ps.createProducer(topic1);
p.close();
@@ -456,8 +413,8 @@
try
{
Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer tp = ps.createProducer(topic);
- MessageProducer qp = ps.createProducer(queue);
+ MessageProducer tp = ps.createProducer(topic1);
+ MessageProducer qp = ps.createProducer(queue1);
assertFalse(tp.getDisableMessageTimestamp());
assertFalse(qp.getDisableMessageTimestamp());
}
@@ -476,8 +433,8 @@
{
Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session cs = cconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = ps.createProducer(queue);
- MessageConsumer c = cs.createConsumer(queue);
+ MessageProducer p = ps.createProducer(queue1);
+ MessageConsumer c = cs.createConsumer(queue1);
cconn.start();
@@ -519,7 +476,7 @@
try
{
Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = ps.createProducer(topic);
+ MessageProducer p = ps.createProducer(topic1);
p.close();
@@ -550,8 +507,8 @@
try
{
Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer tp = ps.createProducer(topic);
- MessageProducer qp = ps.createProducer(queue);
+ MessageProducer tp = ps.createProducer(topic1);
+ MessageProducer qp = ps.createProducer(queue1);
assertEquals(DeliveryMode.PERSISTENT, tp.getDeliveryMode());
assertEquals(DeliveryMode.PERSISTENT, qp.getDeliveryMode());
@@ -569,7 +526,7 @@
try
{
Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = ps.createProducer(topic);
+ MessageProducer p = ps.createProducer(topic1);
p.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
assertEquals(DeliveryMode.NON_PERSISTENT, p.getDeliveryMode());
@@ -590,7 +547,7 @@
try
{
Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = ps.createProducer(topic);
+ MessageProducer p = ps.createProducer(topic1);
p.close();
@@ -621,8 +578,8 @@
try
{
Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer tp = ps.createProducer(topic);
- MessageProducer qp = ps.createProducer(queue);
+ MessageProducer tp = ps.createProducer(topic1);
+ MessageProducer qp = ps.createProducer(queue1);
assertEquals(4, tp.getPriority());
assertEquals(4, qp.getPriority());
@@ -640,7 +597,7 @@
try
{
Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = ps.createProducer(topic);
+ MessageProducer p = ps.createProducer(topic1);
p.setPriority(9);
assertEquals(9, p.getPriority());
@@ -661,7 +618,7 @@
try
{
Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = ps.createProducer(topic);
+ MessageProducer p = ps.createProducer(topic1);
p.close();
@@ -692,8 +649,8 @@
try
{
Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer tp = ps.createProducer(topic);
- MessageProducer qp = ps.createProducer(queue);
+ MessageProducer tp = ps.createProducer(topic1);
+ MessageProducer qp = ps.createProducer(queue1);
assertEquals(0l, tp.getTimeToLive());
assertEquals(0l, qp.getTimeToLive());
@@ -711,7 +668,7 @@
try
{
Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = ps.createProducer(topic);
+ MessageProducer p = ps.createProducer(topic1);
p.setTimeToLive(100l);
assertEquals(100l, p.getTimeToLive());
@@ -732,7 +689,7 @@
try
{
Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = ps.createProducer(topic);
+ MessageProducer p = ps.createProducer(topic1);
p.close();
Modified: trunk/tests/src/org/jboss/test/messaging/jms/MessageProxyTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/MessageProxyTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/MessageProxyTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -23,19 +23,15 @@
import javax.jms.Connection;
import javax.jms.DeliveryMode;
-import javax.jms.Destination;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
-import javax.naming.InitialContext;
-import org.jboss.jms.client.JBossConnectionFactory;
import org.jboss.jms.destination.JBossQueue;
import org.jboss.jms.message.JBossMessage;
import org.jboss.jms.message.MessageProxy;
-import org.jboss.test.messaging.MessagingTestCase;
import org.jboss.test.messaging.tools.ServerManagement;
/**
@@ -48,7 +44,7 @@
* $Id$
*
*/
-public class MessageProxyTest extends MessagingTestCase
+public class MessageProxyTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -56,11 +52,6 @@
// Attributes ----------------------------------------------------
- protected InitialContext initialContext;
-
- protected JBossConnectionFactory cf;
- protected Destination queue;
-
// Constructors --------------------------------------------------
public MessageProxyTest(String name)
@@ -70,34 +61,8 @@
// TestCase overrides -------------------------------------------
- public void setUp() throws Exception
- {
- super.setUp();
- ServerManagement.start("all");
-
-
- initialContext = new InitialContext(ServerManagement.getJNDIEnvironment());
- cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
- ServerManagement.undeployQueue("Queue");
- ServerManagement.deployQueue("Queue");
- queue = (Destination)initialContext.lookup("/queue/Queue");
-
- this.drainDestination(cf, queue);
-
- log.debug("setup done");
- }
-
- public void tearDown() throws Exception
- {
- ServerManagement.undeployQueue("Queue");
- super.tearDown();
- }
-
-
// Public --------------------------------------------------------
-
public void testMessageIDs1() throws Exception
{
if (ServerManagement.isRemote())
@@ -115,10 +80,10 @@
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
Message msent = sess.createMessage();
@@ -143,8 +108,7 @@
assertFalse(id1 == id3);
//But this shouldn't affect the received id
- assertEquals(id2, id4);
-
+ assertEquals(id2, id4);
}
finally
{
@@ -152,11 +116,11 @@
{
conn.close();
}
- }
-
+
+ removeAllMessages(queue1.getQueueName(), true, 0);
+ }
}
-
-
+
public void testMessageIDs2() throws Exception
{
if (ServerManagement.isRemote())
@@ -174,10 +138,10 @@
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
Message msent = sess.createMessage();
@@ -199,8 +163,7 @@
long id3 = ((MessageProxy)msent).getMessage().getMessageID();
//But this shouldn't affect the sent id
- assertEquals(id1, id3);
-
+ assertEquals(id1, id3);
}
finally
{
@@ -208,28 +171,12 @@
{
conn.close();
}
- }
-
+
+ removeAllMessages(queue1.getQueueName(), true, 0);
+ }
}
-
- private void checkSameUnderlyingMessage(JBossMessage m1, JBossMessage m2, boolean same)
- {
- if ((m1 == m2) && (m1.getHeaders() == m2.getHeaders()) && !same)
- {
- fail("Underlying message not same");
- }
- }
-
- private void checkSameBody(JBossMessage m1, JBossMessage m2, boolean same)
- {
- if ((m1.getPayload() == m2.getPayload()) && !same)
- {
- fail("Body not same");
- }
- }
-
-
+
public void testNewMessage() throws Exception
{
if (ServerManagement.isRemote())
@@ -245,7 +192,7 @@
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
@@ -341,8 +288,7 @@
//The message should be the same
- checkSameUnderlyingMessage(check8, check9, true);
-
+ checkSameUnderlyingMessage(check8, check9, true);
}
finally
{
@@ -350,6 +296,8 @@
{
conn.close();
}
+
+ removeAllMessages(queue1.getQueueName(), true, 0);
}
}
@@ -371,13 +319,13 @@
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
MapMessage m = sess.createMapMessage();
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
prod.send(m);
@@ -465,8 +413,7 @@
//The message should be the same
- checkSameUnderlyingMessage(check8, check9, true);
-
+ checkSameUnderlyingMessage(check8, check9, true);
}
finally
{
@@ -474,17 +421,35 @@
{
conn.close();
}
+
+ removeAllMessages(queue1.getQueueName(), true, 0);
}
}
-
-
-
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
// Private -------------------------------------------------------
+ private void checkSameUnderlyingMessage(JBossMessage m1, JBossMessage m2, boolean same)
+ {
+ if ((m1 == m2) && (m1.getHeaders() == m2.getHeaders()) && !same)
+ {
+ fail("Underlying message not same");
+ }
+ }
+
+ private void checkSameBody(JBossMessage m1, JBossMessage m2, boolean same)
+ {
+ if ((m1.getPayload() == m2.getPayload()) && !same)
+ {
+ fail("Body not same");
+ }
+ }
+
+
+
// Inner classes -------------------------------------------------
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/MessageWithReadResolveTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/MessageWithReadResolveTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/MessageWithReadResolveTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -28,14 +28,8 @@
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.ObjectMessage;
-import javax.jms.Queue;
import javax.jms.Session;
-import javax.naming.InitialContext;
-import org.jboss.jms.client.JBossConnectionFactory;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
-
/**
* A MessageWithReadResolveTest
*
@@ -47,7 +41,7 @@
* $Id$
*
*/
-public class MessageWithReadResolveTest extends MessagingTestCase
+public class MessageWithReadResolveTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -56,13 +50,6 @@
// Attributes ----------------------------------------------------
- protected InitialContext initialContext;
-
-
- protected JBossConnectionFactory cf;
- protected Queue queue;
-
-
// Constructors --------------------------------------------------
public MessageWithReadResolveTest(String name)
@@ -71,66 +58,53 @@
}
// TestCase overrides -------------------------------------------
-
- public void setUp() throws Exception
- {
- super.setUp();
- ServerManagement.start("all");
-
- initialContext = new InitialContext(ServerManagement.getJNDIEnvironment());
-
- cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
- ServerManagement.undeployQueue("Queue");
-
- ServerManagement.deployQueue("Queue");
-
- queue = (Queue)initialContext.lookup("/queue/Queue");
-
- }
-
- public void tearDown() throws Exception
- {
- ServerManagement.undeployQueue("Queue");
-
- super.tearDown();
- }
-
// Public --------------------------------------------------------
public void testSendReceiveMessage() throws Exception
{
- Connection conn = cf.createConnection();
+ Connection conn = null;
- Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageProducer prod = sess.createProducer(queue);
-
- //Make persistent to make sure message gets serialized
- prod.setDeliveryMode(DeliveryMode.PERSISTENT);
-
- MessageConsumer cons = sess.createConsumer(queue);
-
- TestMessage tm = new TestMessage(123, false);
-
- ObjectMessage om = sess.createObjectMessage();
-
- om.setObject(tm);
-
- conn.start();
-
- prod.send(om);
-
- ObjectMessage om2 = (ObjectMessage)cons.receive(1000);
-
- assertNotNull(om2);
-
- TestMessage tm2 = (TestMessage)om2.getObject();
-
- assertEquals(123, tm2.getId());
-
- conn.close();
+ try
+ {
+ conn = cf.createConnection();
+
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = sess.createProducer(queue1);
+
+ //Make persistent to make sure message gets serialized
+ prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+
+ MessageConsumer cons = sess.createConsumer(queue1);
+
+ TestMessage tm = new TestMessage(123, false);
+
+ ObjectMessage om = sess.createObjectMessage();
+
+ om.setObject(tm);
+
+ conn.start();
+
+ prod.send(om);
+
+ ObjectMessage om2 = (ObjectMessage)cons.receive(1000);
+
+ assertNotNull(om2);
+
+ TestMessage tm2 = (TestMessage)om2.getObject();
+
+ assertEquals(123, tm2.getId());
+
+ conn.close();
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/MiscellaneousTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/MiscellaneousTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/MiscellaneousTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -21,25 +21,18 @@
*/
package org.jboss.test.messaging.jms;
+import java.util.Enumeration;
+
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
-import javax.jms.MessageProducer;
-import javax.jms.Queue;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.jms.QueueBrowser;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
-import javax.naming.InitialContext;
-import javax.management.ObjectName;
+import javax.jms.MessageProducer;
+import javax.jms.QueueBrowser;
+import javax.jms.Session;
+import javax.jms.TextMessage;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
-
-import java.util.Enumeration;
-
/**
* Various use cases, added here while trying things or fixing forum issues.
*
@@ -48,7 +41,7 @@
*
* $Id$
*/
-public class MiscellaneousTest extends MessagingTestCase
+public class MiscellaneousTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -56,8 +49,6 @@
// Attributes ----------------------------------------------------
- InitialContext ic;
-
// Constructors --------------------------------------------------
public MiscellaneousTest(String name)
@@ -69,29 +60,37 @@
public void testBrowser() throws Exception
{
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
- Queue queue = (Queue)ic.lookup("/queue/MiscellaneousQueue");
-
- Connection conn = cf.createConnection();
- Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = session.createProducer(queue);
-
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-
- TextMessage m = session.createTextMessage("message one");
-
- prod.send(m);
-
- QueueBrowser browser = session.createBrowser(queue);
-
-
- Enumeration e = browser.getEnumeration();
-
- TextMessage bm = (TextMessage)e.nextElement();
-
- assertEquals("message one", bm.getText());
-
- conn.close();
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer prod = session.createProducer(queue1);
+
+ prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ TextMessage m = session.createTextMessage("message one");
+
+ prod.send(m);
+
+ QueueBrowser browser = session.createBrowser(queue1);
+
+ Enumeration e = browser.getEnumeration();
+
+ TextMessage bm = (TextMessage)e.nextElement();
+
+ assertEquals("message one", bm.getText());
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+
+ removeAllMessages(queue1.getQueueName(), true, 0);
+ }
}
/**
@@ -99,55 +98,57 @@
*/
public void testClosingConsumerFromMessageListener() throws Exception
{
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
- Queue queue = (Queue)ic.lookup("/queue/MiscellaneousQueue");
-
- // load the queue
-
- Connection c = cf.createConnection();
- Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = s.createProducer(queue);
- Message m = s.createMessage();
- prod.send(m);
- c.close();
-
- final Result result = new Result();
- Connection conn = cf.createConnection();
- s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- final MessageConsumer cons = s.createConsumer(queue);
- cons.setMessageListener(new MessageListener()
+ Connection c = null;
+
+ try
+ {
+ c = cf.createConnection();
+ Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer prod = s.createProducer(queue1);
+ Message m = s.createMessage();
+ prod.send(m);
+ c.close();
+
+ final Result result = new Result();
+ Connection conn = cf.createConnection();
+ s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ final MessageConsumer cons = s.createConsumer(queue1);
+ cons.setMessageListener(new MessageListener()
+ {
+ public void onMessage(Message m)
+ {
+ // close the connection on the same thread that processed the message
+ try
+ {
+ cons.close();
+ result.setSuccess();
+ }
+ catch(Exception e)
+ {
+ result.setFailure(e);
+ }
+ }
+ });
+
+ conn.start();
+
+ result.waitForResult();
+
+ assertTrue(result.isSuccess());
+ assertNull(result.getFailure());
+
+ // make sure the acknowledgment made it back to the queue
+
+ Thread.sleep(1000);
+ assertRemainingMessages(0);
+ }
+ finally
{
- public void onMessage(Message m)
- {
- // close the connection on the same thread that processed the message
- try
- {
- log.debug("attempting close");
- cons.close();
- log.debug("consumer closed");
- result.setSuccess();
- }
- catch(Exception e)
- {
- result.setFailure(e);
- }
- }
- });
-
- conn.start();
-
- // wait for the message to propagate
- Thread.sleep(3000);
-
- assertTrue(result.isSuccess());
- assertNull(result.getFailure());
-
- // make sure the acknowledgment made it back to the queue
-
- Integer count = (Integer)ServerManagement.
- getAttribute(new ObjectName("jboss.messaging.destination:service=Queue,name=MiscellaneousQueue"),
- "MessageCount");
- assertEquals(0, count.intValue());
+ if (c != null)
+ {
+ c.close();
+ }
+ }
}
/**
@@ -155,56 +156,57 @@
*/
public void testClosingSessionFromMessageListener() throws Exception
{
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
- Queue queue = (Queue)ic.lookup("/queue/MiscellaneousQueue");
-
- // load the queue
-
- Connection c = cf.createConnection();
- Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = s.createProducer(queue);
- Message m = s.createMessage();
- prod.send(m);
- c.close();
-
- final Result result = new Result();
- Connection conn = cf.createConnection();
- final Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = session.createConsumer(queue);
- cons.setMessageListener(new MessageListener()
+ Connection c = null;
+
+ try
+ {
+ c = cf.createConnection();
+ Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer prod = s.createProducer(queue1);
+ Message m = s.createMessage();
+ prod.send(m);
+ c.close();
+
+ final Result result = new Result();
+ Connection conn = cf.createConnection();
+ final Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer cons = session.createConsumer(queue1);
+ cons.setMessageListener(new MessageListener()
+ {
+ public void onMessage(Message m)
+ {
+ // close the connection on the same thread that processed the message
+ try
+ {
+ session.close();
+ result.setSuccess();
+ }
+ catch(Exception e)
+ {
+ result.setFailure(e);
+ }
+ }
+ });
+
+ conn.start();
+
+ result.waitForResult();
+
+ assertTrue(result.isSuccess());
+ assertNull(result.getFailure());
+
+ // make sure the acknowledgment made it back to the queue
+
+ Thread.sleep(1000);
+ assertRemainingMessages(0);
+ }
+ finally
{
- public void onMessage(Message m)
- {
- // close the connection on the same thread that processed the message
- try
- {
- log.debug("attempting close");
- session.close();
- log.debug("session closed");
- result.setSuccess();
- }
- catch(Exception e)
- {
- result.setFailure(e);
- }
- }
- });
-
- conn.start();
-
- // wait for the message to propagate
- Thread.sleep(3000);
-
- assertTrue(result.isSuccess());
- assertNull(result.getFailure());
-
- // make sure the acknowledgment made it back to the queue
-
- Integer count = (Integer)ServerManagement.
- getAttribute(new ObjectName("jboss.messaging.destination:service=Queue,name=MiscellaneousQueue"),
- "MessageCount");
- assertEquals(0, count.intValue());
-
+ if (c != null)
+ {
+ c.close();
+ }
+ }
}
/**
@@ -212,64 +214,65 @@
*/
public void testClosingConnectionFromMessageListener() throws Exception
{
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
- Queue queue = (Queue)ic.lookup("/queue/MiscellaneousQueue");
-
- // load the queue
-
- Connection c = cf.createConnection();
- Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = s.createProducer(queue);
- Message m = s.createMessage();
- prod.send(m);
- c.close();
-
- final Result result = new Result();
- final Connection conn = cf.createConnection();
- s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = s.createConsumer(queue);
- cons.setMessageListener(new MessageListener()
+ Connection c = null;
+
+ try
+ {
+ c = cf.createConnection();
+ Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer prod = s.createProducer(queue1);
+ Message m = s.createMessage();
+ prod.send(m);
+ c.close();
+
+ final Result result = new Result();
+ final Connection conn = cf.createConnection();
+ s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer cons = s.createConsumer(queue1);
+ cons.setMessageListener(new MessageListener()
+ {
+ public void onMessage(Message m)
+ {
+ // close the connection on the same thread that processed the message
+ try
+ {
+ log.debug("attempting close");
+ conn.close();
+ log.debug("conn closed");
+ result.setSuccess();
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ result.setFailure(e);
+ }
+ }
+ });
+
+ conn.start();
+
+ result.waitForResult();
+
+ assertTrue(result.isSuccess());
+ assertNull(result.getFailure());
+
+ // make sure the acknowledgment made it back to the queue
+
+ Thread.sleep(1000);
+ assertRemainingMessages(0);
+ }
+ finally
{
- public void onMessage(Message m)
- {
- // close the connection on the same thread that processed the message
- try
- {
- log.debug("attempting close");
- conn.close();
- log.debug("conn closed");
- result.setSuccess();
- }
- catch(Exception e)
- {
- e.printStackTrace();
- result.setFailure(e);
- }
- }
- });
-
- conn.start();
-
- // wait for the message to propagate
- Thread.sleep(3000);
-
- assertTrue(result.isSuccess());
- assertNull(result.getFailure());
-
- // make sure the acknowledgment made it back to the queue
-
- Integer count = (Integer)ServerManagement.
- getAttribute(new ObjectName("jboss.messaging.destination:service=Queue,name=MiscellaneousQueue"),
- "MessageCount");
- assertEquals(0, count.intValue());
+ if (c != null)
+ {
+ c.close();
+ }
+ }
}
// Test case for http://jira.jboss.com/jira/browse/JBMESSAGING-788
public void testGetDeliveriesForSession() throws Exception
{
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
- Queue queue = (Queue)ic.lookup("/queue/MiscellaneousQueue");
-
Connection conn = null;
try
@@ -280,7 +283,7 @@
Session session2 = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageProducer prod = session2.createProducer(queue);
+ MessageProducer prod = session2.createProducer(queue1);
Message msg = session2.createMessage();
@@ -296,6 +299,8 @@
{
conn.close();
}
+
+ removeAllMessages(queue1.getQueueName(), true, 0);
}
}
@@ -303,30 +308,6 @@
// Protected -----------------------------------------------------
- protected void setUp() throws Exception
- {
- super.setUp();
-
- ServerManagement.start("all");
-
- ic = new InitialContext(ServerManagement.getJNDIEnvironment());
-
- ServerManagement.deployQueue("MiscellaneousQueue");
-
- log.debug("setup done");
- }
-
- protected void tearDown() throws Exception
- {
- ServerManagement.undeployQueue("MiscellaneousQueue");
-
- ic.close();
-
- super.tearDown();
- }
-
-
-
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
@@ -335,6 +316,8 @@
{
private boolean success;
private Exception e;
+
+ private boolean resultSet;
public Result()
{
@@ -345,6 +328,10 @@
public synchronized void setSuccess()
{
success = true;
+
+ this.resultSet = true;
+
+ this.notify();
}
public synchronized boolean isSuccess()
@@ -355,12 +342,24 @@
public synchronized void setFailure(Exception e)
{
this.e = e;
+
+ this.resultSet = true;
+
+ this.notify();
}
public synchronized Exception getFailure()
{
return e;
}
+
+ public synchronized void waitForResult() throws Exception
+ {
+ while (!resultSet)
+ {
+ this.wait();
+ }
+ }
}
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/NonDurableSubscriberTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/NonDurableSubscriberTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/NonDurableSubscriberTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -21,14 +21,10 @@
*/
package org.jboss.test.messaging.jms;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
-
-import javax.naming.InitialContext;
import javax.jms.Session;
import javax.jms.TopicConnection;
-import javax.jms.TopicConnectionFactory;
import javax.jms.TopicSession;
+import javax.naming.InitialContext;
/**
@@ -38,7 +34,7 @@
*
* $Id$
*/
-public class NonDurableSubscriberTest extends MessagingTestCase
+public class NonDurableSubscriberTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -56,52 +52,36 @@
}
// Public --------------------------------------------------------
-
- public void setUp() throws Exception
- {
- super.setUp();
-
- ServerManagement.start("all");
-
-
-
- ServerManagement.undeployTopic("Topic");
- ServerManagement.deployTopic("Topic");
-
- ic = new InitialContext(ServerManagement.getJNDIEnvironment());
-
- log.debug("setup done");
- }
-
- public void tearDown() throws Exception
- {
- log.debug("starting tear down");
-
- ic.close();
-
- ServerManagement.undeployTopic("Topic");
-
- super.tearDown();
- }
-
+
/**
* Test introduced as a result of a TCK failure.
*/
public void testNonDurableSubscriberOnNullTopic() throws Exception
{
- TopicConnectionFactory cf = (TopicConnectionFactory)ic.lookup("ConnectionFactory");
- TopicConnection conn = cf.createTopicConnection();
-
- TopicSession ts = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
-
+ TopicConnection conn = null;
+
try
- {
- ts.createSubscriber(null);
- fail("this should fail");
+ {
+ conn = cf.createTopicConnection();
+
+ TopicSession ts = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ try
+ {
+ ts.createSubscriber(null);
+ fail("this should fail");
+ }
+ catch(javax.jms.InvalidDestinationException e)
+ {
+ // OK
+ }
}
- catch(javax.jms.InvalidDestinationException e)
+ finally
{
- // OK
+ if (conn != null)
+ {
+ conn.close();
+ }
}
}
@@ -110,20 +90,31 @@
*/
public void testNonDurableSubscriberInvalidUnsubscribe() throws Exception
{
- TopicConnectionFactory cf = (TopicConnectionFactory)ic.lookup("ConnectionFactory");
- TopicConnection conn = cf.createTopicConnection();
- conn.setClientID("sofiavergara");
-
- TopicSession ts = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
-
+ TopicConnection conn = null;
+
try
- {
- ts.unsubscribe("invalid-subscription-name");
- fail("this should fail");
+ {
+ conn = cf.createTopicConnection();
+ conn.setClientID("sofiavergara");
+
+ TopicSession ts = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ try
+ {
+ ts.unsubscribe("invalid-subscription-name");
+ fail("this should fail");
+ }
+ catch(javax.jms.InvalidDestinationException e)
+ {
+ // OK
+ }
}
- catch(javax.jms.InvalidDestinationException e)
+ finally
{
- // OK
+ if (conn != null)
+ {
+ conn.close();
+ }
}
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/PersistenceTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/PersistenceTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/PersistenceTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -22,18 +22,12 @@
package org.jboss.test.messaging.jms;
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
-import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
-import javax.jms.Topic;
-import javax.naming.InitialContext;
-import javax.naming.NameNotFoundException;
-import org.jboss.test.messaging.MessagingTestCase;
import org.jboss.test.messaging.tools.ServerManagement;
/**
@@ -46,7 +40,7 @@
* $Id$
*
*/
-public class PersistenceTest extends MessagingTestCase
+public class PersistenceTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -54,12 +48,6 @@
// Attributes ----------------------------------------------------
- protected InitialContext initialContext;
-
- protected ConnectionFactory cf;
- protected Queue queue;
- protected Topic topic;
-
// Constructors --------------------------------------------------
public PersistenceTest(String name)
@@ -69,40 +57,6 @@
// TestCase overrides -------------------------------------------
- public void setUp() throws Exception
- {
- if (ServerManagement.isRemote())
- {
- fail("This test is not supposed to run in a remote configuration!");
- }
-
- super.setUp();
-
- ServerManagement.start("all");
-
- initialContext = new InitialContext(ServerManagement.getJNDIEnvironment());
-
- cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
- ServerManagement.undeployQueue("Queue");
- ServerManagement.deployQueue("Queue");
- ServerManagement.undeployTopic("Topic");
- ServerManagement.deployTopic("Topic");
-
- queue = (Queue)initialContext.lookup("/queue/Queue");
- topic = (Topic)initialContext.lookup("/topic/Topic");
-
- log.debug("setup done");
- }
-
- public void tearDown() throws Exception
- {
- ServerManagement.undeployQueue("Queue");
- ServerManagement.undeployTopic("Topic");
- super.tearDown();
- }
-
-
// Public --------------------------------------------------------
/**
@@ -111,44 +65,52 @@
*/
public void testQueuePersistence() throws Exception
{
- Connection conn = cf.createConnection();
- Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
- prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+ Connection conn = null;
- for (int i = 0; i < 10; i++)
- {
- TextMessage tm = sess.createTextMessage("message" + i);
- prod.send(tm);
+ try
+ {
+ conn = cf.createConnection();
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer prod = sess.createProducer(queue1);
+ prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+
+ for (int i = 0; i < 10; i++)
+ {
+ TextMessage tm = sess.createTextMessage("message" + i);
+ prod.send(tm);
+ }
+
+ conn.close();
+
+ ServerManagement.stopServerPeer();
+
+ ServerManagement.startServerPeer();
+
+ // Messaging server restart implies new ConnectionFactory lookup
+ deployAndLookupAdministeredObjects();
+
+ conn = cf.createConnection();
+ sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ conn.start();
+ MessageConsumer cons = sess.createConsumer(queue1);
+ for (int i = 0; i < 10; i++)
+ {
+ TextMessage tm = (TextMessage)cons.receive(3000);
+ assertNotNull(tm);
+ if (tm == null)
+ {
+ break;
+ }
+ assertEquals("message" + i, tm.getText());
+ }
}
-
- conn.close();
-
- ServerManagement.stopServerPeer();
-
- ServerManagement.startServerPeer();
-
- // Messaging server restart implies new ConnectionFactory lookup
- cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
- ServerManagement.deployQueue("Queue");
-
- conn = cf.createConnection();
- sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- conn.start();
- MessageConsumer cons = sess.createConsumer(queue);
- for (int i = 0; i < 10; i++)
+ finally
{
- TextMessage tm = (TextMessage)cons.receive(3000);
- assertNotNull(tm);
- if (tm == null)
- {
- break;
- }
- assertEquals("message" + i, tm.getText());
+ if (conn != null)
+ {
+ conn.close();
+ }
}
-
- conn.close();
}
/**
@@ -157,83 +119,89 @@
*/
public void testJMSRedeliveredRestart() throws Exception
{
- Connection conn = cf.createConnection();
- Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
- prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+ Connection conn = null;
- for (int i = 0; i < 10; i++)
- {
- TextMessage tm = sess.createTextMessage("message" + i);
- prod.send(tm);
+ try
+ {
+ conn = cf.createConnection();
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer prod = sess.createProducer(queue1);
+ prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+
+ for (int i = 0; i < 10; i++)
+ {
+ TextMessage tm = sess.createTextMessage("message" + i);
+ prod.send(tm);
+ }
+
+ Session sess2 = conn.createSession(true, Session.SESSION_TRANSACTED);
+
+ MessageConsumer cons = sess2.createConsumer(queue1);
+
+ conn.start();
+
+ for (int i = 0; i < 10; i++)
+ {
+ TextMessage tm = (TextMessage)cons.receive(1000);
+
+ assertNotNull(tm);
+
+ assertEquals("message" + i, tm.getText());
+
+ assertFalse(tm.getJMSRedelivered());
+
+ assertEquals(1, tm.getIntProperty("JMSXDeliveryCount"));
+ }
+
+ //rollback
+ sess2.rollback();
+
+ for (int i = 0; i < 10; i++)
+ {
+ TextMessage tm = (TextMessage)cons.receive(1000);
+
+ assertNotNull(tm);
+
+ assertEquals("message" + i, tm.getText());
+
+ assertTrue(tm.getJMSRedelivered());
+
+ assertEquals(2, tm.getIntProperty("JMSXDeliveryCount"));
+ }
+
+ conn.close();
+
+ ServerManagement.stopServerPeer();
+
+ ServerManagement.startServerPeer();
+
+ // Messaging server restart implies new ConnectionFactory lookup
+ deployAndLookupAdministeredObjects();
+
+ conn = cf.createConnection();
+ sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ conn.start();
+ cons = sess.createConsumer(queue1);
+ for (int i = 0; i < 10; i++)
+ {
+ TextMessage tm = (TextMessage)cons.receive(3000);
+
+ assertNotNull(tm);
+
+ assertEquals("message" + i, tm.getText());
+
+ assertTrue(tm.getJMSRedelivered());
+
+ assertEquals(3, tm.getIntProperty("JMSXDeliveryCount"));
+ }
}
-
- Session sess2 = conn.createSession(true, Session.SESSION_TRANSACTED);
-
- MessageConsumer cons = sess2.createConsumer(queue);
-
- conn.start();
-
- for (int i = 0; i < 10; i++)
+ finally
{
- TextMessage tm = (TextMessage)cons.receive(1000);
-
- assertNotNull(tm);
-
- assertEquals("message" + i, tm.getText());
-
- assertFalse(tm.getJMSRedelivered());
-
- assertEquals(1, tm.getIntProperty("JMSXDeliveryCount"));
+ if (conn != null)
+ {
+ conn.close();
+ }
}
-
- //rollback
- sess2.rollback();
-
- for (int i = 0; i < 10; i++)
- {
- TextMessage tm = (TextMessage)cons.receive(1000);
-
- assertNotNull(tm);
-
- assertEquals("message" + i, tm.getText());
-
- assertTrue(tm.getJMSRedelivered());
-
- assertEquals(2, tm.getIntProperty("JMSXDeliveryCount"));
- }
-
- conn.close();
-
-
-
- ServerManagement.stopServerPeer();
-
- ServerManagement.startServerPeer();
-
- // Messaging server restart implies new ConnectionFactory lookup
- cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
- ServerManagement.deployQueue("Queue");
-
- conn = cf.createConnection();
- sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- conn.start();
- cons = sess.createConsumer(queue);
- for (int i = 0; i < 10; i++)
- {
- TextMessage tm = (TextMessage)cons.receive(3000);
-
- assertNotNull(tm);
-
- assertEquals("message" + i, tm.getText());
-
- assertTrue(tm.getJMSRedelivered());
-
- assertEquals(3, tm.getIntProperty("JMSXDeliveryCount"));
- }
-
- conn.close();
}
@@ -242,105 +210,112 @@
*/
public void testMessageOrderPersistence_1() throws Exception
{
- Connection conn = cf.createConnection();
- Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessSend.createProducer(queue);
+ Connection conn = null;
- TextMessage m0 = sessSend.createTextMessage("a");
- TextMessage m1 = sessSend.createTextMessage("b");
- TextMessage m2 = sessSend.createTextMessage("c");
- TextMessage m3 = sessSend.createTextMessage("d");
- TextMessage m4 = sessSend.createTextMessage("e");
- TextMessage m5 = sessSend.createTextMessage("f");
- TextMessage m6 = sessSend.createTextMessage("g");
- TextMessage m7 = sessSend.createTextMessage("h");
- TextMessage m8 = sessSend.createTextMessage("i");
- TextMessage m9 = sessSend.createTextMessage("j");
-
- prod.send(m0, DeliveryMode.PERSISTENT, 0, 0);
- prod.send(m1, DeliveryMode.PERSISTENT, 1, 0);
- prod.send(m2, DeliveryMode.PERSISTENT, 2, 0);
- prod.send(m3, DeliveryMode.PERSISTENT, 3, 0);
- prod.send(m4, DeliveryMode.PERSISTENT, 4, 0);
- prod.send(m5, DeliveryMode.PERSISTENT, 5, 0);
- prod.send(m6, DeliveryMode.PERSISTENT, 6, 0);
- prod.send(m7, DeliveryMode.PERSISTENT, 7, 0);
- prod.send(m8, DeliveryMode.PERSISTENT, 8, 0);
- prod.send(m9, DeliveryMode.PERSISTENT, 9, 0);
-
- conn.close();
-
- ServerManagement.stopServerPeer();
-
- ServerManagement.startServerPeer();
-
- // Messaging server restart implies new ConnectionFactory lookup
- cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
- ServerManagement.deployQueue("Queue");
-
- conn = cf.createConnection();
- Session sessReceive = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- conn.start();
- MessageConsumer cons = sessReceive.createConsumer(queue);
-
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("j", t.getText());
+ try
+ {
+ conn = cf.createConnection();
+ Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer prod = sessSend.createProducer(queue1);
+
+ TextMessage m0 = sessSend.createTextMessage("a");
+ TextMessage m1 = sessSend.createTextMessage("b");
+ TextMessage m2 = sessSend.createTextMessage("c");
+ TextMessage m3 = sessSend.createTextMessage("d");
+ TextMessage m4 = sessSend.createTextMessage("e");
+ TextMessage m5 = sessSend.createTextMessage("f");
+ TextMessage m6 = sessSend.createTextMessage("g");
+ TextMessage m7 = sessSend.createTextMessage("h");
+ TextMessage m8 = sessSend.createTextMessage("i");
+ TextMessage m9 = sessSend.createTextMessage("j");
+
+ prod.send(m0, DeliveryMode.PERSISTENT, 0, 0);
+ prod.send(m1, DeliveryMode.PERSISTENT, 1, 0);
+ prod.send(m2, DeliveryMode.PERSISTENT, 2, 0);
+ prod.send(m3, DeliveryMode.PERSISTENT, 3, 0);
+ prod.send(m4, DeliveryMode.PERSISTENT, 4, 0);
+ prod.send(m5, DeliveryMode.PERSISTENT, 5, 0);
+ prod.send(m6, DeliveryMode.PERSISTENT, 6, 0);
+ prod.send(m7, DeliveryMode.PERSISTENT, 7, 0);
+ prod.send(m8, DeliveryMode.PERSISTENT, 8, 0);
+ prod.send(m9, DeliveryMode.PERSISTENT, 9, 0);
+
+ conn.close();
+
+ ServerManagement.stopServerPeer();
+
+ ServerManagement.startServerPeer();
+
+ // Messaging server restart implies new ConnectionFactory lookup
+ deployAndLookupAdministeredObjects();
+
+ conn = cf.createConnection();
+ Session sessReceive = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ conn.start();
+ MessageConsumer cons = sessReceive.createConsumer(queue1);
+
+ {
+ TextMessage t = (TextMessage)cons.receive(1000);
+ assertNotNull(t);
+ assertEquals("j", t.getText());
+ }
+ {
+ TextMessage t = (TextMessage)cons.receive(1000);
+ assertNotNull(t);
+ assertEquals("i", t.getText());
+ }
+ {
+ TextMessage t = (TextMessage)cons.receive(1000);
+ assertNotNull(t);
+ assertEquals("h", t.getText());
+ }
+ {
+ TextMessage t = (TextMessage)cons.receive(1000);
+ assertNotNull(t);
+ assertEquals("g", t.getText());
+ }
+ {
+ TextMessage t = (TextMessage)cons.receive(1000);
+ assertNotNull(t);
+ assertEquals("f", t.getText());
+ }
+ {
+ TextMessage t = (TextMessage)cons.receive(1000);
+ assertNotNull(t);
+ assertEquals("e", t.getText());
+ }
+ {
+ TextMessage t = (TextMessage)cons.receive(1000);
+ assertNotNull(t);
+ assertEquals("d", t.getText());
+ }
+ {
+ TextMessage t = (TextMessage)cons.receive(1000);
+ assertNotNull(t);
+ assertEquals("c", t.getText());
+ }
+ {
+ TextMessage t = (TextMessage)cons.receive(1000);
+ assertNotNull(t);
+ assertEquals("b", t.getText());
+ }
+ {
+ TextMessage t = (TextMessage)cons.receive(1000);
+ assertNotNull(t);
+ assertEquals("a", t.getText());
+ }
+ {
+ TextMessage t = (TextMessage)cons.receive(500);
+ assertNull(t);
+ }
}
+ finally
{
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("i", t.getText());
+ if (conn != null)
+ {
+ conn.close();
+ }
}
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("h", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("g", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("f", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("e", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("d", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("c", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("b", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("a", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(500);
- assertNull(t);
- }
-
-
- conn.close();
}
@@ -349,105 +324,112 @@
*/
public void testMessageOrderPersistence_2() throws Exception
{
- Connection conn = cf.createConnection();
- Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessSend.createProducer(queue);
+ Connection conn = null;
- TextMessage m0 = sessSend.createTextMessage("a");
- TextMessage m1 = sessSend.createTextMessage("b");
- TextMessage m2 = sessSend.createTextMessage("c");
- TextMessage m3 = sessSend.createTextMessage("d");
- TextMessage m4 = sessSend.createTextMessage("e");
- TextMessage m5 = sessSend.createTextMessage("f");
- TextMessage m6 = sessSend.createTextMessage("g");
- TextMessage m7 = sessSend.createTextMessage("h");
- TextMessage m8 = sessSend.createTextMessage("i");
- TextMessage m9 = sessSend.createTextMessage("j");
-
-
- prod.send(m0, DeliveryMode.PERSISTENT, 0, 0);
- prod.send(m1, DeliveryMode.PERSISTENT, 0, 0);
- prod.send(m2, DeliveryMode.PERSISTENT, 0, 0);
- prod.send(m3, DeliveryMode.PERSISTENT, 3, 0);
- prod.send(m4, DeliveryMode.PERSISTENT, 3, 0);
- prod.send(m5, DeliveryMode.PERSISTENT, 4, 0);
- prod.send(m6, DeliveryMode.PERSISTENT, 4, 0);
- prod.send(m7, DeliveryMode.PERSISTENT, 5, 0);
- prod.send(m8, DeliveryMode.PERSISTENT, 5, 0);
- prod.send(m9, DeliveryMode.PERSISTENT, 6, 0);
-
- conn.close();
-
- ServerManagement.stopServerPeer();
-
- ServerManagement.startServerPeer();
-
- // Messaging server restart implies new ConnectionFactory lookup
- cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
- ServerManagement.deployQueue("Queue");
-
- conn = cf.createConnection();
- Session sessReceive = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- conn.start();
- MessageConsumer cons = sessReceive.createConsumer(queue);
-
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("j", t.getText());
+ try
+ {
+ conn = cf.createConnection();
+ Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer prod = sessSend.createProducer(queue1);
+
+ TextMessage m0 = sessSend.createTextMessage("a");
+ TextMessage m1 = sessSend.createTextMessage("b");
+ TextMessage m2 = sessSend.createTextMessage("c");
+ TextMessage m3 = sessSend.createTextMessage("d");
+ TextMessage m4 = sessSend.createTextMessage("e");
+ TextMessage m5 = sessSend.createTextMessage("f");
+ TextMessage m6 = sessSend.createTextMessage("g");
+ TextMessage m7 = sessSend.createTextMessage("h");
+ TextMessage m8 = sessSend.createTextMessage("i");
+ TextMessage m9 = sessSend.createTextMessage("j");
+
+
+ prod.send(m0, DeliveryMode.PERSISTENT, 0, 0);
+ prod.send(m1, DeliveryMode.PERSISTENT, 0, 0);
+ prod.send(m2, DeliveryMode.PERSISTENT, 0, 0);
+ prod.send(m3, DeliveryMode.PERSISTENT, 3, 0);
+ prod.send(m4, DeliveryMode.PERSISTENT, 3, 0);
+ prod.send(m5, DeliveryMode.PERSISTENT, 4, 0);
+ prod.send(m6, DeliveryMode.PERSISTENT, 4, 0);
+ prod.send(m7, DeliveryMode.PERSISTENT, 5, 0);
+ prod.send(m8, DeliveryMode.PERSISTENT, 5, 0);
+ prod.send(m9, DeliveryMode.PERSISTENT, 6, 0);
+
+ conn.close();
+
+ ServerManagement.stopServerPeer();
+
+ ServerManagement.startServerPeer();
+
+ deployAndLookupAdministeredObjects();
+
+ conn = cf.createConnection();
+ Session sessReceive = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ conn.start();
+ MessageConsumer cons = sessReceive.createConsumer(queue1);
+
+ {
+ TextMessage t = (TextMessage)cons.receive(1000);
+ assertNotNull(t);
+ assertEquals("j", t.getText());
+ }
+ {
+ TextMessage t = (TextMessage)cons.receive(1000);
+ assertNotNull(t);
+ assertEquals("h", t.getText());
+ }
+ {
+ TextMessage t = (TextMessage)cons.receive(1000);
+ assertNotNull(t);
+ assertEquals("i", t.getText());
+ }
+ {
+ TextMessage t = (TextMessage)cons.receive(1000);
+ assertNotNull(t);
+ assertEquals("f", t.getText());
+ }
+ {
+ TextMessage t = (TextMessage)cons.receive(1000);
+ assertNotNull(t);
+ assertEquals("g", t.getText());
+ }
+ {
+ TextMessage t = (TextMessage)cons.receive(1000);
+ assertNotNull(t);
+ assertEquals("d", t.getText());
+ }
+ {
+ TextMessage t = (TextMessage)cons.receive(1000);
+ assertNotNull(t);
+ assertEquals("e", t.getText());
+ }
+ {
+ TextMessage t = (TextMessage)cons.receive(1000);
+ assertNotNull(t);
+ assertEquals("a", t.getText());
+ }
+ {
+ TextMessage t = (TextMessage)cons.receive(1000);
+ assertNotNull(t);
+ assertEquals("b", t.getText());
+ }
+ {
+ TextMessage t = (TextMessage)cons.receive(1000);
+ assertNotNull(t);
+ assertEquals("c", t.getText());
+ }
+ {
+ TextMessage t = (TextMessage)cons.receiveNoWait();
+ assertNull(t);
+ }
}
+ finally
{
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("h", t.getText());
+ if (conn != null)
+ {
+ conn.close();
+ }
}
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("i", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("f", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("g", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("d", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("e", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("a", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("b", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("c", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receiveNoWait();
- assertNull(t);
- }
-
- conn.close();
}
/*
@@ -455,66 +437,51 @@
*/
public void testDurableSubscriptionPersistence_1() throws Exception
{
- ServerManagement.deployTopic("YetAnotherTopic");
- Topic thisTopic = (Topic)initialContext.lookup("/topic/YetAnotherTopic");
-
- Connection conn = cf.createConnection();
- conn.setClientID("five");
-
- Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer ds = s.createDurableSubscriber(thisTopic, "sub", null, false);
-
- MessageProducer p = s.createProducer(thisTopic);
- p.setDeliveryMode(DeliveryMode.PERSISTENT);
- TextMessage tm = s.createTextMessage("thebody");
+ Connection conn = null;
- p.send(tm);
- log.debug("message sent");
-
- conn.close();
-
- log.debug("stopping the server");
-
- ServerManagement.stopServerPeer();
-
try
- {
- initialContext.lookup("/topic/YetAnotherTopic");
- fail("this should throw exception");
+ {
+ conn = cf.createConnection();
+ conn.setClientID("five");
+
+ Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer ds = s.createDurableSubscriber(topic1, "sub", null, false);
+
+ MessageProducer p = s.createProducer(topic1);
+ p.setDeliveryMode(DeliveryMode.PERSISTENT);
+ TextMessage tm = s.createTextMessage("thebody");
+
+ p.send(tm);
+ log.debug("message sent");
+
+ conn.close();
+
+ ServerManagement.stopServerPeer();
+
+ ServerManagement.startServerPeer();
+
+ deployAndLookupAdministeredObjects();
+
+ conn = cf.createConnection();
+ conn.setClientID("five");
+
+ s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ conn.start();
+
+ ds = s.createDurableSubscriber(topic1, "sub", null, false);
+
+ TextMessage rm = (TextMessage)ds.receive(3000);
+ assertNotNull(rm);
+ assertEquals("thebody", rm.getText());
}
- catch(NameNotFoundException e)
+ finally
{
- // OK
+ if (conn != null)
+ {
+ conn.close();
+ }
}
-
- log.debug("starting the server");
- ServerManagement.startServerPeer();
- log.debug("server started");
-
- // Messaging server restart implies new ConnectionFactory lookup
- cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
- ServerManagement.deployTopic("YetAnotherTopic");
- log.debug("topic deployed");
-
- thisTopic = (Topic)initialContext.lookup("/topic/YetAnotherTopic");
-
- conn = cf.createConnection();
- conn.setClientID("five");
-
- s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- conn.start();
-
- ds = s.createDurableSubscriber(thisTopic, "sub", null, false);
-
- TextMessage rm = (TextMessage)ds.receive(3000);
- assertNotNull(rm);
- assertEquals("thebody", rm.getText());
-
-
- conn.close();
- ServerManagement.undeployTopic("YetAnotherTopic");
}
/*
@@ -522,76 +489,83 @@
*/
public void testDurableSubscriptionPersistence_2() throws Exception
{
- Connection conn = cf.createConnection();
- conn.setClientID("Sausages");
+ Connection conn = null;
- Session sessConsume = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer sub1 = sessConsume.createDurableSubscriber(topic, "sub1", null, false);
- MessageConsumer sub2 = sessConsume.createDurableSubscriber(topic, "sub2", null, false);
- MessageConsumer sub3 = sessConsume.createDurableSubscriber(topic, "sub3", null, false);
-
-
- Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessSend.createProducer(topic);
- prod.setDeliveryMode(DeliveryMode.PERSISTENT);
-
- for (int i = 0; i < 10; i++)
- {
- TextMessage tm = sessSend.createTextMessage("message" + i);
- prod.send(tm);
+ try
+ {
+ conn = cf.createConnection();
+ conn.setClientID("Sausages");
+
+ Session sessConsume = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer sub1 = sessConsume.createDurableSubscriber(topic1, "sub1", null, false);
+ MessageConsumer sub2 = sessConsume.createDurableSubscriber(topic1, "sub2", null, false);
+ MessageConsumer sub3 = sessConsume.createDurableSubscriber(topic1, "sub3", null, false);
+
+
+ Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer prod = sessSend.createProducer(topic1);
+ prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+
+ for (int i = 0; i < 10; i++)
+ {
+ TextMessage tm = sessSend.createTextMessage("message" + i);
+ prod.send(tm);
+ }
+
+ conn.close();
+
+ ServerManagement.stopServerPeer();
+
+ ServerManagement.startServerPeer();
+
+ // Messaging server restart implies new ConnectionFactory lookup
+ deployAndLookupAdministeredObjects();
+
+ conn = cf.createConnection();
+ conn.setClientID("Sausages");
+
+ sessConsume = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ conn.start();
+
+ sub1 = sessConsume.createDurableSubscriber(topic1, "sub1", null, false);
+ sub2 = sessConsume.createDurableSubscriber(topic1, "sub2", null, false);
+ sub3 = sessConsume.createDurableSubscriber(topic1, "sub3", null, false);
+
+ for (int i = 0; i < 10; i++)
+ {
+ TextMessage tm1 = (TextMessage)sub1.receive(3000);
+ assertNotNull(tm1);
+ if (tm1 == null)
+ {
+ break;
+ }
+ assertEquals("message" + i, tm1.getText());
+
+ TextMessage tm2 = (TextMessage)sub2.receive(3000);
+ assertNotNull(tm2);
+ if (tm2 == null)
+ {
+ break;
+ }
+ assertEquals("message" + i, tm2.getText());
+
+ TextMessage tm3 = (TextMessage)sub3.receive(3000);
+ assertNotNull(tm3);
+ if (tm3 == null)
+ {
+ break;
+ }
+ assertEquals("message" + i, tm3.getText());
+ }
}
-
- conn.close();
-
- ServerManagement.stopServerPeer();
-
- ServerManagement.startServerPeer();
-
- // Messaging server restart implies new ConnectionFactory lookup
- cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
- ServerManagement.deployTopic("Topic");
-
- conn = cf.createConnection();
- conn.setClientID("Sausages");
-
- sessConsume = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- conn.start();
-
- sub1 = sessConsume.createDurableSubscriber(topic, "sub1", null, false);
- sub2 = sessConsume.createDurableSubscriber(topic, "sub2", null, false);
- sub3 = sessConsume.createDurableSubscriber(topic, "sub3", null, false);
-
- for (int i = 0; i < 10; i++)
+ finally
{
- TextMessage tm1 = (TextMessage)sub1.receive(3000);
- assertNotNull(tm1);
- if (tm1 == null)
- {
- break;
- }
- assertEquals("message" + i, tm1.getText());
-
- TextMessage tm2 = (TextMessage)sub2.receive(3000);
- assertNotNull(tm2);
- if (tm2 == null)
- {
- break;
- }
- assertEquals("message" + i, tm2.getText());
-
- TextMessage tm3 = (TextMessage)sub3.receive(3000);
- assertNotNull(tm3);
- if (tm3 == null)
- {
- break;
- }
- assertEquals("message" + i, tm3.getText());
+ if (conn != null)
+ {
+ conn.close();
+ }
}
-
-
- conn.close();
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/QueueRequestorTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/QueueRequestorTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/QueueRequestorTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -25,27 +25,21 @@
import javax.jms.JMSException;
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.QueueRequestor;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
-import javax.naming.InitialContext;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
-
/**
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
* @version <tt>$Revision$</tt>
*
* $Id$
*/
-public class QueueRequestorTest extends MessagingTestCase
+public class QueueRequestorTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -53,11 +47,6 @@
// Attributes ----------------------------------------------------
- protected InitialContext initialContext;
-
- protected QueueConnectionFactory cf;
- protected Queue queue;
-
// Constructors --------------------------------------------------
public QueueRequestorTest(String name)
@@ -67,58 +56,54 @@
// TestCase overrides -------------------------------------------
- public void setUp() throws Exception
- {
- super.setUp();
- ServerManagement.start("all");
-
- initialContext = new InitialContext(ServerManagement.getJNDIEnvironment());
- cf = (QueueConnectionFactory)initialContext.lookup("/ConnectionFactory");
- ServerManagement.undeployQueue("Queue");
- ServerManagement.deployQueue("Queue");
- queue = (Queue)initialContext.lookup("/queue/Queue");
- }
-
- public void tearDown() throws Exception
- {
- ServerManagement.undeployQueue("Queue");
- super.tearDown();
- }
-
-
// Public --------------------------------------------------------
public void testQueueRequestor() throws Exception
{
// Set up the requestor
- QueueConnection conn1 = cf.createQueueConnection();
- QueueSession sess1 = conn1.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
- QueueRequestor requestor = new QueueRequestor(sess1, queue);
- conn1.start();
+ QueueConnection conn1 = null;
+ QueueConnection conn2 = null;
-
- // And the responder
- QueueConnection conn2 = cf.createQueueConnection();
- QueueSession sess2 = conn2.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
- TestMessageListener listener = new TestMessageListener(sess2);
- QueueReceiver receiver = sess2.createReceiver(queue);
- receiver.setMessageListener(listener);
- conn2.start();
-
- Message m1 = sess1.createMessage();
- log.trace("Sending request message");
- TextMessage m2 = (TextMessage)requestor.request(m1);
-
-
- assertNotNull(m2);
-
- assertEquals("This is the response", m2.getText());
-
- conn1.close();
- conn2.close();
-
- }
+ try
+ {
+
+ conn1 = cf.createQueueConnection();
+ QueueSession sess1 = conn1.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ QueueRequestor requestor = new QueueRequestor(sess1, queue1);
+ conn1.start();
+
+ // And the responder
+ conn2 = cf.createQueueConnection();
+ QueueSession sess2 = conn2.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ TestMessageListener listener = new TestMessageListener(sess2);
+ QueueReceiver receiver = sess2.createReceiver(queue1);
+ receiver.setMessageListener(listener);
+ conn2.start();
+
+ Message m1 = sess1.createMessage();
+ log.trace("Sending request message");
+ TextMessage m2 = (TextMessage)requestor.request(m1);
+
+
+ assertNotNull(m2);
+
+ assertEquals("This is the response", m2.getText());
+ }
+ finally
+ {
+ if (conn1 != null) conn1.close();
+ if (conn2 != null) conn2.close();
+ }
+ }
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
class TestMessageListener implements MessageListener
{
private QueueSession sess;
@@ -147,14 +132,4 @@
}
}
}
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
-
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/QueueTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/QueueTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/QueueTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -25,17 +25,11 @@
import java.util.Set;
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
-import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
-import javax.naming.InitialContext;
-import org.jboss.jms.client.JBossConnection;
-import org.jboss.jms.client.JBossConnectionFactory;
-import org.jboss.test.messaging.MessagingTestCase;
import org.jboss.test.messaging.tools.ServerManagement;
/**
@@ -44,7 +38,7 @@
*
* $Id$
*/
-public class QueueTest extends MessagingTestCase
+public class QueueTest extends JMSTestCase
{
// Constants ------------------------------------------------------------------------------------
@@ -52,43 +46,13 @@
// Attributes -----------------------------------------------------------------------------------
- protected InitialContext ic;
- protected ConnectionFactory cf;
-
// Constructors ---------------------------------------------------------------------------------
public QueueTest(String name)
{
super(name);
}
-
- // TestCase overrides --------------------------------------------------------------------------
-
- public void setUp() throws Exception
- {
- super.setUp();
-
- ServerManagement.start("all");
-
-
- ic = new InitialContext(ServerManagement.getJNDIEnvironment());
- cf = (JBossConnectionFactory)ic.lookup("/ConnectionFactory");
-
- ServerManagement.undeployQueue("TestQueue");
- ServerManagement.deployQueue("TestQueue");
- log.debug("setup done");
- }
-
- public void tearDown() throws Exception
- {
- ServerManagement.undeployQueue("TestQueue");
- super.tearDown();
-
- log.debug("tear down done");
- }
-
-
// Public ---------------------------------------------------------------------------------------
/**
@@ -96,15 +60,15 @@
*/
public void testQueue() throws Exception
{
- Queue queue = (Queue)ic.lookup("/queue/TestQueue");
-
- Connection conn = cf.createConnection();
-
+ Connection conn = null;
+
try
{
+ conn = cf.createConnection();
+
Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = s.createProducer(queue);
- MessageConsumer c = s.createConsumer(queue);
+ MessageProducer p = s.createProducer(queue1);
+ MessageConsumer c = s.createConsumer(queue1);
conn.start();
p.send(s.createTextMessage("payload"));
@@ -124,30 +88,32 @@
// added for http://jira.jboss.org/jira/browse/JBMESSAGING-899
public void testClosedConsumerAfterStart() throws Exception
{
- Queue queue = (Queue) ic.lookup("/queue/TestQueue");
-
// This loop is to increase chances of a failure.
for (int counter = 0; counter < 20; counter++)
{
log.info("Iteration = " + counter);
- Connection conn1 = cf.createConnection();
+ Connection conn1 = null;
+
+ Connection conn2 = null;
+
+ try
+ {
+ conn1 = cf.createConnection();
- assertEquals(0, getServerId(conn1));
+ assertEquals(0, getServerId(conn1));
- Connection conn2 = cf.createConnection();
+ conn2 = cf.createConnection();
- assertEquals(0, getServerId(conn2));
+ assertEquals(0, getServerId(conn2));
- try
- {
- Session s = conn1.createSession(true, Session.AUTO_ACKNOWLEDGE);
+ Session s = conn1.createSession(true, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = s.createProducer(queue);
+ MessageProducer p = s.createProducer(queue1);
- for (int i = 0; i < 20; i++)
- {
- p.send(s.createTextMessage("message " + i));
+ for (int i = 0; i < 20; i++)
+ {
+ p.send(s.createTextMessage("message " + i));
}
s.commit();
@@ -156,11 +122,11 @@
// Create a consumer, start the session, close the consumer..
// This shouldn't cause any message to be lost
- MessageConsumer c2 = s2.createConsumer(queue);
+ MessageConsumer c2 = s2.createConsumer(queue1);
conn2.start();
c2.close();
- c2 = s2.createConsumer(queue);
+ c2 = s2.createConsumer(queue1);
//There is a possibility the messages arrive out of order if they hit the closed
//consumer and are cancelled back before delivery to the other consumer has finished.
@@ -181,7 +147,7 @@
s2.commit();
- assertNull(c2.receive(1000));
+ checkEmpty(queue1);
}
finally
{
@@ -197,20 +163,17 @@
}
}
- /**
- * The simplest possible queue test.
- */
public void testRedeployQueue() throws Exception
{
- Queue queue = (Queue)ic.lookup("/queue/TestQueue");
-
- Connection conn = cf.createConnection();
-
+ Connection conn = null;
+
try
{
+ conn = cf.createConnection();
+
Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = s.createProducer(queue);
- MessageConsumer c = s.createConsumer(queue);
+ MessageProducer p = s.createProducer(queue1);
+ MessageConsumer c = s.createConsumer(queue1);
conn.start();
for (int i = 0; i < 500; i++)
@@ -220,23 +183,16 @@
conn.close();
- //ServerManagement.undeployQueue("TestQueue");
-
- log.info("Stopping server");
ServerManagement.stop(0);
- log.info("Starting server");
ServerManagement.start(0, "all", false);
- ServerManagement.deployQueue("TestQueue");
+ deployAndLookupAdministeredObjects();
- ic = new InitialContext(ServerManagement.getJNDIEnvironment());
- cf = (JBossConnectionFactory)ic.lookup("/ConnectionFactory");
-
conn = cf.createConnection();
s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- p = s.createProducer(queue);
- c = s.createConsumer(queue);
+ p = s.createProducer(queue1);
+ c = s.createConsumer(queue1);
conn.start();
for (int i = 0; i < 500; i++)
@@ -245,7 +201,6 @@
assertNotNull(message);
assertNotNull(message.getJMSDestination());
}
-
}
finally
{
@@ -259,8 +214,7 @@
public void testQueueName() throws Exception
{
- Queue queue = (Queue)ic.lookup("/queue/TestQueue");
- assertEquals("TestQueue", queue.getQueueName());
+ assertEquals("Queue1", queue1.getQueueName());
}
// Package protected ----------------------------------------------------------------------------
Modified: trunk/tests/src/org/jboss/test/messaging/jms/ReferenceableTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/ReferenceableTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/ReferenceableTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -28,16 +28,9 @@
import javax.jms.Destination;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
-import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
-import javax.jms.Topic;
-import javax.naming.InitialContext;
-import org.jboss.jms.client.JBossConnectionFactory;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
-
/**
*
* A ReferenceableTest.
@@ -49,7 +42,7 @@
*
* $Id$
*/
-public class ReferenceableTest extends MessagingTestCase
+public class ReferenceableTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -57,14 +50,6 @@
// Attributes ----------------------------------------------------
- protected Queue queue;
-
- protected Topic topic;
-
- protected InitialContext ic;
-
- protected JBossConnectionFactory cf;
-
// Constructors --------------------------------------------------
public ReferenceableTest(String name)
@@ -72,41 +57,15 @@
super(name);
}
- // TestCase overrides -------------------------------------------
-
- public void setUp() throws Exception
- {
- super.setUp();
- ServerManagement.start("all");
-
- ic = new InitialContext(ServerManagement.getJNDIEnvironment());
-
- cf = (JBossConnectionFactory)ic.lookup("/ConnectionFactory");
-
- ServerManagement.undeployQueue("Queue");
- ServerManagement.deployQueue("Queue");
- ServerManagement.undeployTopic("Topic");
- ServerManagement.deployTopic("Topic");
- queue = (Queue)ic.lookup("/queue/Queue");
- topic = (Topic)ic.lookup("/topic/Topic");
-
- }
-
- public void tearDown() throws Exception
- {
- super.tearDown();
- }
-
-
// Public --------------------------------------------------------
public void testSerializable() throws Exception
{
assertTrue(cf instanceof Serializable);
- assertTrue(queue instanceof Serializable);
+ assertTrue(queue1 instanceof Serializable);
- assertTrue(topic instanceof Serializable);
+ assertTrue(topic1 instanceof Serializable);
}
/* http://jira.jboss.org/jira/browse/JBMESSAGING-395
@@ -187,30 +146,38 @@
protected void simpleSendReceive(ConnectionFactory cf, Destination dest) throws Exception
{
- Connection conn = cf.createConnection();
+ Connection conn = null;
- Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageProducer prod = sess.createProducer(dest);
-
- MessageConsumer cons = sess.createConsumer(dest);
-
- conn.start();
-
- TextMessage tm = sess.createTextMessage("ref test");
-
- prod.send(tm);
-
- tm = (TextMessage)cons.receive(1000);
-
- assertNotNull(tm);
-
- assertEquals("ref test", tm.getText());
-
- conn.close();
-
+ try
+ {
+ conn = cf.createConnection();
+
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = sess.createProducer(dest);
+
+ MessageConsumer cons = sess.createConsumer(dest);
+
+ conn.start();
+
+ TextMessage tm = sess.createTextMessage("ref test");
+
+ prod.send(tm);
+
+ tm = (TextMessage)cons.receive(1000);
+
+ assertNotNull(tm);
+
+ assertEquals("ref test", tm.getText());
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
-
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/ReferencingTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/ReferencingTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/ReferencingTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -22,19 +22,15 @@
package org.jboss.test.messaging.jms;
import javax.jms.Connection;
-import javax.jms.Destination;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
-import javax.naming.InitialContext;
-import org.jboss.jms.client.JBossConnectionFactory;
import org.jboss.jms.message.MessageProxy;
import org.jboss.messaging.core.contract.MessageReference;
import org.jboss.messaging.core.contract.MessageStore;
import org.jboss.messaging.core.impl.message.SimpleMessageReference;
-import org.jboss.test.messaging.MessagingTestCase;
import org.jboss.test.messaging.tools.ServerManagement;
/**
@@ -46,7 +42,7 @@
*
* $Id$
*/
-public class ReferencingTest extends MessagingTestCase
+public class ReferencingTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -54,12 +50,6 @@
// Attributes ----------------------------------------------------
- protected InitialContext initialContext;
-
- protected JBossConnectionFactory cf;
-
- protected Destination queue;
-
// Constructors --------------------------------------------------
public ReferencingTest(String name)
@@ -67,38 +57,6 @@
super(name);
}
- // TestCase overrides -------------------------------------------
-
- public void setUp() throws Exception
- {
- if (ServerManagement.isRemote())
- {
- fail("this test is not supposed to run in a remote configuration!");
- }
-
- super.setUp();
- ServerManagement.start("all");
-
- initialContext = new InitialContext(ServerManagement.getJNDIEnvironment());
- cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
- ServerManagement.undeployQueue("Queue");
- ServerManagement.deployQueue("Queue");
-
- queue = (Destination)initialContext.lookup("/queue/Queue");
-
- this.drainDestination(cf, queue);
-
- }
-
- public void tearDown() throws Exception
- {
- ServerManagement.undeployQueue("Queue");
-
- super.tearDown();
- }
-
-
// Public --------------------------------------------------------
public void testAutoAck1() throws Exception
@@ -109,9 +67,9 @@
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
conn.start();
@@ -139,7 +97,7 @@
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
conn.start();
@@ -147,7 +105,7 @@
prod.send(m);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
TextMessage m2 = (TextMessage)cons.receive(1000);
@@ -171,9 +129,9 @@
Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
conn.start();
@@ -209,7 +167,7 @@
Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
conn.start();
@@ -217,7 +175,7 @@
prod.send(m);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
TextMessage m2 = (TextMessage)cons.receive(1000);
@@ -247,7 +205,7 @@
Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
conn.start();
@@ -255,7 +213,7 @@
prod.send(m);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
TextMessage m2 = (TextMessage)cons.receive(1000);
@@ -298,9 +256,9 @@
Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
conn.start();
@@ -338,9 +296,9 @@
Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
conn.start();
@@ -387,9 +345,9 @@
Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
conn.start();
Modified: trunk/tests/src/org/jboss/test/messaging/jms/RemotingConnectionConfigurationTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/RemotingConnectionConfigurationTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/RemotingConnectionConfigurationTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -23,12 +23,9 @@
import java.lang.reflect.Field;
import java.net.InetAddress;
-import java.util.Map;
import java.util.HashSet;
+import java.util.Map;
-import javax.jms.ConnectionFactory;
-import javax.naming.InitialContext;
-
import org.jboss.jms.client.JBossConnection;
import org.jboss.jms.client.delegate.ClientConnectionDelegate;
import org.jboss.jms.client.remoting.JMSRemotingConnection;
@@ -38,7 +35,6 @@
import org.jboss.remoting.callback.InvokerCallbackHandler;
import org.jboss.remoting.transport.Connector;
import org.jboss.remoting.transport.PortUtil;
-import org.jboss.test.messaging.MessagingTestCase;
import org.jboss.test.messaging.tools.ServerManagement;
import org.jboss.test.messaging.tools.jmx.ServiceContainer;
@@ -49,7 +45,7 @@
*
* $Id$
*/
-public class RemotingConnectionConfigurationTest extends MessagingTestCase
+public class RemotingConnectionConfigurationTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -57,32 +53,12 @@
// Attributes ----------------------------------------------------
- protected ConnectionFactory cf;
-
// Constructors --------------------------------------------------
public RemotingConnectionConfigurationTest(String name)
{
super(name);
}
-
- // TestCase overrides -------------------------------------------
-
- public void setUp() throws Exception
- {
- super.setUp();
- ServerManagement.start("all");
- InitialContext ic = new InitialContext(ServerManagement.getJNDIEnvironment());
- cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
- log.debug("setup done");
- }
-
- public void tearDown() throws Exception
- {
- super.tearDown();
- }
-
-
// Public --------------------------------------------------------
/**
@@ -222,6 +198,15 @@
{
connection.close();
}
+
+ System.clearProperty("jboss.messaging.callback.bind.address");
+
+ System.clearProperty("jboss.messaging.callback.bind.port");
+
+ System.clearProperty("jboss.messaging.callback.pollPeriod");
+
+ System.clearProperty("jboss.messaging.callback.reportPollingStatistics");
+
}
}
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/ScheduledDeliveryTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/ScheduledDeliveryTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/ScheduledDeliveryTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -22,19 +22,14 @@
package org.jboss.test.messaging.jms;
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
-import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
-import javax.jms.Topic;
import javax.management.ObjectName;
-import javax.naming.InitialContext;
import org.jboss.jms.message.JBossMessage;
-import org.jboss.test.messaging.MessagingTestCase;
import org.jboss.test.messaging.tools.ServerManagement;
/**
@@ -47,7 +42,7 @@
* $Id$
*
*/
-public class ScheduledDeliveryTest extends MessagingTestCase
+public class ScheduledDeliveryTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -55,11 +50,6 @@
// Attributes ----------------------------------------------------
- protected InitialContext ic;
- protected ConnectionFactory cf;
- protected Queue queue;
- protected Topic topic;
-
// Constructors --------------------------------------------------
public ScheduledDeliveryTest(String name)
@@ -89,7 +79,7 @@
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
//Send one scheduled
@@ -144,9 +134,7 @@
ServerManagement.startServerPeer();
// Messaging server restart implies new ConnectionFactory lookup
- cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
-
- ServerManagement.deployQueue("Queue");
+ deployAndLookupAdministeredObjects();
conn = cf.createConnection();
@@ -154,7 +142,7 @@
sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
//First the non scheduled messages should be received
@@ -239,7 +227,7 @@
try
{
- ObjectName queueObjectName = new ObjectName("jboss.messaging.destination:service=Queue,name=Queue");
+ ObjectName queueObjectName = new ObjectName("jboss.messaging.destination:service=Queue,name=Queue1");
ServerManagement.setAttribute(queueObjectName, "RedeliveryDelay", "-1");
@@ -253,7 +241,9 @@
}
finally
{
- ServerManagement.setAttribute(serverPeerObjectName, "DefaultRedeliveryDelay", "0");
+ ServerManagement.setAttribute(serverPeerObjectName, "DefaultRedeliveryDelay", "0");
+
+ removeAllMessages(queue1.getQueueName(), true, 0);
}
}
@@ -261,7 +251,7 @@
{
ObjectName serverPeerObjectName = ServerManagement.getServerPeerObjectName();
- ObjectName queueObjectName = new ObjectName("jboss.messaging.destination:service=Queue,name=Queue");
+ ObjectName queueObjectName = new ObjectName("jboss.messaging.destination:service=Queue,name=Queue1");
try
{
@@ -280,6 +270,8 @@
ServerManagement.setAttribute(serverPeerObjectName, "DefaultRedeliveryDelay", "0");
ServerManagement.setAttribute(queueObjectName, "RedeliveryDelay", "-1");
+
+ removeAllMessages(queue1.getQueueName(), true, 0);
}
}
@@ -288,46 +280,14 @@
// Protected -----------------------------------------------------
- protected void setUp() throws Exception
- {
- super.setUp();
-
- ServerManagement.start("all");
-
- ic = new InitialContext(ServerManagement.getJNDIEnvironment());
-
- cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
-
- ServerManagement.undeployQueue("Queue");
-
- ServerManagement.undeployTopic("Topic");
-
- ServerManagement.deployQueue("Queue");
-
- ServerManagement.deployTopic("Topic");
-
- queue = (Queue)ic.lookup("/queue/Queue");
-
- topic = (Topic)ic.lookup("/topic/Topic");
-
- this.drainDestination(cf, queue);
-
- }
-
protected void tearDown() throws Exception
{
super.tearDown();
- ServerManagement.undeployQueue("Queue");
-
- ServerManagement.undeployTopic("Topic");
-
// Some tests here are changing this attribute.. what would affect tests later
// Instead of restart the ServerPeer I'm just restoring the default
ServerManagement.setAttribute(ServerManagement.getServerPeerObjectName(),
"DefaultRedeliveryDelay", "0");
-
- if (ic != null) ic.close();
}
// Private -------------------------------------------------------
@@ -342,7 +302,7 @@
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
final int NUM_MESSAGES = 5;
@@ -353,24 +313,18 @@
prod.send(tm);
}
- log.info("Sent messages");
-
Session sess2 = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageConsumer cons = sess2.createConsumer(queue);
+ MessageConsumer cons = sess2.createConsumer(queue1);
conn.start();
-
- log.info("Started connection");
-
+
for (int i = 0; i < NUM_MESSAGES; i++)
{
TextMessage tm = (TextMessage)cons.receive(500);
assertNotNull(tm);
- log.info("Got message:" + tm.getText());
-
assertEquals("message" + i, tm.getText());
}
@@ -380,12 +334,10 @@
long now = System.currentTimeMillis();
sess2.close();
-
- log.info("Closed session");
-
+
Session sess3 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons2 = sess3.createConsumer(queue);
+ MessageConsumer cons2 = sess3.createConsumer(queue1);
for (int i = 0; i < NUM_MESSAGES; i++)
{
@@ -393,8 +345,6 @@
assertNotNull(tm);
- log.info("Got message 2nd time: " + tm.getText());
-
long time = System.currentTimeMillis();
assertTrue(time - now >= delay);
@@ -424,7 +374,7 @@
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
final int NUM_MESSAGES = 5;
@@ -435,24 +385,18 @@
prod.send(tm);
}
- log.info("Sent messages");
-
Session sess2 = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageConsumer cons = sess2.createConsumer(queue);
+ MessageConsumer cons = sess2.createConsumer(queue1);
conn.start();
- log.info("Started connection");
-
for (int i = 0; i < NUM_MESSAGES; i++)
{
TextMessage tm = (TextMessage)cons.receive(500);
assertNotNull(tm);
- log.info("Got message:" + tm.getText());
-
assertEquals("message" + i, tm.getText());
}
@@ -470,13 +414,8 @@
assertNotNull(tm);
- log.info("Got message 2nd time: " + tm.getText());
-
long time = System.currentTimeMillis();
- log.info("time-now:" + (time-now));
- log.info("delay:" + delay);
-
assertTrue(time - now >= delay);
assertTrue(time - now < delay + 250);
}
@@ -504,9 +443,9 @@
Session sess = conn.createSession(tx, tx ? Session.SESSION_TRANSACTED : Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
conn.start();
Modified: trunk/tests/src/org/jboss/test/messaging/jms/SecurityTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/SecurityTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/SecurityTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -22,7 +22,6 @@
package org.jboss.test.messaging.jms;
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.IllegalStateException;
import javax.jms.JMSSecurityException;
@@ -39,11 +38,9 @@
import javax.jms.TopicPublisher;
import javax.jms.DeliveryMode;
import javax.management.ObjectName;
-import javax.naming.InitialContext;
import org.jboss.logging.Logger;
import org.jboss.messaging.util.XMLUtil;
-import org.jboss.test.messaging.MessagingTestCase;
import org.jboss.test.messaging.tools.ServerManagement;
/**
@@ -61,41 +58,27 @@
* @version <tt>$Revision$</tt>
*
*/
-public class SecurityTest extends MessagingTestCase
+public class SecurityTest extends JMSTestCase
{
// Constants -----------------------------------------------------
private static final Logger log = Logger.getLogger(SecurityTest.class);
+
+ private static final String defConfig = "<security><role name=\"def\" read=\"true\" write=\"true\" create=\"true\"/></security>";
- protected static final String TEST_QUEUE = "queue/testQueue";
- protected static final String TEST_TOPIC = "topic/testTopic";
- protected static final String SECURED_TOPIC = "topic/securedTopic";
- protected static final String UNSECURED_TOPIC = "topic/unsecuredTopic";
-
// Static --------------------------------------------------------
// Attributes ----------------------------------------------------
- protected InitialContext ic;
-
- protected ConnectionFactory cf;
- protected Queue testQueue;
- protected Topic testTopic;
- protected Topic securedTopic;
- protected Topic unsecuredTopic;
-
- protected String oldDefaultConfig;
-
+ private String oldDefaultConfig;
+
// Constructors --------------------------------------------------
public SecurityTest(String name)
{
super(name);
}
-
- // TestCase overrides -------------------------------------------
-
-
+
// Public --------------------------------------------------------
/**
@@ -276,7 +259,7 @@
try
{
conn = cf.createConnection();
- assertTrue(canWriteDestination(conn, testQueue));
+ assertTrue(canWriteDestination(conn, queue1));
}
finally
{
@@ -293,7 +276,7 @@
try
{
conn = cf.createConnection("john", "needle");
- assertTrue(canWriteDestination(conn, testTopic));
+ assertTrue(canWriteDestination(conn, topic1));
}
finally
{
@@ -310,7 +293,7 @@
try
{
conn = cf.createConnection("nobody", "nobody");
- assertFalse(canWriteDestination(conn, testTopic));
+ assertFalse(canWriteDestination(conn, topic1));
}
finally
{
@@ -327,7 +310,7 @@
try
{
conn = cf.createConnection("john", "needle");
- assertTrue(canReadDestination(conn, testTopic));
+ assertTrue(canReadDestination(conn, topic1));
}
finally
{
@@ -344,7 +327,7 @@
try
{
conn = cf.createConnection("nobody", "nobody");
- assertFalse(canReadDestination(conn, testTopic));
+ assertFalse(canReadDestination(conn, topic1));
}
finally
{
@@ -359,7 +342,7 @@
{
conn = cf.createConnection("john", "needle");
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- sess.createBrowser(testQueue);
+ sess.createBrowser(queue1);
}
finally
{
@@ -374,7 +357,7 @@
{
conn = cf.createConnection("nobody", "nobody");
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- sess.createBrowser(testQueue);
+ sess.createBrowser(queue1);
fail("should throw JMSSecurityException");
}
catch (JMSSecurityException e)
@@ -393,7 +376,7 @@
try
{
conn = cf.createConnection("john", "needle");
- assertTrue(this.canWriteDestination(conn, testQueue));
+ assertTrue(this.canWriteDestination(conn, queue1));
}
finally
{
@@ -407,7 +390,7 @@
try
{
conn = cf.createConnection("nobody", "nobody");
- assertFalse(this.canWriteDestination(conn, testQueue));
+ assertFalse(this.canWriteDestination(conn, queue1));
}
finally
{
@@ -421,7 +404,7 @@
try
{
conn = cf.createConnection("john", "needle");
- assertTrue(this.canReadDestination(conn, testQueue));
+ assertTrue(this.canReadDestination(conn, queue1));
}
finally
{
@@ -435,7 +418,7 @@
try
{
conn = cf.createConnection("nobody", "nobody");
- assertFalse(this.canReadDestination(conn, testQueue));
+ assertFalse(this.canReadDestination(conn, queue1));
}
finally
{
@@ -452,7 +435,7 @@
try
{
conn = cf.createConnection("dilbert", "dogbert");
- assertTrue(this.canCreateDurableSub(conn, testTopic, "sub2"));
+ assertTrue(this.canCreateDurableSub(conn, topic1, "sub2"));
}
finally
{
@@ -461,6 +444,7 @@
}
}
+ //TODO - this test doesn't belong here - this should be added to writeDestination()
public void testTransactedPublish() throws JMSException
{
@@ -468,12 +452,11 @@
try
{
-
conn = ((TopicConnectionFactory)cf).createTopicConnection("nobody", "nobody");
TopicSession topicSess = conn.createTopicSession(true , Session.AUTO_ACKNOWLEDGE);
try
{
- TopicPublisher publisher = topicSess.createPublisher(testTopic);
+ TopicPublisher publisher = topicSess.createPublisher(topic1);
publisher.publish(topicSess.createTextMessage("test"), DeliveryMode.PERSISTENT, 4, 0l);
topicSess.commit();
@@ -485,7 +468,7 @@
try
{
- MessageProducer prod = topicSess.createPublisher(testTopic);
+ MessageProducer prod = topicSess.createPublisher(topic1);
prod.send(topicSess.createTextMessage("hello"));
topicSess.commit();
@@ -494,8 +477,6 @@
catch (JMSSecurityException expected)
{
}
-
-
}
finally
{
@@ -520,7 +501,7 @@
try
{
conn = cf.createConnection("dilbert", "dogbert");
- assertFalse(this.canCreateDurableSub(conn, securedTopic, "sub3"));
+ assertFalse(this.canCreateDurableSub(conn, topic2, "sub3"));
}
finally
{
@@ -539,7 +520,7 @@
{
conn = cf.createConnection("dynsub", "dynsub");
conn.setClientID("myID");
- assertTrue(this.canCreateDurableSub(conn, testTopic, "sub4"));
+ assertTrue(this.canCreateDurableSub(conn, topic1, "sub4"));
}
finally
{
@@ -557,7 +538,7 @@
{
conn = cf.createConnection("dynsub", "dynsub");
conn.setClientID("myID2");
- assertFalse(this.canCreateDurableSub(conn, securedTopic, "sub5"));
+ assertFalse(this.canCreateDurableSub(conn, topic2, "sub5"));
}
finally
{
@@ -572,9 +553,9 @@
{
conn = cf.createConnection("john", "needle");
conn.setClientID("myID5");
- assertTrue(this.canReadDestination(conn, unsecuredTopic));
- assertTrue(this.canWriteDestination(conn, unsecuredTopic));
- assertTrue(this.canCreateDurableSub(conn, unsecuredTopic, "subxyz"));
+ assertTrue(this.canReadDestination(conn, topic3));
+ assertTrue(this.canWriteDestination(conn, topic3));
+ assertTrue(this.canCreateDurableSub(conn, topic3, "subxyz"));
}
finally
{
@@ -589,9 +570,9 @@
{
conn = cf.createConnection("nobody", "nobody");
conn.setClientID("myID6");
- assertFalse(this.canReadDestination(conn, unsecuredTopic));
- assertFalse(this.canWriteDestination(conn, unsecuredTopic));
- assertFalse(this.canCreateDurableSub(conn, unsecuredTopic, "subabc"));
+ assertFalse(this.canReadDestination(conn, topic3));
+ assertFalse(this.canWriteDestination(conn, topic3));
+ assertFalse(this.canCreateDurableSub(conn, topic3, "subabc"));
}
finally
{
@@ -608,51 +589,37 @@
String defSecConf = ServerManagement.getDefaultSecurityConfig();
// Make sure it is the default security configuration I rely on
- String def = "<security><role name=\"def\" read=\"true\" write=\"true\" create=\"true\"/></security>";
- XMLUtil.assertEquivalent(XMLUtil.stringToElement(def),
+
+ XMLUtil.assertEquivalent(XMLUtil.stringToElement(defConfig),
XMLUtil.stringToElement(defSecConf));
// "john" has the role def, so he should be able to create a producer and a consumer on a queue
- ServerManagement.deployQueue("SomeQueue");
Connection conn = null;
try
{
- Queue someQueue = (Queue)ic.lookup("/queue/SomeQueue");
-
conn = cf.createConnection("john", "needle");
- assertTrue(canReadDestination(conn, someQueue));
- assertTrue(canWriteDestination(conn, someQueue));
+ assertTrue(canReadDestination(conn, queue2));
+ assertTrue(canWriteDestination(conn, queue2));
-
String newSecurityConfig =
"<security><role name=\"someotherrole\" read=\"true\" write=\"true\" create=\"false\"/></security>";
ServerManagement.setDefaultSecurityConfig(newSecurityConfig);
- assertFalse(canReadDestination(conn, someQueue));
- assertFalse(canWriteDestination(conn, someQueue));
+ assertFalse(canReadDestination(conn, queue2));
+ assertFalse(canWriteDestination(conn, queue2));
-
newSecurityConfig =
"<security><role name=\"def\" read=\"true\" write=\"false\" create=\"false\"/></security>";
ServerManagement.setDefaultSecurityConfig(newSecurityConfig);
- assertTrue(canReadDestination(conn, someQueue));
- assertFalse(canWriteDestination(conn, someQueue));
-
- newSecurityConfig =
- "<security><role name=\"def\" read=\"true\" write=\"true\" create=\"false\"/></security>";
-
- ServerManagement.setDefaultSecurityConfig(newSecurityConfig);
-
- assertTrue(canReadDestination(conn, someQueue));
- assertTrue(canWriteDestination(conn, someQueue));
+ assertTrue(canReadDestination(conn, queue2));
+ assertFalse(canWriteDestination(conn, queue2));
}
finally
{
- ServerManagement.undeployQueue("SomeQueue");
if (conn != null)
{
conn.close();
@@ -669,55 +636,50 @@
public void testQueueSecurityUpdateStopped() throws Exception
{
// "john" has the role def, so he should be able to create a producer and a consumer on a queue
- ServerManagement.deployQueue("SomeQueue");
+
+ ObjectName on = new ObjectName("jboss.messaging.destination:service=Queue,name=Queue2");
- ObjectName on = new ObjectName("jboss.messaging.destination:service=Queue,name=SomeQueue");
-
Connection conn = null;
try
{
- Queue someQueue = (Queue)ic.lookup("/queue/SomeQueue");
-
conn = cf.createConnection("john", "needle");
- assertTrue(canReadDestination(conn, someQueue));
- assertTrue(canWriteDestination(conn, someQueue));
+ assertTrue(canReadDestination(conn, queue2));
+ assertTrue(canWriteDestination(conn, queue2));
-
String newSecurityConfig =
"<security><role name=\"someotherrole\" read=\"true\" write=\"true\" create=\"false\"/></security>";
ServerManagement.invoke(on, "stop", null, null);
- ServerManagement.configureSecurityForDestination("SomeQueue", newSecurityConfig);
+ ServerManagement.configureSecurityForDestination("Queue2", newSecurityConfig);
ServerManagement.invoke(on, "start", null, null);
- assertFalse(canReadDestination(conn, someQueue));
- assertFalse(canWriteDestination(conn, someQueue));
+ assertFalse(canReadDestination(conn, queue2));
+ assertFalse(canWriteDestination(conn, queue2));
newSecurityConfig =
"<security><role name=\"def\" read=\"true\" write=\"false\" create=\"false\"/></security>";
ServerManagement.invoke(on, "stop", null, null);
- ServerManagement.configureSecurityForDestination("SomeQueue", newSecurityConfig);
+ ServerManagement.configureSecurityForDestination("Queue2", newSecurityConfig);
ServerManagement.invoke(on, "start", null, null);
- assertTrue(canReadDestination(conn, someQueue));
- assertFalse(canWriteDestination(conn, someQueue));
+ assertTrue(canReadDestination(conn, queue2));
+ assertFalse(canWriteDestination(conn, queue2));
newSecurityConfig =
"<security><role name=\"def\" read=\"true\" write=\"true\" create=\"false\"/></security>";
ServerManagement.invoke(on, "stop", null, null);
- ServerManagement.configureSecurityForDestination("SomeQueue", newSecurityConfig);
+ ServerManagement.configureSecurityForDestination("Queue2", newSecurityConfig);
ServerManagement.invoke(on, "start", null, null);
- assertTrue(canReadDestination(conn, someQueue));
- assertTrue(canWriteDestination(conn, someQueue));
+ assertTrue(canReadDestination(conn, queue2));
+ assertTrue(canWriteDestination(conn, queue2));
}
finally
- {
- ServerManagement.undeployQueue("SomeQueue");
+ {
if (conn != null)
{
conn.close();
@@ -734,55 +696,51 @@
public void testTopicSecurityUpdateStopped() throws Exception
{
// "john" has the role def, so he should be able to create a producer and a consumer on a queue
- ServerManagement.deployTopic("SomeTopic");
+
+ ObjectName on = new ObjectName("jboss.messaging.destination:service=Topic,name=Topic2");
- ObjectName on = new ObjectName("jboss.messaging.destination:service=Topic,name=SomeTopic");
-
Connection conn = null;
try
{
- Topic someTopic = (Topic)ic.lookup("/topic/SomeTopic");
-
conn = cf.createConnection("john", "needle");
- assertTrue(canReadDestination(conn, someTopic));
- assertTrue(canWriteDestination(conn, someTopic));
+ assertTrue(canReadDestination(conn, topic2));
+ assertTrue(canWriteDestination(conn, topic2));
String newSecurityConfig =
"<security><role name=\"someotherrole\" read=\"true\" write=\"true\" create=\"false\"/></security>";
ServerManagement.invoke(on, "stop", null, null);
- ServerManagement.configureSecurityForDestination("SomeTopic", newSecurityConfig);
+ ServerManagement.configureSecurityForDestination("Topic2", newSecurityConfig);
ServerManagement.invoke(on, "start", null, null);
- assertFalse(canReadDestination(conn, someTopic));
- assertFalse(canWriteDestination(conn, someTopic));
+ assertFalse(canReadDestination(conn, topic2));
+ assertFalse(canWriteDestination(conn, topic2));
newSecurityConfig =
"<security><role name=\"def\" read=\"true\" write=\"false\" create=\"false\"/></security>";
ServerManagement.invoke(on, "stop", null, null);
- ServerManagement.configureSecurityForDestination("SomeTopic", newSecurityConfig);
+ ServerManagement.configureSecurityForDestination("Topic2", newSecurityConfig);
ServerManagement.invoke(on, "start", null, null);
- assertTrue(canReadDestination(conn, someTopic));
- assertFalse(canWriteDestination(conn, someTopic));
+ assertTrue(canReadDestination(conn, topic2));
+ assertFalse(canWriteDestination(conn, topic2));
newSecurityConfig =
"<security><role name=\"def\" read=\"true\" write=\"true\" create=\"false\"/></security>";
ServerManagement.invoke(on, "stop", null, null);
- ServerManagement.configureSecurityForDestination("SomeTopic", newSecurityConfig);
+ ServerManagement.configureSecurityForDestination("Topic2", newSecurityConfig);
ServerManagement.invoke(on, "start", null, null);
- assertTrue(canReadDestination(conn, someTopic));
- assertTrue(canWriteDestination(conn, someTopic));
+ assertTrue(canReadDestination(conn, topic2));
+ assertTrue(canWriteDestination(conn, topic2));
}
finally
- {
- ServerManagement.undeployTopic("SomeTopic");
+ {
if (conn != null)
{
conn.close();
@@ -797,46 +755,58 @@
public void testQueueSecurityUpdate() throws Exception
{
// "john" has the role def, so he should be able to create a producer and a consumer on a queue
- ServerManagement.deployQueue("SomeQueue");
Connection conn = null;
try
{
- Queue someQueue = (Queue)ic.lookup("/queue/SomeQueue");
-
conn = cf.createConnection("john", "needle");
- assertTrue(canReadDestination(conn, someQueue));
- assertTrue(canWriteDestination(conn, someQueue));
+ assertTrue(canReadDestination(conn, queue2));
+ assertTrue(canWriteDestination(conn, queue2));
-
String newSecurityConfig =
"<security><role name=\"someotherrole\" read=\"true\" write=\"true\" create=\"false\"/></security>";
- ServerManagement.configureSecurityForDestination("SomeQueue", newSecurityConfig);
+ ServerManagement.configureSecurityForDestination("Queue2", newSecurityConfig);
- assertFalse(canReadDestination(conn, someQueue));
- assertFalse(canWriteDestination(conn, someQueue));
+ assertFalse(canReadDestination(conn, queue2));
+ assertFalse(canWriteDestination(conn, queue2));
newSecurityConfig =
"<security><role name=\"def\" read=\"true\" write=\"false\" create=\"false\"/></security>";
- ServerManagement.configureSecurityForDestination("SomeQueue", newSecurityConfig);
+ ServerManagement.configureSecurityForDestination("Queue2", newSecurityConfig);
- assertTrue(canReadDestination(conn, someQueue));
- assertFalse(canWriteDestination(conn, someQueue));
+ assertTrue(canReadDestination(conn, queue2));
+ assertFalse(canWriteDestination(conn, queue2));
newSecurityConfig =
"<security><role name=\"def\" read=\"true\" write=\"true\" create=\"false\"/></security>";
- ServerManagement.configureSecurityForDestination("SomeQueue", newSecurityConfig);
+ ServerManagement.configureSecurityForDestination("Queue2", newSecurityConfig);
- assertTrue(canReadDestination(conn, someQueue));
- assertTrue(canWriteDestination(conn, someQueue));
+ assertTrue(canReadDestination(conn, queue2));
+ assertTrue(canWriteDestination(conn, queue2));
+
+ //Now set to null
+
+ ServerManagement.configureSecurityForDestination("Queue2", null);
+
+ //Should fall back to the default config
+ String lockedConf = "<security><role name=\"alien\" read=\"true\" write=\"true\" create=\"true\"/></security>";
+
+ ServerManagement.setDefaultSecurityConfig(lockedConf);
+
+ assertFalse(canReadDestination(conn, queue2));
+ assertFalse(canWriteDestination(conn, queue2));
+
+ ServerManagement.setDefaultSecurityConfig(defConfig);
+
+ assertTrue(canReadDestination(conn, queue2));
+ assertTrue(canWriteDestination(conn, queue2));
}
finally
- {
- ServerManagement.undeployQueue("SomeQueue");
+ {
if (conn != null)
{
conn.close();
@@ -851,46 +821,59 @@
public void testTopicSecurityUpdate() throws Exception
{
// "john" has the role def, so he should be able to create a producer and a consumer on a queue
- ServerManagement.deployTopic("SomeTopic");
Connection conn = null;
try
{
- Topic someTopic = (Topic)ic.lookup("/topic/SomeTopic");
-
conn = cf.createConnection("john", "needle");
- assertTrue(canReadDestination(conn, someTopic));
- assertTrue(canWriteDestination(conn, someTopic));
+ assertTrue(canReadDestination(conn, topic2));
+ assertTrue(canWriteDestination(conn, topic2));
String newSecurityConfig =
"<security><role name=\"someotherrole\" read=\"true\" write=\"true\" create=\"false\"/></security>";
- ServerManagement.configureSecurityForDestination("SomeTopic", newSecurityConfig);
+ ServerManagement.configureSecurityForDestination("Topic2", newSecurityConfig);
- assertFalse(canReadDestination(conn, someTopic));
- assertFalse(canWriteDestination(conn, someTopic));
+ assertFalse(canReadDestination(conn, topic2));
+ assertFalse(canWriteDestination(conn, topic2));
newSecurityConfig =
"<security><role name=\"def\" read=\"true\" write=\"false\" create=\"false\"/></security>";
- ServerManagement.configureSecurityForDestination("SomeTopic", newSecurityConfig);
+ ServerManagement.configureSecurityForDestination("Topic2", newSecurityConfig);
- assertTrue(canReadDestination(conn, someTopic));
- assertFalse(canWriteDestination(conn, someTopic));
+ assertTrue(canReadDestination(conn, topic2));
+ assertFalse(canWriteDestination(conn, topic2));
newSecurityConfig =
"<security><role name=\"def\" read=\"true\" write=\"true\" create=\"false\"/></security>";
- ServerManagement.configureSecurityForDestination("SomeTopic", newSecurityConfig);
+ ServerManagement.configureSecurityForDestination("Topic2", newSecurityConfig);
- assertTrue(canReadDestination(conn, someTopic));
- assertTrue(canWriteDestination(conn, someTopic));
+ assertTrue(canReadDestination(conn, topic2));
+ assertTrue(canWriteDestination(conn, topic2));
+
+ //Now set to null
+
+ ServerManagement.configureSecurityForDestination("Topic2", null);
+
+ //Should fall back to the default config
+ String lockedConf = "<security><role name=\"alien\" read=\"true\" write=\"true\" create=\"true\"/></security>";
+
+ ServerManagement.setDefaultSecurityConfig(lockedConf);
+
+ assertFalse(canReadDestination(conn, topic2));
+ assertFalse(canWriteDestination(conn, topic2));
+
+ ServerManagement.setDefaultSecurityConfig(defConfig);
+
+ assertTrue(canReadDestination(conn, topic2));
+ assertTrue(canWriteDestination(conn, topic2));
}
finally
{
- ServerManagement.undeployTopic("SomeTopic");
if (conn != null)
{
conn.close();
@@ -953,73 +936,47 @@
protected void setUp() throws Exception
{
super.setUp();
- ServerManagement.start("all");
-
- ServerManagement.undeployQueue("testQueue");
- ServerManagement.deployQueue("testQueue");
-
- final String testQueueConf =
+
+ oldDefaultConfig = ServerManagement.getDefaultSecurityConfig();
+
+ final String queueConf =
"<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>";
- ServerManagement.configureSecurityForDestination("testQueue", testQueueConf);
+ ServerManagement.configureSecurityForDestination("Queue1", queueConf);
- ServerManagement.undeployTopic("testTopic");
- ServerManagement.deployTopic("testTopic");
-
- final String testTopicConf =
+ final String topicConf =
"<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>";
- ServerManagement.configureSecurityForDestination("testTopic", testTopicConf);
+ ServerManagement.configureSecurityForDestination("Topic1", topicConf);
- ServerManagement.undeployTopic("securedTopic");
- ServerManagement.deployTopic("securedTopic");
final String testSecuredTopicConf =
"<security>" +
"<role name=\"publisher\" read=\"true\" write=\"true\" create=\"false\"/>" +
"</security>";
- ServerManagement.configureSecurityForDestination("testSecuredTopic", testSecuredTopicConf);
+ ServerManagement.configureSecurityForDestination("Topic2", testSecuredTopicConf);
- ServerManagement.undeployTopic("unsecuredTopic");
- ServerManagement.deployTopic("unsecuredTopic");
-
- final String defaultSecurityConfig =
- "<security><role name=\"def\" read=\"true\" write=\"true\" create=\"true\"/></security>";
- oldDefaultConfig = ServerManagement.getDefaultSecurityConfig();
- ServerManagement.setDefaultSecurityConfig(defaultSecurityConfig);
-
- ic = new InitialContext(ServerManagement.getJNDIEnvironment());
-
- cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
-
- testQueue = (Queue)ic.lookup("/queue/testQueue");
- testTopic = (Topic)ic.lookup("/topic/testTopic");
- securedTopic = (Topic)ic.lookup("/topic/securedTopic");
- unsecuredTopic = (Topic)ic.lookup("/topic/unsecuredTopic");
-
- drainDestination(cf, testQueue);
-
- log.debug("setup done");
+ ServerManagement.setDefaultSecurityConfig(defConfig);
}
protected void tearDown() throws Exception
{
+ super.tearDown();
+
ServerManagement.setDefaultSecurityConfig(oldDefaultConfig);
- ServerManagement.undeployQueue("testQueue");
- ServerManagement.undeployTopic("testTopic");
- ServerManagement.undeployTopic("securedTopic");
- ServerManagement.undeployTopic("unsecuredTopic");
-
- ic.close();
+ ServerManagement.configureSecurityForDestination("Queue1", null);
+ ServerManagement.configureSecurityForDestination("Queue2", null);
+ ServerManagement.configureSecurityForDestination("Topic1", null);
+ ServerManagement.configureSecurityForDestination("Topic2", null);
}
// Private -------------------------------------------------------
@@ -1070,6 +1027,15 @@
log.trace("Can't write to destination using named producer");
anonSucceeded = false;
}
+
+ if (namedSucceeded || anonSucceeded)
+ {
+ if (dest instanceof Queue)
+ {
+ String destName = ((Queue)dest).getQueueName();
+ removeAllMessages(destName, true, 0);
+ }
+ }
log.trace("namedSucceeded:" + namedSucceeded + ", anonSucceeded:" + anonSucceeded);
return namedSucceeded || anonSucceeded;
@@ -1103,7 +1069,7 @@
private void testSecurityForTemporaryDestination(boolean isQueue) throws Exception
{
- Destination dest = isQueue ? (Destination) testQueue : testTopic;
+ Destination dest = isQueue ? (Destination) queue1 : topic1;
Connection conn = cf.createConnection("guest", "guest");
try
Modified: trunk/tests/src/org/jboss/test/messaging/jms/SessionTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/SessionTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/SessionTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -37,16 +37,12 @@
import javax.jms.TopicSession;
import javax.jms.XAConnection;
import javax.jms.XASession;
-import javax.management.ObjectName;
-import javax.naming.InitialContext;
-import org.jboss.jms.client.JBossConnectionFactory;
import org.jboss.jms.client.JBossSession;
import org.jboss.jms.client.delegate.ClientSessionDelegate;
import org.jboss.jms.client.state.ConnectionState;
import org.jboss.jms.client.state.SessionState;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
+import org.jboss.jms.tx.ResourceManagerFactory;
/**
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
@@ -55,7 +51,7 @@
*
* $Id$
*/
-public class SessionTest extends MessagingTestCase
+public class SessionTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -63,12 +59,6 @@
// Attributes ----------------------------------------------------
- protected InitialContext initialContext;
-
- protected JBossConnectionFactory cf;
- protected Topic topic;
- protected Queue queue;
-
// Constructors --------------------------------------------------
public SessionTest(String name)
@@ -76,40 +66,6 @@
super(name);
}
-
- // TestCase overrides -------------------------------------------
-
- public void setUp() throws Exception
- {
- super.setUp();
-
- ServerManagement.start("all");
-
-
- initialContext = new InitialContext(ServerManagement.getJNDIEnvironment());
- cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
- ServerManagement.undeployTopic("TestTopic");
- ServerManagement.deployTopic("TestTopic");
- topic = (Topic)initialContext.lookup("/topic/TestTopic");
-
- ServerManagement.undeployQueue("TestQueue");
- ServerManagement.deployQueue("TestQueue");
- queue = (Queue)initialContext.lookup("/queue/TestQueue");
-
- log.debug("Done setup()");
-
- }
-
- public void tearDown() throws Exception
- {
- ServerManagement.undeployTopic("TestTopic");
- ServerManagement.undeployQueue("TestQueue");
- super.tearDown();
- }
-
-
-
// Public --------------------------------------------------------
public void testNoTransactionAfterClose() throws Exception
@@ -117,10 +73,10 @@
Connection conn = cf.createConnection();
conn.start();
Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
prod.send(sess.createMessage());
sess.commit();
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
cons.receive();
sess.commit();
@@ -150,7 +106,7 @@
{
Connection conn = cf.createConnection();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- sess.createProducer(topic);
+ sess.createProducer(topic1);
conn.close();
}
@@ -162,9 +118,9 @@
MessageProducer p = sess.createProducer(null);
- p.send(queue, m);
+ p.send(queue1, m);
- MessageConsumer c = sess.createConsumer(queue);
+ MessageConsumer c = sess.createConsumer(queue1);
conn.start();
//receiveNoWait is not guaranteed to return message immediately
@@ -180,7 +136,7 @@
Connection conn = cf.createConnection();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- sess.createConsumer(topic);
+ sess.createConsumer(topic1);
conn.close();
}
@@ -264,7 +220,7 @@
{
Connection conn = cf.createConnection();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Queue queue = sess.createQueue("TestQueue");
+ Queue queue = sess.createQueue("Queue1");
MessageProducer producer = sess.createProducer(queue);
MessageConsumer consumer = sess.createConsumer(queue);
@@ -333,7 +289,7 @@
Connection conn = cf.createConnection();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Topic topic = sess.createTopic("TestTopic");
+ Topic topic = sess.createTopic("Topic1");
MessageProducer producer = sess.createProducer(topic);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
@@ -407,7 +363,7 @@
Connection conn = cf.createConnection();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
Message m = sess.createTextMessage("hello");
prod.send(m);
@@ -429,6 +385,8 @@
{}
conn.close();
+
+ removeAllMessages(queue1.getQueueName(), true, 0);
}
@@ -472,14 +430,14 @@
Connection conn = cf.createConnection();
Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- s.createProducer(queue).send(s.createTextMessage("wont_ack"));
+ s.createProducer(queue1).send(s.createTextMessage("wont_ack"));
conn.close();
conn = cf.createConnection();
s = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
conn.start();
- TextMessage m = (TextMessage)s.createConsumer(queue).receive(1000);
+ TextMessage m = (TextMessage)s.createConsumer(queue1).receive(1000);
assertEquals("wont_ack", m.getText());
@@ -489,7 +447,7 @@
// get the message again
s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- m = (TextMessage)s.createConsumer(queue).receive(1000);
+ m = (TextMessage)s.createConsumer(queue1).receive(1000);
assertEquals("wont_ack", m.getText());
@@ -502,30 +460,26 @@
Connection conn = cf.createConnection();
Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- s.createProducer(queue).send(s.createTextMessage("bex"));
+ s.createProducer(queue1).send(s.createTextMessage("bex"));
conn.close();
conn = cf.createConnection();
Session session = conn.createSession(true, -1);
conn.start();
- TextMessage m = (TextMessage)session.createConsumer(queue).receive(1000);
+ TextMessage m = (TextMessage)session.createConsumer(queue1).receive(1000);
assertEquals("bex", m.getText());
// make sure the acknowledment hasn't been sent to the channel
- ObjectName on = new ObjectName("jboss.messaging.destination:service=Queue,name=TestQueue");
- Integer mc = (Integer)ServerManagement.getAttribute(on, "MessageCount");
-
- assertEquals(1, mc.intValue());
-
+ assertRemainingMessages(1);
+
// close the session
session.close();
// JMS 1.1 4.4.1: "Closing a transacted session must roll back its transaction in progress"
- mc = (Integer)ServerManagement.getAttribute(on, "MessageCount");
- assertEquals(1, mc.intValue());
+ assertRemainingMessages(1);
conn.close();
@@ -534,7 +488,7 @@
conn = cf.createConnection();
s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn.start();
- TextMessage rm = (TextMessage)s.createConsumer(queue).receive(1000);
+ TextMessage rm = (TextMessage)s.createConsumer(queue1).receive(1000);
assertEquals("bex", rm.getText());
@@ -544,9 +498,13 @@
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
-
-
-
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ ResourceManagerFactory.instance.clear();
+ }
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
Modified: trunk/tests/src/org/jboss/test/messaging/jms/String64KLimitTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/String64KLimitTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/String64KLimitTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -27,18 +27,13 @@
import java.io.DataOutputStream;
import javax.jms.Connection;
-import javax.jms.Destination;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.ObjectMessage;
import javax.jms.Session;
import javax.jms.TextMessage;
-import javax.naming.InitialContext;
-import org.jboss.jms.client.JBossConnectionFactory;
import org.jboss.messaging.util.SafeUTF;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
/**
*
@@ -53,7 +48,7 @@
*
* $Id$
*/
-public class String64KLimitTest extends MessagingTestCase
+public class String64KLimitTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -61,11 +56,6 @@
// Attributes ----------------------------------------------------
- protected InitialContext initialContext;
-
- protected JBossConnectionFactory cf;
- protected Destination queue;
-
// Constructors --------------------------------------------------
public String64KLimitTest(String name)
@@ -75,33 +65,6 @@
// TestCase overrides -------------------------------------------
- public void setUp() throws Exception
- {
- super.setUp();
- ServerManagement.start("all");
-
- initialContext = new InitialContext(ServerManagement.getJNDIEnvironment());
- cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
- ServerManagement.undeployQueue("Queue");
- ServerManagement.deployQueue("Queue");
- ServerManagement.undeployTopic("Topic");
- ServerManagement.deployTopic("Topic");
- queue = (Destination)initialContext.lookup("/queue/Queue");
-
- log.debug("setup done");
- }
-
- public void tearDown() throws Exception
- {
- ServerManagement.undeployQueue("Queue");
- ServerManagement.undeployTopic("Topic");
-
- super.tearDown();
-
- }
-
-
// Public --------------------------------------------------------
public void testSafeWriteReadUTFTest1() throws Exception
@@ -188,12 +151,9 @@
int lastReadBufferSize = su.getLastReadBufferSize();
- assertEquals(28, lastReadBufferSize);
-
+ assertEquals(28, lastReadBufferSize);
}
-
-
-
+
protected String genString(int len)
{
char[] chars = new char[len];
@@ -214,9 +174,9 @@
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
conn.start();
@@ -284,9 +244,7 @@
}
}
}
-
-
-
+
public void test64KLimitWithObjectMessage() throws Exception
{
Connection conn = null;
@@ -297,9 +255,9 @@
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
conn.start();
Modified: trunk/tests/src/org/jboss/test/messaging/jms/TemporaryDestinationTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/TemporaryDestinationTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/TemporaryDestinationTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -22,7 +22,6 @@
package org.jboss.test.messaging.jms;
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
@@ -31,11 +30,8 @@
import javax.jms.TemporaryQueue;
import javax.jms.TemporaryTopic;
import javax.jms.TextMessage;
-import javax.naming.InitialContext;
import javax.naming.NamingException;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
import org.jboss.jms.message.MessageProxy;
/**
@@ -45,7 +41,7 @@
*
* $Id$
*/
-public class TemporaryDestinationTest extends MessagingTestCase
+public class TemporaryDestinationTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -53,14 +49,6 @@
// Attributes ----------------------------------------------------
- protected InitialContext initialContext;
-
- protected ConnectionFactory cf;
-
- protected Connection connection;
-
- protected Session producerSession, consumerSession;
-
// Constructors --------------------------------------------------
public TemporaryDestinationTest(String name)
@@ -68,99 +56,103 @@
super(name);
}
- // TestCase overrides -------------------------------------------
-
- public void setUp() throws Exception
- {
- super.setUp();
- ServerManagement.start("all");
-
-
- initialContext = new InitialContext(ServerManagement.getJNDIEnvironment());
- cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
- ServerManagement.undeployTopic("Topic");
- ServerManagement.deployTopic("Topic");
- //topic = (Destination)initialContext.lookup("/topic/Topic");
-
- connection = cf.createConnection();
- producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- consumerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- }
-
- public void tearDown() throws Exception
- {
- connection.close();
-
- ServerManagement.undeployTopic("Topic");
-
- super.tearDown();
- }
-
-
// Public --------------------------------------------------------
public void testTemp() throws Exception
{
- TemporaryTopic tempTopic = producerSession.createTemporaryTopic();
-
- MessageProducer producer = producerSession.createProducer(tempTopic);
-
- MessageConsumer consumer = consumerSession.createConsumer(tempTopic);
-
- connection.start();
-
- final String messageText = "This is a message";
-
- Message m = producerSession.createTextMessage(messageText);
-
- producer.send(m);
-
- TextMessage m2 = (TextMessage)consumer.receive(2000);
-
- assertNotNull(m2);
-
- assertEquals(messageText, m2.getText());
-
- try
- {
- tempTopic.delete();
- fail();
- }
- catch (JMSException e)
- {
- //Can't delete temp dest if there are open consumers
- }
-
- consumer.close();
- tempTopic.delete();
-
-
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+
+ Session producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Session consumerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ TemporaryTopic tempTopic = producerSession.createTemporaryTopic();
+
+ MessageProducer producer = producerSession.createProducer(tempTopic);
+
+ MessageConsumer consumer = consumerSession.createConsumer(tempTopic);
+
+ conn.start();
+
+ final String messageText = "This is a message";
+
+ Message m = producerSession.createTextMessage(messageText);
+
+ producer.send(m);
+
+ TextMessage m2 = (TextMessage)consumer.receive(2000);
+
+ assertNotNull(m2);
+
+ assertEquals(messageText, m2.getText());
+
+ try
+ {
+ tempTopic.delete();
+ fail();
+ }
+ catch (JMSException e)
+ {
+ //Can't delete temp dest if there are open consumers
+ }
+
+ consumer.close();
+
+ tempTopic.delete();
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void testTemporaryQueueBasic() throws Exception
{
-
- TemporaryQueue tempQueue = producerSession.createTemporaryQueue();
-
- MessageProducer producer = producerSession.createProducer(tempQueue);
-
- MessageConsumer consumer = consumerSession.createConsumer(tempQueue);
-
- connection.start();
-
- final String messageText = "This is a message";
-
- Message m = producerSession.createTextMessage(messageText);
-
- producer.send(m);
-
- TextMessage m2 = (TextMessage)consumer.receive(2000);
-
- assertNotNull(m2);
-
- assertEquals(messageText, m2.getText());
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+
+ Session producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Session consumerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ TemporaryQueue tempQueue = producerSession.createTemporaryQueue();
+
+ MessageProducer producer = producerSession.createProducer(tempQueue);
+
+ MessageConsumer consumer = consumerSession.createConsumer(tempQueue);
+
+ conn.start();
+
+ final String messageText = "This is a message";
+
+ Message m = producerSession.createTextMessage(messageText);
+
+ producer.send(m);
+
+ TextMessage m2 = (TextMessage)consumer.receive(2000);
+
+ assertNotNull(m2);
+
+ assertEquals(messageText, m2.getText());
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
/**
@@ -168,137 +160,225 @@
*/
public void testTemporaryQueueOnClosedSession() throws Exception
{
- producerSession.close();
-
- try
- {
- producerSession.createTemporaryQueue();
- fail("should throw exception");
- }
- catch(javax.jms.IllegalStateException e)
- {
- // OK
- }
+ Connection producerConnection = null;
+
+ try
+ {
+ producerConnection = cf.createConnection();
+
+ Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ producerSession.close();
+
+ try
+ {
+ producerSession.createTemporaryQueue();
+ fail("should throw exception");
+ }
+ catch(javax.jms.IllegalStateException e)
+ {
+ // OK
+ }
+ }
+ finally
+ {
+ if (producerConnection != null)
+ {
+ producerConnection.close();
+ }
+ }
}
public void testTemporaryQueueDeleteWithConsumer() throws Exception
{
- TemporaryQueue tempQueue = producerSession.createTemporaryQueue();
+ Connection conn = null;
- MessageConsumer consumer = consumerSession.createConsumer(tempQueue);
-
try
{
- tempQueue.delete();
+ conn = cf.createConnection();
- fail("Should throw JMSException");
+ Session producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Session consumerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ TemporaryQueue tempQueue = producerSession.createTemporaryQueue();
+
+ MessageConsumer consumer = consumerSession.createConsumer(tempQueue);
+
+ try
+ {
+ tempQueue.delete();
+
+ fail("Should throw JMSException");
+ }
+ catch (JMSException e)
+ {
+ //Should fail - you can't delete a temp queue if it has active consumers
+ }
+
+ consumer.close();
}
- catch (JMSException e)
+ finally
{
- //Should fail - you can't delete a temp queue if it has active consumers
+ if (conn != null)
+ {
+ conn.close();
+ }
}
-
- consumer.close();
}
public void testTemporaryTopicDeleteWithConsumer() throws Exception
{
- TemporaryTopic tempTopic = producerSession.createTemporaryTopic();
+ Connection conn = null;
- MessageConsumer consumer = consumerSession.createConsumer(tempTopic);
-
try
{
- tempTopic.delete();
+ conn = cf.createConnection();
- fail("Should throw JMSException");
- }
- catch (JMSException e)
- {
- //Should fail - you can't delete a temp topic if it has active consumers
- }
-
- consumer.close();
+ Session producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Session consumerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ TemporaryTopic tempTopic = producerSession.createTemporaryTopic();
+
+ MessageConsumer consumer = consumerSession.createConsumer(tempTopic);
+
+ try
+ {
+ tempTopic.delete();
+
+ fail("Should throw JMSException");
+ }
+ catch (JMSException e)
+ {
+ //Should fail - you can't delete a temp topic if it has active consumers
+ }
+
+ consumer.close();
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void testTemporaryQueueDeleted() throws Exception
{
- //Make sure temporary queue cannot be used after it has been deleted
-
- TemporaryQueue tempQueue = producerSession.createTemporaryQueue();
-
- MessageProducer producer = producerSession.createProducer(tempQueue);
-
- MessageConsumer consumer = consumerSession.createConsumer(tempQueue);
-
- connection.start();
-
- final String messageText = "This is a message";
-
- Message m = producerSession.createTextMessage(messageText);
-
- producer.send(m);
-
- TextMessage m2 = (TextMessage)consumer.receive(2000);
-
- assertNotNull(m2);
-
- assertEquals(messageText, m2.getText());
-
- consumer.close();
-
- tempQueue.delete();
-
- try
- {
- producer.send(m);
- fail();
- }
- catch (JMSException e) {}
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+
+ Session producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Session consumerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ //Make sure temporary queue cannot be used after it has been deleted
+
+ TemporaryQueue tempQueue = producerSession.createTemporaryQueue();
+
+ MessageProducer producer = producerSession.createProducer(tempQueue);
+
+ MessageConsumer consumer = consumerSession.createConsumer(tempQueue);
+
+ conn.start();
+
+ final String messageText = "This is a message";
+
+ Message m = producerSession.createTextMessage(messageText);
+
+ producer.send(m);
+
+ TextMessage m2 = (TextMessage)consumer.receive(2000);
+
+ assertNotNull(m2);
+
+ assertEquals(messageText, m2.getText());
+
+ consumer.close();
+
+ tempQueue.delete();
+
+ try
+ {
+ producer.send(m);
+ fail();
+ }
+ catch (JMSException e) {}
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void testTemporaryTopicBasic() throws Exception
{
- TemporaryTopic tempTopic = producerSession.createTemporaryTopic();
-
- final MessageProducer producer = producerSession.createProducer(tempTopic);
-
- MessageConsumer consumer = consumerSession.createConsumer(tempTopic);
-
- connection.start();
-
- final String messageText = "This is a message";
-
- final Message m = producerSession.createTextMessage(messageText);
- log.trace("Message reliable:" + ((MessageProxy)m).getMessage().isReliable());
-
- Thread t = new Thread(new Runnable()
- {
- public void run()
- {
- try
- {
- // this is needed to make sure the main thread has enough time to block
- Thread.sleep(500);
- producer.send(m);
- }
- catch(Exception e)
- {
- log.error(e);
- }
- }
- }, "Producer");
- t.start();
-
- TextMessage m2 = (TextMessage)consumer.receive(3000);
-
- assertNotNull(m2);
-
- assertEquals(messageText, m2.getText());
-
- t.join();
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+
+ Session producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Session consumerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ TemporaryTopic tempTopic = producerSession.createTemporaryTopic();
+
+ final MessageProducer producer = producerSession.createProducer(tempTopic);
+
+ MessageConsumer consumer = consumerSession.createConsumer(tempTopic);
+
+ conn.start();
+
+ final String messageText = "This is a message";
+
+ final Message m = producerSession.createTextMessage(messageText);
+ log.trace("Message reliable:" + ((MessageProxy)m).getMessage().isReliable());
+
+ Thread t = new Thread(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ // this is needed to make sure the main thread has enough time to block
+ Thread.sleep(500);
+ producer.send(m);
+ }
+ catch(Exception e)
+ {
+ log.error(e);
+ }
+ }
+ }, "Producer");
+ t.start();
+
+ TextMessage m2 = (TextMessage)consumer.receive(3000);
+
+ assertNotNull(m2);
+
+ assertEquals(messageText, m2.getText());
+
+ t.join();
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
@@ -307,53 +387,100 @@
*/
public void testTemporaryTopicOnClosedSession() throws Exception
{
- producerSession.close();
-
- try
- {
- producerSession.createTemporaryTopic();
- fail("should throw exception");
- }
- catch(javax.jms.IllegalStateException e)
- {
- // OK
- }
+ Connection producerConnection = null;
+
+ try
+ {
+ producerConnection = cf.createConnection();
+
+ Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ producerSession.close();
+
+ try
+ {
+ producerSession.createTemporaryTopic();
+ fail("should throw exception");
+ }
+ catch(javax.jms.IllegalStateException e)
+ {
+ // OK
+ }
+ }
+ finally
+ {
+ if (producerConnection != null)
+ {
+ producerConnection.close();
+ }
+ }
}
public void testTemporaryTopicShouldNotBeInJNDI() throws Exception
{
- TemporaryTopic tempTopic = producerSession.createTemporaryTopic();
- String topicName = tempTopic.getTopicName();
-
- try
- {
- initialContext.lookup("/topic/" + topicName);
- fail("The temporary queue should not be bound to JNDI");
- }
- catch (NamingException e)
- {
- // Expected
- }
+ Connection producerConnection = null;
+
+ try
+ {
+ producerConnection = cf.createConnection();
+
+ Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ TemporaryTopic tempTopic = producerSession.createTemporaryTopic();
+ String topicName = tempTopic.getTopicName();
+
+ try
+ {
+ ic.lookup("/topic/" + topicName);
+ fail("The temporary queue should not be bound to JNDI");
+ }
+ catch (NamingException e)
+ {
+ // Expected
+ }
+ }
+ finally
+ {
+ if (producerConnection != null)
+ {
+ producerConnection.close();
+ }
+ }
}
public void testTemporaryQueueShouldNotBeInJNDI() throws Exception
{
- TemporaryQueue tempQueue = producerSession.createTemporaryQueue();
- String queueName = tempQueue.getQueueName();
-
- try
- {
- initialContext.lookup("/queue/" + queueName);
- fail("The temporary queue should not be bound to JNDI");
- }
- catch (NamingException e)
- {
- // Expected
- }
+ Connection producerConnection = null;
+
+ try
+ {
+ producerConnection = cf.createConnection();
+
+ Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ TemporaryQueue tempQueue = producerSession.createTemporaryQueue();
+ String queueName = tempQueue.getQueueName();
+
+ try
+ {
+ ic.lookup("/queue/" + queueName);
+ fail("The temporary queue should not be bound to JNDI");
+ }
+ catch (NamingException e)
+ {
+ // Expected
+ }
+ }
+ finally
+ {
+ if (producerConnection != null)
+ {
+ producerConnection.close();
+ }
+ }
}
-
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
@@ -361,8 +488,5 @@
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
-
-
-
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/TopicTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/TopicTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/TopicTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -24,7 +24,6 @@
import java.io.Serializable;
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.Message;
import javax.jms.MessageConsumer;
@@ -34,29 +33,21 @@
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;
-import javax.naming.InitialContext;
-import org.jboss.jms.client.JBossConnectionFactory;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
-
/**
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
* @version <tt>$Revision$</tt>
*
* $Id$
*/
-public class TopicTest extends MessagingTestCase
+public class TopicTest extends JMSTestCase
{
// Constants -----------------------------------------------------
// Static --------------------------------------------------------
-
+
// Attributes ----------------------------------------------------
- protected InitialContext ic;
- protected ConnectionFactory cf;
-
// Constructors --------------------------------------------------
public TopicTest(String name)
@@ -64,33 +55,6 @@
super(name);
}
- // TestCase overrides -------------------------------------------
-
- public void setUp() throws Exception
- {
- super.setUp();
-
- ServerManagement.start("all");
-
-
- ic = new InitialContext(ServerManagement.getJNDIEnvironment());
- cf = (JBossConnectionFactory)ic.lookup("/ConnectionFactory");
-
- ServerManagement.undeployTopic("TestTopic");
- ServerManagement.deployTopic("TestTopic");
-
- log.debug("setup done");
- }
-
- public void tearDown() throws Exception
- {
- ServerManagement.undeployTopic("TestTopic");
-
- super.tearDown();
-
- log.debug("tear down done");
- }
-
// Public --------------------------------------------------------
/**
@@ -98,15 +62,15 @@
*/
public void testTopic() throws Exception
{
- Topic topic = (Topic)ic.lookup("/topic/TestTopic");
-
- Connection conn = cf.createConnection();
-
+ Connection conn = null;
+
try
{
+ conn = cf.createConnection();
+
Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = s.createProducer(topic);
- MessageConsumer c = s.createConsumer(topic);
+ MessageProducer p = s.createProducer(topic1);
+ MessageConsumer c = s.createConsumer(topic1);
conn.start();
p.send(s.createTextMessage("payload"));
@@ -125,8 +89,8 @@
public void testTopicName() throws Exception
{
- Topic topic = (Topic)ic.lookup("/topic/TestTopic");
- assertEquals("TestTopic", topic.getTopicName());
+ Topic topic = (Topic)ic.lookup("/topic/Topic1");
+ assertEquals("Topic1", topic.getTopicName());
}
/*
@@ -134,55 +98,64 @@
*/
public void testRace() throws Exception
{
- Topic topic = (Topic)ic.lookup("/topic/TestTopic");
-
- Connection conn = cf.createConnection();
+ Connection conn = null;
- Session sSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageProducer prod = sSend.createProducer(topic);
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-
- Session s1 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Session s2 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Session s3 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer c1 = s1.createConsumer(topic);
- MessageConsumer c2 = s2.createConsumer(topic);
- MessageConsumer c3 = s3.createConsumer(topic);
-
- TestListener l1 = new TestListener();
- TestListener l2 = new TestListener();
- TestListener l3 = new TestListener();
-
- c1.setMessageListener(new TestListener());
- c2.setMessageListener(new TestListener());
- c3.setMessageListener(new TestListener());
-
- conn.start();
-
-
- for (int i = 0; i < 500; i++)
+ try
+ {
+ conn = cf.createConnection();
+
+ Session sSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = sSend.createProducer(topic1);
+ prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ Session s1 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Session s2 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Session s3 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer c1 = s1.createConsumer(topic1);
+ MessageConsumer c2 = s2.createConsumer(topic1);
+ MessageConsumer c3 = s3.createConsumer(topic1);
+
+ final int numMessages = 500;
+
+ TestListener l1 = new TestListener(numMessages);
+ TestListener l2 = new TestListener(numMessages);
+ TestListener l3 = new TestListener(numMessages);
+
+ c1.setMessageListener(l1);
+ c2.setMessageListener(l2);
+ c3.setMessageListener(l3);
+
+ conn.start();
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ byte[] blah = new byte[10000];
+ String str = new String(blah);
+
+ Wibble2 w = new Wibble2();
+ w.s = str;
+ ObjectMessage om = sSend.createObjectMessage(w);
+
+ prod.send(om);
+ }
+
+ l1.waitForMessages();
+ l2.waitForMessages();
+ l3.waitForMessages();
+
+ assertFalse(l1.failed);
+ assertFalse(l2.failed);
+ assertFalse(l3.failed);
+ }
+ finally
{
- byte[] blah = new byte[10000];
- String str = new String(blah);
-
- Wibble2 w = new Wibble2();
- w.s = str;
- ObjectMessage om = sSend.createObjectMessage(w);
-
- prod.send(om);
-
- }
-
- Thread.sleep(10000);
-
- assertFalse(l1.failed);
- assertFalse(l2.failed);
- assertFalse(l3.failed);
-
- conn.close();
-
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
// Package protected ---------------------------------------------
@@ -203,8 +176,17 @@
{
boolean failed;
- public void onMessage(Message m)
+ int count;
+
+ int num;
+
+ TestListener(int num)
{
+ this.num = num;
+ }
+
+ public synchronized void onMessage(Message m)
+ {
ObjectMessage om = (ObjectMessage)m;
try
@@ -215,7 +197,22 @@
{
failed = true;
}
+
+ count++;
+
+ if (count == num)
+ {
+ this.notify();
+ }
}
+
+ synchronized void waitForMessages() throws Exception
+ {
+ while (count < num)
+ {
+ this.wait();
+ }
+ }
}
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/TransactedSessionTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/TransactedSessionTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/TransactedSessionTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -22,21 +22,18 @@
package org.jboss.test.messaging.jms;
import javax.jms.Connection;
-import javax.jms.Destination;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.management.ObjectName;
-import javax.naming.InitialContext;
import org.jboss.jms.client.JBossConnection;
-import org.jboss.jms.client.JBossConnectionFactory;
import org.jboss.jms.client.delegate.ClientConnectionDelegate;
import org.jboss.jms.client.state.ConnectionState;
import org.jboss.jms.tx.ResourceManager;
-import org.jboss.test.messaging.MessagingTestCase;
+import org.jboss.jms.tx.ResourceManagerFactory;
import org.jboss.test.messaging.tools.ServerManagement;
/**
@@ -44,7 +41,7 @@
*
* $Id$
*/
-public class TransactedSessionTest extends MessagingTestCase
+public class TransactedSessionTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -52,56 +49,17 @@
// Attributes ----------------------------------------------------
- protected InitialContext initialContext;
-
- protected JBossConnectionFactory cf;
- protected Destination queue;
- protected Destination topic;
-
// Constructors --------------------------------------------------
- public TransactedSessionTest(String name)
+ public TransactedSessionTest(String name)
{
super(name);
}
- // TestCase overrides -------------------------------------------
-
- public void setUp() throws Exception
- {
- super.setUp();
- ServerManagement.start("all");
-
-
- initialContext = new InitialContext(ServerManagement.getJNDIEnvironment());
- cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
- ServerManagement.undeployQueue("Queue");
- ServerManagement.undeployTopic("Topic");
- ServerManagement.deployQueue("Queue");
- ServerManagement.deployTopic("Topic");
- queue = (Destination)initialContext.lookup("/queue/Queue");
- topic = (Destination)initialContext.lookup("/topic/Topic");
-
- this.drainDestination(cf, queue);
-
- log.debug("setup done");
- }
-
- public void tearDown() throws Exception
- {
- ServerManagement.undeployQueue("Queue");
- ServerManagement.undeployTopic("Topic");
- // TransactionManagerImpl.getInstance().setState(TransactionManagerImpl.OPERATIONAL);
- super.tearDown();
- }
-
-
// Public --------------------------------------------------------
public void testResourceManagerMemoryLeakOnCommit() throws Exception
{
-
Connection conn = null;
try
@@ -117,8 +75,7 @@
ResourceManager rm = state.getResourceManager();
Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
-
-
+
for (int i = 0; i < 100; i++)
{
assertEquals(1, rm.size());
@@ -135,7 +92,6 @@
conn = null;
assertEquals(0, rm.size());
-
}
finally
{
@@ -148,7 +104,6 @@
public void testResourceManagerMemoryLeakOnRollback() throws Exception
{
-
Connection conn = null;
try
@@ -164,8 +119,7 @@
ResourceManager rm = state.getResourceManager();
Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
-
-
+
for (int i = 0; i < 100; i++)
{
assertEquals(1, rm.size());
@@ -182,7 +136,6 @@
conn = null;
assertEquals(0, rm.size());
-
}
finally
{
@@ -197,36 +150,47 @@
public void testSimpleRollback() throws Exception
{
// send a message
- Connection conn = cf.createConnection();
- Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- s.createProducer(queue).send(s.createTextMessage("one"));
-
- log.debug("message sent");
-
- s.close();
-
- s = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageConsumer c = s.createConsumer(queue);
- conn.start();
- Message m = c.receive();
-
- assertEquals("one", ((TextMessage)m).getText());
- assertFalse(m.getJMSRedelivered());
- assertEquals(1, m.getIntProperty("JMSXDeliveryCount"));
-
- s.rollback();
-
- // get the message again
- m = c.receive();
- assertTrue(m.getJMSRedelivered());
- assertEquals(2, m.getIntProperty("JMSXDeliveryCount"));
-
- conn.close();
+ Connection conn = null;
- ObjectName on = new ObjectName("jboss.messaging.destination:service=Queue,name=Queue");
- Integer i = (Integer)ServerManagement.getAttribute(on, "MessageCount");
-
- assertEquals(1, i.intValue());
+ try
+ {
+ conn = cf.createConnection();
+ Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ s.createProducer(queue1).send(s.createTextMessage("one"));
+
+ s.close();
+
+ s = conn.createSession(true, Session.SESSION_TRANSACTED);
+ MessageConsumer c = s.createConsumer(queue1);
+ conn.start();
+ Message m = c.receive();
+
+ assertEquals("one", ((TextMessage)m).getText());
+ assertFalse(m.getJMSRedelivered());
+ assertEquals(1, m.getIntProperty("JMSXDeliveryCount"));
+
+ s.rollback();
+
+ // get the message again
+ m = c.receive();
+ assertTrue(m.getJMSRedelivered());
+ assertEquals(2, m.getIntProperty("JMSXDeliveryCount"));
+
+ conn.close();
+
+ ObjectName on = new ObjectName("jboss.messaging.destination:service=Queue,name=Queue1");
+ Integer i = (Integer)ServerManagement.getAttribute(on, "MessageCount");
+
+ assertEquals(1, i.intValue());
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ removeAllMessages(queue1.getQueueName(), true, 0);
+ }
}
public void testRedeliveredFlagTopic() throws Exception
@@ -239,9 +203,9 @@
Session sessSend = conn.createSession(true, Session.SESSION_TRANSACTED);
Session sess1 = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageConsumer consumer1 = sess1.createConsumer(topic);
+ MessageConsumer consumer1 = sess1.createConsumer(topic1);
- MessageProducer producer = sessSend.createProducer(topic);
+ MessageProducer producer = sessSend.createProducer(topic1);
Message mSent = sessSend.createTextMessage("igloo");
producer.send(mSent);
sessSend.commit();
@@ -266,8 +230,7 @@
{
conn.close();
}
- }
-
+ }
}
@@ -281,12 +244,11 @@
conn = cf.createConnection();
Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageProducer producer = sess.createProducer(topic);
+ MessageProducer producer = sess.createProducer(topic1);
- MessageConsumer consumer = sess.createConsumer(topic);
+ MessageConsumer consumer = sess.createConsumer(topic1);
conn.start();
-
-
+
Message mSent = sess.createTextMessage("igloo");
producer.send(mSent);
@@ -321,17 +283,15 @@
Connection conn = null;
try
- {
-
+ {
conn = cf.createConnection();
Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageProducer producer = sess.createProducer(topic);
+ MessageProducer producer = sess.createProducer(topic1);
- MessageConsumer consumer = sess.createConsumer(topic);
+ MessageConsumer consumer = sess.createConsumer(topic1);
conn.start();
-
-
+
TextMessage mSent = sess.createTextMessage("igloo");
producer.send(mSent);
@@ -380,10 +340,10 @@
conn = cf.createConnection();
Session producerSess = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageProducer producer = producerSess.createProducer(topic);
+ MessageProducer producer = producerSess.createProducer(topic1);
Session consumerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageConsumer consumer = consumerSess.createConsumer(topic);
+ MessageConsumer consumer = consumerSess.createConsumer(topic1);
conn.start();
final int NUM_MESSAGES = 10;
@@ -395,9 +355,7 @@
producer.send(m);
}
- log.trace("Sent messages");
-
- Message m = consumer.receive(2000);
+ Message m = consumer.receive(500);
assertNull(m);
}
finally
@@ -406,13 +364,9 @@
{
conn.close();
}
- }
-
+ }
}
-
-
-
/**
* Send some messages in transacted session. Commit.
* Verify message are received by consumer.
@@ -422,15 +376,14 @@
Connection conn = null;
try
- {
-
+ {
conn = cf.createConnection();
Session producerSess = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageProducer producer = producerSess.createProducer(topic);
+ MessageProducer producer = producerSess.createProducer(topic1);
Session consumerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageConsumer consumer = consumerSess.createConsumer(topic);
+ MessageConsumer consumer = consumerSess.createConsumer(topic1);
conn.start();
final int NUM_MESSAGES = 10;
@@ -443,9 +396,7 @@
}
producerSess.commit();
-
- log.trace("Sent messages");
-
+
int count = 0;
while (true)
{
@@ -465,9 +416,6 @@
}
}
-
-
-
/**
* Send some messages.
* Receive them in a transacted session.
@@ -480,15 +428,14 @@
Connection conn = null;
try
- {
-
+ {
conn = cf.createConnection();
Session producerSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer producer = producerSess.createProducer(topic);
+ MessageProducer producer = producerSess.createProducer(topic1);
Session consumerSess = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageConsumer consumer = consumerSess.createConsumer(topic);
+ MessageConsumer consumer = consumerSess.createConsumer(topic1);
conn.start();
final int NUM_MESSAGES = 10;
@@ -499,9 +446,6 @@
Message m = producerSess.createMessage();
producer.send(m);
}
-
- log.trace("Sent messages");
-
int count = 0;
while (true)
{
@@ -509,15 +453,11 @@
if (m == null) break;
count++;
}
-
- log.trace("Received " + count + " messages");
-
+
assertEquals(NUM_MESSAGES, count);
consumerSess.commit();
- log.trace("Committed session");
-
conn.stop();
consumer.close();
@@ -526,13 +466,11 @@
conn = cf.createConnection();
consumerSess = conn.createSession(true, Session.CLIENT_ACKNOWLEDGE);
- consumer = consumerSess.createConsumer(queue);
+ consumer = consumerSess.createConsumer(queue1);
conn.start();
- Message m = consumer.receive(2000);
+ Message m = consumer.receive(500);
- log.trace("Message is " + m);
-
assertNull(m);
}
finally
@@ -557,15 +495,14 @@
Connection conn = null;
try
- {
-
+ {
conn = cf.createConnection();
Session producerSess = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageProducer producer = producerSess.createProducer(topic);
+ MessageProducer producer = producerSess.createProducer(topic1);
Session consumerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageConsumer consumer = consumerSess.createConsumer(topic);
+ MessageConsumer consumer = consumerSess.createConsumer(topic1);
conn.start();
final int NUM_MESSAGES = 10;
@@ -577,11 +514,9 @@
producer.send(m);
}
- log.trace("Sent messages");
-
producerSess.rollback();
- Message m = consumer.receive(2000);
+ Message m = consumer.receive(500);
assertNull(m);
}
@@ -604,14 +539,12 @@
try
{
conn = cf.createConnection();
-
-
+
Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageProducer producer = sess.createProducer(queue);
+ MessageProducer producer = sess.createProducer(queue1);
- MessageConsumer consumer = sess.createConsumer(queue);
- conn.start();
-
+ MessageConsumer consumer = sess.createConsumer(queue1);
+ conn.start();
Message mSent = sess.createTextMessage("igloo");
producer.send(mSent);
@@ -654,17 +587,15 @@
Session sendSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sendSession.createProducer(queue);
+ MessageProducer prod = sendSession.createProducer(queue1);
prod.send(sendSession.createTextMessage("a message"));
- log.debug("Message was sent to the queue");
-
conn.close();
conn = cf.createConnection();
Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
conn.start();
@@ -680,7 +611,7 @@
Session sess2 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- cons = sess2.createConsumer(queue);
+ cons = sess2.createConsumer(queue1);
tm = (TextMessage)cons.receive();
@@ -704,9 +635,9 @@
Connection conn = cf.createConnection();
Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageProducer producer = sess.createProducer(queue);
+ MessageProducer producer = sess.createProducer(queue1);
- MessageConsumer consumer = sess.createConsumer(queue);
+ MessageConsumer consumer = sess.createConsumer(queue1);
conn.start();
@@ -760,10 +691,10 @@
conn = cf.createConnection();
Session producerSess = conn.createSession(true, Session.CLIENT_ACKNOWLEDGE);
- MessageProducer producer = producerSess.createProducer(queue);
+ MessageProducer producer = producerSess.createProducer(queue1);
Session consumerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageConsumer consumer = consumerSess.createConsumer(queue);
+ MessageConsumer consumer = consumerSess.createConsumer(queue1);
conn.start();
final int NUM_MESSAGES = 10;
@@ -777,8 +708,7 @@
log.trace("Sent messages");
- Message m = consumer.receive(2000);
- assertNull(m);
+ checkEmpty(queue1);
}
finally
{
@@ -802,15 +732,14 @@
Connection conn = null;
try
- {
-
+ {
conn = cf.createConnection();
Session producerSess = conn.createSession(true, Session.CLIENT_ACKNOWLEDGE);
- MessageProducer producer = producerSess.createProducer(queue);
+ MessageProducer producer = producerSess.createProducer(queue1);
Session consumerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageConsumer consumer = consumerSess.createConsumer(queue);
+ MessageConsumer consumer = consumerSess.createConsumer(queue1);
conn.start();
final int NUM_MESSAGES = 10;
@@ -824,8 +753,6 @@
producerSess.commit();
- log.trace("Sent messages");
-
int count = 0;
while (true)
{
@@ -842,6 +769,7 @@
{
conn.close();
}
+ removeAllMessages(queue1.getQueueName(), true, 0);
}
}
@@ -855,8 +783,7 @@
Connection conn = null;
try
- {
-
+ {
conn = cf.createConnection();
Session producerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
@@ -880,7 +807,6 @@
conn.close();
}
}
-
}
@@ -902,10 +828,10 @@
conn = cf.createConnection();
Session producerSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer producer = producerSess.createProducer(queue);
+ MessageProducer producer = producerSess.createProducer(queue1);
Session consumerSess = conn.createSession(true, Session.CLIENT_ACKNOWLEDGE);
- MessageConsumer consumer = consumerSess.createConsumer(queue);
+ MessageConsumer consumer = consumerSess.createConsumer(queue1);
conn.start();
final int NUM_MESSAGES = 10;
@@ -917,8 +843,6 @@
producer.send(m);
}
- log.trace("Sent messages");
-
int count = 0;
while (true)
{
@@ -937,7 +861,7 @@
conn = cf.createConnection();
consumerSess = conn.createSession(true, Session.CLIENT_ACKNOWLEDGE);
- consumer = consumerSess.createConsumer(queue);
+ consumer = consumerSess.createConsumer(queue1);
conn.start();
count = 0;
@@ -956,6 +880,7 @@
{
conn.close();
}
+ removeAllMessages(queue1.getQueueName(), true, 0);
}
}
@@ -973,18 +898,15 @@
{
Connection conn = null;
- try
-
- {
-
+ try
+ {
conn = cf.createConnection();
-
-
+
Session producerSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer producer = producerSess.createProducer(queue);
+ MessageProducer producer = producerSess.createProducer(queue1);
Session consumerSess = conn.createSession(true, Session.CLIENT_ACKNOWLEDGE);
- MessageConsumer consumer = consumerSess.createConsumer(queue);
+ MessageConsumer consumer = consumerSess.createConsumer(queue1);
conn.start();
final int NUM_MESSAGES = 10;
@@ -996,8 +918,6 @@
producer.send(m);
}
- log.trace("Sent messages");
-
int count = 0;
while (true)
{
@@ -1006,14 +926,10 @@
count++;
}
- log.trace("Received " + count + " messages");
-
assertEquals(NUM_MESSAGES, count);
consumerSess.commit();
- log.trace("Committed session");
-
conn.stop();
consumer.close();
@@ -1022,13 +938,11 @@
conn = cf.createConnection();
consumerSess = conn.createSession(true, Session.CLIENT_ACKNOWLEDGE);
- consumer = consumerSess.createConsumer(queue);
+ consumer = consumerSess.createConsumer(queue1);
conn.start();
- Message m = consumer.receive(2000);
+ Message m = consumer.receive(500);
- log.trace("Message is " + m);
-
assertNull(m);
}
finally
@@ -1053,15 +967,14 @@
Connection conn = null;
try
- {
-
+ {
conn = cf.createConnection();
Session producerSess = conn.createSession(true, Session.AUTO_ACKNOWLEDGE);
- MessageProducer producer = producerSess.createProducer(queue);
+ MessageProducer producer = producerSess.createProducer(queue1);
Session consumerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageConsumer consumer = consumerSess.createConsumer(queue);
+ MessageConsumer consumer = consumerSess.createConsumer(queue1);
conn.start();
final int NUM_MESSAGES = 10;
@@ -1073,11 +986,9 @@
producer.send(m);
}
- log.trace("Sent messages");
-
producerSess.rollback();
- Message m = consumer.receive(2000);
+ Message m = consumer.receive(500);
assertNull(m);
}
@@ -1088,8 +999,6 @@
conn.close();
}
}
-
-
}
@@ -1104,8 +1013,7 @@
Connection conn = null;
try
- {
-
+ {
conn = cf.createConnection();
Session producerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
@@ -1129,7 +1037,6 @@
conn.close();
}
}
-
}
@@ -1147,15 +1054,14 @@
Connection conn = null;
try
- {
-
+ {
conn = cf.createConnection();
Session producerSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer producer = producerSess.createProducer(queue);
+ MessageProducer producer = producerSess.createProducer(queue1);
Session consumerSess = conn.createSession(true, Session.CLIENT_ACKNOWLEDGE);
- MessageConsumer consumer = consumerSess.createConsumer(queue);
+ MessageConsumer consumer = consumerSess.createConsumer(queue1);
conn.start();
final int NUM_MESSAGES = 10;
@@ -1166,9 +1072,7 @@
Message m = producerSess.createMessage();
producer.send(m);
}
-
- log.trace("Sent messages");
-
+
int count = 0;
while (true)
{
@@ -1189,7 +1093,7 @@
conn = cf.createConnection();
consumerSess = conn.createSession(true, Session.CLIENT_ACKNOWLEDGE);
- consumer = consumerSess.createConsumer(queue);
+ consumer = consumerSess.createConsumer(queue1);
conn.start();
count = 0;
@@ -1209,6 +1113,7 @@
{
conn.close();
}
+ removeAllMessages(queue1.getQueueName(), true, 0);
}
}
@@ -1222,15 +1127,14 @@
Connection conn = null;
try
- {
-
+ {
conn = cf.createConnection();
Session producerSess = conn.createSession(true, Session.AUTO_ACKNOWLEDGE);
- MessageProducer producer = producerSess.createProducer(queue);
+ MessageProducer producer = producerSess.createProducer(queue1);
Session consumerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageConsumer consumer = consumerSess.createConsumer(queue);
+ MessageConsumer consumer = consumerSess.createConsumer(queue1);
conn.start();
final int NUM_MESSAGES = 10;
@@ -1239,8 +1143,7 @@
//Send some messages
for (int j = 0; j < NUM_TX; j++)
- {
-
+ {
for (int i = 0; i < NUM_MESSAGES; i++)
{
Message m = producerSess.createMessage();
@@ -1250,8 +1153,6 @@
producerSess.commit();
}
- log.trace("Sent messages");
-
int count = 0;
while (true)
{
@@ -1260,8 +1161,7 @@
count++;
}
- assertEquals(NUM_MESSAGES * NUM_TX, count);
-
+ assertEquals(NUM_MESSAGES * NUM_TX, count);
}
finally
{
@@ -1270,17 +1170,23 @@
conn.close();
}
}
-
}
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ ResourceManagerFactory.instance.clear();
+ }
+
+
// Private -------------------------------------------------------
- // Inner classes -------------------------------------------------
-
+ // Inner classes -------------------------------------------------
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/WireFormatTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/WireFormatTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/WireFormatTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -96,8 +96,6 @@
import org.jboss.jms.wireformat.SessionSendRequest;
import org.jboss.jms.wireformat.SessionUnsubscribeRequest;
import org.jboss.remoting.InvocationRequest;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
/**
* @author <a href="tim.fox at jboss.com">Tim Fox</a>
@@ -105,7 +103,7 @@
*
* $Id$
*/
-public class WireFormatTest extends MessagingTestCase
+public class WireFormatTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -126,22 +124,11 @@
public void setUp() throws Exception
{
- if (ServerManagement.isRemote())
- {
- fail("This test should not be run in a remote config");
- }
-
super.setUp();
wf = new TestWireFormat();
}
- public void tearDown() throws Exception
- {
- super.tearDown();
- }
-
-
public void testSerialized() throws Exception
{
wf.testSerialized();
Modified: trunk/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -22,7 +22,6 @@
package org.jboss.test.messaging.jms;
import javax.jms.Connection;
-import javax.jms.Destination;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
@@ -31,14 +30,11 @@
import javax.jms.Topic;
import javax.jms.XAConnection;
import javax.jms.XASession;
-import javax.naming.InitialContext;
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
-import org.jboss.jms.client.JBossConnectionFactory;
import org.jboss.jms.tx.MessagingXid;
import org.jboss.jms.tx.ResourceManagerFactory;
-import org.jboss.test.messaging.MessagingTestCase;
import org.jboss.test.messaging.tools.ServerManagement;
import com.arjuna.ats.arjuna.common.Uid;
@@ -55,7 +51,7 @@
* $Id$
*
*/
-public class XARecoveryTest extends MessagingTestCase
+public class XARecoveryTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -63,12 +59,6 @@
// Attributes ----------------------------------------------------
- protected InitialContext initialContext;
-
- protected JBossConnectionFactory cf;
-
- protected Destination queue, queueA, queueB, queueTX, topicTX;
-
// Constructors --------------------------------------------------
public XARecoveryTest(String name)
@@ -78,54 +68,11 @@
// TestCase overrides -------------------------------------------
- public void setUp() throws Exception
- {
- super.setUp();
- ServerManagement.start("all");
-
- initialContext = new InitialContext(ServerManagement.getJNDIEnvironment());
- cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
- ServerManagement.undeployQueue("Queue");
- ServerManagement.deployQueue("Queue");
-
- ServerManagement.undeployQueue("QA");
- ServerManagement.deployQueue("QA");
-
- ServerManagement.undeployQueue("QB");
- ServerManagement.deployQueue("QB");
-
- ServerManagement.undeployQueue("TXQ");
- ServerManagement.deployQueue("TXQ");
-
- ServerManagement.undeployTopic("TXTOPIC");
- ServerManagement.deployTopic("TXTOPIC");
-
- queue = (Destination)initialContext.lookup("/queue/Queue");
- queueA = (Destination)initialContext.lookup("/queue/QA");
- queueB = (Destination)initialContext.lookup("/queue/QB");
- queueTX = (Destination)initialContext.lookup("/queue/TXQ");
-
- topicTX = (Destination)initialContext.lookup("/topic/TXTOPIC");
-
- drainDestination(cf, queue);
- drainDestination(cf, queueA);
- drainDestination(cf, queueB);
- drainDestination(cf, queueTX);
- }
-
public void tearDown() throws Exception
{
- ServerManagement.undeployQueue("Queue");
- ServerManagement.undeployQueue("QA");
- ServerManagement.undeployQueue("QB");
- ServerManagement.undeployQueue("TXQ");
-
- ServerManagement.undeployTopic("TXTOPIC");
-
- ResourceManagerFactory.instance.clear();
-
super.tearDown();
+
+ ResourceManagerFactory.instance.clear();
}
@@ -153,9 +100,9 @@
Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod1 = sess1.createProducer(queueA);
+ MessageProducer prod1 = sess1.createProducer(queue2);
- MessageProducer prod2 = sess1.createProducer(queueB);
+ MessageProducer prod2 = sess1.createProducer(queue3);
TextMessage tm1 = sess1.createTextMessage("tm1");
TextMessage tm2 = sess1.createTextMessage("tm2");
@@ -190,7 +137,7 @@
res.start(xid1, XAResource.TMNOFLAGS);
- MessageProducer prod3 = sess2.createProducer(queueA);
+ MessageProducer prod3 = sess2.createProducer(queue2);
TextMessage tm9 = sess2.createTextMessage("tm9");
TextMessage tm10 = sess2.createTextMessage("tm10");
@@ -202,7 +149,7 @@
prod3.send(tm11);
prod3.send(tm12);
- MessageProducer prod4 = sess2.createProducer(queueB);
+ MessageProducer prod4 = sess2.createProducer(queue3);
TextMessage tm13 = sess2.createTextMessage("tm13");
TextMessage tm14 = sess2.createTextMessage("tm14");
@@ -214,7 +161,7 @@
prod4.send(tm15);
prod4.send(tm16);
- MessageConsumer cons1 = sess2.createConsumer(queueA);
+ MessageConsumer cons1 = sess2.createConsumer(queue2);
TextMessage rm1 = (TextMessage)cons1.receive(1000);
assertNotNull(rm1);
@@ -236,7 +183,7 @@
assertNull(m);
- MessageConsumer cons2 = sess2.createConsumer(queueB);
+ MessageConsumer cons2 = sess2.createConsumer(queue3);
TextMessage rm5 = (TextMessage)cons2.receive(1000);
assertNotNull(rm5);
@@ -299,7 +246,7 @@
log.trace("creating a consumer");
- cons1 = sess1.createConsumer(queueA);
+ cons1 = sess1.createConsumer(queue2);
log.trace("created a consumer");
@@ -323,7 +270,7 @@
assertNull(m);
- cons2 = sess1.createConsumer(queueB);
+ cons2 = sess1.createConsumer(queue3);
TextMessage rm13 = (TextMessage)cons2.receive(1000);
assertNotNull(rm13);
@@ -392,9 +339,9 @@
Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod1 = sess1.createProducer(queueA);
+ MessageProducer prod1 = sess1.createProducer(queue2);
- MessageProducer prod2 = sess1.createProducer(queueB);
+ MessageProducer prod2 = sess1.createProducer(queue3);
TextMessage tm1 = sess1.createTextMessage("tm1");
TextMessage tm2 = sess1.createTextMessage("tm2");
@@ -427,7 +374,7 @@
res.start(xid1, XAResource.TMNOFLAGS);
- MessageProducer prod3 = sess2.createProducer(queueA);
+ MessageProducer prod3 = sess2.createProducer(queue2);
TextMessage tm9 = sess2.createTextMessage("tm9");
TextMessage tm10 = sess2.createTextMessage("tm10");
@@ -439,7 +386,7 @@
prod3.send(tm11);
prod3.send(tm12);
- MessageProducer prod4 = sess2.createProducer(queueB);
+ MessageProducer prod4 = sess2.createProducer(queue3);
TextMessage tm13 = sess2.createTextMessage("tm13");
TextMessage tm14 = sess2.createTextMessage("tm14");
@@ -451,7 +398,7 @@
prod4.send(tm15);
prod4.send(tm16);
- MessageConsumer cons1 = sess2.createConsumer(queueA);
+ MessageConsumer cons1 = sess2.createConsumer(queue2);
TextMessage rm1 = (TextMessage)cons1.receive(1000);
assertNotNull(rm1);
@@ -473,7 +420,7 @@
assertNull(m);
- MessageConsumer cons2 = sess2.createConsumer(queueB);
+ MessageConsumer cons2 = sess2.createConsumer(queue3);
TextMessage rm5 = (TextMessage)cons2.receive(1000);
assertNotNull(rm5);
@@ -535,7 +482,7 @@
log.trace("creating a consumer");
- cons1 = sess1.createConsumer(queueA);
+ cons1 = sess1.createConsumer(queue2);
log.trace("created a consumer");
@@ -559,7 +506,7 @@
assertNull(m);
- cons2 = sess1.createConsumer(queueB);
+ cons2 = sess1.createConsumer(queue3);
TextMessage rm13 = (TextMessage)cons2.receive(1000);
assertNotNull(rm13);
@@ -649,9 +596,9 @@
Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod1 = sess1.createProducer(queueA);
+ MessageProducer prod1 = sess1.createProducer(queue2);
- MessageProducer prod2 = sess1.createProducer(queueB);
+ MessageProducer prod2 = sess1.createProducer(queue3);
TextMessage tm1 = sess1.createTextMessage("tm1");
TextMessage tm2 = sess1.createTextMessage("tm2");
@@ -684,7 +631,7 @@
res.start(xid1, XAResource.TMNOFLAGS);
- MessageProducer prod3 = sess2.createProducer(queueA);
+ MessageProducer prod3 = sess2.createProducer(queue2);
TextMessage tm9 = sess2.createTextMessage("tm9");
TextMessage tm10 = sess2.createTextMessage("tm10");
@@ -696,7 +643,7 @@
prod3.send(tm11);
prod3.send(tm12);
- MessageProducer prod4 = sess2.createProducer(queueB);
+ MessageProducer prod4 = sess2.createProducer(queue3);
TextMessage tm13 = sess2.createTextMessage("tm13");
TextMessage tm14 = sess2.createTextMessage("tm14");
@@ -708,7 +655,7 @@
prod4.send(tm15);
prod4.send(tm16);
- MessageConsumer cons1 = sess2.createConsumer(queueA);
+ MessageConsumer cons1 = sess2.createConsumer(queue2);
TextMessage rm1 = (TextMessage)cons1.receive(1000);
assertNotNull(rm1);
@@ -730,7 +677,7 @@
assertNull(m);
- MessageConsumer cons2 = sess2.createConsumer(queueB);
+ MessageConsumer cons2 = sess2.createConsumer(queue3);
TextMessage rm5 = (TextMessage)cons2.receive(1000);
assertNotNull(rm5);
@@ -768,11 +715,7 @@
ServerManagement.startServerPeer();
- ServerManagement.deployQueue("QA");
-
- ServerManagement.deployQueue("QB");
-
- cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
+ deployAndLookupAdministeredObjects();
conn3 = cf.createXAConnection();
@@ -803,7 +746,7 @@
log.trace("creating a consumer");
- cons1 = sess1.createConsumer(queueA);
+ cons1 = sess1.createConsumer(queue2);
log.trace("created a consumer");
@@ -827,7 +770,7 @@
assertNull(m);
- cons2 = sess1.createConsumer(queueB);
+ cons2 = sess1.createConsumer(queue3);
TextMessage rm13 = (TextMessage)cons2.receive(1000);
assertNotNull(rm13);
@@ -891,7 +834,9 @@
{
//Ignore
}
- }
+ }
+ removeAllMessages(queue2.getQueueName(), true, 0);
+ removeAllMessages(queue3.getQueueName(), true, 0);
}
}
@@ -919,9 +864,9 @@
Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod1 = sess1.createProducer(queueA);
+ MessageProducer prod1 = sess1.createProducer(queue2);
- MessageProducer prod2 = sess1.createProducer(queueB);
+ MessageProducer prod2 = sess1.createProducer(queue3);
TextMessage tm1 = sess1.createTextMessage("tm1");
TextMessage tm2 = sess1.createTextMessage("tm2");
@@ -954,7 +899,7 @@
res.start(xid1, XAResource.TMNOFLAGS);
- MessageProducer prod3 = sess2.createProducer(queueA);
+ MessageProducer prod3 = sess2.createProducer(queue2);
TextMessage tm9 = sess2.createTextMessage("tm9");
TextMessage tm10 = sess2.createTextMessage("tm10");
@@ -966,7 +911,7 @@
prod3.send(tm11);
prod3.send(tm12);
- MessageProducer prod4 = sess2.createProducer(queueB);
+ MessageProducer prod4 = sess2.createProducer(queue3);
TextMessage tm13 = sess2.createTextMessage("tm13");
TextMessage tm14 = sess2.createTextMessage("tm14");
@@ -978,7 +923,7 @@
prod4.send(tm15);
prod4.send(tm16);
- MessageConsumer cons1 = sess2.createConsumer(queueA);
+ MessageConsumer cons1 = sess2.createConsumer(queue2);
TextMessage rm1 = (TextMessage)cons1.receive(1000);
assertNotNull(rm1);
@@ -1000,7 +945,7 @@
assertNull(m);
- MessageConsumer cons2 = sess2.createConsumer(queueB);
+ MessageConsumer cons2 = sess2.createConsumer(queue3);
TextMessage rm5 = (TextMessage)cons2.receive(1000);
assertNotNull(rm5);
@@ -1038,12 +983,8 @@
ServerManagement.startServerPeer();
- ServerManagement.deployQueue("QA");
+ deployAndLookupAdministeredObjects();
- ServerManagement.deployQueue("QB");
-
- cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
conn3 = cf.createXAConnection();
XASession sess3 = conn3.createXASession();
@@ -1075,7 +1016,7 @@
log.trace("creating a consumer");
- cons1 = sess1.createConsumer(queueA);
+ cons1 = sess1.createConsumer(queue2);
log.trace("created a consumer");
@@ -1099,7 +1040,7 @@
assertNull(m);
- cons2 = sess1.createConsumer(queueB);
+ cons2 = sess1.createConsumer(queue3);
TextMessage rm13 = (TextMessage)cons2.receive(1000);
assertNotNull(rm13);
@@ -1165,7 +1106,7 @@
{
//Ignore
}
- }
+ }
}
}
@@ -1184,9 +1125,9 @@
Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod1 = sess1.createProducer(queueA);
+ MessageProducer prod1 = sess1.createProducer(queue2);
- MessageProducer prod2 = sess1.createProducer(queueB);
+ MessageProducer prod2 = sess1.createProducer(queue3);
TextMessage tm1 = sess1.createTextMessage("tm1");
TextMessage tm2 = sess1.createTextMessage("tm2");
@@ -1219,7 +1160,7 @@
res.start(xid1, XAResource.TMNOFLAGS);
- MessageProducer prod3 = sess2.createProducer(queueA);
+ MessageProducer prod3 = sess2.createProducer(queue2);
TextMessage tm9 = sess2.createTextMessage("tm9");
TextMessage tm10 = sess2.createTextMessage("tm10");
@@ -1231,7 +1172,7 @@
prod3.send(tm11);
prod3.send(tm12);
- MessageProducer prod4 = sess2.createProducer(queueB);
+ MessageProducer prod4 = sess2.createProducer(queue3);
TextMessage tm13 = sess2.createTextMessage("tm13");
TextMessage tm14 = sess2.createTextMessage("tm14");
@@ -1243,7 +1184,7 @@
prod4.send(tm15);
prod4.send(tm16);
- MessageConsumer cons1 = sess2.createConsumer(queueA);
+ MessageConsumer cons1 = sess2.createConsumer(queue2);
TextMessage rm1 = (TextMessage)cons1.receive(1000);
assertNotNull(rm1);
@@ -1265,7 +1206,7 @@
assertNull(m);
- MessageConsumer cons2 = sess2.createConsumer(queueB);
+ MessageConsumer cons2 = sess2.createConsumer(queue3);
TextMessage rm5 = (TextMessage)cons2.receive(1000);
assertNotNull(rm5);
@@ -1298,16 +1239,14 @@
conn1.close();
conn2.close();
-
-
-
+
conn1 = cf.createConnection();
conn1.start();
sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
- cons1 = sess1.createConsumer(queueA);
+ cons1 = sess1.createConsumer(queue2);
TextMessage rm9 = (TextMessage)cons1.receive(1000);
assertNotNull(rm9);
@@ -1329,7 +1268,7 @@
assertNull(m);
- cons2 = sess1.createConsumer(queueB);
+ cons2 = sess1.createConsumer(queue3);
TextMessage rm13 = (TextMessage)cons2.receive(1000);
assertNotNull(rm13);
@@ -1426,7 +1365,7 @@
res1.start(xid1, XAResource.TMNOFLAGS);
- MessageProducer prod1 = sess1.createProducer(queueTX);
+ MessageProducer prod1 = sess1.createProducer(queue4);
TextMessage tm1 = sess1.createTextMessage("tm1");
@@ -1446,7 +1385,7 @@
Session sess2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons2 = sess2.createConsumer(queueTX);
+ MessageConsumer cons2 = sess2.createConsumer(queue4);
conn2.start();
@@ -1564,7 +1503,7 @@
res1.start(xid1, XAResource.TMNOFLAGS);
- MessageProducer prod1 = sess1.createProducer(queueTX);
+ MessageProducer prod1 = sess1.createProducer(queue4);
TextMessage tm1 = sess1.createTextMessage("tm1");
@@ -1584,7 +1523,7 @@
Session sess2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons2 = sess2.createConsumer(queueTX);
+ MessageConsumer cons2 = sess2.createConsumer(queue4);
conn2.start();
@@ -1604,14 +1543,8 @@
ServerManagement.startServerPeer();
- ServerManagement.deployQueue("TXQ");
+ deployAndLookupAdministeredObjects();
- log.trace("Restarted");
-
- //Now recover
-
- cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
conn3 = cf.createXAConnection();
XASession sess3 = conn3.createXASession();
@@ -1634,7 +1567,7 @@
sess2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- cons2 = sess2.createConsumer(queueTX);
+ cons2 = sess2.createConsumer(queue4);
conn2.start();
@@ -1726,7 +1659,7 @@
Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess1.createProducer(queueTX);
+ MessageProducer prod = sess1.createProducer(queue4);
TextMessage tm1 = sess1.createTextMessage("tm1");
@@ -1744,7 +1677,7 @@
res1.start(xid1, XAResource.TMNOFLAGS);
- MessageConsumer cons = sess2.createConsumer(queueTX);
+ MessageConsumer cons = sess2.createConsumer(queue4);
conn2.start();
@@ -1795,7 +1728,7 @@
sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons1 = sess1.createConsumer(queueTX);
+ MessageConsumer cons1 = sess1.createConsumer(queue4);
conn1.start();
@@ -1868,7 +1801,7 @@
Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sess1.createProducer(queueTX);
+ MessageProducer prod = sess1.createProducer(queue4);
TextMessage tm1 = sess1.createTextMessage("tm1");
@@ -1885,7 +1818,7 @@
res1.start(xid1, XAResource.TMNOFLAGS);
- MessageConsumer cons = sess2.createConsumer(queueTX);
+ MessageConsumer cons = sess2.createConsumer(queue4);
conn2.start();
@@ -1913,10 +1846,8 @@
ServerManagement.startServerPeer();
- ServerManagement.deployQueue("TXQ");
+ deployAndLookupAdministeredObjects();
- cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
//Now recover
conn3 = cf.createXAConnection();
@@ -1945,7 +1876,7 @@
sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons1 = sess1.createConsumer(queueTX);
+ MessageConsumer cons1 = sess1.createConsumer(queue4);
conn1.start();
@@ -2025,11 +1956,11 @@
Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod1 = sess1.createProducer(topicTX);
+ MessageProducer prod1 = sess1.createProducer(topic2);
- MessageConsumer sub1 = sess1.createDurableSubscriber((Topic)topicTX, "sub1");
+ MessageConsumer sub1 = sess1.createDurableSubscriber((Topic)topic2, "sub1");
- MessageConsumer sub2 = sess1.createDurableSubscriber((Topic)topicTX, "sub2");
+ MessageConsumer sub2 = sess1.createDurableSubscriber((Topic)topic2, "sub2");
//send four messages
@@ -2063,7 +1994,7 @@
//Now send four more messages in a global tx
- MessageProducer prod2 = sess2.createProducer(topicTX);
+ MessageProducer prod2 = sess2.createProducer(topic2);
TextMessage tm5 = sess2.createTextMessage("tm5");
TextMessage tm6 = sess2.createTextMessage("tm6");
@@ -2077,9 +2008,9 @@
//And consume the first four from each in the tx
- sub1 = sess2.createDurableSubscriber((Topic)topicTX, "sub1");
+ sub1 = sess2.createDurableSubscriber((Topic)topic2, "sub1");
- sub2 = sess2.createDurableSubscriber((Topic)topicTX, "sub2");
+ sub2 = sess2.createDurableSubscriber((Topic)topic2, "sub2");
TextMessage rm1 = (TextMessage)sub1.receive(1000);
assertNotNull(rm1);
@@ -2163,9 +2094,9 @@
//Should now see the last 4 messages
- sub1 = sess1.createDurableSubscriber((Topic)topicTX, "sub1");
+ sub1 = sess1.createDurableSubscriber((Topic)topic2, "sub1");
- sub2 = sess1.createDurableSubscriber((Topic)topicTX, "sub2");
+ sub2 = sess1.createDurableSubscriber((Topic)topic2, "sub2");
TextMessage rm5 = (TextMessage)sub1.receive(1000);
assertNotNull(rm5);
@@ -2207,6 +2138,14 @@
assertNull(m);
+ sub1.close();
+
+ sub2.close();
+
+ sess1.unsubscribe("sub1");
+
+ sess1.unsubscribe("sub2");
+
if (checkNoMessageData())
{
fail("Data remains in database");
@@ -2280,11 +2219,11 @@
Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod1 = sess1.createProducer(topicTX);
+ MessageProducer prod1 = sess1.createProducer(topic2);
- MessageConsumer sub1 = sess1.createDurableSubscriber((Topic)topicTX, "sub1");
+ MessageConsumer sub1 = sess1.createDurableSubscriber((Topic)topic2, "sub1");
- MessageConsumer sub2 = sess1.createDurableSubscriber((Topic)topicTX, "sub2");
+ MessageConsumer sub2 = sess1.createDurableSubscriber((Topic)topic2, "sub2");
//send four messages
@@ -2318,7 +2257,7 @@
//Now send four more messages in a global tx
- MessageProducer prod2 = sess2.createProducer(topicTX);
+ MessageProducer prod2 = sess2.createProducer(topic2);
TextMessage tm5 = sess2.createTextMessage("tm5");
TextMessage tm6 = sess2.createTextMessage("tm6");
@@ -2332,9 +2271,9 @@
//And consume the first four from each in the tx
- sub1 = sess2.createDurableSubscriber((Topic)topicTX, "sub1");
+ sub1 = sess2.createDurableSubscriber((Topic)topic2, "sub1");
- sub2 = sess2.createDurableSubscriber((Topic)topicTX, "sub2");
+ sub2 = sess2.createDurableSubscriber((Topic)topic2, "sub2");
TextMessage rm1 = (TextMessage)sub1.receive(1000);
assertNotNull(rm1);
@@ -2393,9 +2332,7 @@
ServerManagement.startServerPeer();
- ServerManagement.deployTopic("TXTOPIC");
-
- cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
+ deployAndLookupAdministeredObjects();
conn3 = cf.createXAConnection();
@@ -2430,9 +2367,9 @@
//Should now see the last 4 messages
- sub1 = sess1.createDurableSubscriber((Topic)topicTX, "sub1");
+ sub1 = sess1.createDurableSubscriber((Topic)topic2, "sub1");
- sub2 = sess1.createDurableSubscriber((Topic)topicTX, "sub2");
+ sub2 = sess1.createDurableSubscriber((Topic)topic2, "sub2");
TextMessage rm5 = (TextMessage)sub1.receive(1000);
assertNotNull(rm5);
@@ -2474,6 +2411,14 @@
assertNull(m);
+ sub1.close();
+
+ sub2.close();
+
+ sess1.unsubscribe("sub1");
+
+ sess1.unsubscribe("sub2");
+
if (checkNoMessageData())
{
fail("Data remains in database");
@@ -2564,7 +2509,7 @@
res1.start(xid1, XAResource.TMNOFLAGS);
- MessageProducer prod1 = sess1.createProducer(queueTX);
+ MessageProducer prod1 = sess1.createProducer(queue4);
TextMessage tm1 = sess1.createTextMessage("tm1");
@@ -2580,7 +2525,7 @@
res2.start(xid2, XAResource.TMNOFLAGS);
- MessageProducer prod2 = sess2.createProducer(queueTX);
+ MessageProducer prod2 = sess2.createProducer(queue4);
TextMessage tm3 = sess2.createTextMessage("tm3");
@@ -2611,12 +2556,8 @@
ServerManagement.startServerPeer();
- ServerManagement.deployQueue("TXQ");
+ deployAndLookupAdministeredObjects();
- //Try and recover
-
- cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
XAResource res = cf.createXAConnection().createXASession().getXAResource();
log.trace("Recovering");
@@ -2638,7 +2579,7 @@
conn3 = cf.createConnection();
Session sessRec = conn3.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sessRec.createConsumer(queueTX);
+ MessageConsumer cons = sessRec.createConsumer(queue4);
conn3.start();
log.trace("Created conn3");
@@ -2770,7 +2711,7 @@
res1.start(xid1, XAResource.TMNOFLAGS);
- MessageProducer prod1 = sess1.createProducer(queueA);
+ MessageProducer prod1 = sess1.createProducer(queue2);
TextMessage tm1 = sess1.createTextMessage("alpha");
@@ -2781,7 +2722,7 @@
res2.start(xid2, XAResource.TMNOFLAGS);
- MessageProducer prod2 = sess2.createProducer(queueA);
+ MessageProducer prod2 = sess2.createProducer(queue2);
TextMessage tm2 = sess2.createTextMessage("beta");
@@ -2801,10 +2742,8 @@
ServerManagement.startServerPeer();
- ServerManagement.deployQueue("QA");
+ deployAndLookupAdministeredObjects();
- cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
XAResource res = cf.createXAConnection().createXASession().getXAResource();
Xid[] xids = res.recover(XAResource.TMSTARTRSCAN);
@@ -2824,7 +2763,7 @@
conn3 = cf.createConnection();
Session sessRec = conn3.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sessRec.createConsumer(queueA);
+ MessageConsumer cons = sessRec.createConsumer(queue2);
conn3.start();
Message msg = cons.receive(MAX_TIMEOUT);
@@ -2930,7 +2869,7 @@
res1.start(xid1, XAResource.TMNOFLAGS);
- MessageProducer prod1 = sess1.createProducer(queue);
+ MessageProducer prod1 = sess1.createProducer(queue1);
TextMessage tm1 = sess1.createTextMessage("testing1");
@@ -2941,7 +2880,7 @@
res2.start(xid2, XAResource.TMNOFLAGS);
- MessageProducer prod2 = sess2.createProducer(queue);
+ MessageProducer prod2 = sess2.createProducer(queue1);
TextMessage tm2 = sess2.createTextMessage("testing2");
@@ -2961,10 +2900,8 @@
ServerManagement.startServerPeer();
- ServerManagement.deployQueue("Queue");
+ deployAndLookupAdministeredObjects();
- cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
XAResource res = cf.createXAConnection().createXASession().getXAResource();
Xid[] xids = res.recover(XAResource.TMSTARTRSCAN);
@@ -2983,7 +2920,7 @@
conn3 = cf.createConnection();
Session sessRec = conn3.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sessRec.createConsumer(queue);
+ MessageConsumer cons = sessRec.createConsumer(queue1);
conn3.start();
TextMessage m1 = (TextMessage)cons.receive(MAX_TIMEOUT);
@@ -3072,7 +3009,7 @@
res1.start(xid1, XAResource.TMNOFLAGS);
- MessageProducer prod1 = sess1.createProducer(queue);
+ MessageProducer prod1 = sess1.createProducer(queue1);
TextMessage tm1 = sess1.createTextMessage("testing1");
@@ -3083,7 +3020,7 @@
res2.start(xid2, XAResource.TMNOFLAGS);
- MessageProducer prod2 = sess2.createProducer(queue);
+ MessageProducer prod2 = sess2.createProducer(queue1);
TextMessage tm2 = sess2.createTextMessage("testing2");
@@ -3103,10 +3040,8 @@
ServerManagement.startServerPeer();
- ServerManagement.deployQueue("Queue");
+ deployAndLookupAdministeredObjects();
- cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
XAResource res = cf.createXAConnection().createXASession().getXAResource();
Xid[] xids = res.recover(XAResource.TMSTARTRSCAN);
@@ -3125,7 +3060,7 @@
conn3 = cf.createConnection();
Session sessRec = conn3.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sessRec.createConsumer(queue);
+ MessageConsumer cons = sessRec.createConsumer(queue1);
conn3.start();
TextMessage m1 = (TextMessage)cons.receive(MAX_TIMEOUT);
@@ -3214,8 +3149,8 @@
res1.start(xid1, XAResource.TMNOFLAGS);
- MessageProducer prod1 = sess1.createProducer(queueA);
- MessageProducer prod2 = sess1.createProducer(queueB);
+ MessageProducer prod1 = sess1.createProducer(queue2);
+ MessageProducer prod2 = sess1.createProducer(queue3);
TextMessage tm1 = sess1.createTextMessage("testing1");
TextMessage tm2 = sess1.createTextMessage("testing2");
@@ -3228,7 +3163,7 @@
res2.start(xid2, XAResource.TMNOFLAGS);
- MessageProducer prod3 = sess2.createProducer(queue);
+ MessageProducer prod3 = sess2.createProducer(queue1);
TextMessage tm3 = sess2.createTextMessage("testing3");
@@ -3248,12 +3183,7 @@
ServerManagement.startServerPeer();
- ServerManagement.deployQueue("Queue");
- ServerManagement.deployQueue("QA");
- ServerManagement.deployQueue("QB");
-
-
- cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
+ deployAndLookupAdministeredObjects();
XAResource res = cf.createXAConnection().createXASession().getXAResource();
@@ -3274,9 +3204,9 @@
Session sessRec = conn3.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons1 = sessRec.createConsumer(queueA);
- MessageConsumer cons2 = sessRec.createConsumer(queueB);
- MessageConsumer cons3 = sessRec.createConsumer(queue);
+ MessageConsumer cons1 = sessRec.createConsumer(queue2);
+ MessageConsumer cons2 = sessRec.createConsumer(queue3);
+ MessageConsumer cons3 = sessRec.createConsumer(queue1);
conn3.start();
Modified: trunk/tests/src/org/jboss/test/messaging/jms/XAResourceRecoveryTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/XAResourceRecoveryTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/XAResourceRecoveryTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -26,7 +26,6 @@
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
-import javax.jms.Destination;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
@@ -34,15 +33,16 @@
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.XAConnection;
-import javax.jms.XAConnectionFactory;
import javax.jms.XASession;
+import javax.management.ObjectName;
import javax.naming.InitialContext;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import javax.transaction.xa.XAResource;
+import org.jboss.jms.client.JBossConnectionFactory;
import org.jboss.jms.jndi.JMSProviderAdapter;
-import org.jboss.test.messaging.MessagingTestCase;
+import org.jboss.jms.tx.ResourceManagerFactory;
import org.jboss.test.messaging.tools.ServerManagement;
import org.jboss.test.messaging.tools.TestJMSProviderAdaptor;
import org.jboss.test.messaging.tools.aop.PoisonInterceptor;
@@ -62,91 +62,62 @@
* $Id$
*
*/
-public class XAResourceRecoveryTest extends MessagingTestCase
+public class XAResourceRecoveryTest extends JMSTestCase
{
- protected int nodeCount = 2;
-
protected ServiceContainer sc;
- protected XAConnectionFactory cf0, cf1;
+ protected JBossConnectionFactory cf1;
- protected Destination queue0, queue1;
-
protected TransactionManager tm;
protected Transaction suspendedTx;
-
+
+ protected static Queue otherQueue;
+
public XAResourceRecoveryTest(String name)
{
super(name);
}
protected void setUp() throws Exception
- {
- if (!ServerManagement.isRemote())
- {
- throw new IllegalStateException("This test should only be run in remote mode");
- }
-
+ {
super.setUp();
-
- log.info("Starting " + nodeCount + " servers");
-
- for (int i = 0; i < nodeCount; i++)
- {
- // make sure all servers are created and started; make sure that database is zapped
- // ONLY for the first server, the others rely on values they expect to find in shared
- // tables; don't clear the database for those.
- ServerManagement.start(i, "all", i == 0);
- }
+ //Now start another remote server
+ ServerManagement.start(1, "all", false);
+
+ ResourceManagerFactory.instance.clear();
+
//We need a local transaction and recovery manager
//We must start this after the remote servers have been created or it won't
//have deleted the database and the recovery manager may attempt to recover transactions
- sc = new ServiceContainer("jbossjta");
+ sc = new ServiceContainer("all,-transaction,jbossjta");
+ //Don't drop the tables again!
+
sc.start(false);
- ServerManagement.undeployQueue("queue0", 0);
+ InitialContext localIc = new InitialContext(InVMInitialContextFactory.getJNDIEnvironment());
+
+ tm = (TransactionManager)localIc.lookup(ServiceContainer.TRANSACTION_MANAGER_JNDI_NAME);
+
+ log.info("tm is " + tm.getClass().getName());
- ServerManagement.undeployQueue("queue1", 1);
+ assertTrue(tm instanceof TransactionManagerImple);
- ServerManagement.deployQueue("queue0", 0);
- ServerManagement.deployQueue("queue1", 1);
+ ServerManagement.deployQueue("OtherQueue", 1);
- Hashtable props0 = ServerManagement.getJNDIEnvironment(0);
-
Hashtable props1 = ServerManagement.getJNDIEnvironment(1);
-
- InitialContext ic0 = new InitialContext(props0);
-
+
InitialContext ic1 = new InitialContext(props1);
- cf0 = (XAConnectionFactory)ic0.lookup("/XAConnectionFactory");
+ cf1 = (JBossConnectionFactory)ic1.lookup("/XAConnectionFactory");
- cf1 = (XAConnectionFactory)ic1.lookup("/XAConnectionFactory");
+ otherQueue = (Queue)ic1.lookup("/queue/OtherQueue");
- queue0 = (Queue)ic0.lookup("/queue/queue0");
+ checkOtherQueueEmpty();
- queue1 = (Queue)ic1.lookup("/queue/queue1");
-
- InitialContext localIc = new InitialContext(InVMInitialContextFactory.getJNDIEnvironment());
-
- tm = (TransactionManager)localIc.lookup(ServiceContainer.TRANSACTION_MANAGER_JNDI_NAME);
-
- log.info("tm is " + tm.getClass().getName());
- assertTrue(tm instanceof TransactionManagerImple);
-
- drainDestination((ConnectionFactory)cf0, queue0);
-
- drainDestination((ConnectionFactory)cf1, queue1);
-
- if (!ServerManagement.isRemote())
- {
- suspendedTx = tm.suspend();
- }
-
//Now install local JMSProviderAdaptor classes
Properties p1 = new Properties();
@@ -158,26 +129,20 @@
sc.installJMSProviderAdaptor("adaptor1", targetAdaptor);
sc.startRecoveryManager();
-
+
+ suspendedTx = tm.suspend();
}
- protected void tearDown() throws Exception
- {
+ public void tearDown() throws Exception
+ {
+ super.tearDown();
try
{
- ServerManagement.undeployQueue("queue0", 0);
+ ServerManagement.undeployQueue("OtherQueue", 1);
}
catch (Exception ignore)
{
}
-
- try
- {
- ServerManagement.undeployQueue("queue1", 1);
- }
- catch (Exception ignore)
- {
- }
if (TxUtils.isUncommitted(tm))
{
@@ -201,44 +166,13 @@
if (suspendedTx != null)
{
tm.resume(suspendedTx);
- }
-
-// for (int i = 0; i < nodeCount; i++)
-// {
-// try
-// {
-// if (ServerManagement.isStarted(i))
-// {
-// ServerManagement.log(ServerManagement.INFO, "Undeploying Server " + i, i);
-//
-// ServerManagement.stop(i);
-// }
-// }
-// catch (Exception e)
-// {
-// log.error("Failed to stop server", e);
-// }
-// }
-//
-// for (int i = 1; i < nodeCount; i++)
-// {
-// try
-// {
-// ServerManagement.kill(i);
-// }
-// catch (Exception e)
-// {
-// log.error("Failed to kill server", e);
-// }
-// }
+ }
sc.uninstallJMSProviderAdaptor("adaptor1");
sc.stopRecoveryManager();
- sc.stop();
-
- super.tearDown();
+ sc.stop();
}
public void testRecoveryOnSend() throws Exception
@@ -253,11 +187,11 @@
try
{
- conn0 = cf0.createXAConnection();
+ conn0 = cf.createXAConnection();
XASession sess0 = conn0.createXASession();
- MessageProducer prod0 = sess0.createProducer(queue0);
+ MessageProducer prod0 = sess0.createProducer(queue1);
XAResource res0 = sess0.getXAResource();
@@ -266,7 +200,7 @@
XASession sess1 = conn1.createXASession();
- MessageProducer prod1 = sess1.createProducer(queue1);
+ MessageProducer prod1 = sess1.createProducer(otherQueue);
XAResource res1 = sess1.getXAResource();
@@ -288,8 +222,7 @@
TextMessage tm1 = sess1.createTextMessage("message1");
prod1.send(tm1);
-
-
+
// Poison server 1 so it crashes on commit of dest but after prepare
//This means the transaction branch on source will get commmitted
@@ -318,24 +251,21 @@
log.info("Restarted server");
- Thread.sleep(3000);
+ ServerManagement.deployQueue("OtherQueue", 1);
- ServerManagement.deployQueue("queue1", 1);
-
Hashtable props1 = ServerManagement.getJNDIEnvironment(1);
InitialContext ic1 = new InitialContext(props1);
- cf1 = (XAConnectionFactory)ic1.lookup("/XAConnectionFactory");
+ cf1 = (JBossConnectionFactory)ic1.lookup("/XAConnectionFactory");
- queue1 = (Queue)ic1.lookup("/queue/queue1");
+ otherQueue = (Queue)ic1.lookup("/queue/OtherQueue");
+
+ conn2 = cf.createConnection();
-
- conn2 = ((ConnectionFactory)cf0).createConnection();
-
Session sess2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons2 = sess2.createConsumer(queue0);
+ MessageConsumer cons2 = sess2.createConsumer(queue1);
conn2.start();
@@ -345,31 +275,27 @@
assertEquals(tm0.getText(), rm0.getText());
- Message m = cons2.receive(2000);
+ checkEmpty(queue1);
- assertNull(m);
-
//Now even though the commit on the second server failed since the server was dead, the recovery manager should kick in
//eventually and recover it.
- conn3 = ((ConnectionFactory)cf1).createConnection();
+ conn3 = cf1.createConnection();
Session sess3 = conn3.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons3 = sess3.createConsumer(queue1);
+ MessageConsumer cons3 = sess3.createConsumer(otherQueue);
conn3.start();
+ log.info("**** now waiting for recovery to kick in");
TextMessage rm1 = (TextMessage)cons3.receive(60000);
assertNotNull(rm1);
assertEquals(tm1.getText(), rm1.getText());
- m = cons3.receive(2000);
-
- assertNull(m);
-
+ checkOtherQueueEmpty();
}
finally
{
@@ -392,158 +318,153 @@
}
}
+
public void testRecoveryOnAck() throws Exception
{
XAConnection conn0 = null;
-
+
XAConnection conn1 = null;
-
+
Connection conn2 = null;
-
+
Connection conn3 = null;
-
+
try
{
- conn0 = cf0.createXAConnection();
-
+ conn0 = cf.createXAConnection();
+
XASession sess0 = conn0.createXASession();
-
- MessageProducer prod0 = sess0.createProducer(queue0);
-
+
+ MessageProducer prod0 = sess0.createProducer(queue1);
+
XAResource res0 = sess0.getXAResource();
-
-
+
+
conn1 = cf1.createXAConnection();
-
+
XASession sess1 = conn1.createXASession();
-
- MessageConsumer cons1 = sess1.createConsumer(queue1);
-
+
+ MessageConsumer cons1 = sess1.createConsumer(otherQueue);
+
XAResource res1 = sess1.getXAResource();
-
+
conn1.start();
-
+
//first send a few messages to server 1
-
- conn2 = ((ConnectionFactory)cf1).createConnection();
-
+
+ conn2 = cf1.createConnection();
+
Session sess2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageProducer prod2 = sess2.createProducer(queue1);
-
+
+ MessageProducer prod2 = sess2.createProducer(otherQueue);
+
TextMessage tm1 = sess1.createTextMessage("message1");
-
+
prod2.send(tm1);
-
+
TextMessage tm2 = sess1.createTextMessage("message2");
-
+
prod2.send(tm2);
-
+
conn2.close();
-
+
tm.begin();
-
+
Transaction tx = tm.getTransaction();
-
+
tx.enlistResource(res0);
-
+
tx.enlistResource(res1);
-
-
+
+
TextMessage tm0 = sess0.createTextMessage("message0");
-
+
prod0.send(tm0);
-
+
//Consume one of the messages on dest
-
+
TextMessage rm1 = (TextMessage)cons1.receive(1000);
-
+
assertNotNull(rm1);
-
+
assertEquals(tm1.getText(), rm1.getText());
-
+
// Poison server 1 so it crashes on commit of dest but after prepare
-
- //This means the transaction branch on source will get commmitted
- //but the branch on dest won't be - it will remain prepared
- //This corresponds to a HeuristicMixedException
-
- ServerManagement.poisonTheServer(1, PoisonInterceptor.TYPE_2PC_COMMIT);
-
- log.info("Poisoned server");
-
- tx.delistResource(res0, XAResource.TMSUCCESS);
-
- tx.delistResource(res1, XAResource.TMSUCCESS);
-
- tx.commit();
-
- conn0.close();
-
- conn1.close();
-
- //Now restart the server
-
- log.info("Restarting server");
-
- ServerManagement.start(1, "all", false);
-
- log.info("Restarted server");
-
- Thread.sleep(3000);
-
- ServerManagement.deployQueue("queue1", 1);
-
- Hashtable props1 = ServerManagement.getJNDIEnvironment(1);
-
- InitialContext ic1 = new InitialContext(props1);
-
- cf1 = (XAConnectionFactory)ic1.lookup("/XAConnectionFactory");
-
- queue1 = (Queue)ic1.lookup("/queue/queue1");
-
-
- conn2 = ((ConnectionFactory)cf0).createConnection();
-
- sess2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer cons2 = sess2.createConsumer(queue0);
-
- conn2.start();
-
- TextMessage rm0 = (TextMessage)cons2.receive(2000);
-
- assertNotNull(rm0);
-
- assertEquals(tm0.getText(), rm0.getText());
-
- Message m = cons2.receive(2000);
-
- assertNull(m);
-
- //Now even though the commit on the second server failed since the server was dead, the recovery manager should kick in
- //eventually and recover it.
-
- conn3 = ((ConnectionFactory)cf1).createConnection();
-
- Session sess3 = conn3.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer cons3 = sess3.createConsumer(queue1);
-
- conn3.start();
-
- TextMessage rm2 = (TextMessage)cons3.receive(60000);
-
- assertNotNull(rm2);
-
- //tm1 should have been acked on recovery
-
- assertEquals(tm2.getText(), rm2.getText());
-
- m = cons3.receive(2000);
-
- assertNull(m);
-
+
+ //This means the transaction branch on source will get commmitted
+ //but the branch on dest won't be - it will remain prepared
+ //This corresponds to a HeuristicMixedException
+
+ ServerManagement.poisonTheServer(1, PoisonInterceptor.TYPE_2PC_COMMIT);
+
+ log.info("Poisoned server");
+
+ tx.delistResource(res0, XAResource.TMSUCCESS);
+
+ tx.delistResource(res1, XAResource.TMSUCCESS);
+
+ tx.commit();
+
+ conn0.close();
+
+ conn1.close();
+
+ //Now restart the server
+
+ log.info("Restarting server");
+
+ ServerManagement.start(1, "all", false);
+
+ log.info("Restarted server");
+
+ ServerManagement.deployQueue("OtherQueue", 1);
+
+ Hashtable props1 = ServerManagement.getJNDIEnvironment(1);
+
+ InitialContext ic1 = new InitialContext(props1);
+
+ cf1 = (JBossConnectionFactory)ic1.lookup("/XAConnectionFactory");
+
+ otherQueue = (Queue)ic1.lookup("/queue/OtherQueue");
+
+
+ conn2 = cf.createConnection();
+
+ sess2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer cons2 = sess2.createConsumer(queue1);
+
+ conn2.start();
+
+ TextMessage rm0 = (TextMessage)cons2.receive(2000);
+
+ assertNotNull(rm0);
+
+ assertEquals(tm0.getText(), rm0.getText());
+
+ checkEmpty(queue1);
+
+ //Now even though the commit on the second server failed since the server was dead, the recovery manager should kick in
+ //eventually and recover it.
+
+ conn3 = ((ConnectionFactory)cf1).createConnection();
+
+ Session sess3 = conn3.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer cons3 = sess3.createConsumer(otherQueue);
+
+ conn3.start();
+
+ log.info("***** waiting for recovery to kick in");
+ TextMessage rm2 = (TextMessage)cons3.receive(60000);
+
+ assertNotNull(rm2);
+
+ //tm1 should have been acked on recovery
+
+ assertEquals(tm2.getText(), rm2.getText());
+
+ checkOtherQueueEmpty();
}
finally
{
@@ -565,4 +486,13 @@
}
}
}
+
+ private void checkOtherQueueEmpty() throws Exception
+ {
+ ObjectName destObjectName = new ObjectName("jboss.messaging.destination:service=Queue,name=OtherQueue");
+
+ Integer messageCount = (Integer)ServerManagement.getServer(1).getAttribute(destObjectName, "MessageCount");
+
+ assertEquals(0, messageCount.intValue());
+ }
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/XATestBase.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/XATestBase.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/XATestBase.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -24,15 +24,12 @@
import java.util.ArrayList;
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
-import javax.jms.Destination;
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.ServerSession;
import javax.jms.ServerSessionPool;
import javax.jms.Session;
@@ -42,15 +39,14 @@
import javax.jms.XASession;
import javax.management.ObjectName;
import javax.naming.InitialContext;
+import javax.transaction.RollbackException;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
-import javax.transaction.RollbackException;
import javax.transaction.xa.XAException;
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
import org.jboss.jms.client.JBossConnection;
-import org.jboss.jms.client.JBossConnectionFactory;
import org.jboss.jms.client.JBossSession;
import org.jboss.jms.client.delegate.ClientConnectionDelegate;
import org.jboss.jms.client.delegate.DelegateSupport;
@@ -60,8 +56,8 @@
import org.jboss.jms.tx.MessagingXAResource;
import org.jboss.jms.tx.MessagingXid;
import org.jboss.jms.tx.ResourceManager;
+import org.jboss.jms.tx.ResourceManagerFactory;
import org.jboss.logging.Logger;
-import org.jboss.test.messaging.MessagingTestCase;
import org.jboss.test.messaging.tools.ServerManagement;
import org.jboss.test.messaging.tools.jmx.ServiceContainer;
import org.jboss.test.messaging.tools.jndi.InVMInitialContextFactory;
@@ -81,20 +77,14 @@
* $Id$
*
*/
-public abstract class XATestBase extends MessagingTestCase
+public abstract class XATestBase extends JMSTestCase
{
// Constants -----------------------------------------------------
// Static --------------------------------------------------------
// Attributes ----------------------------------------------------
-
- protected InitialContext initialContext;
-
- protected JBossConnectionFactory cf;
-
- protected Destination queue;
-
+
protected TransactionManager tm;
protected Transaction suspendedTx;
@@ -103,7 +93,6 @@
protected boolean useArjuna;
-
// Constructors --------------------------------------------------
public XATestBase(String name)
@@ -116,16 +105,14 @@
public void setUp() throws Exception
{
- super.setUp();
-
if (useArjuna)
{
- ServerManagement.start("all,-transaction,jbossjta");
+ overrideConf = "all,-transaction,jbossjta";
}
- else
- {
- ServerManagement.start("all");
- }
+
+ super.setUp();
+
+ ResourceManagerFactory.instance.clear();
//Also need a local tx mgr if test is running remote
if (ServerManagement.isRemote())
@@ -143,32 +130,19 @@
sc.start(false);
}
- initialContext = new InitialContext(ServerManagement.getJNDIEnvironment());
-
InitialContext localIc = new InitialContext(InVMInitialContextFactory.getJNDIEnvironment());
- cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
tm = (TransactionManager)localIc.lookup(ServiceContainer.TRANSACTION_MANAGER_JNDI_NAME);
if (useArjuna)
{
- log.info("tm is " + tm.getClass().getName());
assertTrue(tm instanceof TransactionManagerImple);
}
else
{
assertTrue(tm instanceof org.jboss.tm.TxManager);
}
-
- ServerManagement.undeployQueue("Queue");
-
- ServerManagement.deployQueue("Queue");
-
- queue = (Destination)initialContext.lookup("/queue/Queue");
-
- drainDestination(cf, queue);
-
+
if (!ServerManagement.isRemote())
{
suspendedTx = tm.suspend();
@@ -176,9 +150,7 @@
}
public void tearDown() throws Exception
- {
- ServerManagement.undeployQueue("Queue");
-
+ {
if (TxUtils.isUncommitted(tm))
{
//roll it back
@@ -207,15 +179,10 @@
{
sc.stop();
}
-
- ServerManagement.stop();
-
+
super.tearDown();
}
-
-
-
// Public --------------------------------------------------------
/* If there is no global tx present the send must behave as non transacted.
@@ -230,38 +197,30 @@
try
{
- ServerManagement.deployQueue("MyQueue");
-
// make sure there's no active JTA transaction
suspended = TransactionManagerLocator.getInstance().locate().suspend();
// send a message to the queue using an XASession that's not enlisted in a global tx
- Queue queue = (Queue)initialContext.lookup("queue/MyQueue");
+ XAConnectionFactory xcf = (XAConnectionFactory)cf;
- XAConnectionFactory xcf =
- (XAConnectionFactory)initialContext.lookup("java:/XAConnectionFactory");
-
XAConnection xconn = xcf.createXAConnection();
XASession xs = xconn.createXASession();
- MessageProducer p = xs.createProducer(queue);
+ MessageProducer p = xs.createProducer(queue1);
Message m = xs.createTextMessage("one");
p.send(m);
- log.debug("message sent");
-
xconn.close();
// receive the message
- ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
Connection conn = cf.createConnection();
conn.start();
Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer c = s.createConsumer(queue);
+ MessageConsumer c = s.createConsumer(queue1);
TextMessage rm = (TextMessage)c.receive(1000);
assertEquals("one", rm.getText());
@@ -270,8 +229,6 @@
}
finally
{
- ServerManagement.undeployQueue("MyQueue");
-
if (suspended != null)
{
TransactionManagerLocator.getInstance().locate().resume(suspended);
@@ -305,101 +262,86 @@
*/
public void testConsumeWithConnectionConsumerNoGlobalTransaction() throws Exception
{
- ServerManagement.deployQueue("MyQueue2");
+ // send a message to the queue
- try
- {
- // send a message to the queue
+ Connection conn = cf.createConnection();
+ Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer p = s.createProducer(queue1);
+ p.setDeliveryMode(DeliveryMode.PERSISTENT);
+ Message m = s.createTextMessage("one");
+ p.send(m);
+ conn.close();
- ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
- Queue queue = (Queue) initialContext.lookup("queue/MyQueue2");
- Connection conn = cf.createConnection();
- Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = s.createProducer(queue);
- p.setDeliveryMode(DeliveryMode.PERSISTENT);
- Message m = s.createTextMessage("one");
- p.send(m);
- conn.close();
+ // make sure there's no active JTA transaction
- // make sure there's no active JTA transaction
+ Transaction suspended = tm.suspend();
- Transaction suspended = tm.suspend();
+ XAConnection xaconn = null;
+ try
+ {
+ ObjectName queueMBean = new ObjectName("jboss.messaging.destination:service=Queue,name=Queue1");
+ Integer count = (Integer) ServerManagement.getAttribute(queueMBean, "MessageCount");
+ assertEquals(1, count.intValue());
- XAConnection xaconn = null;
- try
- {
+ // using XA with a ConnectionConsumer (testing the transaction behavior under MDBs)
- ObjectName queueMBean = new ObjectName("jboss.messaging.destination:service=Queue,name=MyQueue2");
- Integer count = (Integer) ServerManagement.getAttribute(queueMBean, "MessageCount");
- assertEquals(1, count.intValue());
+ XAConnectionFactory xacf = (XAConnectionFactory)cf;
+ xaconn = xacf.createXAConnection();
+ xaconn.start();
+ XASession xasession = xaconn.createXASession();
+ DummyListener listener = new DummyListener();
+ xasession.setMessageListener(listener);
- // using XA with a ConnectionConsumer (testing the transaction behavior under MDBs)
+ ServerSessionPool pool = new MockServerSessionPool(xasession);
- XAConnectionFactory xacf = (XAConnectionFactory) initialContext.lookup("/XAConnectionFactory");
- xaconn = xacf.createXAConnection();
- xaconn.start();
- XASession xasession = xaconn.createXASession();
- DummyListener listener = new DummyListener();
- xasession.setMessageListener(listener);
+ xaconn.createConnectionConsumer(queue1, null, pool, 1);
- ServerSessionPool pool = new MockServerSessionPool(xasession);
+ Thread.sleep(1000);
+ assertEquals(1, listener.messages.size());
- xaconn.createConnectionConsumer(queue, null, pool, 1);
+ // Message should still be on server
+ count = (Integer) ServerManagement.getAttribute(queueMBean, "MessageCount");
+ assertEquals(1, count.intValue());
- Thread.sleep(1000);
- assertEquals(1, listener.messages.size());
+ XAResource resource = xasession.getXAResource();
- // Message should still be on server
- count = (Integer) ServerManagement.getAttribute(queueMBean, "MessageCount");
- assertEquals(1, count.intValue());
+ // Starts a new transaction
+ tm.begin();
- XAResource resource = xasession.getXAResource();
+ Transaction trans = tm.getTransaction();
- // Starts a new transaction
- tm.begin();
+ JBossSession session = (JBossSession)xasession;
+ SessionState state = (SessionState)((DelegateSupport)session.getDelegate()).getState();
- Transaction trans = tm.getTransaction();
+ // Validates TX convertion
+ assertTrue(state.getCurrentTxId() instanceof LocalTx);
- JBossSession session = (JBossSession)xasession;
- SessionState state = (SessionState)((DelegateSupport)session.getDelegate()).getState();
+ // Enlist the transaction... as supposed to be happening on JBossAS with the
+ // default listener (enlist happening after message is received)
+ trans.enlistResource(resource);
- // Validates TX convertion
- assertTrue(state.getCurrentTxId() instanceof LocalTx);
+ // Validates TX convertion
+ assertFalse(state.getCurrentTxId() instanceof LocalTx);
- // Enlist the transaction... as supposed to be happening on JBossAS with the
- // default listener (enlist happening after message is received)
- trans.enlistResource(resource);
+ trans.delistResource(resource, XAResource.TMSUCCESS);
- // Validates TX convertion
- assertFalse(state.getCurrentTxId() instanceof LocalTx);
+ trans.commit();
- trans.delistResource(resource, XAResource.TMSUCCESS);
-
- trans.commit();
-
-
- // After commit the message should be consumed
- count = (Integer) ServerManagement.getAttribute(queueMBean, "MessageCount");
- assertEquals(0, count.intValue());
+ // After commit the message should be consumed
+ count = (Integer) ServerManagement.getAttribute(queueMBean, "MessageCount");
+ assertEquals(0, count.intValue());
+ }
+ finally
+ {
+ if (xaconn != null)
+ {
+ xaconn.close();
}
- finally
+ if (suspended != null)
{
- if (xaconn != null)
- {
- xaconn.close();
- }
- if (suspended != null)
- {
- TransactionManagerLocator.getInstance().locate().resume(suspended);
- }
+ TransactionManagerLocator.getInstance().locate().resume(suspended);
}
}
- finally
- {
- ServerManagement.undeployQueue("MyQueue2");
- }
-
-
}
@@ -428,68 +370,55 @@
*/
public void testConsumeWithoutConnectionConsumerNoGlobalTransaction() throws Exception
{
- try
- {
- ServerManagement.deployQueue("MyQueue2");
+ // send a message to the queue
- // send a message to the queue
+ Connection conn = cf.createConnection();
+ Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer p = s.createProducer(queue1);
+ p.setDeliveryMode(DeliveryMode.PERSISTENT);
+ Message m = s.createTextMessage("one");
+ p.send(m);
+ conn.close();
- ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
- Queue queue = (Queue)initialContext.lookup("queue/MyQueue2");
- Connection conn = cf.createConnection();
- Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = s.createProducer(queue);
- p.setDeliveryMode(DeliveryMode.PERSISTENT);
- Message m = s.createTextMessage("one");
- p.send(m);
- conn.close();
+ // make sure there's no active JTA transaction
- // make sure there's no active JTA transaction
+ Transaction suspended = TransactionManagerLocator.getInstance().locate().suspend();
- Transaction suspended = TransactionManagerLocator.getInstance().locate().suspend();
+ try
+ {
+ ObjectName queueMBean = new ObjectName("jboss.messaging.destination:service=Queue,name=Queue1");
+ Integer count = (Integer)ServerManagement.getAttribute(queueMBean, "MessageCount");
+ assertEquals(1, count.intValue());
- try
- {
+ XAConnectionFactory xcf = (XAConnectionFactory)cf;
+ XAConnection xconn = xcf.createXAConnection();
+ xconn.start();
- ObjectName queueMBean = new ObjectName("jboss.messaging.destination:service=Queue,name=MyQueue2");
- Integer count = (Integer)ServerManagement.getAttribute(queueMBean, "MessageCount");
- assertEquals(1, count.intValue());
+ // no active JTA transaction here
- XAConnectionFactory xcf =
- (XAConnectionFactory)initialContext.lookup("java:/XAConnectionFactory");
- XAConnection xconn = xcf.createXAConnection();
- xconn.start();
+ XASession xs = xconn.createXASession();
- // no active JTA transaction here
+ MessageConsumer c = xs.createConsumer(queue1);
- XASession xs = xconn.createXASession();
+ // the message should be store unacked in the local session
+ TextMessage rm = (TextMessage)c.receive(1000);
- MessageConsumer c = xs.createConsumer(queue);
+ assertEquals("one", rm.getText());
+
+ // messages should be acked
+ count = (Integer)ServerManagement.getAttribute(queueMBean, "MessageCount");
+ assertEquals(0, count.intValue());
+
+ xconn.close();
+ }
+ finally
+ {
- // the message should be store unacked in the local session
- TextMessage rm = (TextMessage)c.receive(1000);
-
- assertEquals("one", rm.getText());
-
- // messages should be acked
- count = (Integer)ServerManagement.getAttribute(queueMBean, "MessageCount");
- assertEquals(0, count.intValue());
-
- xconn.close();
- }
- finally
+ if (suspended != null)
{
-
- if (suspended != null)
- {
- TransactionManagerLocator.getInstance().locate().resume(suspended);
- }
+ TransactionManagerLocator.getInstance().locate().resume(suspended);
}
}
- finally
- {
- ServerManagement.undeployQueue("MyQueue2");
- }
}
@@ -522,21 +451,17 @@
try
{
- ServerManagement.deployQueue("MyQueue2");
-
// send a message to the queue
- ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
- Queue queue = (Queue)initialContext.lookup("queue/MyQueue2");
Connection conn = cf.createConnection();
Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = s.createProducer(queue);
+ MessageProducer p = s.createProducer(queue1);
p.setDeliveryMode(DeliveryMode.PERSISTENT);
Message m = s.createTextMessage("one");
p.send(m);
conn.close();
- ObjectName queueMBean = new ObjectName("jboss.messaging.destination:service=Queue,name=MyQueue2");
+ ObjectName queueMBean = new ObjectName("jboss.messaging.destination:service=Queue,name=Queue1");
Integer count = (Integer)ServerManagement.getAttribute(queueMBean, "MessageCount");
assertEquals(1, count.intValue());
@@ -556,7 +481,7 @@
trans.enlistResource(resouce);
- MessageConsumer consumer = xasession.createConsumer(queue);
+ MessageConsumer consumer = xasession.createConsumer(queue1);
TextMessage messageReceived = (TextMessage)consumer.receive(1000);
@@ -599,7 +524,6 @@
{
xaconn.close();
}
- ServerManagement.undeployQueue("MyQueue2");
}
}
@@ -623,15 +547,11 @@
try
{
- ServerManagement.deployQueue("MyQueue2");
-
// send a message to the queue
- ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
- Queue queue = (Queue)initialContext.lookup("queue/MyQueue2");
Connection conn = cf.createConnection();
Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = s.createProducer(queue);
+ MessageProducer p = s.createProducer(queue1);
p.setDeliveryMode(DeliveryMode.PERSISTENT);
Message m = s.createTextMessage("one");
p.send(m);
@@ -639,7 +559,7 @@
p.send(m);
conn.close();
- ObjectName queueMBean = new ObjectName("jboss.messaging.destination:service=Queue,name=MyQueue2");
+ ObjectName queueMBean = new ObjectName("jboss.messaging.destination:service=Queue,name=Queue1");
Integer count = (Integer)ServerManagement.getAttribute(queueMBean, "MessageCount");
assertEquals(2, count.intValue());
@@ -651,7 +571,7 @@
XASession xasession = xaconn.createXASession();
- MessageConsumer consumer = xasession.createConsumer(queue);
+ MessageConsumer consumer = xasession.createConsumer(queue1);
TextMessage messageReceived = (TextMessage)consumer.receive(1000);
@@ -673,8 +593,6 @@
count = (Integer)ServerManagement.getAttribute(queueMBean, "MessageCount");
assertEquals(0, count.intValue());
-
-
}
finally
{
@@ -682,14 +600,12 @@
{
xaconn.close();
}
- ServerManagement.undeployQueue("MyQueue2");
}
}
//See http://jira.jboss.com/jira/browse/JBMESSAGING-638
public void testResourceManagerMemoryLeakOnCommit() throws Exception
{
-
XAConnection xaConn = null;
try
@@ -714,7 +630,6 @@
for (int i = 0; i < 100; i++)
{
-
tm.begin();
Transaction tx = tm.getTransaction();
@@ -819,13 +734,12 @@
XAConnection xaConn = null;
-
try
{
//First send some messages to a queue
- ObjectName queueMBean = new ObjectName("jboss.messaging.destination:service=Queue,name=Queue");
+ ObjectName queueMBean = new ObjectName("jboss.messaging.destination:service=Queue,name=Queue1");
Integer count = (Integer) ServerManagement.getAttribute(queueMBean, "MessageCount");
assertEquals(0, count.intValue());
@@ -833,7 +747,7 @@
Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessSend.createProducer(queue);
+ MessageProducer prod = sessSend.createProducer(queue1);
TextMessage tm1 = sessSend.createTextMessage("message1");
@@ -858,7 +772,7 @@
ServerSessionPool pool = new MockServerSessionPool(xaSession);
- xaConn.createConnectionConsumer(queue, null, pool, 1);
+ xaConn.createConnectionConsumer(queue1, null, pool, 1);
Thread.sleep(1000);
@@ -923,8 +837,6 @@
assertEquals(0, count.intValue());
assertNull(tm.getTransaction());
-
-
}
finally
{
@@ -956,14 +868,13 @@
try
{
-
//First send some messages to a queue
conn = cf.createConnection();
Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessSend.createProducer(queue);
+ MessageProducer prod = sessSend.createProducer(queue1);
TextMessage tm1 = sessSend.createTextMessage("message1");
@@ -980,7 +891,7 @@
xaConn.start();
- MessageConsumer cons = xaSession.createConsumer(queue);
+ MessageConsumer cons = xaSession.createConsumer(queue1);
//Now we enlist the session in an xa transaction
@@ -1073,14 +984,13 @@
try
{
-
//First send some messages to a queue
conn = cf.createConnection();
Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessSend.createProducer(queue);
+ MessageProducer prod = sessSend.createProducer(queue1);
TextMessage tm1 = sessSend.createTextMessage("message1");
@@ -1090,14 +1000,13 @@
prod.send(tm2);
-
xaConn = cf.createXAConnection();
XASession xaSession = xaConn.createXASession();
xaConn.start();
- MessageConsumer cons = xaSession.createConsumer(queue);
+ MessageConsumer cons = xaSession.createConsumer(queue1);
//Now we enlist the session in an xa transaction
@@ -1112,12 +1021,10 @@
//Then we do a rollback
tm.rollback();
-
tm.begin();
//And enlist again - the work should then be converted into the global tx branch
-
// I have changed where this begin was originally set
// as when you don't have a resource enlisted, XASessions will act as
// non transacted + AutoAck
@@ -1176,7 +1083,6 @@
xaConn.close();
}
}
-
}
// See http://jira.jboss.org/jira/browse/JBMESSAGING-825
@@ -1207,7 +1113,7 @@
res1.start(trailing, XAResource.TMNOFLAGS);
- MessageProducer prod1 = sess1.createProducer(queue);
+ MessageProducer prod1 = sess1.createProducer(queue1);
TextMessage tm1 = sess1.createTextMessage("testing1");
@@ -1215,20 +1121,16 @@
res1.end(trailing, XAResource.TMSUCCESS);
-
res1.prepare(trailing);
-
//Now "crash" the server
ServerManagement.stopServerPeer();
ServerManagement.startServerPeer();
- ServerManagement.deployQueue("Queue");
+ deployAndLookupAdministeredObjects();
- cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
conn1.close();
conn1 = cf.createXAConnection();
@@ -1258,6 +1160,8 @@
}
finally
{
+ removeAllMessages(queue1.getQueueName(), true, 0);
+
if (conn1 != null)
{
try
@@ -1294,12 +1198,12 @@
tx.enlistResource(res);
tx.enlistResource(res2);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
Message m = sess.createTextMessage("XATest1");
- prod.send(queue, m);
+ prod.send(queue1, m);
m = sess.createTextMessage("XATest2");
- prod.send(queue, m);
+ prod.send(queue1, m);
tx.delistResource(res, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
@@ -1309,7 +1213,7 @@
conn2 = cf.createConnection();
conn2.start();
Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sessReceiver.createConsumer(queue);
+ MessageConsumer cons = sessReceiver.createConsumer(queue1);
TextMessage m2 = (TextMessage)cons.receive(1000);
assertNotNull(m2);
assertEquals("XATest1", m2.getText());
@@ -1328,7 +1232,6 @@
conn2.close();
}
}
-
}
@@ -1340,7 +1243,6 @@
try
{
-
conn = cf.createXAConnection();
tm.begin();
@@ -1357,12 +1259,12 @@
tx.enlistResource(res);
tx.enlistResource(res2);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
Message m = sess.createTextMessage("XATest1");
- prod.send(queue, m);
+ prod.send(queue1, m);
m = sess.createTextMessage("XATest2");
- prod.send(queue, m);
+ prod.send(queue1, m);
tx.delistResource(res, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
@@ -1372,7 +1274,7 @@
conn2 = cf.createConnection();
conn2.start();
Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sessReceiver.createConsumer(queue);
+ MessageConsumer cons = sessReceiver.createConsumer(queue1);
TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
assertNotNull(m2);
assertEquals("XATest1", m2.getText());
@@ -1391,7 +1293,6 @@
conn2.close();
}
}
-
}
@@ -1416,12 +1317,12 @@
tx.enlistResource(res);
tx.enlistResource(res2);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
Message m = sess.createTextMessage("XATest1");
- prod.send(queue, m);
+ prod.send(queue1, m);
m = sess.createTextMessage("XATest2");
- prod.send(queue, m);
+ prod.send(queue1, m);
tx.delistResource(res, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
@@ -1431,7 +1332,7 @@
conn2 = cf.createConnection();
conn2.start();
Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sessReceiver.createConsumer(queue);
+ MessageConsumer cons = sessReceiver.createConsumer(queue1);
Message m2 = cons.receive(MIN_TIMEOUT);
assertNull(m2);
@@ -1476,12 +1377,12 @@
tx.enlistResource(res3);
tx.enlistResource(res4);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
Message m = sess.createTextMessage("XATest1");
- prod.send(queue, m);
+ prod.send(queue1, m);
m = sess.createTextMessage("XATest2");
- prod.send(queue, m);
+ prod.send(queue1, m);
tx.delistResource(res, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
@@ -1502,10 +1403,9 @@
conn2 = cf.createConnection();
conn2.start();
Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sessReceiver.createConsumer(queue);
+ MessageConsumer cons = sessReceiver.createConsumer(queue1);
Message m2 = cons.receive(MIN_TIMEOUT);
assertNull(m2);
-
}
finally
{
@@ -1542,12 +1442,12 @@
tx.enlistResource(res);
tx.enlistResource(res2);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
Message m = sess.createTextMessage("XATest1");
- prod.send(queue, m);
+ prod.send(queue1, m);
m = sess.createTextMessage("XATest2");
- prod.send(queue, m);
+ prod.send(queue1, m);
tx.delistResource(res, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
@@ -1557,7 +1457,7 @@
conn2 = cf.createConnection();
conn2.start();
Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sessReceiver.createConsumer(queue);
+ MessageConsumer cons = sessReceiver.createConsumer(queue1);
Message m2 = cons.receive(MIN_TIMEOUT);
assertNull(m2);
@@ -1587,7 +1487,7 @@
conn2 = cf.createConnection();
conn2.start();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue);
+ MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("XATest1");
prod.send(m);
m = sessProducer.createTextMessage("XATest2");
@@ -1607,7 +1507,7 @@
tx.enlistResource(res);
tx.enlistResource(res2);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
@@ -1639,8 +1539,6 @@
tx.delistResource(res2, XAResource.TMSUCCESS);
tm.commit();
-
-
}
finally
{
@@ -1666,7 +1564,7 @@
conn2 = cf.createConnection();
conn2.start();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue);
+ MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("XATest1");
prod.send(m);
m = sessProducer.createTextMessage("XATest2");
@@ -1687,7 +1585,7 @@
tx.enlistResource(res);
tx.enlistResource(res2);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
@@ -1719,8 +1617,6 @@
tx.delistResource(res2, XAResource.TMSUCCESS);
tm.commit();
-
-
}
finally
{
@@ -1747,14 +1643,13 @@
{
conn2 = cf.createConnection();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue);
+ MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("XATest1");
prod.send(m);
m = sessProducer.createTextMessage("XATest2");
prod.send(m);
-
conn = cf.createXAConnection();
conn.start();
@@ -1769,7 +1664,7 @@
tx.enlistResource(res);
tx.enlistResource(res2);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
@@ -1805,7 +1700,6 @@
tx.delistResource(res2, XAResource.TMSUCCESS);
tm.commit();
-
}
finally
{
@@ -1818,7 +1712,6 @@
conn2.close();
}
}
-
}
public void test2PCReceiveRollback() throws Exception
@@ -1830,7 +1723,7 @@
{
conn2 = cf.createConnection();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue);
+ MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("XATest1");
prod.send(m);
@@ -1853,7 +1746,7 @@
tx.enlistResource(res);
tx.enlistResource(res2);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
@@ -1913,7 +1806,6 @@
try
{
-
conn = cf.createXAConnection();
tm.begin();
@@ -1926,12 +1818,12 @@
tx.enlistResource(res);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
Message m = sess.createTextMessage("XATest1");
- prod.send(queue, m);
+ prod.send(queue1, m);
m = sess.createTextMessage("XATest2");
- prod.send(queue, m);
+ prod.send(queue1, m);
tx.delistResource(res, XAResource.TMSUCCESS);
@@ -1940,7 +1832,7 @@
conn2 = cf.createConnection();
conn2.start();
Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sessReceiver.createConsumer(queue);
+ MessageConsumer cons = sessReceiver.createConsumer(queue1);
TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
assertNotNull(m2);
assertEquals("XATest1", m2.getText());
@@ -1979,12 +1871,12 @@
Transaction tx = tm.getTransaction();
tx.enlistResource(res);
- MessageProducer prod = sess.createProducer(queue);
+ MessageProducer prod = sess.createProducer(queue1);
prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
Message m = sess.createTextMessage("XATest1");
- prod.send(queue, m);
+ prod.send(queue1, m);
m = sess.createTextMessage("XATest2");
- prod.send(queue, m);
+ prod.send(queue1, m);
tx.delistResource(res, XAResource.TMSUCCESS);
@@ -1993,7 +1885,7 @@
conn2 = cf.createConnection();
conn2.start();
Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sessReceiver.createConsumer(queue);
+ MessageConsumer cons = sessReceiver.createConsumer(queue1);
Message m2 = cons.receive(MIN_TIMEOUT);
assertNull(m2);
@@ -2021,7 +1913,7 @@
conn2 = cf.createConnection();
conn2.start();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue);
+ MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("XATest1");
prod.send(m);
m = sessProducer.createTextMessage("XATest2");
@@ -2038,7 +1930,7 @@
Transaction tx = tm.getTransaction();
tx.enlistResource(res);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
@@ -2066,8 +1958,6 @@
tx.delistResource(res, XAResource.TMSUCCESS);
tm.commit();
-
-
}
finally
{
@@ -2092,7 +1982,7 @@
{
conn2 = cf.createConnection();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue);
+ MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("XATest1");
prod.send(m);
m = sessProducer.createTextMessage("XATest2");
@@ -2110,7 +2000,7 @@
Transaction tx = tm.getTransaction();
tx.enlistResource(res);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
@@ -2177,7 +2067,7 @@
//First send 2 messages
conn2 = cf.createConnection();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue);
+ MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("jellyfish1");
prod.send(m);
m = sessProducer.createTextMessage("jellyfish2");
@@ -2200,7 +2090,7 @@
tx.enlistResource(res2);
//Receive the messages, one on each consumer
- MessageConsumer cons1 = sess1.createConsumer(queue);
+ MessageConsumer cons1 = sess1.createConsumer(queue1);
TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
assertNotNull(r1);
@@ -2208,7 +2098,7 @@
cons1.close();
- MessageConsumer cons2 = sess2.createConsumer(queue);
+ MessageConsumer cons2 = sess2.createConsumer(queue1);
TextMessage r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
assertNotNull(r2);
@@ -2221,7 +2111,7 @@
tm.commit();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
conn2.start();
TextMessage r3 = (TextMessage)cons.receive(MIN_TIMEOUT);
@@ -2252,7 +2142,7 @@
//First send 2 messages
conn2 = cf.createConnection();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue);
+ MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("jellyfish1");
prod.send(m);
m = sessProducer.createTextMessage("jellyfish2");
@@ -2277,7 +2167,7 @@
tx.enlistResource(res2);
//Receive the messages, one on each consumer
- MessageConsumer cons1 = sess1.createConsumer(queue);
+ MessageConsumer cons1 = sess1.createConsumer(queue1);
TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
assertNotNull(r1);
@@ -2285,7 +2175,7 @@
cons1.close();
- MessageConsumer cons2 = sess2.createConsumer(queue);
+ MessageConsumer cons2 = sess2.createConsumer(queue1);
TextMessage r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
assertNotNull(r2);
@@ -2298,7 +2188,7 @@
tm.commit();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
conn2.start();
TextMessage r3 = (TextMessage)cons.receive(MIN_TIMEOUT);
@@ -2332,7 +2222,7 @@
//First send 2 messages
conn2 = cf.createConnection();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue);
+ MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("jellyfish1");
prod.send(m);
m = sessProducer.createTextMessage("jellyfish2");
@@ -2359,7 +2249,7 @@
tx.enlistResource(res2);
//Receive the messages, two on each consumer
- MessageConsumer cons1 = sess1.createConsumer(queue);
+ MessageConsumer cons1 = sess1.createConsumer(queue1);
TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
assertNotNull(r1);
@@ -2372,7 +2262,7 @@
cons1.close();
- MessageConsumer cons2 = sess2.createConsumer(queue);
+ MessageConsumer cons2 = sess2.createConsumer(queue1);
TextMessage r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
assertNotNull(r2);
@@ -2399,7 +2289,7 @@
//the sessions - this is implementation dependent
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
conn2.start();
TextMessage r = (TextMessage)cons.receive(MAX_TIMEOUT);
@@ -2492,7 +2382,7 @@
//First send 2 messages
conn2 = cf.createConnection();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue);
+ MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("jellyfish1");
prod.send(m);
m = sessProducer.createTextMessage("jellyfish2");
@@ -2521,7 +2411,7 @@
tx.enlistResource(res2);
//Receive the messages, two on each consumer
- MessageConsumer cons1 = sess1.createConsumer(queue);
+ MessageConsumer cons1 = sess1.createConsumer(queue1);
TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
assertNotNull(r1);
@@ -2537,7 +2427,7 @@
//Cancel is asynch
Thread.sleep(500);
- MessageConsumer cons2 = sess2.createConsumer(queue);
+ MessageConsumer cons2 = sess2.createConsumer(queue1);
TextMessage r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
assertNotNull(r2);
@@ -2565,7 +2455,7 @@
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
conn2.start();
TextMessage r = (TextMessage)cons.receive(MAX_TIMEOUT);
@@ -2632,8 +2522,6 @@
r = (TextMessage)cons.receive(MIN_TIMEOUT);
assertNull(r);
-
-
}
finally
{
@@ -2646,7 +2534,6 @@
conn2.close();
}
}
-
}
public void testMultipleSessionsOneTxRollbackAcknowledgeForceFailureInCommit() throws Exception
@@ -2659,7 +2546,7 @@
//First send 4 messages
conn2 = cf.createConnection();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue);
+ MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("jellyfish1");
prod.send(m);
@@ -2684,7 +2571,7 @@
tx.enlistResource(res1);
tx.enlistResource(res2);
- MessageConsumer cons1 = sess1.createConsumer(queue);
+ MessageConsumer cons1 = sess1.createConsumer(queue1);
TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
assertNotNull(r1);
@@ -2736,7 +2623,7 @@
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
conn2.start();
TextMessage r = (TextMessage)cons.receive(MAX_TIMEOUT);
@@ -2808,8 +2695,8 @@
// Send 2 messages - one from each session
- MessageProducer prod1 = sess1.createProducer(queue);
- MessageProducer prod2 = sess2.createProducer(queue);
+ MessageProducer prod1 = sess1.createProducer(queue1);
+ MessageProducer prod2 = sess2.createProducer(queue1);
prod1.send(sess1.createTextMessage("echidna1"));
prod2.send(sess2.createTextMessage("echidna2"));
@@ -2824,7 +2711,7 @@
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
conn2.start();
TextMessage r1 = (TextMessage)cons.receive(MAX_TIMEOUT);
@@ -2846,9 +2733,7 @@
{
conn2.close();
}
-
}
-
}
public void testMultipleSessionsOneTxCommitSend() throws Exception
@@ -2881,8 +2766,8 @@
// Send 2 messages - one from each session
- MessageProducer prod1 = sess1.createProducer(queue);
- MessageProducer prod2 = sess2.createProducer(queue);
+ MessageProducer prod1 = sess1.createProducer(queue1);
+ MessageProducer prod2 = sess2.createProducer(queue1);
prod1.send(sess1.createTextMessage("echidna1"));
prod2.send(sess2.createTextMessage("echidna2"));
@@ -2897,7 +2782,7 @@
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
conn2.start();
TextMessage r1 = (TextMessage)cons.receive(MAX_TIMEOUT);
@@ -2935,7 +2820,6 @@
try
{
-
conn = cf.createXAConnection();
conn.start();
@@ -2953,8 +2837,8 @@
// Send 2 messages - one from each session
- MessageProducer prod1 = sess1.createProducer(queue);
- MessageProducer prod2 = sess2.createProducer(queue);
+ MessageProducer prod1 = sess1.createProducer(queue1);
+ MessageProducer prod2 = sess2.createProducer(queue1);
prod1.send(sess1.createTextMessage("echidna1"));
prod2.send(sess2.createTextMessage("echidna2"));
@@ -2969,13 +2853,12 @@
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
conn2.start();
TextMessage r1 = (TextMessage)cons.receive(MIN_TIMEOUT);
assertNull(r1);
-
}
finally
{
@@ -2987,9 +2870,7 @@
{
conn2.close();
}
-
}
-
}
public void testMultipleSessionsOneTxRollbackSend() throws Exception
@@ -3020,8 +2901,8 @@
// Send 2 messages - one from each session
- MessageProducer prod1 = sess1.createProducer(queue);
- MessageProducer prod2 = sess2.createProducer(queue);
+ MessageProducer prod1 = sess1.createProducer(queue1);
+ MessageProducer prod2 = sess2.createProducer(queue1);
prod1.send(sess1.createTextMessage("echidna1"));
prod2.send(sess2.createTextMessage("echidna2"));
@@ -3036,13 +2917,11 @@
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
conn2.start();
TextMessage r1 = (TextMessage)cons.receive(MIN_TIMEOUT);
assertNull(r1);
-
-
}
finally
{
@@ -3054,9 +2933,7 @@
{
conn2.close();
}
-
}
-
}
@@ -3071,7 +2948,7 @@
//First send 2 messages
conn2 = cf.createConnection();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue);
+ MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("jellyfish1");
prod.send(m);
m = sessProducer.createTextMessage("jellyfish2");
@@ -3084,7 +2961,7 @@
XAResource res1 = sess1.getXAResource();
conn.start();
- MessageConsumer cons1 = sess1.createConsumer(queue);
+ MessageConsumer cons1 = sess1.createConsumer(queue1);
tm.begin();
@@ -3119,7 +2996,7 @@
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn2.start();
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
TextMessage r3 = (TextMessage)cons.receive(MIN_TIMEOUT);
assertNull(r3);
@@ -3129,8 +3006,6 @@
tx1.delistResource(res1, XAResource.TMSUCCESS);
tm.commit();
-
-
}
finally
{
@@ -3142,9 +3017,7 @@
{
conn2.close();
}
-
}
-
}
@@ -3159,7 +3032,7 @@
//First send 2 messages
conn2 = cf.createConnection();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue);
+ MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("jellyfish1");
prod.send(m);
m = sessProducer.createTextMessage("jellyfish2");
@@ -3172,7 +3045,7 @@
XAResource res1 = sess1.getXAResource();
conn.start();
- MessageConsumer cons1 = sess1.createConsumer(queue);
+ MessageConsumer cons1 = sess1.createConsumer(queue1);
tm.begin();
@@ -3209,7 +3082,7 @@
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn2.start();
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
TextMessage r3 = (TextMessage)cons.receive(MAX_TIMEOUT);
@@ -3255,14 +3128,13 @@
try
{
-
conn = cf.createXAConnection();
//Create a session
XASession sess1 = conn.createXASession();
XAResource res1 = sess1.getXAResource();
- MessageProducer prod1 = sess1.createProducer(queue);
+ MessageProducer prod1 = sess1.createProducer(queue1);
tm.begin();
@@ -3293,7 +3165,7 @@
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn2.start();
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
TextMessage r1 = (TextMessage)cons.receive(MAX_TIMEOUT);
assertNotNull(r1);
assertEquals("kangaroo2", r1.getText());
@@ -3344,7 +3216,7 @@
XASession sess1 = conn.createXASession();
XAResource res1 = sess1.getXAResource();
- MessageProducer prod1 = sess1.createProducer(queue);
+ MessageProducer prod1 = sess1.createProducer(queue1);
tm.begin();
@@ -3375,7 +3247,7 @@
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn2.start();
- MessageConsumer cons = sess.createConsumer(queue);
+ MessageConsumer cons = sess.createConsumer(queue1);
TextMessage r1 = (TextMessage)cons.receive(MIN_TIMEOUT);
assertNull(r1);
@@ -3409,6 +3281,8 @@
}
+
+ //FIXME - this test doesn't belong here - should be in SecurityTest
/**
* This Validate sending messages on an Queue where the user don't have write authorization
* @throws Exception
@@ -3432,12 +3306,10 @@
XAResource resouce = xasession.getXAResource();
- MessageProducer producer = xasession.createProducer(queue);
+ MessageProducer producer = xasession.createProducer(queue1);
trans.enlistResource(resouce);
-
-
for (int i=0;i<10;i++)
{
producer.send(xasession.createTextMessage("Test " + i));
Modified: trunk/tests/src/org/jboss/test/messaging/jms/bridge/BridgeTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/bridge/BridgeTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/bridge/BridgeTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -73,8 +73,7 @@
{
super.tearDown();
}
-
-
+
// MaxBatchSize but no MaxBatchTime
public void testNoMaxBatchTime_AtMostOnce_P() throws Exception
Modified: trunk/tests/src/org/jboss/test/messaging/jms/clustering/DistributedRequestResponseTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/clustering/DistributedRequestResponseTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/clustering/DistributedRequestResponseTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -33,10 +33,8 @@
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
-import javax.management.ObjectName;
import javax.naming.InitialContext;
-import org.jboss.jms.client.JBossConnection;
import org.jboss.test.messaging.MessagingTestCase;
import org.jboss.test.messaging.tools.ServerManagement;
@@ -246,13 +244,6 @@
}
}
- private void removeAllMessages(String destName, boolean isQueue, int server) throws Exception
- {
- String on = "jboss.messaging.destination:service=" + (isQueue ? "Queue" : "Topic") + ",name=" + destName;
-
- ServerManagement.getServer(server).invoke(new ObjectName(on), "removeAllMessages", null, null);
- }
-
// Inner classes --------------------------------------------------------------------------------
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/ExpiredMessageTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/ExpiredMessageTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/ExpiredMessageTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -7,24 +7,20 @@
package org.jboss.test.messaging.jms.message;
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
-import javax.jms.Queue;
import javax.jms.Session;
-import javax.naming.InitialContext;
import org.jboss.logging.Logger;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
+import org.jboss.test.messaging.jms.JMSTestCase;
/**
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
* @version <tt>$Revision$</tt>
* $Id$
*/
-public class ExpiredMessageTest extends MessagingTestCase
+public class ExpiredMessageTest extends JMSTestCase
{
// Constants ------------------------------------------------------------------------------------
@@ -34,10 +30,6 @@
// Attributes -----------------------------------------------------------------------------------
- private InitialContext ic;
- private ConnectionFactory cf;
- private Queue queue;
-
// Constructors ---------------------------------------------------------------------------------
public ExpiredMessageTest(String name)
@@ -53,7 +45,7 @@
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = session.createProducer(queue);
+ MessageProducer prod = session.createProducer(queue1);
prod.setTimeToLive(1);
Message m = session.createTextMessage("This message will die");
@@ -64,11 +56,11 @@
Thread.sleep(250);
- MessageConsumer cons = session.createConsumer(queue);
+ MessageConsumer cons = session.createConsumer(queue1);
conn.start();
- assertNull(cons.receive(3000));
+ assertNull(cons.receive(2000));
conn.close();
}
@@ -79,7 +71,7 @@
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = session.createProducer(queue);
+ MessageProducer prod = session.createProducer(queue1);
prod.setTimeToLive(1);
Message m = session.createTextMessage("This message will die");
@@ -91,12 +83,10 @@
prod.send(m);
}
- MessageConsumer cons = session.createConsumer(queue);
+ MessageConsumer cons = session.createConsumer(queue1);
conn.start();
- final int TIMEOUT = 2000;
-
- assertNull(cons.receive(TIMEOUT));
+ assertNull(cons.receive(2000));
conn.close();
}
@@ -106,37 +96,7 @@
// Package protected ----------------------------------------------------------------------------
// Protected ------------------------------------------------------------------------------------
-
- protected void setUp() throws Exception
- {
- super.setUp();
-
- ServerManagement.start("all");
-
- ic = new InitialContext(ServerManagement.getJNDIEnvironment());
-
- ServerManagement.deployQueue("expiredMessageTestQueue");
- ServerManagement.deployQueue("ExpiryQueue");
-
- cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
-
- queue = (Queue)ic.lookup("/queue/expiredMessageTestQueue");
-
- log.debug("setup done");
- }
-
- protected void tearDown() throws Exception
- {
- ServerManagement.undeployQueue("expiredMessageTestQueue");
- ServerManagement.undeployQueue("ExpiryQueue");
-
- ic.close();
-
- ServerManagement.stop();
-
- super.tearDown();
- }
-
+
// Private --------------------------------------------------------------------------------------
// Inner classes --------------------------------------------------------------------------------
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/JMSCorrelationIDHeaderTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/JMSCorrelationIDHeaderTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/JMSCorrelationIDHeaderTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -29,7 +29,7 @@
*
* $Id$
*/
-public class JMSCorrelationIDHeaderTest extends MessageTest
+public class JMSCorrelationIDHeaderTest extends MessageHeaderTestBase
{
// Constants -----------------------------------------------------
@@ -46,17 +46,6 @@
// Public --------------------------------------------------------
- public void setUp() throws Exception
- {
- super.setUp();
- }
-
- public void tearDown() throws Exception
- {
- super.tearDown();
- }
-
-
public void testJMSDestination() throws Exception
{
Message m1 = queueProducerSession.createMessage();
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/JMSDeliveryModeHeaderTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/JMSDeliveryModeHeaderTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/JMSDeliveryModeHeaderTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -28,7 +28,7 @@
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
* @version <tt>$Revision$</tt>
*/
-public class JMSDeliveryModeHeaderTest extends MessageTest
+public class JMSDeliveryModeHeaderTest extends MessageHeaderTestBase
{
// Constants -----------------------------------------------------
@@ -45,16 +45,6 @@
// Public --------------------------------------------------------
- public void setUp() throws Exception
- {
- super.setUp();
- }
-
- public void tearDown() throws Exception
- {
- super.tearDown();
- }
-
public void testDefaultDeliveryMode() throws Exception
{
assertEquals(DeliveryMode.PERSISTENT, queueProducer.getDeliveryMode());
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/JMSDestinationHeaderTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/JMSDestinationHeaderTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/JMSDestinationHeaderTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -27,7 +27,7 @@
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
* @version <tt>$Revision$</tt>
*/
-public class JMSDestinationHeaderTest extends MessageTest
+public class JMSDestinationHeaderTest extends MessageHeaderTestBase
{
// Constants -----------------------------------------------------
@@ -44,26 +44,13 @@
// Public --------------------------------------------------------
- public void setUp() throws Exception
- {
- super.setUp();
- }
-
- public void tearDown() throws Exception
- {
- super.tearDown();
- }
-
-
public void testJMSDestination() throws Exception
{
queueProducer.send(queueProducerSession.createMessage());
Message m = queueConsumer.receive();
- assertEquals(queue, m.getJMSDestination());
+ assertEquals(queue1, m.getJMSDestination());
}
-
-
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
@@ -71,5 +58,4 @@
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
-
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/JMSExpirationHeaderTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/JMSExpirationHeaderTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/JMSExpirationHeaderTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -21,16 +21,11 @@
*/
package org.jboss.test.messaging.jms.message;
-
-import java.util.List;
-
-import javax.jms.Message;
import javax.jms.DeliveryMode;
-import javax.management.ObjectName;
+import javax.jms.Message;
import org.jboss.jms.message.JBossMessage;
import org.jboss.jms.message.MessageProxy;
-import org.jboss.test.messaging.tools.ServerManagement;
import EDU.oswego.cs.dl.util.concurrent.Latch;
@@ -41,7 +36,7 @@
*
* $Id$
*/
-public class JMSExpirationHeaderTest extends MessageTest
+public class JMSExpirationHeaderTest extends MessageHeaderTestBase
{
// Constants -----------------------------------------------------
@@ -325,17 +320,7 @@
//Need to check message isn't still in queue
- ObjectName destObjectName =
- new ObjectName("jboss.messaging.destination:service=Queue,name=Queue");
-
- List list = (List)ServerManagement.invoke(
- destObjectName,
- "listAllMessages",
- new Object[] {null},
- new String[] {"java.lang.String"});
- assertNotNull(list);
-
- assertEquals(0, list.size());
+ checkEmpty(queue1);
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/JMSMessageIDHeaderTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/JMSMessageIDHeaderTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/JMSMessageIDHeaderTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -27,7 +27,7 @@
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
* @version <tt>$Revision$</tt>
*/
-public class JMSMessageIDHeaderTest extends MessageTest
+public class JMSMessageIDHeaderTest extends MessageHeaderTestBase
{
// Constants -----------------------------------------------------
@@ -44,16 +44,6 @@
// Public --------------------------------------------------------
- public void setUp() throws Exception
- {
- super.setUp();
- }
-
- public void tearDown() throws Exception
- {
- super.tearDown();
- }
-
public void testJMSMessageIDPrefix() throws Exception
{
Message m = queueProducerSession.createMessage();
@@ -70,5 +60,4 @@
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
-
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/JMSPriorityHeaderTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/JMSPriorityHeaderTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/JMSPriorityHeaderTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -25,14 +25,10 @@
import javax.jms.DeliveryMode;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
-import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
-import javax.naming.InitialContext;
-import org.jboss.jms.client.JBossConnectionFactory;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
+import org.jboss.test.messaging.jms.JMSTestCase;
/**
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
@@ -40,7 +36,7 @@
*
* $Id$
*/
-public class JMSPriorityHeaderTest extends MessagingTestCase
+public class JMSPriorityHeaderTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -48,9 +44,6 @@
// Attributes ----------------------------------------------------
- protected JBossConnectionFactory cf;
- protected Queue queue;
-
// Constructors --------------------------------------------------
public JMSPriorityHeaderTest(String name)
@@ -60,28 +53,7 @@
// Public --------------------------------------------------------
- public void setUp() throws Exception
- {
- super.setUp();
- ServerManagement.start("all");
-
-
- InitialContext initialContext = new InitialContext(ServerManagement.getJNDIEnvironment());
- cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
- ServerManagement.undeployQueue("Queue");
-
- ServerManagement.deployQueue("Queue");
- queue = (Queue)initialContext.lookup("/queue/Queue");
-
- }
- public void tearDown() throws Exception
- {
- super.tearDown();
- }
-
-
/*
* Note - this test is testing our current implementation of message ordering since the spec
* does not mandate that all higher priority messages are delivered first - this
@@ -95,7 +67,7 @@
Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessSend.createProducer(queue);
+ MessageProducer prod = sessSend.createProducer(queue1);
TextMessage m0 = sessSend.createTextMessage("a");
TextMessage m1 = sessSend.createTextMessage("b");
@@ -122,7 +94,7 @@
Session sessReceive = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sessReceive.createConsumer(queue);
+ MessageConsumer cons = sessReceive.createConsumer(queue1);
{
TextMessage t = (TextMessage)cons.receive(1000);
@@ -192,7 +164,7 @@
prod.send(m8, DeliveryMode.NON_PERSISTENT, 5, 0);
prod.send(m9, DeliveryMode.NON_PERSISTENT, 6, 0);
- cons = sessReceive.createConsumer(queue);
+ cons = sessReceive.createConsumer(queue1);
{
TextMessage t = (TextMessage)cons.receive(1000);
@@ -268,7 +240,7 @@
Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessSend.createProducer(queue);
+ MessageProducer prod = sessSend.createProducer(queue1);
TextMessage m0 = sessSend.createTextMessage("a");
TextMessage m1 = sessSend.createTextMessage("b");
@@ -283,7 +255,7 @@
Session sessReceive = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sessReceive.createConsumer(queue);
+ MessageConsumer cons = sessReceive.createConsumer(queue1);
prod.send(m0, DeliveryMode.NON_PERSISTENT, 0, 0);
@@ -359,7 +331,7 @@
cons.close();
- cons = sessReceive.createConsumer(queue);
+ cons = sessReceive.createConsumer(queue1);
prod.send(m0, DeliveryMode.NON_PERSISTENT, 0, 0);
prod.send(m1, DeliveryMode.NON_PERSISTENT, 0, 0);
@@ -441,7 +413,7 @@
Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessSend.createProducer(queue);
+ MessageProducer prod = sessSend.createProducer(queue1);
TextMessage m0 = sessSend.createTextMessage("a");
@@ -449,7 +421,7 @@
Session sessReceive = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sessReceive.createConsumer(queue);
+ MessageConsumer cons = sessReceive.createConsumer(queue1);
{
TextMessage t = (TextMessage)cons.receive(1000);
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/JMSReplyToHeaderTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/JMSReplyToHeaderTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/JMSReplyToHeaderTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -34,7 +34,7 @@
* $Id$
*
*/
-public class JMSReplyToHeaderTest extends MessageTest
+public class JMSReplyToHeaderTest extends MessageHeaderTestBase
{
// Constants -----------------------------------------------------
@@ -51,17 +51,7 @@
// Public --------------------------------------------------------
- public void setUp() throws Exception
- {
- super.setUp();
- }
- public void tearDown() throws Exception
- {
- super.tearDown();
- }
-
-
public void testJMSDestinationSimple() throws Exception
{
Message m = queueProducerSession.createMessage();
@@ -83,11 +73,6 @@
assertNull(m.getJMSReplyTo());
}
-
-
-
-
-
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/JMSTimestampHeaderTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/JMSTimestampHeaderTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/JMSTimestampHeaderTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -27,7 +27,7 @@
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
* @version <tt>$Revision$</tt>
*/
-public class JMSTimestampHeaderTest extends MessageTest
+public class JMSTimestampHeaderTest extends MessageHeaderTestBase
{
// Constants -----------------------------------------------------
@@ -44,16 +44,6 @@
// Public --------------------------------------------------------
- public void setUp() throws Exception
- {
- super.setUp();
- }
-
- public void tearDown() throws Exception
- {
- super.tearDown();
- }
-
public void testJMSTimestamp() throws Exception
{
Message m = queueProducerSession.createMessage();
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/JMSTypeHeaderTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/JMSTypeHeaderTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/JMSTypeHeaderTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -27,7 +27,7 @@
* @author <a href="mailto:dua_rajdeep at yahoo.com">Rajdeep Dua</a>
* @version <tt>$Revision$</tt>
*/
-public class JMSTypeHeaderTest extends MessageTest
+public class JMSTypeHeaderTest extends MessageHeaderTestBase
{
// Constants -----------------------------------------------------
@@ -44,16 +44,6 @@
// Public --------------------------------------------------------
- public void setUp() throws Exception
- {
- super.setUp();
- }
-
- public void tearDown() throws Exception
- {
- super.tearDown();
- }
-
public void testJMSType() throws Exception
{
Message m = queueProducerSession.createMessage();
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/JMSXDeliveryCountTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/JMSXDeliveryCountTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/JMSXDeliveryCountTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -26,22 +26,18 @@
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
-import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
-import javax.jms.Topic;
import javax.jms.XAConnection;
import javax.jms.XAConnectionFactory;
import javax.jms.XASession;
-import javax.naming.InitialContext;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import javax.transaction.xa.XAException;
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
-import org.jboss.jms.client.JBossConnectionFactory;
-import org.jboss.test.messaging.MessagingTestCase;
+import org.jboss.test.messaging.jms.JMSTestCase;
import org.jboss.test.messaging.tools.ServerManagement;
import org.jboss.test.messaging.tools.jmx.ServiceContainer;
import org.jboss.tm.TransactionManagerLocator;
@@ -56,7 +52,7 @@
* $Id$
*
*/
-public class JMSXDeliveryCountTest extends MessagingTestCase
+public class JMSXDeliveryCountTest extends JMSTestCase
{
// Constants ------------------------------------------------------------------------------------
@@ -64,10 +60,6 @@
// Attributes -----------------------------------------------------------------------------------
- protected JBossConnectionFactory cf;
- protected Queue queue;
- protected Topic topic;
-
protected ServiceContainer sc;
// Constructors ---------------------------------------------------------------------------------
@@ -82,24 +74,7 @@
public void setUp() throws Exception
{
super.setUp();
- ServerManagement.start("all");
-
-
- InitialContext initialContext = new InitialContext(ServerManagement.getJNDIEnvironment());
- cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
- ServerManagement.undeployQueue("Queue");
- ServerManagement.deployQueue("Queue");
-
- ServerManagement.undeployTopic("Topic");
- ServerManagement.deployTopic("Topic");
-
- queue = (Queue)initialContext.lookup("/queue/Queue");
-
- this.drainDestination(cf, queue);
-
- topic = (Topic)initialContext.lookup("/topic/Topic");
-
+
if (ServerManagement.isRemote())
{
// We need to start a service container otherwise transaction manager jndi lookup
@@ -122,129 +97,174 @@
public void testSimpleJMSXDeliveryCount() throws Exception
{
- Connection conn = cf.createConnection();
- Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = s.createProducer(queue);
- p.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-
- p.send(s.createTextMessage("xoxo"));
-
- s.close();
-
- s = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageConsumer c = s.createConsumer(queue);
-
- conn.start();
-
- TextMessage tm = (TextMessage)c.receive(1000);
-
- assertEquals("xoxo", tm.getText());
- assertEquals(1, tm.getIntProperty("JMSXDeliveryCount"));
-
- s.recover();
-
- tm = (TextMessage)c.receive(1000);
-
- assertEquals("xoxo", tm.getText());
- assertEquals(2, tm.getIntProperty("JMSXDeliveryCount"));
-
- conn.close();
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+ Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer p = s.createProducer(queue1);
+ p.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ p.send(s.createTextMessage("xoxo"));
+
+ s.close();
+
+ s = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+ MessageConsumer c = s.createConsumer(queue1);
+
+ conn.start();
+
+ TextMessage tm = (TextMessage)c.receive(1000);
+
+ assertEquals("xoxo", tm.getText());
+ assertEquals(1, tm.getIntProperty("JMSXDeliveryCount"));
+
+ s.recover();
+
+ tm = (TextMessage)c.receive(1000);
+
+ assertEquals("xoxo", tm.getText());
+ assertEquals(2, tm.getIntProperty("JMSXDeliveryCount"));
+
+ tm.acknowledge();
+
+ conn.close();
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void testRedeliveryOnQueue() throws Exception
{
- Connection conn = cf.createConnection();
+ Connection conn = null;
- Session sess1 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageProducer prod = sess1.createProducer(queue);
-
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-
- final int NUM_MESSAGES = 1000;
-
- final int NUM_RECOVERIES = 8;
-
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- TextMessage tm = sess1.createTextMessage();
- tm.setText("testing" + i);
- prod.send(tm);
- }
-
- Session sess2 = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
-
- MessageConsumer cons = sess2.createConsumer(queue);
-
- conn.start();
-
- for (int j = 0; j < NUM_RECOVERIES; j++)
+ try
{
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- TextMessage tm = (TextMessage)cons.receive(3000);
- assertNotNull(tm);
- assertEquals("testing" + i, tm.getText());
- assertEquals(j + 1, tm.getIntProperty("JMSXDeliveryCount"));
- }
- sess2.recover();
+ conn = cf.createConnection();
+
+ Session sess1 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = sess1.createProducer(queue1);
+
+ prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ final int NUM_MESSAGES = 100;
+
+ final int NUM_RECOVERIES = 8;
+
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ TextMessage tm = sess1.createTextMessage();
+ tm.setText("testing" + i);
+ prod.send(tm);
+ }
+
+ Session sess2 = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+
+ MessageConsumer cons = sess2.createConsumer(queue1);
+
+ conn.start();
+
+ TextMessage tm = null;
+
+ for (int j = 0; j < NUM_RECOVERIES; j++)
+ {
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ tm = (TextMessage)cons.receive(3000);
+ assertNotNull(tm);
+ assertEquals("testing" + i, tm.getText());
+ assertEquals(j + 1, tm.getIntProperty("JMSXDeliveryCount"));
+ }
+ if (j != NUM_RECOVERIES -1)
+ {
+ sess2.recover();
+ }
+ }
+
+ tm.acknowledge();
}
-
- conn.close();
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void testRedeliveryOnTopic() throws Exception
{
- Connection conn = cf.createConnection();
+ Connection conn = null;
- conn.setClientID("myclientid");
-
- Session sess1 = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- Session sess2 = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- Session sess3 = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
-
- MessageConsumer cons1 = sess1.createConsumer(topic);
- MessageConsumer cons2 = sess2.createConsumer(topic);
- MessageConsumer cons3 = sess3.createDurableSubscriber(topic, "subxyz");
-
- conn.start();
-
- final int NUM_MESSAGES = 300;
- final int NUM_RECOVERIES = 9;
-
- Receiver r1 = new Receiver("R1", sess1, cons1, NUM_MESSAGES, NUM_RECOVERIES);
- Receiver r2 = new Receiver("R2", sess2, cons2, NUM_MESSAGES, NUM_RECOVERIES);
- Receiver r3 = new Receiver("R3", sess3, cons3, NUM_MESSAGES, NUM_RECOVERIES);
-
- Thread t1 = new Thread(r1);
- Thread t2 = new Thread(r2);
- Thread t3 = new Thread(r3);
-
- t1.start();
- t2.start();
- t3.start();
-
- Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessSend.createProducer(topic);
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-
-
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- TextMessage tm1 = sessSend.createTextMessage("testing" + i);
- prod.send(tm1);
+ try
+ {
+ conn = cf.createConnection();
+
+ conn.setClientID("myclientid");
+
+ Session sess1 = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+ Session sess2 = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+ Session sess3 = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+
+ MessageConsumer cons1 = sess1.createConsumer(topic1);
+ MessageConsumer cons2 = sess2.createConsumer(topic1);
+ MessageConsumer cons3 = sess3.createDurableSubscriber(topic1, "subxyz");
+
+ conn.start();
+
+ final int NUM_MESSAGES = 100;
+ final int NUM_RECOVERIES = 9;
+
+ Receiver r1 = new Receiver("R1", sess1, cons1, NUM_MESSAGES, NUM_RECOVERIES);
+ Receiver r2 = new Receiver("R2", sess2, cons2, NUM_MESSAGES, NUM_RECOVERIES);
+ Receiver r3 = new Receiver("R3", sess3, cons3, NUM_MESSAGES, NUM_RECOVERIES);
+
+ Thread t1 = new Thread(r1);
+ Thread t2 = new Thread(r2);
+ Thread t3 = new Thread(r3);
+
+ t1.start();
+ t2.start();
+ t3.start();
+
+ Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer prod = sessSend.createProducer(topic1);
+ prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ TextMessage tm1 = sessSend.createTextMessage("testing" + i);
+ prod.send(tm1);
+ }
+
+ t1.join();
+ t2.join();
+ t3.join();
+
+ assertFalse(r1.failed);
+ assertFalse(r2.failed);
+ assertFalse(r3.failed);
+
+ cons3.close();
+
+ sess3.unsubscribe("subxyz");
}
-
- t1.join();
- t2.join();
- t3.join();
-
- assertFalse(r1.failed);
- assertFalse(r2.failed);
- assertFalse(r3.failed);
-
- conn.close();
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void testDeliveryCountUpdatedOnCloseTransacted() throws Exception
@@ -256,10 +276,10 @@
conn = cf.createConnection();
Session producerSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer producer = producerSess.createProducer(queue);
+ MessageProducer producer = producerSess.createProducer(queue1);
Session consumerSess = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageConsumer consumer = consumerSess.createConsumer(queue);
+ MessageConsumer consumer = consumerSess.createConsumer(queue1);
conn.start();
TextMessage tm = producerSess.createTextMessage("message1");
@@ -308,7 +328,7 @@
consumerSess = conn.createSession(true, Session.SESSION_TRANSACTED);
- consumer = consumerSess.createConsumer(queue);
+ consumer = consumerSess.createConsumer(queue1);
rm = (TextMessage)consumer.receive(1000);
@@ -320,6 +340,7 @@
assertTrue(rm.getJMSRedelivered());
+ consumerSess.commit();
}
finally
{
@@ -339,10 +360,10 @@
conn = cf.createConnection();
Session producerSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer producer = producerSess.createProducer(queue);
+ MessageProducer producer = producerSess.createProducer(queue1);
Session consumerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- MessageConsumer consumer = consumerSess.createConsumer(queue);
+ MessageConsumer consumer = consumerSess.createConsumer(queue1);
conn.start();
TextMessage tm = producerSess.createTextMessage("message1");
@@ -389,7 +410,7 @@
consumerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- consumer = consumerSess.createConsumer(queue);
+ consumer = consumerSess.createConsumer(queue1);
rm = (TextMessage)consumer.receive(1000);
@@ -401,6 +422,7 @@
assertTrue(rm.getJMSRedelivered());
+ rm.acknowledge();
}
finally
{
@@ -418,7 +440,7 @@
Connection conn = null;
TransactionManager mgr = TransactionManagerLocator.getInstance().locate();
-
+
Transaction toResume = null;
Transaction tx = null;
@@ -432,18 +454,16 @@
//Send a message
Session producerSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer producer = producerSess.createProducer(queue);
+ MessageProducer producer = producerSess.createProducer(queue1);
TextMessage tm = producerSess.createTextMessage("message1");
producer.send(tm);
-
-
-
+
xaConn = ((XAConnectionFactory)cf).createXAConnection();
XASession consumerSess = xaConn.createXASession();
- MessageConsumer consumer = consumerSess.createConsumer(queue);
+ MessageConsumer consumer = consumerSess.createConsumer(queue1);
xaConn.start();
DummyXAResource res = new DummyXAResource();
@@ -519,9 +539,7 @@
tx.delistResource(consumerSess.getXAResource(), XAResource.TMSUCCESS);
tx.rollback();
-
- log.info("Closing the consumer");
-
+
//Must close consumer first
consumer.close();
@@ -530,7 +548,7 @@
consumerSess = xaConn.createXASession();
- consumer = consumerSess.createConsumer(queue);
+ consumer = consumerSess.createConsumer(queue1);
mgr.begin();
@@ -552,33 +570,31 @@
tx.delistResource(res, XAResource.TMSUCCESS);
- tx.delistResource(consumerSess.getXAResource(), XAResource.TMSUCCESS);
-
+ tx.delistResource(consumerSess.getXAResource(), XAResource.TMSUCCESS);
}
finally
{
if (conn != null)
{
- try
- {
- conn.close();
- }
- catch (Exception ignore)
- {
- }
+ conn.close();
}
if (tx != null)
{
- try
- {
- tx.commit();
- }
- catch (Exception ignore)
- {
- }
+ try
+ {
+ tx.commit();
+ }
+ catch (Exception ignore)
+ {
+ }
}
+ if (xaConn != null)
+ {
+ xaConn.close();
+ }
+
if (toResume != null)
{
try
@@ -589,13 +605,13 @@
{
}
}
+
+ // ***********************
+ // * REMOVE THIS WHEN ABOVE TEST PASSES
+ removeAllMessages(queue1.getQueueName(), true, 0);
}
}
-
-
-
-
class Receiver implements Runnable
{
MessageConsumer cons;
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/MapMessageTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/MapMessageTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/MapMessageTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -61,6 +61,7 @@
public void tearDown() throws Exception
{
message = null;
+
super.tearDown();
}
@@ -72,10 +73,14 @@
queueProd.send(m);
- conn.start();
+ MapMessage rm = (MapMessage)queueCons.receive(2000);
+
+ log.info("Got rm:" + rm);
+
+ assertNotNull(rm);
+
+ log.info("String is " + rm.getString("nullValue"));
- MapMessage rm = (MapMessage)queueCons.receive();
-
assertNull(rm.getString("nullValue"));
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/MessageBodyTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/MessageBodyTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/MessageBodyTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -27,10 +27,7 @@
import javax.jms.BytesMessage;
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.Destination;
import javax.jms.MapMessage;
-import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageEOFException;
import javax.jms.MessageFormatException;
@@ -41,10 +38,8 @@
import javax.jms.Session;
import javax.jms.StreamMessage;
import javax.jms.TextMessage;
-import javax.naming.InitialContext;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
+import org.jboss.test.messaging.jms.JMSTestCase;
/**
*
@@ -56,7 +51,7 @@
* $Id$
*
*/
-public class MessageBodyTest extends MessagingTestCase
+public class MessageBodyTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -64,8 +59,6 @@
// Attributes ----------------------------------------------------
- protected Destination queue;
-
protected Connection producerConnection, consumerConnection;
protected Session queueProducerSession, queueConsumerSession;
@@ -86,47 +79,25 @@
public void setUp() throws Exception
{
super.setUp();
-
- ServerManagement.start("all");
-
-
- ServerManagement.undeployQueue("Queue");
- ServerManagement.deployQueue("Queue");
-
- InitialContext ic = new InitialContext(ServerManagement.getJNDIEnvironment());
- ConnectionFactory cf = (ConnectionFactory) ic.lookup("/ConnectionFactory");
- queue = (Destination) ic.lookup("/queue/Queue");
-
+
producerConnection = cf.createConnection();
consumerConnection = cf.createConnection();
queueProducerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
queueConsumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- queueProducer = queueProducerSession.createProducer(queue);
- queueConsumer = queueConsumerSession.createConsumer(queue);
+ queueProducer = queueProducerSession.createProducer(queue1);
+ queueConsumer = queueConsumerSession.createConsumer(queue1);
consumerConnection.start();
}
public void tearDown() throws Exception
{
- // TODO uncomment these
+ super.tearDown();
-
- //Drain the queue
- while (true)
- {
- Message m = queueConsumer.receive(2000);
- if (m == null) break;
- }
-
producerConnection.close();
consumerConnection.close();
-
- ServerManagement.undeployQueue("Queue");
-
- super.tearDown();
}
public void testSMBodyReadable() throws Exception
@@ -313,7 +284,7 @@
// OK
}
- queueProducer.send(queue, m);
+ queueProducer.send(queue1, m);
BytesMessage m2 = (BytesMessage)queueConsumer.receive(2000);
@@ -659,7 +630,7 @@
{
}
- queueProducer.send(queue, m1);
+ queueProducer.send(queue1, m1);
MapMessage m2 = (MapMessage) queueConsumer.receive(2000);
@@ -1220,7 +1191,7 @@
ObjectMessage m1 = queueProducerSession.createObjectMessage(obj);
- queueProducer.send(queue, m1);
+ queueProducer.send(queue1, m1);
ObjectMessage m2 = (ObjectMessage) queueConsumer.receive(2000);
@@ -1235,7 +1206,7 @@
obj.str = "xyz123";
- queueProducer.send(queue, m3);
+ queueProducer.send(queue1, m3);
ObjectMessage m4 = (ObjectMessage) queueConsumer.receive(2000);
@@ -1381,7 +1352,7 @@
{
}
- queueProducer.send(queue, m);
+ queueProducer.send(queue1, m);
StreamMessage m2 = (StreamMessage) queueConsumer.receive(2000);
@@ -1656,14 +1627,14 @@
m.setText(myString);
- queueProducer.send(queue, m);
+ queueProducer.send(queue1, m);
TextMessage m2 = (TextMessage)queueConsumer.receive(2000);
assertEquals(myString, m2.getText());
m = queueProducerSession.createTextMessage(myString);
- queueProducer.send(queue, m);
+ queueProducer.send(queue1, m);
m2 = (TextMessage)queueConsumer.receive(2000);
Copied: trunk/tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTest.java (from rev 2909, trunk/tests/src/org/jboss/test/messaging/jms/message/MessageTest.java)
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTest.java (rev 0)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -0,0 +1,870 @@
+/*
+ * 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.messaging.jms.message;
+
+import java.io.Serializable;
+import java.util.Enumeration;
+import java.util.HashSet;
+
+import javax.jms.BytesMessage;
+import javax.jms.DeliveryMode;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.MapMessage;
+import javax.jms.Message;
+import javax.jms.MessageFormatException;
+import javax.jms.MessageNotWriteableException;
+import javax.jms.ObjectMessage;
+import javax.jms.StreamMessage;
+import javax.jms.TextMessage;
+
+import org.jboss.jms.message.JBossBytesMessage;
+import org.jboss.jms.message.JBossMapMessage;
+import org.jboss.jms.message.JBossMessage;
+import org.jboss.jms.message.JBossObjectMessage;
+import org.jboss.jms.message.JBossStreamMessage;
+import org.jboss.jms.message.JBossTextMessage;
+import org.jboss.jms.message.MessageProxy;
+
+/**
+ *
+ * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @version <tt>$Revision$</tt>
+ *
+ * $Id$
+ */
+public class MessageHeaderTest extends MessageHeaderTestBase
+{
+ // Constants -----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ public MessageHeaderTest(String name)
+ {
+ super(name);
+ }
+
+ // Public --------------------------------------------------------
+
+
+ public void testMessageOrderQueue() throws Exception
+ {
+ final int NUM_MESSAGES = 10;
+
+ queueProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ Message m = queueProducerSession.createMessage();
+ m.setIntProperty("count", i);
+ queueProducer.send(m);
+ }
+
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ Message m = queueConsumer.receive(3000);
+ assertNotNull(m);
+ int count = m.getIntProperty("count");
+ assertEquals(i, count);
+ }
+
+ queueProducer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ Message m = queueProducerSession.createMessage();
+ m.setIntProperty("count2", i);
+ queueProducer.send(m);
+ }
+
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ Message m = queueConsumer.receive(3000);
+ assertNotNull(m);
+ int count = m.getIntProperty("count2");
+ assertEquals(i, count);
+ }
+ }
+
+ public void testMessageOrderTopic() throws Exception
+ {
+ final int NUM_MESSAGES = 10;
+
+ topicProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ Message m = topicProducerSession.createMessage();
+ m.setIntProperty("count", i);
+ topicProducer.send(m);
+ }
+
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ Message m = topicConsumer.receive(3000);
+ assertNotNull(m);
+ int count = m.getIntProperty("count");
+ assertEquals(i, count);
+ }
+
+ topicProducer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ Message m = topicProducerSession.createMessage();
+ m.setIntProperty("count2", i);
+ topicProducer.send(m);
+ }
+
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ Message m = topicConsumer.receive(3000);
+ assertNotNull(m);
+ int count = m.getIntProperty("count2");
+ assertEquals(i, count);
+ }
+ }
+
+
+ public void testProperties() throws Exception
+ {
+ Message m1 = queueProducerSession.createMessage();
+
+ //Some arbitrary values
+ boolean myBool = true;
+ byte myByte = 13;
+ short myShort = 15321;
+ int myInt = 0x71ab6c80;
+ long myLong = 0x20bf1e3fb6fa31dfL;
+ float myFloat = Float.MAX_VALUE - 23465;
+ double myDouble = Double.MAX_VALUE - 72387633;
+ String myString = "abcdef&^*&!^ghijkl";
+
+ m1.setBooleanProperty("myBool", myBool);
+ m1.setByteProperty("myByte", myByte);
+ m1.setShortProperty("myShort", myShort);
+ m1.setIntProperty("myInt", myInt);
+ m1.setLongProperty("myLong", myLong);
+ m1.setFloatProperty("myFloat", myFloat);
+ m1.setDoubleProperty("myDouble", myDouble);
+ m1.setStringProperty("myString", myString);
+
+ m1.setObjectProperty("myBool", new Boolean(myBool));
+ m1.setObjectProperty("myByte", new Byte(myByte));
+ m1.setObjectProperty("myShort", new Short(myShort));
+ m1.setObjectProperty("myInt", new Integer(myInt));
+ m1.setObjectProperty("myLong", new Long(myLong));
+ m1.setObjectProperty("myFloat", new Float(myFloat));
+ m1.setObjectProperty("myDouble", new Double(myDouble));
+ m1.setObjectProperty("myString", myString);
+
+ try
+ {
+ m1.setObjectProperty("myIllegal", new Object());
+ fail();
+ }
+ catch (javax.jms.MessageFormatException e)
+ {}
+
+
+ queueProducer.send(queue1, m1);
+
+ Message m2 = queueConsumer.receive(2000);
+
+ assertNotNull(m2);
+
+ assertEquals(myBool, m2.getBooleanProperty("myBool"));
+ assertEquals(myByte, m2.getByteProperty("myByte"));
+ assertEquals(myShort, m2.getShortProperty("myShort"));
+ assertEquals(myInt, m2.getIntProperty("myInt"));
+ assertEquals(myLong, m2.getLongProperty("myLong"));
+ assertEquals(myFloat, m2.getFloatProperty("myFloat"), 0);
+ assertEquals(myDouble, m2.getDoubleProperty("myDouble"), 0);
+ assertEquals(myString, m2.getStringProperty("myString"));
+
+
+ //Properties should now be read-only
+ try
+ {
+ m2.setBooleanProperty("myBool", myBool);
+ fail();
+ }
+ catch (MessageNotWriteableException e) {}
+
+ try
+ {
+ m2.setByteProperty("myByte", myByte);
+ fail();
+ }
+ catch (MessageNotWriteableException e) {}
+
+ try
+ {
+ m2.setShortProperty("myShort", myShort);
+ fail();
+ }
+ catch (MessageNotWriteableException e) {}
+
+ try
+ {
+ m2.setIntProperty("myInt", myInt);
+ fail();
+ }
+ catch (MessageNotWriteableException e) {}
+
+ try
+ {
+ m2.setLongProperty("myLong", myLong);
+ fail();
+ }
+ catch (MessageNotWriteableException e) {}
+
+ try
+ {
+ m2.setFloatProperty("myFloat", myFloat);
+ fail();
+ }
+ catch (MessageNotWriteableException e) {}
+
+ try
+ {
+ m2.setDoubleProperty("myDouble", myDouble);
+ fail();
+ }
+ catch (MessageNotWriteableException e) {}
+
+ try
+ {
+ m2.setStringProperty("myString", myString);
+ fail();
+ }
+ catch (MessageNotWriteableException e) {}
+
+ assertTrue(m2.propertyExists("myBool"));
+ assertTrue(m2.propertyExists("myByte"));
+ assertTrue(m2.propertyExists("myShort"));
+ assertTrue(m2.propertyExists("myInt"));
+ assertTrue(m2.propertyExists("myLong"));
+ assertTrue(m2.propertyExists("myFloat"));
+ assertTrue(m2.propertyExists("myDouble"));
+ assertTrue(m2.propertyExists("myString"));
+
+ assertFalse(m2.propertyExists("sausages"));
+
+ HashSet propNames = new HashSet();
+ Enumeration en = m2.getPropertyNames();
+ while (en.hasMoreElements())
+ {
+ String propName = (String)en.nextElement();
+ propNames.add(propName);
+ }
+
+ assertEquals(8, propNames.size());
+
+ assertTrue(propNames.contains("myBool"));
+ assertTrue(propNames.contains("myByte"));
+ assertTrue(propNames.contains("myShort"));
+ assertTrue(propNames.contains("myInt"));
+ assertTrue(propNames.contains("myLong"));
+ assertTrue(propNames.contains("myFloat"));
+ assertTrue(propNames.contains("myDouble"));
+ assertTrue(propNames.contains("myString"));
+
+
+ // Check property conversions
+
+ //Boolean property can be read as String but not anything else
+
+ assertEquals(String.valueOf(myBool), m2.getStringProperty("myBool"));
+
+ try
+ {
+ m2.getByteProperty("myBool");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getShortProperty("myBool");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getIntProperty("myBool");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getLongProperty("myBool");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getFloatProperty("myBool");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getDoubleProperty("myBool");
+ fail();
+ } catch (MessageFormatException e) {}
+
+
+ // byte property can be read as short, int, long or String
+
+ assertEquals((short)myByte, m2.getShortProperty("myByte"));
+ assertEquals((int)myByte, m2.getIntProperty("myByte"));
+ assertEquals((long)myByte, m2.getLongProperty("myByte"));
+ assertEquals(String.valueOf(myByte), m2.getStringProperty("myByte"));
+
+ try
+ {
+ m2.getBooleanProperty("myByte");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getFloatProperty("myByte");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getDoubleProperty("myByte");
+ fail();
+ } catch (MessageFormatException e) {}
+
+
+ // short property can be read as int, long or String
+
+ assertEquals((int)myShort, m2.getIntProperty("myShort"));
+ assertEquals((long)myShort, m2.getLongProperty("myShort"));
+ assertEquals(String.valueOf(myShort), m2.getStringProperty("myShort"));
+
+ try
+ {
+ m2.getByteProperty("myShort");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getBooleanProperty("myShort");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getFloatProperty("myShort");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getDoubleProperty("myShort");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ // int property can be read as long or String
+
+ assertEquals((long)myInt, m2.getLongProperty("myInt"));
+ assertEquals(String.valueOf(myInt), m2.getStringProperty("myInt"));
+
+ try
+ {
+ m2.getShortProperty("myInt");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getByteProperty("myInt");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getBooleanProperty("myInt");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getFloatProperty("myInt");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getDoubleProperty("myInt");
+ fail();
+ } catch (MessageFormatException e) {}
+
+
+ // long property can be read as String
+
+ assertEquals(String.valueOf(myLong), m2.getStringProperty("myLong"));
+
+ try
+ {
+ m2.getIntProperty("myLong");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getShortProperty("myLong");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getByteProperty("myLong");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getBooleanProperty("myLong");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getFloatProperty("myLong");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getDoubleProperty("myLong");
+ fail();
+ } catch (MessageFormatException e) {}
+
+
+ // float property can be read as double or String
+
+ assertEquals(String.valueOf(myFloat), m2.getStringProperty("myFloat"));
+ assertEquals((double)myFloat, m2.getDoubleProperty("myFloat"), 0);
+
+ try
+ {
+ m2.getIntProperty("myFloat");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getShortProperty("myFloat");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getLongProperty("myFloat");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getByteProperty("myFloat");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getBooleanProperty("myFloat");
+ fail();
+ } catch (MessageFormatException e) {}
+
+
+
+ // double property can be read as String
+
+ assertEquals(String.valueOf(myDouble), m2.getStringProperty("myDouble"));
+
+
+ try
+ {
+ m2.getFloatProperty("myDouble");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getIntProperty("myDouble");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getShortProperty("myDouble");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getByteProperty("myDouble");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getBooleanProperty("myDouble");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ try
+ {
+ m2.getFloatProperty("myDouble");
+ fail();
+ } catch (MessageFormatException e) {}
+
+ m2.clearProperties();
+
+ Enumeration en2 = m2.getPropertyNames();
+ assertFalse(en2.hasMoreElements());
+
+
+
+
+ // Test String -> Numeric and bool conversions
+ Message m3 = queueProducerSession.createMessage();
+
+ m3.setStringProperty("myBool", String.valueOf(myBool));
+ m3.setStringProperty("myByte", String.valueOf(myByte));
+ m3.setStringProperty("myShort", String.valueOf(myShort));
+ m3.setStringProperty("myInt", String.valueOf(myInt));
+ m3.setStringProperty("myLong", String.valueOf(myLong));
+ m3.setStringProperty("myFloat", String.valueOf(myFloat));
+ m3.setStringProperty("myDouble", String.valueOf(myDouble));
+ m3.setStringProperty("myIllegal", "xyz123");
+
+ assertEquals(myBool, m3.getBooleanProperty("myBool"));
+ assertEquals(myByte, m3.getByteProperty("myByte"));
+ assertEquals(myShort, m3.getShortProperty("myShort"));
+ assertEquals(myInt, m3.getIntProperty("myInt"));
+ assertEquals(myLong, m3.getLongProperty("myLong"));
+ assertEquals(myFloat, m3.getFloatProperty("myFloat"), 0);
+ assertEquals(myDouble, m3.getDoubleProperty("myDouble"), 0);
+
+ m3.getBooleanProperty("myIllegal");
+
+ try
+ {
+ m3.getByteProperty("myIllegal");
+ fail();
+ }
+ catch (NumberFormatException e) {}
+ try
+ {
+ m3.getShortProperty("myIllegal");
+ fail();
+ }
+ catch (NumberFormatException e) {}
+ try
+ {
+ m3.getIntProperty("myIllegal");
+ fail();
+ }
+ catch (NumberFormatException e) {}
+ try
+ {
+ m3.getLongProperty("myIllegal");
+ fail();
+ }
+ catch (NumberFormatException e) {}
+ try
+ {
+ m3.getFloatProperty("myIllegal");
+ fail();
+ }
+ catch (NumberFormatException e) {}
+ try
+ {
+ m3.getDoubleProperty("myIllegal");
+ fail();
+ }
+ catch (NumberFormatException e) {}
+ }
+
+
+
+ public void testSendReceiveForeignMessage() throws JMSException
+ {
+
+ log.trace("Starting da test");
+
+ SimpleJMSMessage foreignMessage = new SimpleJMSMessage();
+
+ foreignMessage.setStringProperty("animal", "aardvark");
+
+ //foreign messages don't have to be serializable
+ assertFalse(foreignMessage instanceof Serializable);
+
+ log.trace("Sending message");
+
+ queueProducer.send(foreignMessage);
+
+ log.trace("Sent message");
+
+ Message m2 = queueConsumer.receive(3000);
+ log.trace("The message is " + m2);
+
+ assertNotNull(m2);
+
+ assertEquals("aardvark", m2.getStringProperty("animal"));
+
+ log.trace("Received message");
+
+ log.trace("Done that test");
+ }
+
+ public void testCopyOnJBossMessage() throws JMSException
+ {
+ JBossMessage jbossMessage = ((MessageProxy)queueProducerSession.createMessage()).getMessage();
+
+ configureMessage(jbossMessage);
+
+ JBossMessage copy = new JBossMessage(jbossMessage, 0);
+
+ ensureEquivalent(jbossMessage, copy);
+ }
+
+
+ public void testCopyOnForeignMessage() throws JMSException
+ {
+ Message foreignMessage = new SimpleJMSMessage();
+
+ JBossMessage copy = new JBossMessage(foreignMessage, 0);
+
+ ensureEquivalent(foreignMessage, copy);
+ }
+
+
+ public void testCopyOnJBossBytesMessage() throws JMSException
+ {
+ JBossBytesMessage jbossBytesMessage = (JBossBytesMessage)(((MessageProxy)queueProducerSession.
+ createBytesMessage()).getMessage());
+
+ for(int i = 0; i < 20; i++)
+ {
+ jbossBytesMessage.writeByte((byte)i);
+ }
+
+
+ jbossBytesMessage.reset();
+ JBossBytesMessage copy = new JBossBytesMessage(jbossBytesMessage);
+
+ copy.reset();
+
+ ensureEquivalent(jbossBytesMessage, copy);
+ }
+
+
+ public void testCopyOnForeignBytesMessage() throws JMSException
+ {
+ BytesMessage foreignBytesMessage = new SimpleJMSBytesMessage();
+ for(int i = 0; i < 20; i++)
+ {
+ foreignBytesMessage.writeByte((byte)i);
+ }
+
+ JBossBytesMessage copy = new JBossBytesMessage(foreignBytesMessage, 0);
+
+ foreignBytesMessage.reset();
+ copy.reset();
+
+ ensureEquivalent(foreignBytesMessage, copy);
+ }
+
+ public void testCopyOnJBossMapMessage() throws JMSException
+ {
+ JBossMapMessage jbossMapMessage = (JBossMapMessage)(((MessageProxy)queueProducerSession.
+ createMapMessage()).getMessage());
+
+ jbossMapMessage.setInt("int", 1);
+ jbossMapMessage.setString("string", "test");
+
+ JBossMapMessage copy = new JBossMapMessage((JBossMapMessage)jbossMapMessage);
+
+ ensureEquivalent(jbossMapMessage, copy);
+ }
+
+
+ public void testCopyOnForeignMapMessage() throws JMSException
+ {
+ MapMessage foreignMapMessage = new SimpleJMSMapMessage();
+ foreignMapMessage.setInt("int", 1);
+ foreignMapMessage.setString("string", "test");
+
+ JBossMapMessage copy = new JBossMapMessage(foreignMapMessage, 0);
+
+ ensureEquivalent(foreignMapMessage, copy);
+ }
+
+
+ public void testCopyOnJBossObjectMessage() throws JMSException
+ {
+ JBossObjectMessage jbossObjectMessage = (JBossObjectMessage)
+ (((MessageProxy)queueProducerSession.createObjectMessage()).getMessage());
+
+ JBossObjectMessage copy = new JBossObjectMessage(jbossObjectMessage);
+
+ ensureEquivalent(jbossObjectMessage, copy);
+ }
+
+
+ public void testCopyOnForeignObjectMessage() throws JMSException
+ {
+ ObjectMessage foreignObjectMessage = new SimpleJMSObjectMessage();
+
+ JBossObjectMessage copy = new JBossObjectMessage(foreignObjectMessage, 0);
+
+ ensureEquivalent(foreignObjectMessage, copy);
+ }
+
+
+ public void testCopyOnJBossStreamMessage() throws JMSException
+ {
+ JBossStreamMessage jbossStreamMessage = (JBossStreamMessage)
+ (((MessageProxy)queueProducerSession.createStreamMessage()).getMessage());
+
+ jbossStreamMessage.writeByte((byte)1);
+ jbossStreamMessage.writeByte((byte)2);
+ jbossStreamMessage.writeByte((byte)3);
+
+ JBossStreamMessage copy = new JBossStreamMessage((JBossStreamMessage)jbossStreamMessage);
+
+ ensureEquivalent(jbossStreamMessage, copy);
+ }
+
+
+ public void testCopyOnForeignStreamMessage() throws JMSException
+ {
+ StreamMessage foreignStreamMessage = new SimpleJMSStreamMessage();
+ foreignStreamMessage.writeByte((byte)1);
+ foreignStreamMessage.writeByte((byte)2);
+ foreignStreamMessage.writeByte((byte)3);
+
+ JBossStreamMessage copy = new JBossStreamMessage(foreignStreamMessage, 0);
+
+ ensureEquivalent(foreignStreamMessage, copy);
+ }
+
+
+ public void testCopyOnJBossTextMessage() throws JMSException
+ {
+ JBossTextMessage jbossTextMessage = (JBossTextMessage)
+ (((MessageProxy)queueProducerSession.createTextMessage()).getMessage());
+
+ JBossTextMessage copy = new JBossTextMessage(jbossTextMessage);
+
+ ensureEquivalent(jbossTextMessage, copy);
+ }
+
+
+ public void testCopyOnForeignTextMessage() throws JMSException
+ {
+ TextMessage foreignTextMessage = new SimpleJMSTextMessage();
+
+ JBossTextMessage copy = new JBossTextMessage(foreignTextMessage, 0);
+
+ ensureEquivalent(foreignTextMessage, copy);
+ }
+
+ public void testForeignJMSDestination() throws JMSException
+ {
+ Message message = queueProducerSession.createMessage();
+
+ Destination foreignDestination = new ForeignDestination();
+
+ message.setJMSDestination(foreignDestination);
+
+ assertSame(foreignDestination, message.getJMSDestination());
+
+ queueProducer.send(message);
+
+ assertSame(queue1, message.getJMSDestination());
+
+ Message receivedMessage = queueConsumer.receive(2000);
+
+ ensureEquivalent(receivedMessage, ((MessageProxy) message).getMessage());
+ }
+
+ public void testForeignJMSReplyTo() throws JMSException
+ {
+ JBossMessage jbossMessage = ((MessageProxy) queueProducerSession.createTextMessage()).getMessage();
+
+ Destination foreignDestination = new ForeignDestination();
+
+ jbossMessage.setJMSReplyTo(foreignDestination);
+
+ queueProducer.send(jbossMessage);
+
+ Message receivedMessage = queueConsumer.receive(2000);
+
+ ensureEquivalent(receivedMessage, jbossMessage);
+ }
+
+ public void testCopyForeignDestinationAndReplyTo() throws JMSException
+ {
+ Message foreignMessage = new SimpleJMSMessage();
+ foreignMessage.setJMSDestination(new ForeignDestination());
+ foreignMessage.setJMSReplyTo(new ForeignDestination());
+
+ JBossMessage copy = new JBossMessage(foreignMessage, 0);
+
+ ensureEquivalent(foreignMessage, copy);
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+ private static class ForeignDestination implements Destination, Serializable
+ {
+ private static final long serialVersionUID = 5545509674580823610L;
+
+ // A ForeignDestination equals any other ForeignDestination, for simplicity
+ public boolean equals(Object obj)
+ {
+ return obj instanceof ForeignDestination;
+ }
+
+ public int hashCode()
+ {
+ return 157;
+ }
+ }
+
+}
Added: trunk/tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTestBase.java (rev 0)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTestBase.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -0,0 +1,488 @@
+/*
+ * 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.messaging.jms.message;
+
+import java.util.Arrays;
+import java.util.Enumeration;
+
+import javax.jms.BytesMessage;
+import javax.jms.Connection;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
+import javax.jms.MapMessage;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageEOFException;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.jms.Session;
+import javax.jms.StreamMessage;
+import javax.jms.TextMessage;
+
+import org.jboss.jms.destination.JBossQueue;
+import org.jboss.jms.message.JBossBytesMessage;
+import org.jboss.jms.message.JBossMapMessage;
+import org.jboss.jms.message.JBossMessage;
+import org.jboss.jms.message.JBossObjectMessage;
+import org.jboss.jms.message.JBossStreamMessage;
+import org.jboss.jms.message.JBossTextMessage;
+import org.jboss.test.messaging.jms.JMSTestCase;
+
+/**
+ *
+ * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @version <tt>$Revision: 2883 $</tt>
+ *
+ * $Id: MessageTest.java 2883 2007-07-12 23:36:16Z timfox $
+ */
+public class MessageHeaderTestBase extends JMSTestCase
+{
+ // Constants -----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ /**
+ * Loads the message header fields with significant values.
+ */
+ public static void configureMessage(JBossMessage m) throws JMSException
+ {
+ //m.setJMSMessageID("messageID777");
+ m.setMessageId(123456);
+ m.setJMSTimestamp(123456789l);
+ m.setJMSCorrelationID("correlationID777");
+ m.setJMSReplyTo(new JBossQueue("ReplyToQueue"));
+ m.setJMSDestination(new JBossQueue("DestinationQueue"));
+ m.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
+ m.setJMSExpiration(987654321l);
+ m.setJMSPriority(9);
+ m.setBooleanProperty("booleanProperty", true);
+ m.setByteProperty("byteProperty", (byte)2);
+ m.setShortProperty("shortProperty", (short)3);
+ m.setIntProperty("intProperty", 4);
+ m.setLongProperty("longProperty", 5l);
+ m.setFloatProperty("floatProperty", 6);
+ m.setDoubleProperty("doubleProperty", 7);
+ m.setStringProperty("stringPoperty", "someString");
+ }
+
+ /**
+ * Makes sure two physically different message are equivalent: they have identical JMS fields and
+ * body.
+ */
+ public static void ensureEquivalent(Message m1, JBossMessage m2) throws JMSException
+ {
+ assertTrue(m1 != m2);
+
+ //Can't compare message id since not set until send
+
+ assertEquals(m1.getJMSTimestamp(), m2.getJMSTimestamp());
+
+ byte[] corrIDBytes = null;
+ String corrIDString = null;
+
+ try
+ {
+ corrIDBytes = m1.getJMSCorrelationIDAsBytes();
+ }
+ catch(JMSException e)
+ {
+ // correlation ID specified as String
+ corrIDString = m1.getJMSCorrelationID();
+ }
+
+ if (corrIDBytes != null)
+ {
+ assertTrue(Arrays.equals(corrIDBytes, m2.getJMSCorrelationIDAsBytes()));
+ }
+ else if (corrIDString != null)
+ {
+ assertEquals(corrIDString, m2.getJMSCorrelationID());
+ }
+ else
+ {
+ // no correlation id
+
+ try
+ {
+ byte[] corrID2 = m2.getJMSCorrelationIDAsBytes();
+ assertNull(corrID2);
+ }
+ catch(JMSException e)
+ {
+ // correlatin ID specified as String
+ String corrID2 = m2.getJMSCorrelationID();
+ assertNull(corrID2);
+ }
+ }
+ assertEquals(m1.getJMSReplyTo(), m2.getJMSReplyTo());
+ assertEquals(m1.getJMSDestination(), m2.getJMSDestination());
+ assertEquals(m1.getJMSDeliveryMode(), m2.getJMSDeliveryMode());
+ //We don't check redelivered since this is always dealt with on the proxy
+ assertEquals(m1.getJMSType(), m2.getJMSType());
+ assertEquals(m1.getJMSExpiration(), m2.getJMSExpiration());
+ assertEquals(m1.getJMSPriority(), m2.getJMSPriority());
+
+ int m1PropertyCount = 0, m2PropertyCount = 0;
+ for(Enumeration p = m1.getPropertyNames(); p.hasMoreElements(); m1PropertyCount++)
+ {
+ p.nextElement();
+ }
+ for(Enumeration p = m2.getPropertyNames(); p.hasMoreElements(); m2PropertyCount++)
+ {
+ p.nextElement();
+ }
+
+ assertEquals(m1PropertyCount, m2PropertyCount);
+
+ for(Enumeration props = m1.getPropertyNames(); props.hasMoreElements(); )
+ {
+ boolean found = false;
+
+ String name = (String)props.nextElement();
+
+ boolean booleanProperty = false;
+ try
+ {
+ booleanProperty = m1.getBooleanProperty(name);
+ found = true;
+ }
+ catch(JMSException e)
+ {
+ // not a boolean
+ }
+
+ if (found)
+ {
+ assertEquals(booleanProperty, m2.getBooleanProperty(name));
+ continue;
+ }
+
+ byte byteProperty = 0;
+ try
+ {
+ byteProperty = m1.getByteProperty(name);
+ found = true;
+ }
+ catch(JMSException e)
+ {
+ // not a byte
+ }
+
+ if (found)
+ {
+ assertEquals(byteProperty, m2.getByteProperty(name));
+ continue;
+ }
+
+ short shortProperty = 0;
+ try
+ {
+ shortProperty = m1.getShortProperty(name);
+ found = true;
+ }
+ catch(JMSException e)
+ {
+ // not a short
+ }
+
+ if (found)
+ {
+ assertEquals(shortProperty, m2.getShortProperty(name));
+ continue;
+ }
+
+
+ int intProperty = 0;
+ try
+ {
+ intProperty = m1.getIntProperty(name);
+ found = true;
+ }
+ catch(JMSException e)
+ {
+ // not a int
+ }
+
+ if (found)
+ {
+ assertEquals(intProperty, m2.getIntProperty(name));
+ continue;
+ }
+
+
+ long longProperty = 0;
+ try
+ {
+ longProperty = m1.getLongProperty(name);
+ found = true;
+ }
+ catch(JMSException e)
+ {
+ // not a long
+ }
+
+ if (found)
+ {
+ assertEquals(longProperty, m2.getLongProperty(name));
+ continue;
+ }
+
+
+ float floatProperty = 0;
+ try
+ {
+ floatProperty = m1.getFloatProperty(name);
+ found = true;
+ }
+ catch(JMSException e)
+ {
+ // not a float
+ }
+
+ if (found)
+ {
+ assertTrue(floatProperty == m2.getFloatProperty(name));
+ continue;
+ }
+
+ double doubleProperty = 0;
+ try
+ {
+ doubleProperty = m1.getDoubleProperty(name);
+ found = true;
+ }
+ catch(JMSException e)
+ {
+ // not a double
+ }
+
+ if (found)
+ {
+ assertTrue(doubleProperty == m2.getDoubleProperty(name));
+ continue;
+ }
+
+ String stringProperty = null;
+ try
+ {
+ stringProperty = m1.getStringProperty(name);
+ found = true;
+ }
+ catch(JMSException e)
+ {
+ // not a String
+ }
+
+ if (found)
+ {
+ assertEquals(stringProperty, m2.getStringProperty(name));
+ continue;
+ }
+
+
+ fail("Cannot identify property " + name);
+ }
+ }
+
+ public static void ensureEquivalent(BytesMessage m1, JBossBytesMessage m2) throws JMSException
+ {
+ ensureEquivalent((Message)m1, m2);
+
+ long len = m1.getBodyLength();
+ for(int i = 0; i < len; i++)
+ {
+ assertEquals(m1.readByte(), m2.readByte());
+ }
+
+ try
+ {
+ m1.readByte();
+ fail("should throw MessageEOFException");
+ }
+ catch(MessageEOFException e)
+ {
+ // OK
+ }
+
+ try
+ {
+ m2.readByte();
+ fail("should throw MessageEOFException");
+ }
+ catch(MessageEOFException e)
+ {
+ // OK
+ }
+ }
+
+ public static void ensureEquivalent(MapMessage m1, JBossMapMessage m2) throws JMSException
+ {
+ ensureEquivalent((Message)m1, m2);
+
+ for(Enumeration e = m1.getMapNames(); e.hasMoreElements(); )
+ {
+ String name = (String)e.nextElement();
+ assertEquals(m1.getObject(name), m2.getObject(name));
+ }
+
+ for(Enumeration e = m2.getMapNames(); e.hasMoreElements(); )
+ {
+ String name = (String)e.nextElement();
+ assertEquals(m2.getObject(name), m1.getObject(name));
+ }
+ }
+
+ public static void ensureEquivalent(ObjectMessage m1, JBossObjectMessage m2) throws JMSException
+ {
+ ensureEquivalent((Message)m1, m2);
+ assertEquals(m1.getObject(), m2.getObject());
+ }
+
+ public static void ensureEquivalent(StreamMessage m1, JBossStreamMessage m2) throws JMSException
+ {
+ ensureEquivalent((Message)m1, m2);
+
+ m1.reset();
+ m2.reset();
+ boolean m1eof = false, m2eof = false;
+ while(true)
+ {
+ byte b1, b2;
+ try
+ {
+ b1 = m1.readByte();
+ }
+ catch(MessageEOFException e)
+ {
+ m1eof = true;
+ break;
+ }
+
+ try
+ {
+ b2 = m2.readByte();
+ }
+ catch(MessageEOFException e)
+ {
+ m2eof = true;
+ break;
+ }
+
+ assertEquals(b1, b2);
+ }
+
+
+ if (m1eof)
+ {
+ try
+ {
+ m2.readByte();
+ fail("should throw MessageEOFException");
+ }
+ catch(MessageEOFException e)
+ {
+ // OK
+ }
+ }
+
+ if (m2eof)
+ {
+ try
+ {
+ m1.readByte();
+ fail("should throw MessageEOFException");
+ }
+ catch(MessageEOFException e)
+ {
+ // OK
+ }
+ }
+ }
+
+ public static void ensureEquivalent(TextMessage m1, JBossTextMessage m2) throws JMSException
+ {
+ ensureEquivalent((Message)m1, m2);
+ assertEquals(m1.getText(), m2.getText());
+ }
+
+ // Attributes ----------------------------------------------------
+
+ protected Connection producerConnection, consumerConnection;
+ protected Session queueProducerSession, queueConsumerSession;
+ protected MessageProducer queueProducer;
+ protected MessageConsumer queueConsumer;
+ protected Session topicProducerSession, topicConsumerSession;
+ protected MessageProducer topicProducer;
+ protected MessageConsumer topicConsumer;
+
+
+ // Constructors --------------------------------------------------
+
+ public MessageHeaderTestBase(String name)
+ {
+ super(name);
+ }
+
+ // Public --------------------------------------------------------
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ producerConnection = cf.createConnection();
+ consumerConnection = cf.createConnection();
+
+ queueProducerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ queueConsumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ queueProducer = queueProducerSession.createProducer(queue1);
+ queueConsumer = queueConsumerSession.createConsumer(queue1);
+
+ topicProducerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ topicConsumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ topicProducer = topicProducerSession.createProducer(topic1);
+ topicConsumer = topicConsumerSession.createConsumer(topic1);
+
+ consumerConnection.start();
+ }
+
+ public void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ producerConnection.close();
+ consumerConnection.close();
+ }
+
+
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/MessagePropertyConversionTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/MessagePropertyConversionTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/MessagePropertyConversionTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -31,7 +31,7 @@
import javax.jms.Session;
import javax.naming.InitialContext;
-import org.jboss.test.messaging.MessagingTestCase;
+import org.jboss.test.messaging.jms.JMSTestCase;
import org.jboss.test.messaging.tools.ServerManagement;
/**
@@ -44,11 +44,10 @@
*
* $Id$
*/
-public class MessagePropertyConversionTest extends MessagingTestCase
+public class MessagePropertyConversionTest extends JMSTestCase
{
// Attributes ----------------------------------------------------
- private Destination queue;
private Connection producerConnection, consumerConnection;
private Session queueProducerSession, queueConsumerSession;
private MessageProducer queueProducer;
@@ -67,36 +66,24 @@
{
super.setUp();
- ServerManagement.start("all");
-
- ServerManagement.undeployQueue("Queue");
- ServerManagement.deployQueue("Queue");
-
- InitialContext ic = new InitialContext(ServerManagement.getJNDIEnvironment());
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
- queue = (Destination)ic.lookup("/queue/Queue");
-
producerConnection = cf.createConnection();
consumerConnection = cf.createConnection();
queueProducerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
queueConsumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- queueProducer = queueProducerSession.createProducer(queue);
- queueConsumer = queueConsumerSession.createConsumer(queue);
+ queueProducer = queueProducerSession.createProducer(queue1);
+ queueConsumer = queueConsumerSession.createConsumer(queue1);
consumerConnection.start();
}
public void tearDown() throws Exception
{
+ super.tearDown();
+
producerConnection.close();
consumerConnection.close();
-
- ServerManagement.undeployQueue("Queue");
-
-
- super.tearDown();
}
public void testBooleanConversion() throws Exception
@@ -106,7 +93,7 @@
boolean myBool = true;
m1.setBooleanProperty("myBool", myBool);
- queueProducer.send(queue, m1);
+ queueProducer.send(queue1, m1);
Message m2 = queueConsumer.receive(2000);
// Boolean property can be read as boolean and String but not anything else
@@ -158,7 +145,7 @@
byte myByte = 13;
m1.setByteProperty("myByte", myByte);
- queueProducer.send(queue, m1);
+ queueProducer.send(queue1, m1);
Message m2 = queueConsumer.receive(2000);
// Byte property can be read as byte, short, int, long or String
@@ -195,7 +182,7 @@
short myShort = 15321;
m1.setShortProperty("myShort", myShort);
- queueProducer.send(queue, m1);
+ queueProducer.send(queue1, m1);
Message m2 = queueConsumer.receive(2000);
// Short property can be read as short, int, long or String
@@ -237,7 +224,7 @@
int myInt = 0x71ab6c80;
m1.setIntProperty("myInt", myInt);
- queueProducer.send(queue, m1);
+ queueProducer.send(queue1, m1);
Message m2 = queueConsumer.receive(2000);
// Int property can be read as int, long or String
@@ -284,7 +271,7 @@
long myLong = 0x20bf1e3fb6fa31dfL;
m1.setLongProperty("myLong", myLong);
- queueProducer.send(queue, m1);
+ queueProducer.send(queue1, m1);
Message m2 = queueConsumer.receive(2000);
// Long property can be read as long and String
@@ -336,7 +323,7 @@
float myFloat = Float.MAX_VALUE - 23465;
m1.setFloatProperty("myFloat", myFloat);
- queueProducer.send(queue, m1);
+ queueProducer.send(queue1, m1);
Message m2 = queueConsumer.receive(2000);
// Float property can be read as float, double or String
@@ -383,7 +370,7 @@
double myDouble = Double.MAX_VALUE - 72387633;
m1.setDoubleProperty("myDouble", myDouble);
- queueProducer.send(queue, m1);
+ queueProducer.send(queue1, m1);
Message m2 = queueConsumer.receive(2000);
// Double property can be read as double and String
@@ -443,7 +430,7 @@
m1.setStringProperty("myString", myString);
- queueProducer.send(queue, m1);
+ queueProducer.send(queue1, m1);
Message m2 = queueConsumer.receive(2000);
assertEquals(myString, m2.getStringProperty("myString"));
@@ -466,7 +453,7 @@
m3.setStringProperty("myDouble", String.valueOf(myDouble));
m3.setStringProperty("myIllegal", "xyz123");
- queueProducer.send(queue, m3);
+ queueProducer.send(queue1, m3);
Message m4 = queueConsumer.receive(2000);
@@ -521,7 +508,7 @@
public void testJMSXDeliveryCountConversion() throws Exception
{
Message m1 = queueProducerSession.createMessage();
- queueProducer.send(queue, m1);
+ queueProducer.send(queue1, m1);
Message m2 = queueConsumer.receive(2000);
Deleted: trunk/tests/src/org/jboss/test/messaging/jms/message/MessageTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/MessageTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/MessageTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -1,1303 +0,0 @@
-/*
- * 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.messaging.jms.message;
-
-import java.io.Serializable;
-import java.util.Arrays;
-import java.util.Enumeration;
-import java.util.HashSet;
-
-import javax.naming.InitialContext;
-import javax.jms.Destination;
-import javax.jms.Connection;
-import javax.jms.Session;
-import javax.jms.MessageProducer;
-import javax.jms.MessageConsumer;
-import javax.jms.DeliveryMode;
-import javax.jms.Message;
-import javax.jms.ConnectionFactory;
-import javax.jms.MessageNotWriteableException;
-import javax.jms.MessageFormatException;
-import javax.jms.JMSException;
-import javax.jms.BytesMessage;
-import javax.jms.MapMessage;
-import javax.jms.ObjectMessage;
-import javax.jms.StreamMessage;
-import javax.jms.TextMessage;
-import javax.jms.MessageEOFException;
-
-import org.jboss.jms.destination.JBossQueue;
-import org.jboss.jms.message.JBossMessage;
-import org.jboss.jms.message.JBossBytesMessage;
-import org.jboss.jms.message.JBossMapMessage;
-import org.jboss.jms.message.JBossObjectMessage;
-import org.jboss.jms.message.JBossStreamMessage;
-import org.jboss.jms.message.JBossTextMessage;
-import org.jboss.jms.message.MessageProxy;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
-
-/**
- * Base class for all tests concerning message headers, properties, etc.
- *
- * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- */
-public class MessageTest extends MessagingTestCase
-{
- // Constants -----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- /**
- * Loads the message header fields with significant values.
- */
- public static void configureMessage(JBossMessage m) throws JMSException
- {
- //m.setJMSMessageID("messageID777");
- m.setMessageId(123456);
- m.setJMSTimestamp(123456789l);
- m.setJMSCorrelationID("correlationID777");
- m.setJMSReplyTo(new JBossQueue("ReplyToQueue"));
- m.setJMSDestination(new JBossQueue("DestinationQueue"));
- m.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
- m.setJMSExpiration(987654321l);
- m.setJMSPriority(9);
- m.setBooleanProperty("booleanProperty", true);
- m.setByteProperty("byteProperty", (byte)2);
- m.setShortProperty("shortProperty", (short)3);
- m.setIntProperty("intProperty", 4);
- m.setLongProperty("longProperty", 5l);
- m.setFloatProperty("floatProperty", 6);
- m.setDoubleProperty("doubleProperty", 7);
- m.setStringProperty("stringPoperty", "someString");
- }
-
- /**
- * Makes sure two physically different message are equivalent: they have identical JMS fields and
- * body.
- */
- public static void ensureEquivalent(Message m1, JBossMessage m2) throws JMSException
- {
- assertTrue(m1 != m2);
-
- //Can't compare message id since not set until send
-
- assertEquals(m1.getJMSTimestamp(), m2.getJMSTimestamp());
-
- byte[] corrIDBytes = null;
- String corrIDString = null;
-
- try
- {
- corrIDBytes = m1.getJMSCorrelationIDAsBytes();
- }
- catch(JMSException e)
- {
- // correlation ID specified as String
- corrIDString = m1.getJMSCorrelationID();
- }
-
- if (corrIDBytes != null)
- {
- assertTrue(Arrays.equals(corrIDBytes, m2.getJMSCorrelationIDAsBytes()));
- }
- else if (corrIDString != null)
- {
- assertEquals(corrIDString, m2.getJMSCorrelationID());
- }
- else
- {
- // no correlation id
-
- try
- {
- byte[] corrID2 = m2.getJMSCorrelationIDAsBytes();
- assertNull(corrID2);
- }
- catch(JMSException e)
- {
- // correlatin ID specified as String
- String corrID2 = m2.getJMSCorrelationID();
- assertNull(corrID2);
- }
- }
- assertEquals(m1.getJMSReplyTo(), m2.getJMSReplyTo());
- assertEquals(m1.getJMSDestination(), m2.getJMSDestination());
- assertEquals(m1.getJMSDeliveryMode(), m2.getJMSDeliveryMode());
- //We don't check redelivered since this is always dealt with on the proxy
- assertEquals(m1.getJMSType(), m2.getJMSType());
- assertEquals(m1.getJMSExpiration(), m2.getJMSExpiration());
- assertEquals(m1.getJMSPriority(), m2.getJMSPriority());
-
- int m1PropertyCount = 0, m2PropertyCount = 0;
- for(Enumeration p = m1.getPropertyNames(); p.hasMoreElements(); m1PropertyCount++)
- {
- p.nextElement();
- }
- for(Enumeration p = m2.getPropertyNames(); p.hasMoreElements(); m2PropertyCount++)
- {
- p.nextElement();
- }
-
- assertEquals(m1PropertyCount, m2PropertyCount);
-
- for(Enumeration props = m1.getPropertyNames(); props.hasMoreElements(); )
- {
- boolean found = false;
-
- String name = (String)props.nextElement();
-
- boolean booleanProperty = false;
- try
- {
- booleanProperty = m1.getBooleanProperty(name);
- found = true;
- }
- catch(JMSException e)
- {
- // not a boolean
- }
-
- if (found)
- {
- assertEquals(booleanProperty, m2.getBooleanProperty(name));
- continue;
- }
-
- byte byteProperty = 0;
- try
- {
- byteProperty = m1.getByteProperty(name);
- found = true;
- }
- catch(JMSException e)
- {
- // not a byte
- }
-
- if (found)
- {
- assertEquals(byteProperty, m2.getByteProperty(name));
- continue;
- }
-
- short shortProperty = 0;
- try
- {
- shortProperty = m1.getShortProperty(name);
- found = true;
- }
- catch(JMSException e)
- {
- // not a short
- }
-
- if (found)
- {
- assertEquals(shortProperty, m2.getShortProperty(name));
- continue;
- }
-
-
- int intProperty = 0;
- try
- {
- intProperty = m1.getIntProperty(name);
- found = true;
- }
- catch(JMSException e)
- {
- // not a int
- }
-
- if (found)
- {
- assertEquals(intProperty, m2.getIntProperty(name));
- continue;
- }
-
-
- long longProperty = 0;
- try
- {
- longProperty = m1.getLongProperty(name);
- found = true;
- }
- catch(JMSException e)
- {
- // not a long
- }
-
- if (found)
- {
- assertEquals(longProperty, m2.getLongProperty(name));
- continue;
- }
-
-
- float floatProperty = 0;
- try
- {
- floatProperty = m1.getFloatProperty(name);
- found = true;
- }
- catch(JMSException e)
- {
- // not a float
- }
-
- if (found)
- {
- assertTrue(floatProperty == m2.getFloatProperty(name));
- continue;
- }
-
- double doubleProperty = 0;
- try
- {
- doubleProperty = m1.getDoubleProperty(name);
- found = true;
- }
- catch(JMSException e)
- {
- // not a double
- }
-
- if (found)
- {
- assertTrue(doubleProperty == m2.getDoubleProperty(name));
- continue;
- }
-
- String stringProperty = null;
- try
- {
- stringProperty = m1.getStringProperty(name);
- found = true;
- }
- catch(JMSException e)
- {
- // not a String
- }
-
- if (found)
- {
- assertEquals(stringProperty, m2.getStringProperty(name));
- continue;
- }
-
-
- fail("Cannot identify property " + name);
- }
- }
-
- public static void ensureEquivalent(BytesMessage m1, JBossBytesMessage m2) throws JMSException
- {
- ensureEquivalent((Message)m1, m2);
-
- long len = m1.getBodyLength();
- for(int i = 0; i < len; i++)
- {
- assertEquals(m1.readByte(), m2.readByte());
- }
-
- try
- {
- m1.readByte();
- fail("should throw MessageEOFException");
- }
- catch(MessageEOFException e)
- {
- // OK
- }
-
- try
- {
- m2.readByte();
- fail("should throw MessageEOFException");
- }
- catch(MessageEOFException e)
- {
- // OK
- }
- }
-
- public static void ensureEquivalent(MapMessage m1, JBossMapMessage m2) throws JMSException
- {
- ensureEquivalent((Message)m1, m2);
-
- for(Enumeration e = m1.getMapNames(); e.hasMoreElements(); )
- {
- String name = (String)e.nextElement();
- assertEquals(m1.getObject(name), m2.getObject(name));
- }
-
- for(Enumeration e = m2.getMapNames(); e.hasMoreElements(); )
- {
- String name = (String)e.nextElement();
- assertEquals(m2.getObject(name), m1.getObject(name));
- }
- }
-
- public static void ensureEquivalent(ObjectMessage m1, JBossObjectMessage m2) throws JMSException
- {
- ensureEquivalent((Message)m1, m2);
- assertEquals(m1.getObject(), m2.getObject());
- }
-
- public static void ensureEquivalent(StreamMessage m1, JBossStreamMessage m2) throws JMSException
- {
- ensureEquivalent((Message)m1, m2);
-
- m1.reset();
- m2.reset();
- boolean m1eof = false, m2eof = false;
- while(true)
- {
- byte b1, b2;
- try
- {
- b1 = m1.readByte();
- }
- catch(MessageEOFException e)
- {
- m1eof = true;
- break;
- }
-
- try
- {
- b2 = m2.readByte();
- }
- catch(MessageEOFException e)
- {
- m2eof = true;
- break;
- }
-
- assertEquals(b1, b2);
- }
-
-
- if (m1eof)
- {
- try
- {
- m2.readByte();
- fail("should throw MessageEOFException");
- }
- catch(MessageEOFException e)
- {
- // OK
- }
- }
-
- if (m2eof)
- {
- try
- {
- m1.readByte();
- fail("should throw MessageEOFException");
- }
- catch(MessageEOFException e)
- {
- // OK
- }
- }
- }
-
- public static void ensureEquivalent(TextMessage m1, JBossTextMessage m2) throws JMSException
- {
- ensureEquivalent((Message)m1, m2);
- assertEquals(m1.getText(), m2.getText());
- }
-
- // Attributes ----------------------------------------------------
-
- protected Destination queue;
- protected Destination topic;
- protected Connection producerConnection, consumerConnection;
- protected Session queueProducerSession, queueConsumerSession;
- protected MessageProducer queueProducer;
- protected MessageConsumer queueConsumer;
- protected Session topicProducerSession, topicConsumerSession;
- protected MessageProducer topicProducer;
- protected MessageConsumer topicConsumer;
-
-
- // Constructors --------------------------------------------------
-
- public MessageTest(String name)
- {
- super(name);
- }
-
- // Public --------------------------------------------------------
-
- public void setUp() throws Exception
- {
- super.setUp();
-
- ServerManagement.start("all");
-
- ServerManagement.undeployQueue("Queue");
- ServerManagement.deployQueue("Queue");
-
- ServerManagement.undeployTopic("Topic");
- ServerManagement.deployTopic("Topic");
-
- InitialContext ic = new InitialContext(ServerManagement.getJNDIEnvironment());
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
- queue = (Destination)ic.lookup("/queue/Queue");
- topic = (Destination)ic.lookup("/topic/Topic");
-
- drainDestination(cf, queue);
-
- producerConnection = cf.createConnection();
- consumerConnection = cf.createConnection();
-
- queueProducerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- queueConsumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- queueProducer = queueProducerSession.createProducer(queue);
- queueConsumer = queueConsumerSession.createConsumer(queue);
-
- topicProducerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- topicConsumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- topicProducer = topicProducerSession.createProducer(topic);
- topicConsumer = topicConsumerSession.createConsumer(topic);
-
- consumerConnection.start();
- }
-
- public void tearDown() throws Exception
- {
- producerConnection.close();
- consumerConnection.close();
-
- ServerManagement.undeployQueue("Queue");
-
-
- super.tearDown();
- }
-
- public void messageOrderTestQueue() throws Exception
- {
- final int NUM_MESSAGES = 10;
-
- queueProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- Message m = queueProducerSession.createMessage();
- m.setIntProperty("count", i);
- queueProducer.send(m);
- }
-
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- Message m = queueConsumer.receive(3000);
- assertNotNull(m);
- int count = m.getIntProperty("count");
- assertEquals(i, count);
- }
-
- queueProducer.setDeliveryMode(DeliveryMode.PERSISTENT);
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- Message m = queueProducerSession.createMessage();
- m.setIntProperty("count2", i);
- queueProducer.send(m);
- }
-
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- Message m = queueConsumer.receive(3000);
- assertNotNull(m);
- int count = m.getIntProperty("count2");
- assertEquals(i, count);
- }
- }
-
- public void messageOrderTestTopic() throws Exception
- {
- final int NUM_MESSAGES = 10;
-
- topicProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- Message m = topicProducerSession.createMessage();
- m.setIntProperty("count", i);
- topicProducer.send(m);
- }
-
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- Message m = topicConsumer.receive(3000);
- assertNotNull(m);
- int count = m.getIntProperty("count");
- assertEquals(i, count);
- }
-
- topicProducer.setDeliveryMode(DeliveryMode.PERSISTENT);
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- Message m = topicProducerSession.createMessage();
- m.setIntProperty("count2", i);
- topicProducer.send(m);
- }
-
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- Message m = topicConsumer.receive(3000);
- assertNotNull(m);
- int count = m.getIntProperty("count2");
- assertEquals(i, count);
- }
- }
-
-
- public void testProperties() throws Exception
- {
- Message m1 = queueProducerSession.createMessage();
-
-
- //Some arbitrary values
- boolean myBool = true;
- byte myByte = 13;
- short myShort = 15321;
- int myInt = 0x71ab6c80;
- long myLong = 0x20bf1e3fb6fa31dfL;
- float myFloat = Float.MAX_VALUE - 23465;
- double myDouble = Double.MAX_VALUE - 72387633;
- String myString = "abcdef&^*&!^ghijkl";
-
- m1.setBooleanProperty("myBool", myBool);
- m1.setByteProperty("myByte", myByte);
- m1.setShortProperty("myShort", myShort);
- m1.setIntProperty("myInt", myInt);
- m1.setLongProperty("myLong", myLong);
- m1.setFloatProperty("myFloat", myFloat);
- m1.setDoubleProperty("myDouble", myDouble);
- m1.setStringProperty("myString", myString);
-
- m1.setObjectProperty("myBool", new Boolean(myBool));
- m1.setObjectProperty("myByte", new Byte(myByte));
- m1.setObjectProperty("myShort", new Short(myShort));
- m1.setObjectProperty("myInt", new Integer(myInt));
- m1.setObjectProperty("myLong", new Long(myLong));
- m1.setObjectProperty("myFloat", new Float(myFloat));
- m1.setObjectProperty("myDouble", new Double(myDouble));
- m1.setObjectProperty("myString", myString);
-
- try
- {
- m1.setObjectProperty("myIllegal", new Object());
- fail();
- }
- catch (javax.jms.MessageFormatException e)
- {}
-
-
- queueProducer.send(queue, m1);
-
- Message m2 = queueConsumer.receive(2000);
-
- assertNotNull(m2);
-
- assertEquals(myBool, m2.getBooleanProperty("myBool"));
- assertEquals(myByte, m2.getByteProperty("myByte"));
- assertEquals(myShort, m2.getShortProperty("myShort"));
- assertEquals(myInt, m2.getIntProperty("myInt"));
- assertEquals(myLong, m2.getLongProperty("myLong"));
- assertEquals(myFloat, m2.getFloatProperty("myFloat"), 0);
- assertEquals(myDouble, m2.getDoubleProperty("myDouble"), 0);
- assertEquals(myString, m2.getStringProperty("myString"));
-
-
- //Properties should now be read-only
- try
- {
- m2.setBooleanProperty("myBool", myBool);
- fail();
- }
- catch (MessageNotWriteableException e) {}
-
- try
- {
- m2.setByteProperty("myByte", myByte);
- fail();
- }
- catch (MessageNotWriteableException e) {}
-
- try
- {
- m2.setShortProperty("myShort", myShort);
- fail();
- }
- catch (MessageNotWriteableException e) {}
-
- try
- {
- m2.setIntProperty("myInt", myInt);
- fail();
- }
- catch (MessageNotWriteableException e) {}
-
- try
- {
- m2.setLongProperty("myLong", myLong);
- fail();
- }
- catch (MessageNotWriteableException e) {}
-
- try
- {
- m2.setFloatProperty("myFloat", myFloat);
- fail();
- }
- catch (MessageNotWriteableException e) {}
-
- try
- {
- m2.setDoubleProperty("myDouble", myDouble);
- fail();
- }
- catch (MessageNotWriteableException e) {}
-
- try
- {
- m2.setStringProperty("myString", myString);
- fail();
- }
- catch (MessageNotWriteableException e) {}
-
- assertTrue(m2.propertyExists("myBool"));
- assertTrue(m2.propertyExists("myByte"));
- assertTrue(m2.propertyExists("myShort"));
- assertTrue(m2.propertyExists("myInt"));
- assertTrue(m2.propertyExists("myLong"));
- assertTrue(m2.propertyExists("myFloat"));
- assertTrue(m2.propertyExists("myDouble"));
- assertTrue(m2.propertyExists("myString"));
-
- assertFalse(m2.propertyExists("sausages"));
-
- HashSet propNames = new HashSet();
- Enumeration en = m2.getPropertyNames();
- while (en.hasMoreElements())
- {
- String propName = (String)en.nextElement();
- propNames.add(propName);
- }
-
- assertEquals(8, propNames.size());
-
- assertTrue(propNames.contains("myBool"));
- assertTrue(propNames.contains("myByte"));
- assertTrue(propNames.contains("myShort"));
- assertTrue(propNames.contains("myInt"));
- assertTrue(propNames.contains("myLong"));
- assertTrue(propNames.contains("myFloat"));
- assertTrue(propNames.contains("myDouble"));
- assertTrue(propNames.contains("myString"));
-
-
- // Check property conversions
-
- //Boolean property can be read as String but not anything else
-
- assertEquals(String.valueOf(myBool), m2.getStringProperty("myBool"));
-
- try
- {
- m2.getByteProperty("myBool");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getShortProperty("myBool");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getIntProperty("myBool");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getLongProperty("myBool");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getFloatProperty("myBool");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getDoubleProperty("myBool");
- fail();
- } catch (MessageFormatException e) {}
-
-
- // byte property can be read as short, int, long or String
-
- assertEquals((short)myByte, m2.getShortProperty("myByte"));
- assertEquals((int)myByte, m2.getIntProperty("myByte"));
- assertEquals((long)myByte, m2.getLongProperty("myByte"));
- assertEquals(String.valueOf(myByte), m2.getStringProperty("myByte"));
-
- try
- {
- m2.getBooleanProperty("myByte");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getFloatProperty("myByte");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getDoubleProperty("myByte");
- fail();
- } catch (MessageFormatException e) {}
-
-
- // short property can be read as int, long or String
-
- assertEquals((int)myShort, m2.getIntProperty("myShort"));
- assertEquals((long)myShort, m2.getLongProperty("myShort"));
- assertEquals(String.valueOf(myShort), m2.getStringProperty("myShort"));
-
- try
- {
- m2.getByteProperty("myShort");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getBooleanProperty("myShort");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getFloatProperty("myShort");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getDoubleProperty("myShort");
- fail();
- } catch (MessageFormatException e) {}
-
- // int property can be read as long or String
-
- assertEquals((long)myInt, m2.getLongProperty("myInt"));
- assertEquals(String.valueOf(myInt), m2.getStringProperty("myInt"));
-
- try
- {
- m2.getShortProperty("myInt");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getByteProperty("myInt");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getBooleanProperty("myInt");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getFloatProperty("myInt");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getDoubleProperty("myInt");
- fail();
- } catch (MessageFormatException e) {}
-
-
- // long property can be read as String
-
- assertEquals(String.valueOf(myLong), m2.getStringProperty("myLong"));
-
- try
- {
- m2.getIntProperty("myLong");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getShortProperty("myLong");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getByteProperty("myLong");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getBooleanProperty("myLong");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getFloatProperty("myLong");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getDoubleProperty("myLong");
- fail();
- } catch (MessageFormatException e) {}
-
-
- // float property can be read as double or String
-
- assertEquals(String.valueOf(myFloat), m2.getStringProperty("myFloat"));
- assertEquals((double)myFloat, m2.getDoubleProperty("myFloat"), 0);
-
- try
- {
- m2.getIntProperty("myFloat");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getShortProperty("myFloat");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getLongProperty("myFloat");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getByteProperty("myFloat");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getBooleanProperty("myFloat");
- fail();
- } catch (MessageFormatException e) {}
-
-
-
- // double property can be read as String
-
- assertEquals(String.valueOf(myDouble), m2.getStringProperty("myDouble"));
-
-
- try
- {
- m2.getFloatProperty("myDouble");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getIntProperty("myDouble");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getShortProperty("myDouble");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getByteProperty("myDouble");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getBooleanProperty("myDouble");
- fail();
- } catch (MessageFormatException e) {}
-
- try
- {
- m2.getFloatProperty("myDouble");
- fail();
- } catch (MessageFormatException e) {}
-
- m2.clearProperties();
-
- Enumeration en2 = m2.getPropertyNames();
- assertFalse(en2.hasMoreElements());
-
-
-
-
- // Test String -> Numeric and bool conversions
- Message m3 = queueProducerSession.createMessage();
-
- m3.setStringProperty("myBool", String.valueOf(myBool));
- m3.setStringProperty("myByte", String.valueOf(myByte));
- m3.setStringProperty("myShort", String.valueOf(myShort));
- m3.setStringProperty("myInt", String.valueOf(myInt));
- m3.setStringProperty("myLong", String.valueOf(myLong));
- m3.setStringProperty("myFloat", String.valueOf(myFloat));
- m3.setStringProperty("myDouble", String.valueOf(myDouble));
- m3.setStringProperty("myIllegal", "xyz123");
-
- assertEquals(myBool, m3.getBooleanProperty("myBool"));
- assertEquals(myByte, m3.getByteProperty("myByte"));
- assertEquals(myShort, m3.getShortProperty("myShort"));
- assertEquals(myInt, m3.getIntProperty("myInt"));
- assertEquals(myLong, m3.getLongProperty("myLong"));
- assertEquals(myFloat, m3.getFloatProperty("myFloat"), 0);
- assertEquals(myDouble, m3.getDoubleProperty("myDouble"), 0);
-
- m3.getBooleanProperty("myIllegal");
-
- try
- {
- m3.getByteProperty("myIllegal");
- fail();
- }
- catch (NumberFormatException e) {}
- try
- {
- m3.getShortProperty("myIllegal");
- fail();
- }
- catch (NumberFormatException e) {}
- try
- {
- m3.getIntProperty("myIllegal");
- fail();
- }
- catch (NumberFormatException e) {}
- try
- {
- m3.getLongProperty("myIllegal");
- fail();
- }
- catch (NumberFormatException e) {}
- try
- {
- m3.getFloatProperty("myIllegal");
- fail();
- }
- catch (NumberFormatException e) {}
- try
- {
- m3.getDoubleProperty("myIllegal");
- fail();
- }
- catch (NumberFormatException e) {}
- }
-
-
-
- public void testSendReceiveForeignMessage() throws JMSException
- {
-
- log.trace("Starting da test");
-
- SimpleJMSMessage foreignMessage = new SimpleJMSMessage();
-
- foreignMessage.setStringProperty("animal", "aardvark");
-
- //foreign messages don't have to be serializable
- assertFalse(foreignMessage instanceof Serializable);
-
- log.trace("Sending message");
-
- queueProducer.send(foreignMessage);
-
- log.trace("Sent message");
-
- Message m2 = queueConsumer.receive(3000);
- log.trace("The message is " + m2);
-
- assertNotNull(m2);
-
- assertEquals("aardvark", m2.getStringProperty("animal"));
-
- log.trace("Received message");
-
- log.trace("Done that test");
- }
-
- public void testCopyOnJBossMessage() throws JMSException
- {
- JBossMessage jbossMessage = ((MessageProxy)queueProducerSession.createMessage()).getMessage();
-
- configureMessage(jbossMessage);
-
- JBossMessage copy = new JBossMessage(jbossMessage, 0);
-
- ensureEquivalent(jbossMessage, copy);
- }
-
-
- public void testCopyOnForeignMessage() throws JMSException
- {
- Message foreignMessage = new SimpleJMSMessage();
-
- JBossMessage copy = new JBossMessage(foreignMessage, 0);
-
- ensureEquivalent(foreignMessage, copy);
- }
-
-
- public void testCopyOnJBossBytesMessage() throws JMSException
- {
- JBossBytesMessage jbossBytesMessage = (JBossBytesMessage)(((MessageProxy)queueProducerSession.
- createBytesMessage()).getMessage());
-
- for(int i = 0; i < 20; i++)
- {
- jbossBytesMessage.writeByte((byte)i);
- }
-
-
- jbossBytesMessage.reset();
- JBossBytesMessage copy = new JBossBytesMessage(jbossBytesMessage);
-
- copy.reset();
-
- ensureEquivalent(jbossBytesMessage, copy);
- }
-
-
- public void testCopyOnForeignBytesMessage() throws JMSException
- {
- BytesMessage foreignBytesMessage = new SimpleJMSBytesMessage();
- for(int i = 0; i < 20; i++)
- {
- foreignBytesMessage.writeByte((byte)i);
- }
-
- JBossBytesMessage copy = new JBossBytesMessage(foreignBytesMessage, 0);
-
- foreignBytesMessage.reset();
- copy.reset();
-
- ensureEquivalent(foreignBytesMessage, copy);
- }
-
- public void testCopyOnJBossMapMessage() throws JMSException
- {
- JBossMapMessage jbossMapMessage = (JBossMapMessage)(((MessageProxy)queueProducerSession.
- createMapMessage()).getMessage());
-
- jbossMapMessage.setInt("int", 1);
- jbossMapMessage.setString("string", "test");
-
- JBossMapMessage copy = new JBossMapMessage((JBossMapMessage)jbossMapMessage);
-
- ensureEquivalent(jbossMapMessage, copy);
- }
-
-
- public void testCopyOnForeignMapMessage() throws JMSException
- {
- MapMessage foreignMapMessage = new SimpleJMSMapMessage();
- foreignMapMessage.setInt("int", 1);
- foreignMapMessage.setString("string", "test");
-
- JBossMapMessage copy = new JBossMapMessage(foreignMapMessage, 0);
-
- ensureEquivalent(foreignMapMessage, copy);
- }
-
-
- public void testCopyOnJBossObjectMessage() throws JMSException
- {
- JBossObjectMessage jbossObjectMessage = (JBossObjectMessage)
- (((MessageProxy)queueProducerSession.createObjectMessage()).getMessage());
-
- JBossObjectMessage copy = new JBossObjectMessage(jbossObjectMessage);
-
- ensureEquivalent(jbossObjectMessage, copy);
- }
-
-
- public void testCopyOnForeignObjectMessage() throws JMSException
- {
- ObjectMessage foreignObjectMessage = new SimpleJMSObjectMessage();
-
- JBossObjectMessage copy = new JBossObjectMessage(foreignObjectMessage, 0);
-
- ensureEquivalent(foreignObjectMessage, copy);
- }
-
-
- public void testCopyOnJBossStreamMessage() throws JMSException
- {
- JBossStreamMessage jbossStreamMessage = (JBossStreamMessage)
- (((MessageProxy)queueProducerSession.createStreamMessage()).getMessage());
-
- jbossStreamMessage.writeByte((byte)1);
- jbossStreamMessage.writeByte((byte)2);
- jbossStreamMessage.writeByte((byte)3);
-
- JBossStreamMessage copy = new JBossStreamMessage((JBossStreamMessage)jbossStreamMessage);
-
- ensureEquivalent(jbossStreamMessage, copy);
- }
-
-
- public void testCopyOnForeignStreamMessage() throws JMSException
- {
- StreamMessage foreignStreamMessage = new SimpleJMSStreamMessage();
- foreignStreamMessage.writeByte((byte)1);
- foreignStreamMessage.writeByte((byte)2);
- foreignStreamMessage.writeByte((byte)3);
-
- JBossStreamMessage copy = new JBossStreamMessage(foreignStreamMessage, 0);
-
- ensureEquivalent(foreignStreamMessage, copy);
- }
-
-
- public void testCopyOnJBossTextMessage() throws JMSException
- {
- JBossTextMessage jbossTextMessage = (JBossTextMessage)
- (((MessageProxy)queueProducerSession.createTextMessage()).getMessage());
-
- JBossTextMessage copy = new JBossTextMessage(jbossTextMessage);
-
- ensureEquivalent(jbossTextMessage, copy);
- }
-
-
- public void testCopyOnForeignTextMessage() throws JMSException
- {
- TextMessage foreignTextMessage = new SimpleJMSTextMessage();
-
- JBossTextMessage copy = new JBossTextMessage(foreignTextMessage, 0);
-
- ensureEquivalent(foreignTextMessage, copy);
- }
-
- public void testForeignJMSDestination() throws JMSException
- {
- Message message = queueProducerSession.createMessage();
-
- Destination foreignDestination = new ForeignDestination();
-
- message.setJMSDestination(foreignDestination);
-
- assertSame(foreignDestination, message.getJMSDestination());
-
- queueProducer.send(message);
-
- assertSame(queue, message.getJMSDestination());
-
- Message receivedMessage = queueConsumer.receive(2000);
-
- ensureEquivalent(receivedMessage, ((MessageProxy) message).getMessage());
- }
-
- public void testForeignJMSReplyTo() throws JMSException
- {
- JBossMessage jbossMessage = ((MessageProxy) queueProducerSession.createTextMessage()).getMessage();
-
- Destination foreignDestination = new ForeignDestination();
-
- jbossMessage.setJMSReplyTo(foreignDestination);
-
- queueProducer.send(jbossMessage);
-
- Message receivedMessage = queueConsumer.receive(2000);
-
- ensureEquivalent(receivedMessage, jbossMessage);
- }
-
- public void testCopyForeignDestinationAndReplyTo() throws JMSException
- {
- Message foreignMessage = new SimpleJMSMessage();
- foreignMessage.setJMSDestination(new ForeignDestination());
- foreignMessage.setJMSReplyTo(new ForeignDestination());
-
- JBossMessage copy = new JBossMessage(foreignMessage, 0);
-
- ensureEquivalent(foreignMessage, copy);
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
- private static class ForeignDestination implements Destination, Serializable
- {
- // A ForeignDestination equals any other ForeignDestination, for simplicity
- public boolean equals(Object obj)
- {
- return obj instanceof ForeignDestination;
- }
-
- public int hashCode()
- {
- return 157;
- }
- }
-
-}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/MessageTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/MessageTestBase.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/MessageTestBase.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -22,20 +22,14 @@
package org.jboss.test.messaging.jms.message;
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
-import javax.jms.Queue;
import javax.jms.Session;
-import javax.jms.Topic;
-import javax.naming.InitialContext;
-import org.jboss.jms.client.JBossConnectionFactory;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
+import org.jboss.test.messaging.jms.JMSTestCase;
/**
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
@@ -43,7 +37,7 @@
*
* $Id$
*/
-public class MessageTestBase extends MessagingTestCase
+public class MessageTestBase extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -53,16 +47,14 @@
protected Message message;
- protected ConnectionFactory connFactory;
protected Connection conn;
+
protected Session session;
+
protected MessageProducer queueProd;
+
protected MessageConsumer queueCons;
-
- protected Queue queue;
- protected Topic topic;
-
-
+
// Constructors --------------------------------------------------
public MessageTestBase(String name)
@@ -76,38 +68,20 @@
{
super.setUp();
- ServerManagement.start("all");
-
- InitialContext ic = new InitialContext(ServerManagement.getJNDIEnvironment());
- connFactory = (JBossConnectionFactory)ic.lookup("/ConnectionFactory");
-
- conn = connFactory.createConnection();
+ conn = cf.createConnection();
session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ queueProd = session.createProducer(queue1);
+ queueCons = session.createConsumer(queue1);
- ServerManagement.undeployQueue("Queue");
- ServerManagement.deployQueue("Queue");
- queue = (Queue)ic.lookup("/queue/Queue");
-
- ServerManagement.undeployTopic("Topic");
- ServerManagement.deployTopic("Topic");
- topic = (Topic)ic.lookup("/topic/Topic");
-
- queueProd = session.createProducer(queue);
- queueCons = session.createConsumer(queue);
-
conn.start();
-
- ic.close();
}
public void tearDown() throws Exception
{
- conn.close();
-
- ServerManagement.undeployQueue("Queue");
- ServerManagement.undeployTopic("Topic");
-
super.tearDown();
+
+ conn.close();
}
public void testNonPersistentSend() throws Exception
@@ -162,7 +136,7 @@
m.setStringProperty("stringProperty", "this is a String property");
m.setJMSCorrelationID("this is the correlation ID");
- m.setJMSReplyTo(topic);
+ m.setJMSReplyTo(topic1);
m.setJMSType("someArbitraryType");
}
@@ -178,9 +152,9 @@
assertEquals("this is a String property", m.getStringProperty("stringProperty"));
assertEquals("this is the correlation ID", m.getJMSCorrelationID());
- assertEquals(topic, m.getJMSReplyTo());
+ assertEquals(topic1, m.getJMSReplyTo());
assertEquals("someArbitraryType", m.getJMSType());
- assertEquals(queue, m.getJMSDestination());
+ assertEquals(queue1, m.getJMSDestination());
assertFalse(m.getJMSRedelivered());
assertEquals(mode, m.getJMSDeliveryMode());
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/ObjectMessageDeliveryTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/ObjectMessageDeliveryTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/ObjectMessageDeliveryTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -25,17 +25,12 @@
import javax.jms.ObjectMessage;
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.InitialContext;
-import org.jboss.jms.client.JBossConnectionFactory;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
+import org.jboss.test.messaging.jms.JMSTestCase;
/**
@@ -48,7 +43,7 @@
* $Id$
*
*/
-public class ObjectMessageDeliveryTest extends MessagingTestCase
+public class ObjectMessageDeliveryTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -56,9 +51,6 @@
// Attributes ----------------------------------------------------
- protected InitialContext ic;
- protected TopicConnectionFactory cf;
-
// Constructors --------------------------------------------------
public ObjectMessageDeliveryTest(String name)
@@ -66,35 +58,7 @@
super(name);
}
- // TestCase overrides -------------------------------------------
-
- public void setUp() throws Exception
- {
- super.setUp();
-
- ServerManagement.start("all");
-
-
- ic = new InitialContext(ServerManagement.getJNDIEnvironment());
- cf = (JBossConnectionFactory)ic.lookup("/ConnectionFactory");
-
- ServerManagement.undeployTopic("TestTopic");
- ServerManagement.deployTopic("TestTopic");
-
- log.debug("setup done");
- }
-
- public void tearDown() throws Exception
- {
- ServerManagement.undeployTopic("TestTopic");
-
- super.tearDown();
-
- log.debug("tear down done");
- }
-
// Public --------------------------------------------------------
-
static class TestObject implements Serializable
{
@@ -107,15 +71,13 @@
*/
public void testTopic() throws Exception
{
- Topic topic = (Topic)ic.lookup("/topic/TestTopic");
-
TopicConnection conn = cf.createTopicConnection();
try
{
TopicSession s = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
- TopicPublisher publisher = s.createPublisher(topic);
- TopicSubscriber sub = s.createSubscriber(topic);
+ TopicPublisher publisher = s.createPublisher(topic1);
+ TopicSubscriber sub = s.createSubscriber(topic1);
conn.start();
//Create 3 object messages with different bodies
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/foreign/ForeignBytesMessageTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/foreign/ForeignBytesMessageTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/foreign/ForeignBytesMessageTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -41,19 +41,9 @@
{
public ForeignBytesMessageTest(String name)
{
- super(name);
+ super(name);
}
- public void setUp() throws Exception
- {
- super.setUp();
- }
-
- public void tearDown() throws Exception
- {
- super.tearDown();
- }
-
protected Message createForeignMessage() throws Exception
{
SimpleJMSBytesMessage m = new SimpleJMSBytesMessage();
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/foreign/ForeignMapMessageTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/foreign/ForeignMapMessageTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/foreign/ForeignMapMessageTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -39,23 +39,13 @@
*/
public class ForeignMapMessageTest extends ForeignMessageTest
{
- private String obj = new String("stringobject");
+ private String obj = new String("stringobject");
public ForeignMapMessageTest(String name)
{
super(name);
}
- public void setUp() throws Exception
- {
- super.setUp();
- }
-
- public void tearDown() throws Exception
- {
- super.tearDown();
- }
-
protected Message createForeignMessage() throws Exception
{
SimpleJMSMapMessage m = new SimpleJMSMapMessage();
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/foreign/ForeignStreamMessageTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/foreign/ForeignStreamMessageTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/foreign/ForeignStreamMessageTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -45,16 +45,6 @@
super(name);
}
- public void setUp() throws Exception
- {
- super.setUp();
- }
-
- public void tearDown() throws Exception
- {
- super.tearDown();
- }
-
protected Message createForeignMessage() throws Exception
{
SimpleJMSStreamMessage m = new SimpleJMSStreamMessage();
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/foreign/ForeignTextMessageTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/foreign/ForeignTextMessageTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/foreign/ForeignTextMessageTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -45,16 +45,6 @@
super(name);
}
- public void setUp() throws Exception
- {
- super.setUp();
- }
-
- public void tearDown() throws Exception
- {
- super.tearDown();
- }
-
protected Message createForeignMessage() throws Exception
{
SimpleJMSTextMessage m = new SimpleJMSTextMessage();
Modified: trunk/tests/src/org/jboss/test/messaging/jms/selector/SelectorTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/selector/SelectorTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/jms/selector/SelectorTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -21,23 +21,19 @@
*/
package org.jboss.test.messaging.jms.selector;
-import org.jboss.test.messaging.tools.ServerManagement;
-import org.jboss.test.messaging.MessagingTestCase;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
import javax.jms.Connection;
-import javax.jms.Session;
-import javax.jms.MessageProducer;
-import javax.jms.MessageConsumer;
-import javax.jms.Queue;
-import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.Message;
-import javax.jms.Topic;
-import javax.naming.InitialContext;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Iterator;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import org.jboss.test.messaging.jms.JMSTestCase;
+
import EDU.oswego.cs.dl.util.concurrent.Latch;
/**
@@ -46,7 +42,7 @@
*
* $Id$
*/
-public class SelectorTest extends MessagingTestCase
+public class SelectorTest extends JMSTestCase
{
// Constants -----------------------------------------------------
@@ -54,10 +50,6 @@
// Attributes ----------------------------------------------------
- protected ConnectionFactory cf;
- protected Queue queue;
- protected Topic topic;
-
// Constructors --------------------------------------------------
public SelectorTest(String name)
@@ -67,38 +59,6 @@
// Public --------------------------------------------------------
- public void setUp() throws Exception
- {
- super.setUp();
-
- ServerManagement.start("all");
-
-
- ServerManagement.undeployQueue("Queue");
- ServerManagement.deployQueue("Queue");
- ServerManagement.undeployTopic("Topic");
- ServerManagement.deployTopic("Topic");
-
-
- InitialContext ic = new InitialContext(ServerManagement.getJNDIEnvironment());
- cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
- queue = (Queue)ic.lookup("/queue/Queue");
- topic = (Topic)ic.lookup("/topic/Topic");
-
- log.debug("setup done");
- }
-
- public void tearDown() throws Exception
- {
- ServerManagement.undeployQueue("Queue");
-
- super.tearDown();
- }
-
-
- // Public --------------------------------------------------------
-
-
/**
* Test case for http://jira.jboss.org/jira/browse/JBMESSAGING-105
*
@@ -109,148 +69,178 @@
*/
public void testSelectiveClosingConsumer() throws Exception
{
- Connection conn = cf.createConnection();
- conn.start();
-
- Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = session.createProducer(queue);
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-
- String selector = "color = 'red'";
- MessageConsumer redConsumer = session.createConsumer(queue, selector);
- conn.start();
-
- Message redMessage = session.createMessage();
- redMessage.setStringProperty("color", "red");
-
- Message blueMessage = session.createMessage();
- blueMessage.setStringProperty("color", "blue");
-
- prod.send(redMessage);
- prod.send(blueMessage);
-
- Message rec = redConsumer.receive();
- assertEquals(redMessage.getJMSMessageID(), rec.getJMSMessageID());
- assertEquals("red", rec.getStringProperty("color"));
-
- assertNull(redConsumer.receive(3000));
-
- redConsumer.close();
-
- MessageConsumer universalConsumer = session.createConsumer(queue);
-
- rec = universalConsumer.receive();
-
- assertEquals(rec.getJMSMessageID(), blueMessage.getJMSMessageID());
- assertEquals("blue", rec.getStringProperty("color"));
-
- session.close();
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+ conn.start();
+
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer prod = session.createProducer(queue1);
+ prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ String selector = "color = 'red'";
+ MessageConsumer redConsumer = session.createConsumer(queue1, selector);
+ conn.start();
+
+ Message redMessage = session.createMessage();
+ redMessage.setStringProperty("color", "red");
+
+ Message blueMessage = session.createMessage();
+ blueMessage.setStringProperty("color", "blue");
+
+ prod.send(redMessage);
+ prod.send(blueMessage);
+
+ Message rec = redConsumer.receive();
+ assertEquals(redMessage.getJMSMessageID(), rec.getJMSMessageID());
+ assertEquals("red", rec.getStringProperty("color"));
+
+ assertNull(redConsumer.receive(3000));
+
+ redConsumer.close();
+
+ MessageConsumer universalConsumer = session.createConsumer(queue1);
+
+ rec = universalConsumer.receive();
+
+ assertEquals(rec.getJMSMessageID(), blueMessage.getJMSMessageID());
+ assertEquals("blue", rec.getStringProperty("color"));
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void testManyTopic() throws Exception
{
String selector1 = "beatle = 'john'";
- Connection conn = cf.createConnection();
- conn.start();
-
- Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer cons1 = sess.createConsumer(topic, selector1);
-
- MessageProducer prod = sess.createProducer(topic);
-
- for (int j = 0; j < 100; j++)
- {
- Message m = sess.createMessage();
-
- m.setStringProperty("beatle", "john");
-
- prod.send(m);
-
- m = sess.createMessage();
-
- m.setStringProperty("beatle", "kermit the frog");
-
- prod.send(m);
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+ conn.start();
+
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer cons1 = sess.createConsumer(topic1, selector1);
+
+ MessageProducer prod = sess.createProducer(topic1);
+
+ for (int j = 0; j < 100; j++)
+ {
+ Message m = sess.createMessage();
+
+ m.setStringProperty("beatle", "john");
+
+ prod.send(m);
+
+ m = sess.createMessage();
+
+ m.setStringProperty("beatle", "kermit the frog");
+
+ prod.send(m);
+ }
+
+ for (int j = 0; j < 100; j++)
+ {
+ Message m = cons1.receive(1000);
+
+ assertNotNull(m);
+ }
+
+ Thread.sleep(500);
+
+ Message m = cons1.receiveNoWait();
+
+ assertNull(m);
}
-
- for (int j = 0; j < 100; j++)
+ finally
{
- Message m = cons1.receive(1000);
-
- assertNotNull(m);
+ if (conn != null)
+ {
+ conn.close();
+ }
}
-
- Thread.sleep(500);
-
- Message m = cons1.receiveNoWait();
-
- assertNull(m);
-
- sess.close();
}
public void testManyQueue() throws Exception
{
String selector1 = "beatle = 'john'";
- Connection conn = cf.createConnection();
- conn.start();
-
- Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer cons1 = sess.createConsumer(queue, selector1);
-
- MessageProducer prod = sess.createProducer(queue);
-
- for (int j = 0; j < 100; j++)
- {
- Message m = sess.createMessage();
-
- m.setStringProperty("beatle", "john");
-
- prod.send(m);
-
- m = sess.createMessage();
-
- m.setStringProperty("beatle", "kermit the frog");
-
- prod.send(m);
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+ conn.start();
+
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer cons1 = sess.createConsumer(queue1, selector1);
+
+ MessageProducer prod = sess.createProducer(queue1);
+
+ for (int j = 0; j < 100; j++)
+ {
+ Message m = sess.createMessage();
+
+ m.setStringProperty("beatle", "john");
+
+ prod.send(m);
+
+ m = sess.createMessage();
+
+ m.setStringProperty("beatle", "kermit the frog");
+
+ prod.send(m);
+ }
+
+ for (int j = 0; j < 100; j++)
+ {
+ Message m = cons1.receive(1000);
+
+ assertNotNull(m);
+
+ assertEquals("john", m.getStringProperty("beatle"));
+ }
+
+ Message m = cons1.receiveNoWait();
+
+ assertNull(m);
+
+ String selector2 = "beatle = 'kermit the frog'";
+
+ MessageConsumer cons2 = sess.createConsumer(queue1, selector2);
+
+ for (int j = 0; j < 100; j++)
+ {
+ m = cons2.receive(1000);
+
+ assertNotNull(m);
+
+ assertEquals("kermit the frog", m.getStringProperty("beatle"));
+ }
+
+ m = cons2.receiveNoWait();
+
+ assertNull(m);
}
-
- for (int j = 0; j < 100; j++)
+ finally
{
- Message m = cons1.receive(1000);
-
- assertNotNull(m);
-
- assertEquals("john", m.getStringProperty("beatle"));
+ if (conn != null)
+ {
+ conn.close();
+ }
}
- Message m = cons1.receive(1000);
-
- assertNull(m);
-
- String selector2 = "beatle = 'kermit the frog'";
-
- MessageConsumer cons2 = sess.createConsumer(queue, selector2);
-
- for (int j = 0; j < 100; j++)
- {
- m = cons2.receive(1000);
-
- assertNotNull(m);
-
- assertEquals("kermit the frog", m.getStringProperty("beatle"));
- }
-
- m = cons2.receive(1000);
-
- assertNull(m);
-
-
- sess.close();
}
// http://jira.jboss.org/jira/browse/JBMESSAGING-775
@@ -259,133 +249,151 @@
{
String selector1 = "beatle = 'john'";
- Connection conn = cf.createConnection();
- conn.start();
-
- Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- int NUM_MESSAGES = 2;
-
- MessageProducer prod = sess.createProducer(queue);
-
- for (int j = 0; j < NUM_MESSAGES; j++)
- {
- Message m = sess.createMessage();
-
- m.setStringProperty("beatle", "john");
-
- prod.setTimeToLive(0);
-
- prod.send(m);
-
- m = sess.createMessage();
-
- m.setStringProperty("beatle", "john");
-
- prod.setTimeToLive(1);
-
- prod.send(m);
-
- m = sess.createMessage();
-
- m.setStringProperty("beatle", "kermit the frog");
-
- prod.setTimeToLive(0);
-
- prod.send(m);
-
- m = sess.createMessage();
-
- m.setStringProperty("beatle", "kermit the frog");
-
- m.setJMSExpiration(System.currentTimeMillis());
-
- prod.setTimeToLive(1);
-
- prod.send(m);
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+ conn.start();
+
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ int NUM_MESSAGES = 2;
+
+ MessageProducer prod = sess.createProducer(queue1);
+
+ for (int j = 0; j < NUM_MESSAGES; j++)
+ {
+ Message m = sess.createMessage();
+
+ m.setStringProperty("beatle", "john");
+
+ prod.setTimeToLive(0);
+
+ prod.send(m);
+
+ m = sess.createMessage();
+
+ m.setStringProperty("beatle", "john");
+
+ prod.setTimeToLive(1);
+
+ prod.send(m);
+
+ m = sess.createMessage();
+
+ m.setStringProperty("beatle", "kermit the frog");
+
+ prod.setTimeToLive(0);
+
+ prod.send(m);
+
+ m = sess.createMessage();
+
+ m.setStringProperty("beatle", "kermit the frog");
+
+ m.setJMSExpiration(System.currentTimeMillis());
+
+ prod.setTimeToLive(1);
+
+ prod.send(m);
+ }
+
+ MessageConsumer cons1 = sess.createConsumer(queue1, selector1);
+
+ for (int j = 0; j < NUM_MESSAGES; j++)
+ {
+ Message m = cons1.receive(1000);
+
+ assertNotNull(m);
+
+ assertEquals("john", m.getStringProperty("beatle"));
+ }
+
+ Message m = cons1.receiveNoWait();
+
+ assertNull(m);
+
+ String selector2 = "beatle = 'kermit the frog'";
+
+ MessageConsumer cons2 = sess.createConsumer(queue1, selector2);
+
+ for (int j = 0; j < NUM_MESSAGES; j++)
+ {
+ m = cons2.receive(1000);
+
+ assertNotNull(m);
+
+ assertEquals("kermit the frog", m.getStringProperty("beatle"));
+ }
+
+ m = cons1.receiveNoWait();
+
+ assertNull(m);
}
-
- Thread.sleep(2000);
-
- MessageConsumer cons1 = sess.createConsumer(queue, selector1);
-
- for (int j = 0; j < NUM_MESSAGES; j++)
+ finally
{
- Message m = cons1.receive(1000);
-
- assertNotNull(m);
-
- assertEquals("john", m.getStringProperty("beatle"));
+ if (conn != null)
+ {
+ conn.close();
+ }
}
-
- Message m = cons1.receive(1000);
-
- assertNull(m);
-
- String selector2 = "beatle = 'kermit the frog'";
-
- MessageConsumer cons2 = sess.createConsumer(queue, selector2);
-
- for (int j = 0; j < NUM_MESSAGES; j++)
- {
- m = cons2.receive(1000);
-
- assertNotNull(m);
-
- assertEquals("kermit the frog", m.getStringProperty("beatle"));
- }
-
- m = cons2.receive(1000);
-
- assertNull(m);
-
-
- sess.close();
}
public void testManyRedeliveriesTopic() throws Exception
{
String selector1 = "beatle = 'john'";
- Connection conn = cf.createConnection();
- conn.start();
-
- for (int i = 0; i < 30; i++)
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+ conn.start();
+
+ for (int i = 0; i < 5; i++)
+ {
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer cons1 = sess.createConsumer(topic1, selector1);
+
+ MessageProducer prod = sess.createProducer(topic1);
+
+ for (int j = 0; j < 10; j++)
+ {
+ Message m = sess.createMessage();
+
+ m.setStringProperty("beatle", "john");
+
+ prod.send(m);
+
+ m = sess.createMessage();
+
+ m.setStringProperty("beatle", "kermit the frog");
+
+ prod.send(m);
+ }
+
+ for (int j = 0; j < 10; j++)
+ {
+ Message m = cons1.receive(1000);
+
+ assertNotNull(m);
+ }
+
+ Message m = cons1.receiveNoWait();
+
+ assertNull(m);
+
+ sess.close();
+ }
+ }
+ finally
{
- Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer cons1 = sess.createConsumer(topic, selector1);
-
- MessageProducer prod = sess.createProducer(topic);
-
- for (int j = 0; j < 10; j++)
- {
- Message m = sess.createMessage();
-
- m.setStringProperty("beatle", "john");
-
- prod.send(m);
-
- m = sess.createMessage();
-
- m.setStringProperty("beatle", "kermit the frog");
-
- prod.send(m);
- }
-
- for (int j = 0; j < 10; j++)
- {
- Message m = cons1.receive(1000);
-
- assertNotNull(m);
- }
-
- Message m = cons1.receiveNoWait();
-
- assertNull(m);
-
- sess.close();
-
+ if (conn != null)
+ {
+ conn.close();
+ }
}
}
@@ -393,48 +401,60 @@
{
String selector1 = "beatle = 'john'";
- Connection conn = cf.createConnection();
- conn.start();
-
- for (int i = 0; i < 30; i++)
+ Connection conn = null;
+
+ try
{
- Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer cons1 = sess.createConsumer(queue, selector1);
-
- MessageProducer prod = sess.createProducer(queue);
-
- for (int j = 0; j < 10; j++)
- {
- Message m = sess.createMessage();
-
- m.setStringProperty("beatle", "john");
-
- prod.send(m);
-
- m = sess.createMessage();
-
- m.setStringProperty("beatle", "kermit the frog");
-
- prod.send(m);
- }
-
- for (int j = 0; j < 10; j++)
- {
- Message m = cons1.receive(1000);
-
- assertNotNull(m);
- }
-
- Message m = cons1.receiveNoWait();
-
- assertNull(m);
-
- sess.close();
-
+ conn = cf.createConnection();
+
+ conn.start();
+
+ for (int i = 0; i < 5; i++)
+ {
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer cons1 = sess.createConsumer(queue1, selector1);
+
+ MessageProducer prod = sess.createProducer(queue1);
+
+ for (int j = 0; j < 10; j++)
+ {
+ Message m = sess.createMessage();
+
+ m.setStringProperty("beatle", "john");
+
+ prod.send(m);
+
+ m = sess.createMessage();
+
+ m.setStringProperty("beatle", "kermit the frog");
+
+ prod.send(m);
+ }
+
+ for (int j = 0; j < 10; j++)
+ {
+ Message m = cons1.receive(1000);
+
+ assertNotNull(m);
+ }
+
+ Message m = cons1.receiveNoWait();
+
+ assertNull(m);
+
+ sess.close();
+ }
}
-
- super.drainDestination(cf, queue);
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+
+ removeAllMessages(queue1.getQueueName(), true, 0);
+ }
}
public void testWithSelector() throws Exception
@@ -445,174 +465,192 @@
String selector4 = "beatle = 'ringo'";
String selector5 = "beatle = 'jesus'";
- Connection conn = cf.createConnection();
- conn.start();
- Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons1 = sess.createConsumer(topic, selector1);
- MessageConsumer cons2 = sess.createConsumer(topic, selector2);
- MessageConsumer cons3 = sess.createConsumer(topic, selector3);
- MessageConsumer cons4 = sess.createConsumer(topic, selector4);
- MessageConsumer cons5 = sess.createConsumer(topic, selector5);
-
- Message m1 = sess.createMessage();
- m1.setStringProperty("beatle", "john");
-
- Message m2 = sess.createMessage();
- m2.setStringProperty("beatle", "paul");
-
- Message m3 = sess.createMessage();
- m3.setStringProperty("beatle", "george");
-
- Message m4 = sess.createMessage();
- m4.setStringProperty("beatle", "ringo");
-
- Message m5 = sess.createMessage();
- m5.setStringProperty("beatle", "jesus");
-
- MessageProducer prod = sess.createProducer(topic);
-
- prod.send(m1);
- prod.send(m2);
- prod.send(m3);
- prod.send(m4);
- prod.send(m5);
-
- Message r1 = cons1.receive(500);
- assertNotNull(r1);
- Message n = cons1.receive(500);
- assertNull(n);
-
- Message r2 = cons2.receive(500);
- assertNotNull(r2);
- n = cons2.receive(500);
- assertNull(n);
-
- Message r3 = cons3.receive(500);
- assertNotNull(r3);
- n = cons3.receive(500);
- assertNull(n);
-
- Message r4 = cons4.receive(500);
- assertNotNull(r4);
- n = cons4.receive(500);
- assertNull(n);
-
- Message r5 = cons5.receive(500);
- assertNotNull(r5);
- n = cons5.receive(500);
- assertNull(n);
-
- assertEquals("john", r1.getStringProperty("beatle"));
- assertEquals("paul", r2.getStringProperty("beatle"));
- assertEquals("george", r3.getStringProperty("beatle"));
- assertEquals("ringo", r4.getStringProperty("beatle"));
- assertEquals("jesus", r5.getStringProperty("beatle"));
-
- conn.close();
-
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+ conn.start();
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer cons1 = sess.createConsumer(topic1, selector1);
+ MessageConsumer cons2 = sess.createConsumer(topic1, selector2);
+ MessageConsumer cons3 = sess.createConsumer(topic1, selector3);
+ MessageConsumer cons4 = sess.createConsumer(topic1, selector4);
+ MessageConsumer cons5 = sess.createConsumer(topic1, selector5);
+
+ Message m1 = sess.createMessage();
+ m1.setStringProperty("beatle", "john");
+
+ Message m2 = sess.createMessage();
+ m2.setStringProperty("beatle", "paul");
+
+ Message m3 = sess.createMessage();
+ m3.setStringProperty("beatle", "george");
+
+ Message m4 = sess.createMessage();
+ m4.setStringProperty("beatle", "ringo");
+
+ Message m5 = sess.createMessage();
+ m5.setStringProperty("beatle", "jesus");
+
+ MessageProducer prod = sess.createProducer(topic1);
+
+ prod.send(m1);
+ prod.send(m2);
+ prod.send(m3);
+ prod.send(m4);
+ prod.send(m5);
+
+ Message r1 = cons1.receive(500);
+ assertNotNull(r1);
+ Message n = cons1.receive(500);
+ assertNull(n);
+
+ Message r2 = cons2.receive(500);
+ assertNotNull(r2);
+ n = cons2.receive(500);
+ assertNull(n);
+
+ Message r3 = cons3.receive(500);
+ assertNotNull(r3);
+ n = cons3.receive(500);
+ assertNull(n);
+
+ Message r4 = cons4.receive(500);
+ assertNotNull(r4);
+ n = cons4.receive(500);
+ assertNull(n);
+
+ Message r5 = cons5.receive(500);
+ assertNotNull(r5);
+ n = cons5.receive(500);
+ assertNull(n);
+
+ assertEquals("john", r1.getStringProperty("beatle"));
+ assertEquals("paul", r2.getStringProperty("beatle"));
+ assertEquals("george", r3.getStringProperty("beatle"));
+ assertEquals("ringo", r4.getStringProperty("beatle"));
+ assertEquals("jesus", r5.getStringProperty("beatle"));
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void testManyConsumersWithDifferentSelectors() throws Exception
{
- Connection conn = cf.createConnection();
- Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = sess.createProducer(queue);
-
- Session cs = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- final MessageConsumer c = cs.createConsumer(queue, "weight = 1");
-
- Session cs2 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- final MessageConsumer c2 = cs2.createConsumer(queue, "weight = 2");
-
- for(int i = 0; i < 10; i++)
- {
- Message m = sess.createTextMessage("message" + i);
- m.setIntProperty("weight", i % 2 + 1);
- p.send(m);
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer p = sess.createProducer(queue1);
+
+ Session cs = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ final MessageConsumer c = cs.createConsumer(queue1, "weight = 1");
+
+ Session cs2 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ final MessageConsumer c2 = cs2.createConsumer(queue1, "weight = 2");
+
+ for(int i = 0; i < 10; i++)
+ {
+ Message m = sess.createTextMessage("message" + i);
+ m.setIntProperty("weight", i % 2 + 1);
+ p.send(m);
+ }
+
+ conn.start();
+
+ final List received = new ArrayList();
+ final List received2 = new ArrayList();
+ final Latch latch = new Latch();
+ final Latch latch2 = new Latch();
+
+ new Thread(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ while(true)
+ {
+ Message m = c.receive(1000);
+ if (m != null)
+ {
+ received.add(m);
+ }
+ else
+ {
+ latch.release();
+ return;
+ }
+ }
+ }
+ catch(Exception e)
+ {
+ log.error("receive failed", e);
+ }
+ }
+ }, "consumer thread 1").start();
+
+ new Thread(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ while(true)
+ {
+ Message m = c2.receive(1000);
+ if (m != null)
+ {
+ received2.add(m);
+ }
+ else
+ {
+ latch2.release();
+ return;
+ }
+ }
+ }
+ catch(Exception e)
+ {
+ log.error("receive failed", e);
+ }
+ }
+ }, "consumer thread 2").start();
+
+ latch.acquire();
+ latch2.acquire();
+
+ assertEquals(5, received.size());
+ for(Iterator i = received.iterator(); i.hasNext(); )
+ {
+ Message m = (Message)i.next();
+ int value = m.getIntProperty("weight");
+ assertEquals(value, 1);
+ }
+
+ assertEquals(5, received2.size());
+ for(Iterator i = received2.iterator(); i.hasNext(); )
+ {
+ Message m = (Message)i.next();
+ int value = m.getIntProperty("weight");
+ assertEquals(value, 2);
+ }
}
-
- conn.start();
-
- final List received = new ArrayList();
- final List received2 = new ArrayList();
- final Latch latch = new Latch();
- final Latch latch2 = new Latch();
-
- new Thread(new Runnable()
+ finally
{
- public void run()
- {
- try
- {
- while(true)
- {
- Message m = c.receive(1000);
- if (m != null)
- {
- received.add(m);
- }
- else
- {
- latch.release();
- return;
- }
- }
- }
- catch(Exception e)
- {
- log.error("receive failed", e);
- }
- }
- }, "consumer thread 1").start();
-
- new Thread(new Runnable()
- {
- public void run()
- {
- try
- {
- while(true)
- {
- Message m = c2.receive(1000);
- if (m != null)
- {
- received2.add(m);
- }
- else
- {
- latch2.release();
- return;
- }
- }
- }
- catch(Exception e)
- {
- log.error("receive failed", e);
- }
- }
- }, "consumer thread 2").start();
-
- latch.acquire();
- latch2.acquire();
-
- assertEquals(5, received.size());
- for(Iterator i = received.iterator(); i.hasNext(); )
- {
- Message m = (Message)i.next();
- int value = m.getIntProperty("weight");
- assertEquals(value, 1);
+ if (conn != null)
+ {
+ conn.close();
+ }
}
-
- assertEquals(5, received2.size());
- for(Iterator i = received2.iterator(); i.hasNext(); )
- {
- Message m = (Message)i.next();
- int value = m.getIntProperty("weight");
- assertEquals(value, 2);
- }
-
-
- conn.close();
}
// Package protected ---------------------------------------------
Modified: trunk/tests/src/org/jboss/test/messaging/tools/ServerManagement.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/ServerManagement.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/tools/ServerManagement.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -64,6 +64,8 @@
public class ServerManagement
{
// Constants -----------------------------------------------------
+
+ public static int wibble = 0;
public static final int MAX_SERVER_COUNT = 10;
@@ -173,6 +175,9 @@
*/
public static void start(String config) throws Exception
{
+ wibble++;
+
+ log.info("*** wiblle is now " + wibble);
start(0, config, true);
}
@@ -324,6 +329,7 @@
*/
public static synchronized List destroySpawnedServers() throws Exception
{
+ log.info("################# Destroying spawned servers****");
List destroyed = new ArrayList();
for(int i = 0; i < servers.length; i++)
Modified: trunk/tests/src/org/jboss/test/messaging/tools/ant/JUnitTestSuiteListener.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/ant/JUnitTestSuiteListener.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/tools/ant/JUnitTestSuiteListener.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -6,18 +6,15 @@
*/
package org.jboss.test.messaging.tools.ant;
-import org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter;
-import org.apache.tools.ant.taskdefs.optional.junit.JUnitTest;
-import org.apache.tools.ant.BuildException;
-import org.jboss.test.messaging.tools.ServerManagement;
-
import java.io.OutputStream;
-import java.util.List;
-import java.util.Iterator;
-import junit.framework.Test;
import junit.framework.AssertionFailedError;
+import junit.framework.Test;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter;
+import org.apache.tools.ant.taskdefs.optional.junit.JUnitTest;
+
/**
* This class is a hack.
*
@@ -44,27 +41,27 @@
public void endTestSuite(JUnitTest suite) throws BuildException
{
- try
- {
- List destroyed = ServerManagement.destroySpawnedServers();
- if (destroyed.size() > 0)
- {
- StringBuffer sb = new StringBuffer("Destroyed spawned test servers ");
- for(Iterator i = destroyed.iterator(); i.hasNext();)
- {
- sb.append(i.next());
- if (i.hasNext())
- {
- sb.append(',');
- }
- }
- System.out.println(sb);
- }
- }
- catch(Throwable t)
- {
- t.printStackTrace();
- }
+// try
+// {
+// List destroyed = ServerManagement.destroySpawnedServers();
+// if (destroyed.size() > 0)
+// {
+// StringBuffer sb = new StringBuffer("Destroyed spawned test servers ");
+// for(Iterator i = destroyed.iterator(); i.hasNext();)
+// {
+// sb.append(i.next());
+// if (i.hasNext())
+// {
+// sb.append(',');
+// }
+// }
+// System.out.println(sb);
+// }
+// }
+// catch(Throwable t)
+// {
+// t.printStackTrace();
+// }
}
public void startTestSuite(JUnitTest suite) throws BuildException
Modified: trunk/tests/src/org/jboss/test/messaging/tools/jmx/ServiceContainer.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/jmx/ServiceContainer.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/tools/jmx/ServiceContainer.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -283,7 +283,14 @@
}
else if ("org.w3c.dom.Element".equals(type))
{
- return XMLUtil.stringToElement(valueAsString);
+ if (valueAsString == null)
+ {
+ return null;
+ }
+ else
+ {
+ return XMLUtil.stringToElement(valueAsString);
+ }
}
else if (type.startsWith("org.jboss."))
{
@@ -534,7 +541,8 @@
public void stop() throws Exception
{
-
+ log.info("Stopping serviceconatiner");
+
unloadJNDIContexts();
stopService(REMOTING_OBJECT_NAME);
@@ -568,11 +576,11 @@
{
initialContext.unbind(MockJBossSecurityManager.TEST_SECURITY_DOMAIN);
}
+
+ cleanJNDI();
initialContext.close();
- cleanJNDI();
-
if (jndiNamingFactory != null)
{
System.setProperty("java.naming.factory.initial", jndiNamingFactory);
@@ -1424,14 +1432,12 @@
private void cleanJNDI() throws Exception
{
- InitialContext ic = new InitialContext();
-
- for(Iterator i = toUnbindAtExit.iterator(); i.hasNext(); )
+ for (Iterator i = toUnbindAtExit.iterator(); i.hasNext(); )
{
String name = (String)i.next();
- ic.unbind(name);
+
+ initialContext.unbind(name);
}
- ic.close();
}
private void executeStatement(TransactionManager mgr, DataSource ds, String statement) throws Exception
Modified: trunk/tests/src/org/jboss/test/messaging/tools/misc/ConfigurableSecurityManager.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/misc/ConfigurableSecurityManager.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/tools/misc/ConfigurableSecurityManager.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -89,7 +89,7 @@
// Public ---------------------------------------------------------------------------------------
- public void dissalow(Class permissionClass, String action)
+ public void disallow(Class permissionClass, String action)
{
if (!Permission.class.isAssignableFrom(permissionClass))
{
Modified: trunk/tests/src/org/jboss/test/messaging/util/prioritylinkedlist/PriorityLinkedListTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/util/prioritylinkedlist/PriorityLinkedListTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/messaging/util/prioritylinkedlist/PriorityLinkedListTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -415,6 +415,7 @@
c++;
}
assertEquals(c, 26);
+ assertEquals(26, list.size());
iter = list.iterator();
assertTrue(iter.hasNext());
@@ -479,6 +480,8 @@
iter.remove();
+ assertEquals(25, list.size());
+
w = (Wibble)iter.next();
assertEquals("b", w.s);
w = (Wibble)iter.next();
@@ -488,6 +491,8 @@
iter.remove();
+ assertEquals(24, list.size());
+
w = (Wibble)iter.next();
assertEquals("e", w.s);
w = (Wibble)iter.next();
@@ -503,6 +508,8 @@
iter.remove();
+ assertEquals(23, list.size());
+
w = (Wibble)iter.next();
assertEquals("k", w.s);
w = (Wibble)iter.next();
Modified: trunk/tests/src/org/jboss/test/thirdparty/jbosssx/SecurityAssociationTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/thirdparty/jbosssx/SecurityAssociationTest.java 2007-07-24 00:09:28 UTC (rev 2924)
+++ trunk/tests/src/org/jboss/test/thirdparty/jbosssx/SecurityAssociationTest.java 2007-07-25 10:43:58 UTC (rev 2925)
@@ -21,26 +21,24 @@
*/
package org.jboss.test.thirdparty.jbosssx;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
-import org.jboss.test.messaging.tools.jmx.MockJBossSecurityManager;
-import org.jboss.security.SecurityAssociation;
-import org.jboss.security.SimplePrincipal;
+import java.security.Principal;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
-import javax.naming.InitialContext;
-import javax.jms.ConnectionFactory;
-import javax.jms.Queue;
import javax.jms.Connection;
-import javax.jms.Session;
-import javax.jms.MessageProducer;
import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
import javax.jms.TextMessage;
import javax.security.auth.Subject;
-import java.security.Principal;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Collections;
+import org.jboss.security.SecurityAssociation;
+import org.jboss.security.SimplePrincipal;
+import org.jboss.test.messaging.jms.JMSTestCase;
+import org.jboss.test.messaging.tools.ServerManagement;
+import org.jboss.test.messaging.tools.jmx.MockJBossSecurityManager;
+
/**
* Set of tests to insure consistent behavior relative to the JBoss AS security infrastructure.
* This is just a safety layer, full fledged security tests should be present in the integration
@@ -52,7 +50,7 @@
* @version <tt>$Revision$</tt>
* $Id$
*/
-public class SecurityAssociationTest extends MessagingTestCase
+public class SecurityAssociationTest extends JMSTestCase
{
// Constants ------------------------------------------------------------------------------------
@@ -60,8 +58,6 @@
// Attributes -----------------------------------------------------------------------------------
- private InitialContext ic;
-
// Constructors ---------------------------------------------------------------------------------
public SecurityAssociationTest(String name)
@@ -81,9 +77,6 @@
fail("This test is supposed to be run in a local configuration");
}
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
- Queue queue = (Queue)ic.lookup("/queue/TestQueue");
-
Principal nabopolassar = new SimplePrincipal("nabopolassar");
Set principals = new HashSet();
principals.add(nabopolassar);
@@ -102,8 +95,8 @@
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = session.createProducer(queue);
- MessageConsumer cons = session.createConsumer(queue);
+ MessageProducer prod = session.createProducer(queue1);
+ MessageConsumer cons = session.createConsumer(queue1);
TextMessage m = session.createTextMessage("floccinaucinihilipilification");
@@ -161,9 +154,6 @@
(MockJBossSecurityManager)ic.lookup(MockJBossSecurityManager.TEST_SECURITY_DOMAIN);
assertTrue(sm.isSimulateJBossJaasSecurityManager());
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
- Queue queue = (Queue)ic.lookup("/queue/SecureTestQueue");
-
Principal nabopolassar = new SimplePrincipal("nabopolassar");
Set principals = new HashSet();
principals.add(nabopolassar);
@@ -182,8 +172,8 @@
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = session.createProducer(queue);
- MessageConsumer cons = session.createConsumer(queue);
+ MessageProducer prod = session.createProducer(queue2);
+ MessageConsumer cons = session.createConsumer(queue2);
TextMessage m = session.createTextMessage("floccinaucinihilipilification");
@@ -240,9 +230,6 @@
(MockJBossSecurityManager)ic.lookup(MockJBossSecurityManager.TEST_SECURITY_DOMAIN);
assertTrue(sm.isSimulateJBossJaasSecurityManager());
- ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
- Queue queue = (Queue)ic.lookup("/queue/SecureTestQueue");
-
Principal nabopolassar = new SimplePrincipal("nabopolassar");
Set principals = new HashSet();
principals.add(nabopolassar);
@@ -261,8 +248,8 @@
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = session.createProducer(queue);
- MessageConsumer cons = session.createConsumer(queue);
+ MessageProducer prod = session.createProducer(queue2);
+ MessageConsumer cons = session.createConsumer(queue2);
TextMessage m = session.createTextMessage("floccinaucinihilipilification");
@@ -307,27 +294,19 @@
protected void setUp() throws Exception
{
- if(ServerManagement.isRemote())
+ if (ServerManagement.isRemote())
{
fail("This test is supposed to be run in a local configuration");
}
super.setUp();
-
- ServerManagement.start("all");
-
- ic = new InitialContext(ServerManagement.getJNDIEnvironment());
-
- ServerManagement.deployQueue("TestQueue");
-
- ServerManagement.deployQueue("SecureTestQueue");
-
+
final String secureQueueConfig =
"<security>" +
"<role name=\"publisher\" read=\"true\" write=\"true\" create=\"false\"/>" +
"<role name=\"guest\" read=\"true\" write=\"true\" create=\"false\"/>" +
"</security>";
- ServerManagement.configureSecurityForDestination("SecureTestQueue", secureQueueConfig);
+ ServerManagement.configureSecurityForDestination("Queue2", secureQueueConfig);
// make MockSecurityManager simulate JaasSecurityManager behavior. This is the whole point
// of this test, to catch JBoss AS integreation failure before the integration test suite
@@ -343,19 +322,15 @@
}
protected void tearDown() throws Exception
- {
- ServerManagement.undeployQueue("TestQueue");
-
- ServerManagement.undeployQueue("SecureTestQueue");
-
+ {
+ super.tearDown();
+
MockJBossSecurityManager sm =
(MockJBossSecurityManager)ic.lookup(MockJBossSecurityManager.TEST_SECURITY_DOMAIN);
sm.setSimulateJBossJaasSecurityManager(false);
- ic.close();
-
- super.tearDown();
+ ServerManagement.configureSecurityForDestination("Queue2", null);
}
// Private --------------------------------------------------------------------------------------
More information about the jboss-cvs-commits
mailing list