You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2010/09/03 01:13:58 UTC
svn commit: r992152 - in
/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp: ConsumerTest.cs
ForgeinMessageTransformationTest.cs MapMessageTest.cs MessageTest.cs
StreamMessageTest.cs TempDestinationDeletionTest.cs
Author: tabish
Date: Thu Sep 2 23:13:58 2010
New Revision: 992152
URL: http://svn.apache.org/viewvc?rev=992152&view=rev
Log:
Make these tests a bit more compatible with NMS providers that don't offer the full range of NMS features such as Stomp.
Modified:
activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs
activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ForgeinMessageTransformationTest.cs
activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/MapMessageTest.cs
activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/MessageTest.cs
activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/StreamMessageTest.cs
activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/TempDestinationDeletionTest.cs
Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs?rev=992152&r1=992151&r2=992152&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs Thu Sep 2 23:13:58 2010
@@ -21,111 +21,110 @@ using NUnit.Framework;
namespace Apache.NMS.Test
{
- [TestFixture]
- public class ConsumerTest : NMSTestSupport
- {
- protected static string TEST_CLIENT_ID = "TestConsumerClientId";
- protected const int COUNT = 25;
+ [TestFixture]
+ public class ConsumerTest : NMSTestSupport
+ {
+ protected const int COUNT = 25;
protected const string VALUE_NAME = "value";
private bool dontAck;
// The .NET CF does not have the ability to interrupt threads, so this test is impossible.
#if !NETCF
- [Test]
- public void TestNoTimeoutConsumer(
- [Values(AcknowledgementMode.AutoAcknowledge, AcknowledgementMode.ClientAcknowledge,
- AcknowledgementMode.DupsOkAcknowledge, AcknowledgementMode.Transactional)]
- AcknowledgementMode ackMode)
- {
- // Launch a thread to perform IMessageConsumer.Receive().
- // If it doesn't fail in less than three seconds, no exception was thrown.
- Thread receiveThread = new Thread(new ThreadStart(TimeoutConsumerThreadProc));
- using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
- {
- connection.Start();
- using(ISession session = connection.CreateSession(ackMode))
- {
- ITemporaryQueue queue = session.CreateTemporaryQueue();
- using(this.timeoutConsumer = session.CreateConsumer(queue))
- {
- receiveThread.Start();
- if(receiveThread.Join(3000))
- {
- Assert.Fail("IMessageConsumer.Receive() returned without blocking. Test failed.");
- }
- else
- {
- // Kill the thread - otherwise it'll sit in Receive() until a message arrives.
- receiveThread.Interrupt();
- }
- }
- }
- }
- }
-
- protected IMessageConsumer timeoutConsumer;
-
- protected void TimeoutConsumerThreadProc()
- {
- try
- {
- timeoutConsumer.Receive();
- }
- catch(ArgumentOutOfRangeException e)
- {
- // The test failed. We will know because the timeout will expire inside TestNoTimeoutConsumer().
- Assert.Fail("Test failed with exception: " + e.Message);
- }
- catch(ThreadInterruptedException)
- {
- // The test succeeded! We were still blocked when we were interrupted.
- }
- catch(Exception e)
- {
- // Some other exception occurred.
- Assert.Fail("Test failed with exception: " + e.Message);
- }
- }
-
- [Test]
- public void TestSyncReceiveConsumerClose(
- [Values(AcknowledgementMode.AutoAcknowledge, AcknowledgementMode.ClientAcknowledge,
- AcknowledgementMode.DupsOkAcknowledge, AcknowledgementMode.Transactional)]
- AcknowledgementMode ackMode)
- {
- // Launch a thread to perform IMessageConsumer.Receive().
- // If it doesn't fail in less than three seconds, no exception was thrown.
- Thread receiveThread = new Thread(new ThreadStart(TimeoutConsumerThreadProc));
- using (IConnection connection = CreateConnection(TEST_CLIENT_ID))
- {
- connection.Start();
- using (ISession session = connection.CreateSession(ackMode))
- {
- ITemporaryQueue queue = session.CreateTemporaryQueue();
- using (this.timeoutConsumer = session.CreateConsumer(queue))
- {
- receiveThread.Start();
- if (receiveThread.Join(3000))
- {
- Assert.Fail("IMessageConsumer.Receive() returned without blocking. Test failed.");
- }
- else
- {
- // Kill the thread - otherwise it'll sit in Receive() until a message arrives.
- this.timeoutConsumer.Close();
- receiveThread.Join(10000);
- if (receiveThread.IsAlive)
- {
- // Kill the thread - otherwise it'll sit in Receive() until a message arrives.
- receiveThread.Interrupt();
- Assert.Fail("IMessageConsumer.Receive() thread is still alive, Close should have killed it.");
- }
- }
- }
- }
- }
- }
+ [Test]
+ public void TestNoTimeoutConsumer(
+ [Values(AcknowledgementMode.AutoAcknowledge, AcknowledgementMode.ClientAcknowledge,
+ AcknowledgementMode.DupsOkAcknowledge, AcknowledgementMode.Transactional)]
+ AcknowledgementMode ackMode)
+ {
+ // Launch a thread to perform IMessageConsumer.Receive().
+ // If it doesn't fail in less than three seconds, no exception was thrown.
+ Thread receiveThread = new Thread(new ThreadStart(TimeoutConsumerThreadProc));
+ using(IConnection connection = CreateConnection())
+ {
+ connection.Start();
+ using(ISession session = connection.CreateSession(ackMode))
+ {
+ ITemporaryQueue queue = session.CreateTemporaryQueue();
+ using(this.timeoutConsumer = session.CreateConsumer(queue))
+ {
+ receiveThread.Start();
+ if(receiveThread.Join(3000))
+ {
+ Assert.Fail("IMessageConsumer.Receive() returned without blocking. Test failed.");
+ }
+ else
+ {
+ // Kill the thread - otherwise it'll sit in Receive() until a message arrives.
+ receiveThread.Interrupt();
+ }
+ }
+ }
+ }
+ }
+
+ protected IMessageConsumer timeoutConsumer;
+
+ protected void TimeoutConsumerThreadProc()
+ {
+ try
+ {
+ timeoutConsumer.Receive();
+ }
+ catch(ArgumentOutOfRangeException e)
+ {
+ // The test failed. We will know because the timeout will expire inside TestNoTimeoutConsumer().
+ Assert.Fail("Test failed with exception: " + e.Message);
+ }
+ catch(ThreadInterruptedException)
+ {
+ // The test succeeded! We were still blocked when we were interrupted.
+ }
+ catch(Exception e)
+ {
+ // Some other exception occurred.
+ Assert.Fail("Test failed with exception: " + e.Message);
+ }
+ }
+
+ [Test]
+ public void TestSyncReceiveConsumerClose(
+ [Values(AcknowledgementMode.AutoAcknowledge, AcknowledgementMode.ClientAcknowledge,
+ AcknowledgementMode.DupsOkAcknowledge, AcknowledgementMode.Transactional)]
+ AcknowledgementMode ackMode)
+ {
+ // Launch a thread to perform IMessageConsumer.Receive().
+ // If it doesn't fail in less than three seconds, no exception was thrown.
+ Thread receiveThread = new Thread(new ThreadStart(TimeoutConsumerThreadProc));
+ using (IConnection connection = CreateConnection())
+ {
+ connection.Start();
+ using (ISession session = connection.CreateSession(ackMode))
+ {
+ ITemporaryQueue queue = session.CreateTemporaryQueue();
+ using (this.timeoutConsumer = session.CreateConsumer(queue))
+ {
+ receiveThread.Start();
+ if (receiveThread.Join(3000))
+ {
+ Assert.Fail("IMessageConsumer.Receive() returned without blocking. Test failed.");
+ }
+ else
+ {
+ // Kill the thread - otherwise it'll sit in Receive() until a message arrives.
+ this.timeoutConsumer.Close();
+ receiveThread.Join(10000);
+ if (receiveThread.IsAlive)
+ {
+ // Kill the thread - otherwise it'll sit in Receive() until a message arrives.
+ receiveThread.Interrupt();
+ Assert.Fail("IMessageConsumer.Receive() thread is still alive, Close should have killed it.");
+ }
+ }
+ }
+ }
+ }
+ }
internal class ThreadArg
{
@@ -146,7 +145,7 @@ namespace Apache.NMS.Test
{
// Give the consumer time to enter the receive.
Thread.Sleep(5000);
-
+
producer.Send(args.session.CreateTextMessage("Hello World"));
}
}
@@ -157,14 +156,14 @@ namespace Apache.NMS.Test
Assert.Fail("Test failed with exception: " + e.Message);
}
}
-
+
[Test]
public void TestDoChangeSentMessage(
- [Values(AcknowledgementMode.AutoAcknowledge, AcknowledgementMode.ClientAcknowledge,
- AcknowledgementMode.DupsOkAcknowledge, AcknowledgementMode.Transactional)]
- AcknowledgementMode ackMode)
+ [Values(AcknowledgementMode.AutoAcknowledge, AcknowledgementMode.ClientAcknowledge,
+ AcknowledgementMode.DupsOkAcknowledge, AcknowledgementMode.Transactional)]
+ AcknowledgementMode ackMode)
{
- using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
+ using(IConnection connection = CreateConnection())
{
connection.Start();
using(ISession session = connection.CreateSession(ackMode))
@@ -172,53 +171,53 @@ namespace Apache.NMS.Test
ITemporaryQueue queue = session.CreateTemporaryQueue();
using(IMessageConsumer consumer = session.CreateConsumer(queue))
{
- IMessageProducer producer = session.CreateProducer(queue);
- ITextMessage message = session.CreateTextMessage();
-
- string prefix = "ConsumerTest - TestDoChangeSentMessage: ";
-
- for(int i = 0; i < COUNT; i++)
- {
- message.Properties[VALUE_NAME] = i;
- message.Text = prefix + Convert.ToString(i);
-
- producer.Send(message);
-
- message.ClearBody();
- message.ClearProperties();
- }
-
- if(ackMode == AcknowledgementMode.Transactional)
- {
- session.Commit();
- }
-
- for(int i = 0; i < COUNT; i++)
- {
- ITextMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(2000)) as ITextMessage;
- Assert.AreEqual(msg.Text, prefix + Convert.ToString(i));
- Assert.AreEqual(msg.Properties[VALUE_NAME], i);
- }
-
- if(ackMode == AcknowledgementMode.Transactional)
- {
- session.Commit();
- }
-
+ IMessageProducer producer = session.CreateProducer(queue);
+ ITextMessage message = session.CreateTextMessage();
+
+ string prefix = "ConsumerTest - TestDoChangeSentMessage: ";
+
+ for(int i = 0; i < COUNT; i++)
+ {
+ message.Properties[VALUE_NAME] = i;
+ message.Text = prefix + Convert.ToString(i);
+
+ producer.Send(message);
+
+ message.ClearBody();
+ message.ClearProperties();
+ }
+
+ if(ackMode == AcknowledgementMode.Transactional)
+ {
+ session.Commit();
+ }
+
+ for(int i = 0; i < COUNT; i++)
+ {
+ ITextMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(2000)) as ITextMessage;
+ Assert.AreEqual(msg.Text, prefix + Convert.ToString(i));
+ Assert.AreEqual(msg.Properties.GetInt(VALUE_NAME), i);
+ }
+
+ if(ackMode == AcknowledgementMode.Transactional)
+ {
+ session.Commit();
+ }
+
}
}
}
}
-
+
[Test]
public void TestConsumerReceiveBeforeMessageDispatched(
- [Values(AcknowledgementMode.AutoAcknowledge, AcknowledgementMode.ClientAcknowledge,
- AcknowledgementMode.DupsOkAcknowledge, AcknowledgementMode.Transactional)]
- AcknowledgementMode ackMode)
+ [Values(AcknowledgementMode.AutoAcknowledge, AcknowledgementMode.ClientAcknowledge,
+ AcknowledgementMode.DupsOkAcknowledge, AcknowledgementMode.Transactional)]
+ AcknowledgementMode ackMode)
{
// Launch a thread to perform a delayed send.
Thread sendThread = new Thread(DelayedProducerThreadProc);
- using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
+ using(IConnection connection = CreateConnection())
{
connection.Start();
using(ISession session = connection.CreateSession(ackMode))
@@ -231,7 +230,7 @@ namespace Apache.NMS.Test
arg.connection = connection;
arg.session = session;
arg.destination = queue;
-
+
sendThread.Start(arg);
IMessage message = consumer.Receive(TimeSpan.FromMinutes(1));
Assert.IsNotNull(message);
@@ -242,20 +241,20 @@ namespace Apache.NMS.Test
[Test]
public void TestDontStart(
- [Values(MsgDeliveryMode.NonPersistent)]
- MsgDeliveryMode deliveryMode,
- [Values(DestinationType.Queue, DestinationType.Topic)]
- DestinationType destinationType )
+ [Values(MsgDeliveryMode.NonPersistent)]
+ MsgDeliveryMode deliveryMode,
+ [Values(DestinationType.Queue, DestinationType.Topic)]
+ DestinationType destinationType )
{
- using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
+ using(IConnection connection = CreateConnection())
{
ISession session = connection.CreateSession();
IDestination destination = CreateDestination(session, destinationType);
IMessageConsumer consumer = session.CreateConsumer(destination);
-
+
// Send the messages
SendMessages(session, destination, deliveryMode, 1);
-
+
// Make sure no messages were delivered.
Assert.IsNull(consumer.Receive(TimeSpan.FromMilliseconds(1000)));
}
@@ -263,12 +262,12 @@ namespace Apache.NMS.Test
[Test]
public void TestSendReceiveTransacted(
- [Values(MsgDeliveryMode.NonPersistent, MsgDeliveryMode.Persistent)]
- MsgDeliveryMode deliveryMode,
- [Values(DestinationType.Queue, DestinationType.Topic, DestinationType.TemporaryQueue, DestinationType.TemporaryTopic)]
- DestinationType destinationType)
+ [Values(MsgDeliveryMode.NonPersistent, MsgDeliveryMode.Persistent)]
+ MsgDeliveryMode deliveryMode,
+ [Values(DestinationType.Queue, DestinationType.Topic, DestinationType.TemporaryQueue, DestinationType.TemporaryTopic)]
+ DestinationType destinationType)
{
- using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
+ using(IConnection connection = CreateConnection())
{
// Send a message to the broker.
connection.Start();
@@ -279,27 +278,27 @@ namespace Apache.NMS.Test
producer.DeliveryMode = deliveryMode;
producer.Send(session.CreateTextMessage("Test"));
-
+
// Message should not be delivered until commit.
Thread.Sleep(1000);
Assert.IsNull(consumer.ReceiveNoWait());
session.Commit();
-
+
// Make sure only 1 message was delivered.
IMessage message = consumer.Receive(TimeSpan.FromMilliseconds(1000));
Assert.IsNotNull(message);
Assert.IsFalse(message.NMSRedelivered);
Assert.IsNull(consumer.ReceiveNoWait());
-
+
// Message should be redelivered is rollback is used.
session.Rollback();
-
+
// Make sure only 1 message was delivered.
message = consumer.Receive(TimeSpan.FromMilliseconds(2000));
Assert.IsNotNull(message);
Assert.IsTrue(message.NMSRedelivered);
Assert.IsNull(consumer.ReceiveNoWait());
-
+
// If we commit now, the message should not be redelivered.
session.Commit();
Thread.Sleep(1000);
@@ -310,29 +309,29 @@ namespace Apache.NMS.Test
[Test]
public void TestAckedMessageAreConsumed()
{
- using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
- {
+ using(IConnection connection = CreateConnection())
+ {
connection.Start();
ISession session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);
IQueue queue = session.GetQueue(Guid.NewGuid().ToString());
IMessageProducer producer = session.CreateProducer(queue);
producer.Send(session.CreateTextMessage("Hello"));
-
+
// Consume the message...
IMessageConsumer consumer = session.CreateConsumer(queue);
IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
Assert.IsNotNull(msg);
msg.Acknowledge();
-
+
// Reset the session.
session.Close();
session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);
-
+
// Attempt to Consume the message...
consumer = session.CreateConsumer(queue);
msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
Assert.IsNull(msg);
-
+
session.Close();
}
}
@@ -340,8 +339,8 @@ namespace Apache.NMS.Test
[Test]
public void TestLastMessageAcked()
{
- using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
- {
+ using(IConnection connection = CreateConnection())
+ {
connection.Start();
ISession session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);
IQueue queue = session.GetQueue(Guid.NewGuid().ToString());
@@ -349,97 +348,97 @@ namespace Apache.NMS.Test
producer.Send(session.CreateTextMessage("Hello"));
producer.Send(session.CreateTextMessage("Hello2"));
producer.Send(session.CreateTextMessage("Hello3"));
-
+
// Consume the message...
IMessageConsumer consumer = session.CreateConsumer(queue);
IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
Assert.IsNotNull(msg);
msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
- Assert.IsNotNull(msg);
+ Assert.IsNotNull(msg);
msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
Assert.IsNotNull(msg);
msg.Acknowledge();
-
+
// Reset the session.
session.Close();
session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);
-
+
// Attempt to Consume the message...
consumer = session.CreateConsumer(queue);
msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
Assert.IsNull(msg);
-
+
session.Close();
}
}
[Test]
- public void TestUnAckedMessageAreNotConsumedOnSessionClose()
+ public void TestUnAckedMessageAreNotConsumedOnSessionClose()
{
- using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
- {
+ using(IConnection connection = CreateConnection())
+ {
connection.Start();
ISession session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);
IQueue queue = session.GetQueue(Guid.NewGuid().ToString());
IMessageProducer producer = session.CreateProducer(queue);
producer.Send(session.CreateTextMessage("Hello"));
-
+
// Consume the message...
IMessageConsumer consumer = session.CreateConsumer(queue);
IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
- Assert.IsNotNull(msg);
+ Assert.IsNotNull(msg);
// Don't ack the message.
-
+
// Reset the session. This should cause the unacknowledged message to be re-delivered.
session.Close();
session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);
-
+
// Attempt to Consume the message...
consumer = session.CreateConsumer(queue);
msg = consumer.Receive(TimeSpan.FromMilliseconds(2000));
- Assert.IsNotNull(msg);
+ Assert.IsNotNull(msg);
msg.Acknowledge();
-
+
session.Close();
}
}
[Test]
- public void TestAsyncAckedMessageAreConsumed()
+ public void TestAsyncAckedMessageAreConsumed()
{
- using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
- {
+ using(IConnection connection = CreateConnection())
+ {
connection.Start();
ISession session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);
IQueue queue = session.GetQueue(Guid.NewGuid().ToString());
IMessageProducer producer = session.CreateProducer(queue);
producer.Send(session.CreateTextMessage("Hello"));
-
+
// Consume the message...
IMessageConsumer consumer = session.CreateConsumer(queue);
consumer.Listener += new MessageListener(OnMessage);
-
+
Thread.Sleep(5000);
-
+
// Reset the session.
session.Close();
-
+
session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);
-
+
// Attempt to Consume the message...
consumer = session.CreateConsumer(queue);
IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
Assert.IsNull(msg);
-
+
session.Close();
}
}
[Test]
- public void TestAsyncUnAckedMessageAreNotConsumedOnSessionClose()
+ public void TestAsyncUnAckedMessageAreNotConsumedOnSessionClose()
{
- using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
- {
+ using(IConnection connection = CreateConnection())
+ {
connection.Start();
// don't aknowledge message on onMessage() call
dontAck = true;
@@ -447,16 +446,16 @@ namespace Apache.NMS.Test
IQueue queue = session.GetQueue("Guid.NewGuid().ToString()");
IMessageProducer producer = session.CreateProducer(queue);
producer.Send(session.CreateTextMessage("Hello"));
-
+
// Consume the message...
IMessageConsumer consumer = session.CreateConsumer(queue);
consumer.Listener += new MessageListener(OnMessage);
// Don't ack the message.
-
+
// Reset the session. This should cause the Unacked message to be
// redelivered.
session.Close();
-
+
Thread.Sleep(5000);
session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);
// Attempt to Consume the message...
@@ -464,47 +463,47 @@ namespace Apache.NMS.Test
IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(2000));
Assert.IsNotNull(msg);
msg.Acknowledge();
-
+
session.Close();
}
}
-
- [Test]
- public void TestAddRemoveAsnycMessageListener()
- {
- using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
+
+ [Test]
+ public void TestAddRemoveAsnycMessageListener()
+ {
+ using(IConnection connection = CreateConnection())
{
- connection.Start();
-
+ connection.Start();
+
ISession session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);
ITemporaryTopic topic = session.CreateTemporaryTopic();
IMessageConsumer consumer = session.CreateConsumer(topic);
- consumer.Listener += OnMessage;
- consumer.Listener -= OnMessage;
- consumer.Listener += OnMessage;
-
- consumer.Close();
- }
- }
-
- public void OnMessage(IMessage message)
+ consumer.Listener += OnMessage;
+ consumer.Listener -= OnMessage;
+ consumer.Listener += OnMessage;
+
+ consumer.Close();
+ }
+ }
+
+ public void OnMessage(IMessage message)
{
Assert.IsNotNull(message);
-
+
if(!dontAck)
{
- try
+ try
{
message.Acknowledge();
- }
+ }
catch(Exception)
{
- }
+ }
}
}
-
+
#endif
- }
+ }
}
Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ForgeinMessageTransformationTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ForgeinMessageTransformationTest.cs?rev=992152&r1=992151&r2=992152&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ForgeinMessageTransformationTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ForgeinMessageTransformationTest.cs Thu Sep 2 23:13:58 2010
@@ -24,18 +24,18 @@ using Apache.NMS.Commands;
namespace Apache.NMS.Test
{
- [TestFixture]
- public class ForeignMessageTransformationTest : NMSTestSupport
- {
- protected static string DESTINATION_NAME = "topic://MessageTransformationDestination";
-
- private string propertyName = "Test-Property";
- private string propertyValue = "Test-Property-Value";
- private string mapElementName = "Test-Map-Property";
- private string mapElementValue = "Test-Map-Property-Value";
- private string textBody = "This is a TextMessage from a Foreign Provider";
- private byte[] bytesContent = {1, 2, 3, 4, 5, 6, 7, 8};
-
+ [TestFixture]
+ public class ForeignMessageTransformationTest : NMSTestSupport
+ {
+ protected static string DESTINATION_NAME = "topic://MessageTransformationDestination";
+
+ private string propertyName = "Test-Property";
+ private string propertyValue = "Test-Property-Value";
+ private string mapElementName = "Test-Map-Property";
+ private string mapElementValue = "Test-Map-Property-Value";
+ private string textBody = "This is a TextMessage from a Foreign Provider";
+ private byte[] bytesContent = {1, 2, 3, 4, 5, 6, 7, 8};
+
private bool a = true;
private byte b = 123;
private char c = 'c';
@@ -51,227 +51,257 @@ namespace Apache.NMS.Test
private float m = 2.1F;
private double n = 2.3;
- [Test]
- public void SendReceiveForeignMessageTest(
- [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
- MsgDeliveryMode deliveryMode)
- {
- using(IConnection connection = CreateConnection())
- {
- connection.Start();
- using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
- {
- IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
- using(IMessageConsumer consumer = session.CreateConsumer(destination))
- using(IMessageProducer producer = session.CreateProducer(destination))
- {
- producer.DeliveryMode = deliveryMode;
- Message request = new Message();
- request.Properties[propertyName] = propertyValue;
-
- producer.Send(request);
-
- IMessage message = consumer.Receive(receiveTimeout);
- Assert.IsNotNull(message, "No message returned!");
- Assert.AreEqual(request.Properties.Count, message.Properties.Count, "Invalid number of properties.");
- Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
-
- // use generic API to access entries
- Assert.AreEqual(propertyValue, message.Properties[propertyName], "generic map entry: " + propertyName);
-
- // use type safe APIs
- Assert.AreEqual(propertyValue, message.Properties.GetString(propertyName), "map entry: " + propertyName);
- }
- }
- }
- }
-
- [Test]
- public void SendReceiveForeignTextMessageTest(
- [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
- MsgDeliveryMode deliveryMode)
- {
- using(IConnection connection = CreateConnection())
- {
- connection.Start();
- using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
- {
- IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
- using(IMessageConsumer consumer = session.CreateConsumer(destination))
- using(IMessageProducer producer = session.CreateProducer(destination))
- {
- producer.DeliveryMode = deliveryMode;
- TextMessage request = new TextMessage();
- request.Properties[propertyName] = propertyValue;
- request.Text = textBody;
-
- producer.Send(request);
-
- ITextMessage message = consumer.Receive(receiveTimeout) as ITextMessage;
- Assert.IsNotNull(message, "No message returned!");
- Assert.AreEqual(request.Properties.Count, message.Properties.Count, "Invalid number of properties.");
- Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
-
- // Check the body
- Assert.AreEqual(textBody, message.Text, "TextMessage body was wrong.");
-
- // use generic API to access entries
- Assert.AreEqual(propertyValue, message.Properties[propertyName], "generic map entry: " + propertyName);
-
- // use type safe APIs
- Assert.AreEqual(propertyValue, message.Properties.GetString(propertyName), "map entry: " + propertyName);
- }
- }
- }
- }
-
- [Test]
- public void SendReceiveForeignBytesMessageTest(
- [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
- MsgDeliveryMode deliveryMode)
- {
- using(IConnection connection = CreateConnection())
- {
- connection.Start();
- using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
- {
- IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
- using(IMessageConsumer consumer = session.CreateConsumer(destination))
- using(IMessageProducer producer = session.CreateProducer(destination))
- {
- producer.DeliveryMode = deliveryMode;
- BytesMessage request = new BytesMessage();
- request.Properties[propertyName] = propertyValue;
- request.WriteBytes(bytesContent);
-
- producer.Send(request);
-
- IBytesMessage message = consumer.Receive(receiveTimeout) as IBytesMessage;
- Assert.IsNotNull(message, "No message returned!");
- Assert.AreEqual(request.Properties.Count, message.Properties.Count, "Invalid number of properties.");
- Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
-
- // Check the body
- byte[] content = new byte[bytesContent.Length];
- Assert.AreEqual(bytesContent.Length, message.ReadBytes(content));
- Assert.AreEqual(bytesContent, content, "BytesMessage body was wrong.");
-
- // use generic API to access entries
- Assert.AreEqual(propertyValue, message.Properties[propertyName], "generic map entry: " + propertyName);
-
- // use type safe APIs
- Assert.AreEqual(propertyValue, message.Properties.GetString(propertyName), "map entry: " + propertyName);
- }
- }
- }
- }
-
- [Test]
- public void SendReceiveForeignMapMessageTest(
- [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
- MsgDeliveryMode deliveryMode)
- {
- using(IConnection connection = CreateConnection())
- {
- connection.Start();
- using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
- {
- IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
- using(IMessageConsumer consumer = session.CreateConsumer(destination))
- using(IMessageProducer producer = session.CreateProducer(destination))
- {
- producer.DeliveryMode = deliveryMode;
- MapMessage request = new MapMessage();
- request.Properties[propertyName] = propertyValue;
- request.Body[mapElementName] = mapElementValue;
-
- producer.Send(request);
-
- IMapMessage message = consumer.Receive(receiveTimeout) as IMapMessage;
- Assert.IsNotNull(message, "No message returned!");
- Assert.AreEqual(request.Properties.Count, message.Properties.Count, "Invalid number of properties.");
- Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
-
- // Check the body
- Assert.AreEqual(request.Body.Count, message.Body.Count);
- Assert.AreEqual(mapElementValue, message.Body[mapElementName], "MapMessage body was wrong.");
-
- // use generic API to access entries
- Assert.AreEqual(propertyValue, message.Properties[propertyName], "generic map entry: " + propertyName);
-
- // use type safe APIs
- Assert.AreEqual(propertyValue, message.Properties.GetString(propertyName), "map entry: " + propertyName);
- }
- }
- }
- }
-
- [Test]
- public void SendReceiveForeignStreamMessageTest(
- [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
- MsgDeliveryMode deliveryMode)
- {
- using(IConnection connection = CreateConnection())
- {
- connection.Start();
- using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
- {
- IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
- using(IMessageConsumer consumer = session.CreateConsumer(destination))
- using(IMessageProducer producer = session.CreateProducer(destination))
- {
- producer.DeliveryMode = deliveryMode;
- StreamMessage request = new StreamMessage();
- request.Properties[propertyName] = propertyValue;
-
- request.WriteBoolean(a);
- request.WriteByte(b);
- request.WriteChar(c);
- request.WriteInt16(d);
- request.WriteInt32(e);
- request.WriteInt64(f);
- request.WriteString(g);
- request.WriteBoolean(h);
- request.WriteByte(i);
- request.WriteInt16(j);
- request.WriteInt32(k);
- request.WriteInt64(l);
- request.WriteSingle(m);
- request.WriteDouble(n);
-
- producer.Send(request);
-
- IStreamMessage message = consumer.Receive(receiveTimeout) as IStreamMessage;
- Assert.IsNotNull(message, "No message returned!");
- Assert.AreEqual(request.Properties.Count, message.Properties.Count, "Invalid number of properties.");
- Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
-
- // Check the body
- Assert.AreEqual(a, message.ReadBoolean(), "Stream Boolean Value: a");
- Assert.AreEqual(b, message.ReadByte(), "Stream Byte Value: b");
- Assert.AreEqual(c, message.ReadChar(), "Stream Char Value: c");
- Assert.AreEqual(d, message.ReadInt16(), "Stream Int16 Value: d");
- Assert.AreEqual(e, message.ReadInt32(), "Stream Int32 Value: e");
- Assert.AreEqual(f, message.ReadInt64(), "Stream Int64 Value: f");
- Assert.AreEqual(g, message.ReadString(), "Stream String Value: g");
- Assert.AreEqual(h, message.ReadBoolean(), "Stream Boolean Value: h");
- Assert.AreEqual(i, message.ReadByte(), "Stream Byte Value: i");
- Assert.AreEqual(j, message.ReadInt16(), "Stream Int16 Value: j");
- Assert.AreEqual(k, message.ReadInt32(), "Stream Int32 Value: k");
- Assert.AreEqual(l, message.ReadInt64(), "Stream Int64 Value: l");
- Assert.AreEqual(m, message.ReadSingle(), "Stream Single Value: m");
- Assert.AreEqual(n, message.ReadDouble(), "Stream Double Value: n");
-
- // use generic API to access entries
- Assert.AreEqual(propertyValue, message.Properties[propertyName], "generic map entry: " + propertyName);
-
- // use type safe APIs
- Assert.AreEqual(propertyValue, message.Properties.GetString(propertyName), "map entry: " + propertyName);
- }
- }
- }
- }
-
- }
+ [Test]
+ public void SendReceiveForeignMessageTest(
+ [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
+ MsgDeliveryMode deliveryMode)
+ {
+ using(IConnection connection = CreateConnection())
+ {
+ connection.Start();
+ using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+ {
+ IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ using(IMessageProducer producer = session.CreateProducer(destination))
+ {
+ try
+ {
+ producer.DeliveryMode = deliveryMode;
+ Message request = new Message();
+ request.Properties[propertyName] = propertyValue;
+
+ producer.Send(request);
+
+ IMessage message = consumer.Receive(receiveTimeout);
+ Assert.IsNotNull(message, "No message returned!");
+ Assert.AreEqual(request.Properties.Count, message.Properties.Count, "Invalid number of properties.");
+ Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
+
+ // use generic API to access entries
+ Assert.AreEqual(propertyValue, message.Properties[propertyName], "generic map entry: " + propertyName);
+
+ // use type safe APIs
+ Assert.AreEqual(propertyValue, message.Properties.GetString(propertyName), "map entry: " + propertyName);
+ }
+ catch(NotSupportedException)
+ {
+ }
+ }
+ }
+ }
+ }
+
+ [Test]
+ public void SendReceiveForeignTextMessageTest(
+ [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
+ MsgDeliveryMode deliveryMode)
+ {
+ using(IConnection connection = CreateConnection())
+ {
+ connection.Start();
+ using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+ {
+ IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ using(IMessageProducer producer = session.CreateProducer(destination))
+ {
+ try
+ {
+ producer.DeliveryMode = deliveryMode;
+ TextMessage request = new TextMessage();
+ request.Properties[propertyName] = propertyValue;
+ request.Text = textBody;
+
+ producer.Send(request);
+
+ ITextMessage message = consumer.Receive(receiveTimeout) as ITextMessage;
+ Assert.IsNotNull(message, "No message returned!");
+ Assert.AreEqual(request.Properties.Count, message.Properties.Count, "Invalid number of properties.");
+ Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
+
+ // Check the body
+ Assert.AreEqual(textBody, message.Text, "TextMessage body was wrong.");
+
+ // use generic API to access entries
+ Assert.AreEqual(propertyValue, message.Properties[propertyName], "generic map entry: " + propertyName);
+
+ // use type safe APIs
+ Assert.AreEqual(propertyValue, message.Properties.GetString(propertyName), "map entry: " + propertyName);
+ }
+ catch(NotSupportedException)
+ {
+ }
+ }
+ }
+ }
+ }
+
+ [Test]
+ public void SendReceiveForeignBytesMessageTest(
+ [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
+ MsgDeliveryMode deliveryMode)
+ {
+ using(IConnection connection = CreateConnection())
+ {
+ connection.Start();
+ using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+ {
+ IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ using(IMessageProducer producer = session.CreateProducer(destination))
+ {
+ try
+ {
+ producer.DeliveryMode = deliveryMode;
+ BytesMessage request = new BytesMessage();
+ request.Properties[propertyName] = propertyValue;
+ request.WriteBytes(bytesContent);
+
+ producer.Send(request);
+
+ IBytesMessage message = consumer.Receive(receiveTimeout) as IBytesMessage;
+ Assert.IsNotNull(message, "No message returned!");
+ Assert.AreEqual(request.Properties.Count, message.Properties.Count, "Invalid number of properties.");
+ Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
+
+ // Check the body
+ byte[] content = new byte[bytesContent.Length];
+ Assert.AreEqual(bytesContent.Length, message.ReadBytes(content));
+ Assert.AreEqual(bytesContent, content, "BytesMessage body was wrong.");
+
+ // use generic API to access entries
+ Assert.AreEqual(propertyValue, message.Properties[propertyName], "generic map entry: " + propertyName);
+
+ // use type safe APIs
+ Assert.AreEqual(propertyValue, message.Properties.GetString(propertyName), "map entry: " + propertyName);
+ }
+ catch(NotSupportedException)
+ {
+ }
+ }
+ }
+ }
+ }
+
+ [Test]
+ public void SendReceiveForeignMapMessageTest(
+ [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
+ MsgDeliveryMode deliveryMode)
+ {
+ using(IConnection connection = CreateConnection())
+ {
+ connection.Start();
+ using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+ {
+ IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ using(IMessageProducer producer = session.CreateProducer(destination))
+ {
+ try
+ {
+ producer.DeliveryMode = deliveryMode;
+ MapMessage request = new MapMessage();
+ request.Properties[propertyName] = propertyValue;
+ request.Body[mapElementName] = mapElementValue;
+
+ producer.Send(request);
+
+ IMapMessage message = consumer.Receive(receiveTimeout) as IMapMessage;
+ Assert.IsNotNull(message, "No message returned!");
+ Assert.AreEqual(request.Properties.Count, message.Properties.Count, "Invalid number of properties.");
+ Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
+
+ // Check the body
+ Assert.AreEqual(request.Body.Count, message.Body.Count);
+ Assert.AreEqual(mapElementValue, message.Body[mapElementName], "MapMessage body was wrong.");
+
+ // use generic API to access entries
+ Assert.AreEqual(propertyValue, message.Properties[propertyName], "generic map entry: " + propertyName);
+
+ // use type safe APIs
+ Assert.AreEqual(propertyValue, message.Properties.GetString(propertyName), "map entry: " + propertyName);
+ }
+ catch(NotSupportedException)
+ {
+ }
+ }
+ }
+ }
+ }
+
+ [Test]
+ public void SendReceiveForeignStreamMessageTest(
+ [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
+ MsgDeliveryMode deliveryMode)
+ {
+ using(IConnection connection = CreateConnection())
+ {
+ connection.Start();
+ using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+ {
+ IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ using(IMessageProducer producer = session.CreateProducer(destination))
+ {
+ try
+ {
+ producer.DeliveryMode = deliveryMode;
+ StreamMessage request = new StreamMessage();
+ request.Properties[propertyName] = propertyValue;
+
+ request.WriteBoolean(a);
+ request.WriteByte(b);
+ request.WriteChar(c);
+ request.WriteInt16(d);
+ request.WriteInt32(e);
+ request.WriteInt64(f);
+ request.WriteString(g);
+ request.WriteBoolean(h);
+ request.WriteByte(i);
+ request.WriteInt16(j);
+ request.WriteInt32(k);
+ request.WriteInt64(l);
+ request.WriteSingle(m);
+ request.WriteDouble(n);
+
+ producer.Send(request);
+
+ IStreamMessage message = consumer.Receive(receiveTimeout) as IStreamMessage;
+ Assert.IsNotNull(message, "No message returned!");
+ Assert.AreEqual(request.Properties.Count, message.Properties.Count, "Invalid number of properties.");
+ Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
+
+ // Check the body
+ Assert.AreEqual(a, message.ReadBoolean(), "Stream Boolean Value: a");
+ Assert.AreEqual(b, message.ReadByte(), "Stream Byte Value: b");
+ Assert.AreEqual(c, message.ReadChar(), "Stream Char Value: c");
+ Assert.AreEqual(d, message.ReadInt16(), "Stream Int16 Value: d");
+ Assert.AreEqual(e, message.ReadInt32(), "Stream Int32 Value: e");
+ Assert.AreEqual(f, message.ReadInt64(), "Stream Int64 Value: f");
+ Assert.AreEqual(g, message.ReadString(), "Stream String Value: g");
+ Assert.AreEqual(h, message.ReadBoolean(), "Stream Boolean Value: h");
+ Assert.AreEqual(i, message.ReadByte(), "Stream Byte Value: i");
+ Assert.AreEqual(j, message.ReadInt16(), "Stream Int16 Value: j");
+ Assert.AreEqual(k, message.ReadInt32(), "Stream Int32 Value: k");
+ Assert.AreEqual(l, message.ReadInt64(), "Stream Int64 Value: l");
+ Assert.AreEqual(m, message.ReadSingle(), "Stream Single Value: m");
+ Assert.AreEqual(n, message.ReadDouble(), "Stream Double Value: n");
+
+ // use generic API to access entries
+ Assert.AreEqual(propertyValue, message.Properties[propertyName], "generic map entry: " + propertyName);
+
+ // use type safe APIs
+ Assert.AreEqual(propertyValue, message.Properties.GetString(propertyName), "map entry: " + propertyName);
+ }
+ catch(NotSupportedException)
+ {
+ }
+ }
+ }
+ }
+ }
+
+ }
}
Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/MapMessageTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/MapMessageTest.cs?rev=992152&r1=992151&r2=992152&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/MapMessageTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/MapMessageTest.cs Thu Sep 2 23:13:58 2010
@@ -22,176 +22,186 @@ using NUnit.Framework;
namespace Apache.NMS.Test
{
- [TestFixture]
- public class MapMessageTest : NMSTestSupport
- {
- protected static string DESTINATION_NAME = "MessagePropsDestination";
- protected static string TEST_CLIENT_ID = "MessagePropsClientId";
-
- protected bool a = true;
- protected byte b = 123;
- protected char c = 'c';
- protected short d = 0x1234;
- protected int e = 0x12345678;
- protected long f = 0x1234567812345678;
- protected string g = "Hello World!";
- protected bool h = false;
- protected byte i = 0xFF;
- protected short j = -0x1234;
- protected int k = -0x12345678;
- protected long l = -0x1234567812345678;
- protected float m = 2.1F;
- protected double n = 2.3;
- protected byte[] o = {1, 2, 3, 4, 5};
-
- [Test]
- public void SendReceiveMapMessage(
- [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
- MsgDeliveryMode deliveryMode)
- {
- using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
- {
- connection.Start();
- using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
- {
- IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
- using(IMessageConsumer consumer = session.CreateConsumer(destination))
- using(IMessageProducer producer = session.CreateProducer(destination))
- {
- producer.DeliveryMode = deliveryMode;
- IMapMessage request = session.CreateMapMessage();
- request.Body["a"] = a;
- request.Body["b"] = b;
- request.Body["c"] = c;
- request.Body["d"] = d;
- request.Body["e"] = e;
- request.Body["f"] = f;
- request.Body["g"] = g;
- request.Body["h"] = h;
- request.Body["i"] = i;
- request.Body["j"] = j;
- request.Body["k"] = k;
- request.Body["l"] = l;
- request.Body["m"] = m;
- request.Body["n"] = n;
- request.Body["o"] = o;
- producer.Send(request);
-
- IMapMessage message = consumer.Receive(receiveTimeout) as IMapMessage;
- Assert.IsNotNull(message, "No message returned!");
- Assert.AreEqual(request.Body.Count, message.Body.Count, "Invalid number of message maps.");
- Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
- Assert.AreEqual(ToHex(f), ToHex(message.Body.GetLong("f")), "map entry: f as hex");
-
- // use generic API to access entries
- Assert.AreEqual(a, message.Body["a"], "generic map entry: a");
- Assert.AreEqual(b, message.Body["b"], "generic map entry: b");
- Assert.AreEqual(c, message.Body["c"], "generic map entry: c");
- Assert.AreEqual(d, message.Body["d"], "generic map entry: d");
- Assert.AreEqual(e, message.Body["e"], "generic map entry: e");
- Assert.AreEqual(f, message.Body["f"], "generic map entry: f");
- Assert.AreEqual(g, message.Body["g"], "generic map entry: g");
- Assert.AreEqual(h, message.Body["h"], "generic map entry: h");
- Assert.AreEqual(i, message.Body["i"], "generic map entry: i");
- Assert.AreEqual(j, message.Body["j"], "generic map entry: j");
- Assert.AreEqual(k, message.Body["k"], "generic map entry: k");
- Assert.AreEqual(l, message.Body["l"], "generic map entry: l");
- Assert.AreEqual(m, message.Body["m"], "generic map entry: m");
- Assert.AreEqual(n, message.Body["n"], "generic map entry: n");
- Assert.AreEqual(o, message.Body["o"], "generic map entry: o");
-
- // use type safe APIs
- Assert.AreEqual(a, message.Body.GetBool("a"), "map entry: a");
- Assert.AreEqual(b, message.Body.GetByte("b"), "map entry: b");
- Assert.AreEqual(c, message.Body.GetChar("c"), "map entry: c");
- Assert.AreEqual(d, message.Body.GetShort("d"), "map entry: d");
- Assert.AreEqual(e, message.Body.GetInt("e"), "map entry: e");
- Assert.AreEqual(f, message.Body.GetLong("f"), "map entry: f");
- Assert.AreEqual(g, message.Body.GetString("g"), "map entry: g");
- Assert.AreEqual(h, message.Body.GetBool("h"), "map entry: h");
- Assert.AreEqual(i, message.Body.GetByte("i"), "map entry: i");
- Assert.AreEqual(j, message.Body.GetShort("j"), "map entry: j");
- Assert.AreEqual(k, message.Body.GetInt("k"), "map entry: k");
- Assert.AreEqual(l, message.Body.GetLong("l"), "map entry: l");
- Assert.AreEqual(m, message.Body.GetFloat("m"), "map entry: m");
- Assert.AreEqual(n, message.Body.GetDouble("n"), "map entry: n");
- Assert.AreEqual(o, message.Body.GetBytes("o"), "map entry: o");
- }
- }
- }
- }
-
- [Test]
- public void SendReceiveNestedMapMessage(
- [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
- MsgDeliveryMode deliveryMode)
- {
- using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
- {
- connection.Start();
- using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
- {
- IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
- using(IMessageConsumer consumer = session.CreateConsumer(destination))
- using(IMessageProducer producer = session.CreateProducer(destination))
- {
- producer.DeliveryMode = deliveryMode;
- IMapMessage request = session.CreateMapMessage();
- const string textFieldValue = "Nested Map Messages Rule!";
-
- request.Body.SetString("textField", textFieldValue);
-
- IDictionary grandChildMap = new Hashtable();
- grandChildMap["x"] = "abc";
- grandChildMap["y"] = new ArrayList(new object[] { "a", "b", "c" });
-
- IDictionary nestedMap = new Hashtable();
- nestedMap["a"] = "foo";
- nestedMap["b"] = (int) 23;
- nestedMap["c"] = (long) 45;
- nestedMap["d"] = grandChildMap;
-
- request.Body.SetDictionary("mapField", nestedMap);
- request.Body.SetList("listField", new ArrayList(new Object[] { "a", "b", "c" }));
-
- producer.Send(request);
-
- IMapMessage message = consumer.Receive(receiveTimeout) as IMapMessage;
- Assert.IsNotNull(message, "No message returned!");
- Assert.AreEqual(request.Body.Count, message.Body.Count, "Invalid number of message maps.");
- Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
-
- string textFieldResponse = message.Body.GetString("textField");
- Assert.AreEqual(textFieldValue, textFieldResponse, "textField does not match.");
-
- IDictionary nestedMapResponse = message.Body.GetDictionary("mapField");
- Assert.IsNotNull(nestedMapResponse, "Nested map not returned.");
- Assert.AreEqual(nestedMap.Count, nestedMapResponse.Count, "nestedMap: Wrong number of elements");
- Assert.AreEqual("foo", nestedMapResponse["a"], "nestedMap: a");
- Assert.AreEqual(23, nestedMapResponse["b"], "nestedMap: b");
- Assert.AreEqual(45, nestedMapResponse["c"], "nestedMap: c");
-
- IDictionary grandChildMapResponse = nestedMapResponse["d"] as IDictionary;
- Assert.IsNotNull(grandChildMapResponse, "Grand child map not returned.");
- Assert.AreEqual(grandChildMap.Count, grandChildMapResponse.Count, "grandChildMap: Wrong number of elements");
- Assert.AreEqual(grandChildMapResponse["x"], "abc", "grandChildMap: x");
-
- IList grandChildList = grandChildMapResponse["y"] as IList;
- Assert.IsNotNull(grandChildList, "Grand child list not returned.");
- Assert.AreEqual(3, grandChildList.Count, "grandChildList: Wrong number of list elements.");
- Assert.AreEqual("a", grandChildList[0], "grandChildList: a");
- Assert.AreEqual("b", grandChildList[1], "grandChildList: b");
- Assert.AreEqual("c", grandChildList[2], "grandChildList: c");
-
- IList listFieldResponse = message.Body.GetList("listField");
- Assert.IsNotNull(listFieldResponse, "Nested list not returned.");
- Assert.AreEqual(3, listFieldResponse.Count, "listFieldResponse: Wrong number of list elements.");
- Assert.AreEqual("a", listFieldResponse[0], "listFieldResponse: a");
- Assert.AreEqual("b", listFieldResponse[1], "listFieldResponse: b");
- Assert.AreEqual("c", listFieldResponse[2], "listFieldResponse: c");
- }
- }
- }
- }
- }
+ [TestFixture]
+ public class MapMessageTest : NMSTestSupport
+ {
+ protected static string DESTINATION_NAME = "MessagePropsDestination";
+ protected static string TEST_CLIENT_ID = "MessagePropsClientId";
+
+ protected bool a = true;
+ protected byte b = 123;
+ protected char c = 'c';
+ protected short d = 0x1234;
+ protected int e = 0x12345678;
+ protected long f = 0x1234567812345678;
+ protected string g = "Hello World!";
+ protected bool h = false;
+ protected byte i = 0xFF;
+ protected short j = -0x1234;
+ protected int k = -0x12345678;
+ protected long l = -0x1234567812345678;
+ protected float m = 2.1F;
+ protected double n = 2.3;
+ protected byte[] o = {1, 2, 3, 4, 5};
+
+ [Test]
+ public void SendReceiveMapMessage(
+ [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
+ MsgDeliveryMode deliveryMode)
+ {
+ using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
+ {
+ connection.Start();
+ using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+ {
+ IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ using(IMessageProducer producer = session.CreateProducer(destination))
+ {
+ producer.DeliveryMode = deliveryMode;
+ IMapMessage request = session.CreateMapMessage();
+ request.Body["a"] = a;
+ request.Body["b"] = b;
+ request.Body["c"] = c;
+ request.Body["d"] = d;
+ request.Body["e"] = e;
+ request.Body["f"] = f;
+ request.Body["g"] = g;
+ request.Body["h"] = h;
+ request.Body["i"] = i;
+ request.Body["j"] = j;
+ request.Body["k"] = k;
+ request.Body["l"] = l;
+ request.Body["m"] = m;
+ request.Body["n"] = n;
+ request.Body["o"] = o;
+ producer.Send(request);
+
+ IMapMessage message = consumer.Receive(receiveTimeout) as IMapMessage;
+ Assert.IsNotNull(message, "No message returned!");
+ Assert.AreEqual(request.Body.Count, message.Body.Count, "Invalid number of message maps.");
+ Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
+ Assert.AreEqual(ToHex(f), ToHex(message.Body.GetLong("f")), "map entry: f as hex");
+
+ // use generic API to access entries
+ Assert.AreEqual(a, message.Body["a"], "generic map entry: a");
+ Assert.AreEqual(b, message.Body["b"], "generic map entry: b");
+ Assert.AreEqual(c, message.Body["c"], "generic map entry: c");
+ Assert.AreEqual(d, message.Body["d"], "generic map entry: d");
+ Assert.AreEqual(e, message.Body["e"], "generic map entry: e");
+ Assert.AreEqual(f, message.Body["f"], "generic map entry: f");
+ Assert.AreEqual(g, message.Body["g"], "generic map entry: g");
+ Assert.AreEqual(h, message.Body["h"], "generic map entry: h");
+ Assert.AreEqual(i, message.Body["i"], "generic map entry: i");
+ Assert.AreEqual(j, message.Body["j"], "generic map entry: j");
+ Assert.AreEqual(k, message.Body["k"], "generic map entry: k");
+ Assert.AreEqual(l, message.Body["l"], "generic map entry: l");
+ Assert.AreEqual(m, message.Body["m"], "generic map entry: m");
+ Assert.AreEqual(n, message.Body["n"], "generic map entry: n");
+ Assert.AreEqual(o, message.Body["o"], "generic map entry: o");
+
+ // use type safe APIs
+ Assert.AreEqual(a, message.Body.GetBool("a"), "map entry: a");
+ Assert.AreEqual(b, message.Body.GetByte("b"), "map entry: b");
+ Assert.AreEqual(c, message.Body.GetChar("c"), "map entry: c");
+ Assert.AreEqual(d, message.Body.GetShort("d"), "map entry: d");
+ Assert.AreEqual(e, message.Body.GetInt("e"), "map entry: e");
+ Assert.AreEqual(f, message.Body.GetLong("f"), "map entry: f");
+ Assert.AreEqual(g, message.Body.GetString("g"), "map entry: g");
+ Assert.AreEqual(h, message.Body.GetBool("h"), "map entry: h");
+ Assert.AreEqual(i, message.Body.GetByte("i"), "map entry: i");
+ Assert.AreEqual(j, message.Body.GetShort("j"), "map entry: j");
+ Assert.AreEqual(k, message.Body.GetInt("k"), "map entry: k");
+ Assert.AreEqual(l, message.Body.GetLong("l"), "map entry: l");
+ Assert.AreEqual(m, message.Body.GetFloat("m"), "map entry: m");
+ Assert.AreEqual(n, message.Body.GetDouble("n"), "map entry: n");
+ Assert.AreEqual(o, message.Body.GetBytes("o"), "map entry: o");
+ }
+ }
+ }
+ }
+
+ [Test]
+ public void SendReceiveNestedMapMessage(
+ [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
+ MsgDeliveryMode deliveryMode)
+ {
+ using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
+ {
+ connection.Start();
+ using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+ {
+ IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ using(IMessageProducer producer = session.CreateProducer(destination))
+ {
+ try
+ {
+ producer.DeliveryMode = deliveryMode;
+ IMapMessage request = session.CreateMapMessage();
+ const string textFieldValue = "Nested Map Messages Rule!";
+
+ request.Body.SetString("textField", textFieldValue);
+
+ IDictionary grandChildMap = new Hashtable();
+ grandChildMap["x"] = "abc";
+ grandChildMap["y"] = new ArrayList(new object[] { "a", "b", "c" });
+
+ IDictionary nestedMap = new Hashtable();
+ nestedMap["a"] = "foo";
+ nestedMap["b"] = (int) 23;
+ nestedMap["c"] = (long) 45;
+ nestedMap["d"] = grandChildMap;
+
+ request.Body.SetDictionary("mapField", nestedMap);
+ request.Body.SetList("listField", new ArrayList(new Object[] { "a", "b", "c" }));
+
+ producer.Send(request);
+
+ IMapMessage message = consumer.Receive(receiveTimeout) as IMapMessage;
+ Assert.IsNotNull(message, "No message returned!");
+ Assert.AreEqual(request.Body.Count, message.Body.Count, "Invalid number of message maps.");
+ Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
+
+ string textFieldResponse = message.Body.GetString("textField");
+ Assert.AreEqual(textFieldValue, textFieldResponse, "textField does not match.");
+
+ IDictionary nestedMapResponse = message.Body.GetDictionary("mapField");
+ Assert.IsNotNull(nestedMapResponse, "Nested map not returned.");
+ Assert.AreEqual(nestedMap.Count, nestedMapResponse.Count, "nestedMap: Wrong number of elements");
+ Assert.AreEqual("foo", nestedMapResponse["a"], "nestedMap: a");
+ Assert.AreEqual(23, nestedMapResponse["b"], "nestedMap: b");
+ Assert.AreEqual(45, nestedMapResponse["c"], "nestedMap: c");
+
+ IDictionary grandChildMapResponse = nestedMapResponse["d"] as IDictionary;
+ Assert.IsNotNull(grandChildMapResponse, "Grand child map not returned.");
+ Assert.AreEqual(grandChildMap.Count, grandChildMapResponse.Count, "grandChildMap: Wrong number of elements");
+ Assert.AreEqual(grandChildMapResponse["x"], "abc", "grandChildMap: x");
+
+ IList grandChildList = grandChildMapResponse["y"] as IList;
+ Assert.IsNotNull(grandChildList, "Grand child list not returned.");
+ Assert.AreEqual(3, grandChildList.Count, "grandChildList: Wrong number of list elements.");
+ Assert.AreEqual("a", grandChildList[0], "grandChildList: a");
+ Assert.AreEqual("b", grandChildList[1], "grandChildList: b");
+ Assert.AreEqual("c", grandChildList[2], "grandChildList: c");
+
+ IList listFieldResponse = message.Body.GetList("listField");
+ Assert.IsNotNull(listFieldResponse, "Nested list not returned.");
+ Assert.AreEqual(3, listFieldResponse.Count, "listFieldResponse: Wrong number of list elements.");
+ Assert.AreEqual("a", listFieldResponse[0], "listFieldResponse: a");
+ Assert.AreEqual("b", listFieldResponse[1], "listFieldResponse: b");
+ Assert.AreEqual("c", listFieldResponse[2], "listFieldResponse: c");
+ }
+ catch(NotSupportedException)
+ {
+ }
+ catch(NMSException e)
+ {
+ Assert.IsTrue(e.InnerException.GetType() == typeof(NotSupportedException));
+ }
+ }
+ }
+ }
+ }
+ }
}
Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/MessageTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/MessageTest.cs?rev=992152&r1=992151&r2=992152&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/MessageTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/MessageTest.cs Thu Sep 2 23:13:58 2010
@@ -15,7 +15,10 @@
* limitations under the License.
*/
+using System;
+
using Apache.NMS.Util;
+
using NUnit.Framework;
namespace Apache.NMS.Test
Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/StreamMessageTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/StreamMessageTest.cs?rev=992152&r1=992151&r2=992152&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/StreamMessageTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/StreamMessageTest.cs Thu Sep 2 23:13:58 2010
@@ -56,7 +56,17 @@ namespace Apache.NMS.Test
using(IMessageProducer producer = session.CreateProducer(destination))
{
producer.DeliveryMode = deliveryMode;
- IStreamMessage request = session.CreateStreamMessage();
+ IStreamMessage request;
+
+ try
+ {
+ request = session.CreateStreamMessage();
+ }
+ catch(System.NotSupportedException)
+ {
+ return;
+ }
+
request.WriteBoolean(a);
request.WriteByte(b);
request.WriteChar(c);
Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/TempDestinationDeletionTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/TempDestinationDeletionTest.cs?rev=992152&r1=992151&r2=992152&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/TempDestinationDeletionTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/TempDestinationDeletionTest.cs Thu Sep 2 23:13:58 2010
@@ -15,6 +15,7 @@
* limitations under the License.
*/
+using System;
using Apache.NMS.Util;
using NUnit.Framework;
@@ -36,7 +37,7 @@ namespace Apache.NMS.Test
[Values(QUEUE_DESTINATION_NAME, TOPIC_DESTINATION_NAME, TEMP_QUEUE_DESTINATION_NAME, TEMP_TOPIC_DESTINATION_NAME)]
string destinationName)
{
- using(IConnection connection1 = CreateConnection(TEST_CLIENT_ID))
+ using(IConnection connection1 = CreateConnection(TEST_CLIENT_ID + new System.Random().Next()))
{
connection1.Start();
using(ISession session = connection1.CreateSession(AcknowledgementMode.AutoAcknowledge))
@@ -56,11 +57,23 @@ namespace Apache.NMS.Test
request.NMSType = "TEMP_MSG";
producer.Send(request);
- IMessage receivedMsg = consumer.Receive();
+ IMessage receivedMsg = consumer.Receive(TimeSpan.FromMilliseconds(5000));
+ Assert.IsNotNull(receivedMsg);
Assert.AreEqual(receivedMsg.NMSType, "TEMP_MSG");
+
+ // Ensures that Consumer closes out its subscription
+ consumer.Close();
}
- session.DeleteDestination(destination);
+ try
+ {
+ session.DeleteDestination(destination);
+ }
+ catch(NotSupportedException)
+ {
+ // Might as well not try this again.
+ break;
+ }
}
}
}