Author: jgomes
Date: Tue Dec 9 12:18:41 2008
New Revision: 724861
URL: http://svn.apache.org/viewvc?rev=724861&view=rev
Log:
Add new transaction tests to verify that an exception is thrown when attempting
to perform transaction functions on a non-transacted session.
Fixes [AMQNET-124]. (See https://issues.apache.org/activemq/browse/AMQNET-124)
Added:
activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/MessageSelectorTest.cs
Modified:
activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/SessionUtils.cs
activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs
activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/TransactionTest.cs
Modified:
activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/SessionUtils.cs
URL:
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/SessionUtils.cs?rev=724861&r1=724860&r2=724861&view=diff
==============================================================================
---
activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/SessionUtils.cs
(original)
+++
activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/SessionUtils.cs
Tue Dec 9 12:18:41 2008
@@ -131,6 +131,59 @@
{
return GetDestination(session, topicName,
DestinationType.Topic) as ITopic;
}
+
+ /// <summary>
+ /// Delete the named destination by parsing the embedded type
prefix. Default is Queue if no prefix is
+ /// embedded in the destinationName.
+ /// </summary>
+ /// <param name="session">Session object to use to get the
destination.</param>
+ /// <param name="destinationName">Name of destination with
embedded prefix. The embedded prefix can be one of the following:
+ /// <list type="bullet">
+ /// <item>queue://</item>
+ /// <item>topic://</item>
+ /// <item>temp-queue://</item>
+ /// <item>temp-topic://</item>
+ /// </list>
+ /// </param>
+ /// <returns></returns>
+ public static void DeleteDestination(ISession session, string
destinationName)
+ {
+ SessionUtil.DeleteDestination(session, destinationName,
DestinationType.Queue);
+ }
+
+ /// <summary>
+ /// Delete the named destination by parsing the embedded type
prefix.
+ /// </summary>
+ /// <param name="session">Session object to use to get the
destination.</param>
+ /// <param name="destinationName">Name of destination with
embedded prefix. The embedded prefix can be one of the following:
+ /// <list type="bullet">
+ /// <item>queue://</item>
+ /// <item>topic://</item>
+ /// <item>temp-queue://</item>
+ /// <item>temp-topic://</item>
+ /// </list>
+ /// </param>
+ /// <param name="defaultType">Default type if no embedded
prefix is specified.</param>
+ /// <returns></returns>
+ public static void DeleteDestination(ISession session, string
destinationName, DestinationType defaultType)
+ {
+ IDestination destination =
SessionUtil.GetDestination(session, destinationName, defaultType);
+
+ if(null != destination)
+ {
+ session.DeleteDestination(destination);
+ }
+ }
+
+ public static void DeleteQueue(ISession session, string
queueName)
+ {
+ DeleteDestination(session, queueName,
DestinationType.Queue);
+ }
+
+ public static void DeleteTopic(ISession session, string
topicName)
+ {
+ DeleteDestination(session, topicName,
DestinationType.Topic);
+ }
}
}
Added:
activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/MessageSelectorTest.cs
URL:
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/MessageSelectorTest.cs?rev=724861&view=auto
==============================================================================
---
activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/MessageSelectorTest.cs
(added)
+++
activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/MessageSelectorTest.cs
Tue Dec 9 12:18:41 2008
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using Apache.NMS.Util;
+using NUnit.Framework;
+using NUnit.Framework.Extensions;
+using System.Threading;
+
+namespace Apache.NMS.Test
+{
+ [TestFixture]
+ [Explicit]
+ public class MessageSelectorTest : NMSTestSupport
+ {
+ protected const string QUEUE_DESTINATION_NAME =
"queue://MessageSelectorQueue";
+ protected const string TOPIC_DESTINATION_NAME =
"topic://MessageSelectorTopic";
+ protected const string TEST_CLIENT_ID =
"MessageSelectorClientId";
+ protected const string TEST_CLIENT_ID2 =
"MessageSelectorClientId2";
+
+ private int receivedNonIgnoredMsgCount = 0;
+
+#if !NET_1_1
+ [RowTest]
+ [Row(true, QUEUE_DESTINATION_NAME)]
+ [Row(false, QUEUE_DESTINATION_NAME)]
+ [Row(true, TOPIC_DESTINATION_NAME)]
+ [Row(false, TOPIC_DESTINATION_NAME)]
+#endif
+ public void FilterIgnoredMessagesTest(bool persistent, string
destinationName)
+ {
+ using(IConnection connection1 =
CreateConnection(TEST_CLIENT_ID))
+ using(IConnection connection2 =
CreateConnection(TEST_CLIENT_ID2))
+ {
+ connection1.Start();
+ connection2.Start();
+ using(ISession session1 =
connection1.CreateSession(AcknowledgementMode.AutoAcknowledge))
+ using(ISession session2 =
connection2.CreateSession(AcknowledgementMode.AutoAcknowledge))
+ {
+ IDestination destination1 =
CreateDestination(session1, destinationName);
+ IDestination destination2 =
CreateDestination(session2, destinationName);
+
+ using(IMessageProducer producer =
session1.CreateProducer(destination1))
+ using(IMessageConsumer consumer =
session2.CreateConsumer(destination2, "JMSType NOT LIKE '%IGNORE'"))
+ {
+ const int MaxNumRequests =
100000;
+ int numNonIgnoredMsgsSent = 0;
+
+ producer.Persistent =
persistent;
+ // producer.RequestTimeout =
receiveTimeout;
+
+ receivedNonIgnoredMsgCount = 0;
+ consumer.Listener += new
MessageListener(OnNonIgnoredMessage);
+
+ for(int index = 1; index <=
MaxNumRequests; index++)
+ {
+ IMessage request =
session1.CreateTextMessage(String.Format("Hello World! [{0} of {1}]", index,
MaxNumRequests));
+
+ //request.NMSTimeToLive
= TimeSpan.FromSeconds(10);
+ if(0 == (index % 2))
+ {
+ request.NMSType
= "ACTIVE";
+
numNonIgnoredMsgsSent++;
+ }
+ else
+ {
+ request.NMSType
= "ACTIVE.IGNORE";
+ }
+
+ producer.Send(request);
+ }
+
+
while(receivedNonIgnoredMsgCount < numNonIgnoredMsgsSent)
+ {
+
Console.WriteLine("Waiting to receive all non-ignored messages...");
+ Thread.Sleep(1000);
+ }
+ }
+ }
+ }
+ }
+
+ protected void OnNonIgnoredMessage(IMessage message)
+ {
+ receivedNonIgnoredMsgCount++;
+ Assert.AreEqual(message.NMSType, "ACTIVE");
+ }
+ }
+}
Modified:
activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs
URL:
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs?rev=724861&r1=724860&r2=724861&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs
Tue Dec 9 12:18:41 2008
@@ -217,6 +217,18 @@
}
/// <summary>
+ /// Create a destination. This will delete an existing
destination and re-create it.
+ /// </summary>
+ /// <param name="session"></param>
+ /// <param name="destinationName"></param>
+ /// <returns></returns>
+ public virtual IDestination CreateDestination(ISession session,
string destinationName)
+ {
+ SessionUtil.DeleteDestination(session, destinationName);
+ return SessionUtil.GetDestination(session,
destinationName);
+ }
+
+ /// <summary>
/// Register a durable consumer
/// </summary>
/// <param name="connectionID">Connection ID of the
consumer.</param>
Modified:
activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/TransactionTest.cs
URL:
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/TransactionTest.cs?rev=724861&r1=724860&r2=724861&view=diff
==============================================================================
---
activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/TransactionTest.cs
(original)
+++
activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/TransactionTest.cs
Tue Dec 9 12:18:41 2008
@@ -42,7 +42,7 @@
connection.Start();
using(ISession session =
connection.CreateSession(AcknowledgementMode.Transactional))
{
- IDestination destination =
SessionUtil.GetDestination(session, DESTINATION_NAME);
+ IDestination destination =
CreateDestination(session, DESTINATION_NAME);
using(IMessageConsumer consumer =
session.CreateConsumer(destination))
using(IMessageProducer producer =
session.CreateProducer(destination))
{
@@ -90,7 +90,7 @@
connection1.Start();
using(ISession session1 =
connection1.CreateSession(AcknowledgementMode.Transactional))
{
- IDestination destination1 =
SessionUtil.GetDestination(session1, DESTINATION_NAME);
+ IDestination destination1 =
CreateDestination(session1, DESTINATION_NAME);
using(IMessageConsumer consumer =
session1.CreateConsumer(destination1))
{
// First connection session
that sends one message, and the
@@ -160,7 +160,7 @@
connection.Start();
using(ISession session =
connection.CreateSession(AcknowledgementMode.Transactional))
{
- IDestination destination =
SessionUtil.GetDestination(session, DESTINATION_NAME);
+ IDestination destination =
CreateDestination(session, DESTINATION_NAME);
using(IMessageConsumer consumer =
session.CreateConsumer(destination))
using(IMessageProducer producer =
session.CreateProducer(destination))
{
@@ -205,7 +205,7 @@
connection.Start();
using(ISession session =
connection.CreateSession(AcknowledgementMode.Transactional))
{
- IDestination destination =
SessionUtil.GetDestination(session, DESTINATION_NAME);
+ IDestination destination =
CreateDestination(session, DESTINATION_NAME);
using(IMessageConsumer consumer =
session.CreateConsumer(destination))
using(IMessageProducer producer =
session.CreateProducer(destination))
{
@@ -246,7 +246,6 @@
[Row(AcknowledgementMode.ClientAcknowledge, true)]
[Row(AcknowledgementMode.ClientAcknowledge, false)]
#endif
- [ExpectedException(typeof(InvalidOperationException))]
public void TestSendCommitNonTransaction(AcknowledgementMode
ackMode, bool persistent)
{
using(IConnection connection =
CreateConnection(TEST_CLIENT_ID))
@@ -254,7 +253,7 @@
connection.Start();
using(ISession session =
connection.CreateSession(ackMode))
{
- IDestination destination =
SessionUtil.GetDestination(session, DESTINATION_NAME);
+ IDestination destination =
CreateDestination(session, DESTINATION_NAME);
using(IMessageConsumer consumer =
session.CreateConsumer(destination))
using(IMessageProducer producer =
session.CreateProducer(destination))
{
@@ -262,7 +261,14 @@
producer.RequestTimeout =
receiveTimeout;
ITextMessage firstMsgSend =
session.CreateTextMessage("SendCommitNonTransaction Message");
producer.Send(firstMsgSend);
- session.Commit();
+ try
+ {
+ session.Commit();
+ Assert.Fail("Should
have thrown an InvalidOperationException.");
+ }
+ catch(InvalidOperationException)
+ {
+ }
}
}
}
@@ -275,7 +281,6 @@
[Row(AcknowledgementMode.ClientAcknowledge, true)]
[Row(AcknowledgementMode.ClientAcknowledge, false)]
#endif
- [ExpectedException(typeof(InvalidOperationException))]
public void TestReceiveCommitNonTransaction(AcknowledgementMode
ackMode, bool persistent)
{
using(IConnection connection =
CreateConnection(TEST_CLIENT_ID))
@@ -283,7 +288,7 @@
connection.Start();
using(ISession session =
connection.CreateSession(ackMode))
{
- IDestination destination =
SessionUtil.GetDestination(session, DESTINATION_NAME);
+ IDestination destination =
CreateDestination(session, DESTINATION_NAME);
using(IMessageConsumer consumer =
session.CreateConsumer(destination))
using(IMessageProducer producer =
session.CreateProducer(destination))
{
@@ -296,8 +301,64 @@
IMessage message =
consumer.Receive(receiveTimeout);
AssertTextMessageEqual(firstMsgSend, message, "First message does not match.");
- message.Acknowledge();
- session.Commit();
+
if(AcknowledgementMode.ClientAcknowledge == ackMode)
+ {
+ message.Acknowledge();
+ }
+
+ try
+ {
+ session.Commit();
+ Assert.Fail("Should
have thrown an InvalidOperationException.");
+ }
+ catch(InvalidOperationException)
+ {
+ }
+ }
+ }
+ }
+ }
+
+#if !NET_1_1
+ [RowTest]
+ [Row(AcknowledgementMode.AutoAcknowledge, true)]
+ [Row(AcknowledgementMode.AutoAcknowledge, false)]
+ [Row(AcknowledgementMode.ClientAcknowledge, true)]
+ [Row(AcknowledgementMode.ClientAcknowledge, false)]
+#endif
+ public void
TestReceiveRollbackNonTransaction(AcknowledgementMode ackMode, bool persistent)
+ {
+ using(IConnection connection =
CreateConnection(TEST_CLIENT_ID))
+ {
+ connection.Start();
+ using(ISession session =
connection.CreateSession(ackMode))
+ {
+ IDestination destination =
CreateDestination(session, DESTINATION_NAME);
+ using(IMessageConsumer consumer =
session.CreateConsumer(destination))
+ using(IMessageProducer producer =
session.CreateProducer(destination))
+ {
+ producer.Persistent =
persistent;
+ producer.RequestTimeout =
receiveTimeout;
+ ITextMessage firstMsgSend =
session.CreateTextMessage("ReceiveCommitNonTransaction Message");
+ producer.Send(firstMsgSend);
+
+ // Receive the messages
+
+ IMessage message =
consumer.Receive(receiveTimeout);
+
AssertTextMessageEqual(firstMsgSend, message, "First message does not match.");
+
if(AcknowledgementMode.ClientAcknowledge == ackMode)
+ {
+ message.Acknowledge();
+ }
+
+ try
+ {
+ session.Rollback();
+ Assert.Fail("Should
have thrown an InvalidOperationException.");
+ }
+ catch(InvalidOperationException)
+ {
+ }
}
}
}