Skip to content
Permalink
Browse files
Unit Test cleanup:
1. Fix FilterIgnoredMessagesTest.  It would get blocked by producer flow control and fail to run.
2. Standardized the destination naming convention to prefix names with "TEST.".
3. Standardized destination creation API.

All tests pass on ActiveMQ 5.7.0.
  • Loading branch information
Jim Gomes committed Feb 26, 2013
1 parent 6dd0bc9 commit d205dc21f23b779c9336f9c2665313c83867e268
Showing 18 changed files with 627 additions and 663 deletions.
@@ -24,7 +24,6 @@ namespace Apache.NMS.Test
[TestFixture]
public class AsyncConsumeTest : NMSTestSupport
{
protected static string DESTINATION_NAME = "AsyncConsumeDestination";
protected string RESPONSE_CLIENT_ID;
protected AutoResetEvent semaphore;
protected bool received;
@@ -58,7 +57,7 @@ public override void TearDown()
connection.Start();
using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
{
IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
IDestination destination = CreateDestination(session, DestinationType.Queue);
using(IMessageConsumer consumer = session.CreateConsumer(destination))
using(IMessageProducer producer = session.CreateProducer(destination))
{
@@ -87,7 +86,7 @@ public override void TearDown()
connection.Start();
using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
{
IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
IDestination destination = CreateDestination(session, DestinationType.Queue);
using(IMessageProducer producer = session.CreateProducer(destination))
{
producer.DeliveryMode = deliveryMode;
@@ -118,7 +117,7 @@ public override void TearDown()
connection.Start();
using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
{
IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
IDestination destination = CreateDestination(session, DestinationType.Queue);
using(IMessageConsumer consumer = session.CreateConsumer(destination))
using(IMessageProducer producer = session.CreateProducer(destination))
{
@@ -148,7 +147,7 @@ public override void TearDown()
connection.Start();
using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
{
IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
IDestination destination = CreateDestination(session, DestinationType.Queue);
using(IMessageConsumer consumer = session.CreateConsumer(destination))
{
consumer.Listener += new MessageListener(OnMessage);
@@ -184,7 +183,7 @@ public override void TearDown()
connection.Start();
using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
{
IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
IDestination destination = CreateDestination(session, DestinationType.Queue);
ITemporaryQueue tempReplyDestination = session.CreateTemporaryQueue();

using(IMessageConsumer consumer = session.CreateConsumer(destination))
@@ -24,7 +24,6 @@ namespace Apache.NMS.Test
[TestFixture]
public class BytesMessageTest : NMSTestSupport
{
protected static string DESTINATION_NAME = "BytesMessageDestination";
protected byte[] msgContent = {1, 2, 3, 4, 5, 6, 7, 8};

[Test]
@@ -37,7 +36,7 @@ public class BytesMessageTest : NMSTestSupport
connection.Start();
using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
{
IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
IDestination destination = CreateDestination(session, DestinationType.Queue);
using(IMessageConsumer consumer = session.CreateConsumer(destination))
using(IMessageProducer producer = session.CreateProducer(destination))
{
@@ -65,7 +64,7 @@ public class BytesMessageTest : NMSTestSupport
connection.Start();
using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
{
IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
IDestination destination = CreateDestination(session, DestinationType.Queue);
using(IMessageConsumer consumer = session.CreateConsumer(destination))
using(IMessageProducer producer = session.CreateProducer(destination))
{
@@ -154,38 +154,6 @@ public static Destination Transform(IDestination destination)
return result;
}

/// <summary>
/// Create a Destination
/// </summary>
/// <param name="type"></param>
/// <param name="pyhsicalName"></param>
/// <returns></returns>
public static Destination CreateDestination(int type, String pyhsicalName)
{
Destination result = null;
if(pyhsicalName == null)
{
return null;
}
else if(type == TOPIC)
{
result = new Topic(pyhsicalName);
}
else if(type == TEMPORARY_TOPIC)
{
result = new TempTopic(pyhsicalName);
}
else if(type == QUEUE)
{
result = new Queue(pyhsicalName);
}
else
{
result = new TempQueue(pyhsicalName);
}
return result;
}

/// <summary>
/// Create a temporary name from the clientId
/// </summary>
@@ -75,8 +75,8 @@ public void TwoConnections()

using(ISession session = connection.CreateSession())
{
IQueue queue = session.GetQueue("DisposalTestQueue");
IMessageConsumer consumer = session.CreateConsumer(queue);
IDestination destination = CreateDestination(session, DestinationType.Queue);
IMessageConsumer consumer = session.CreateConsumer(destination);

connection.Stop();
if(disposeConsumer)
@@ -98,8 +98,8 @@ public void TwoConnections()

using(ISession session = connection.CreateSession())
{
IQueue queue = session.GetQueue("DisposalTestQueue");
IMessageProducer producer = session.CreateProducer(queue);
IDestination destination = CreateDestination(session, DestinationType.Queue);
IMessageProducer producer = session.CreateProducer(destination);

connection.Stop();
if(disposeProducer)
@@ -146,7 +146,7 @@ public void TestStoppedConsumerHoldsMessagesTillStarted()
ISession stoppedSession = stoppedConnection.CreateSession(AcknowledgementMode.AutoAcknowledge);

// Setup the consumers.
ITopic topic = startedSession.GetTopic("ConnectionTestTopic");
IDestination topic = CreateDestination(startedSession, DestinationType.Topic);
IMessageConsumer startedConsumer = startedSession.CreateConsumer(topic);
IMessageConsumer stoppedConsumer = stoppedSession.CreateConsumer(topic);

@@ -317,12 +317,12 @@ public void TestAckedMessageAreConsumed()
{
connection.Start();
ISession session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);
IQueue queue = session.GetQueue(Guid.NewGuid().ToString());
IMessageProducer producer = session.CreateProducer(queue);
IDestination destination = CreateDestination(session, DestinationType.Queue);
IMessageProducer producer = session.CreateProducer(destination);
producer.Send(session.CreateTextMessage("Hello"));

// Consume the message...
IMessageConsumer consumer = session.CreateConsumer(queue);
IMessageConsumer consumer = session.CreateConsumer(destination);
IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
Assert.IsNotNull(msg);
msg.Acknowledge();
@@ -332,7 +332,7 @@ public void TestAckedMessageAreConsumed()
session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);

// Attempt to Consume the message...
consumer = session.CreateConsumer(queue);
consumer = session.CreateConsumer(destination);
msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
Assert.IsNull(msg);

@@ -347,14 +347,14 @@ public void TestLastMessageAcked()
{
connection.Start();
ISession session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);
IQueue queue = session.GetQueue(Guid.NewGuid().ToString());
IMessageProducer producer = session.CreateProducer(queue);
IDestination destination = CreateDestination(session, DestinationType.Queue);
IMessageProducer producer = session.CreateProducer(destination);
producer.Send(session.CreateTextMessage("Hello"));
producer.Send(session.CreateTextMessage("Hello2"));
producer.Send(session.CreateTextMessage("Hello3"));

// Consume the message...
IMessageConsumer consumer = session.CreateConsumer(queue);
IMessageConsumer consumer = session.CreateConsumer(destination);
IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
Assert.IsNotNull(msg);
msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
@@ -368,7 +368,7 @@ public void TestLastMessageAcked()
session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);

// Attempt to Consume the message...
consumer = session.CreateConsumer(queue);
consumer = session.CreateConsumer(destination);
msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
Assert.IsNull(msg);

@@ -383,12 +383,12 @@ public void TestUnAckedMessageAreNotConsumedOnSessionClose()
{
connection.Start();
ISession session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);
IQueue queue = session.GetQueue(Guid.NewGuid().ToString());
IMessageProducer producer = session.CreateProducer(queue);
IDestination destination = CreateDestination(session, DestinationType.Queue);
IMessageProducer producer = session.CreateProducer(destination);
producer.Send(session.CreateTextMessage("Hello"));

// Consume the message...
IMessageConsumer consumer = session.CreateConsumer(queue);
IMessageConsumer consumer = session.CreateConsumer(destination);
IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
Assert.IsNotNull(msg);
// Don't ack the message.
@@ -398,7 +398,7 @@ public void TestUnAckedMessageAreNotConsumedOnSessionClose()
session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);

// Attempt to Consume the message...
consumer = session.CreateConsumer(queue);
consumer = session.CreateConsumer(destination);
msg = consumer.Receive(TimeSpan.FromMilliseconds(2000));
Assert.IsNotNull(msg);
msg.Acknowledge();
@@ -414,12 +414,12 @@ public void TestAsyncAckedMessageAreConsumed()
{
connection.Start();
ISession session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);
IQueue queue = session.GetQueue(Guid.NewGuid().ToString());
IMessageProducer producer = session.CreateProducer(queue);
IDestination destination = CreateDestination(session, DestinationType.Queue);
IMessageProducer producer = session.CreateProducer(destination);
producer.Send(session.CreateTextMessage("Hello"));

// Consume the message...
IMessageConsumer consumer = session.CreateConsumer(queue);
IMessageConsumer consumer = session.CreateConsumer(destination);
consumer.Listener += new MessageListener(OnMessage);

Thread.Sleep(5000);
@@ -430,7 +430,7 @@ public void TestAsyncAckedMessageAreConsumed()
session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);

// Attempt to Consume the message...
consumer = session.CreateConsumer(queue);
consumer = session.CreateConsumer(destination);
IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(1000));
Assert.IsNull(msg);

@@ -447,12 +447,12 @@ public void TestAsyncUnAckedMessageAreNotConsumedOnSessionClose()
// don't aknowledge message on onMessage() call
dontAck = true;
ISession session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);
IQueue queue = session.GetQueue("Guid.NewGuid().ToString()");
IMessageProducer producer = session.CreateProducer(queue);
IDestination destination = CreateDestination(session, DestinationType.Queue);
IMessageProducer producer = session.CreateProducer(destination);
producer.Send(session.CreateTextMessage("Hello"));

// Consume the message...
IMessageConsumer consumer = session.CreateConsumer(queue);
IMessageConsumer consumer = session.CreateConsumer(destination);
consumer.Listener += new MessageListener(OnMessage);
// Don't ack the message.

@@ -463,7 +463,7 @@ public void TestAsyncUnAckedMessageAreNotConsumedOnSessionClose()
Thread.Sleep(5000);
session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);
// Attempt to Consume the message...
consumer = session.CreateConsumer(queue);
consumer = session.CreateConsumer(destination);
IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(2000));
Assert.IsNotNull(msg);
msg.Acknowledge();
@@ -25,7 +25,7 @@ namespace Apache.NMS.Test
[TestFixture]
public class DurableTest : NMSTestSupport
{
protected static string DURABLE_TOPIC = "TestDurableConsumerTopic";
protected static string DURABLE_TOPIC = "topic://TEST.DurableConsumerTopic";
protected static string DURABLE_SELECTOR = "2 > 1";

protected string TEST_CLIENT_AND_CONSUMER_ID;
@@ -46,7 +46,6 @@ public override void SetUp()
AcknowledgementMode.DupsOkAcknowledge, AcknowledgementMode.Transactional)]
AcknowledgementMode ackMode)
{
string TEST_DURABLE_TOPIC = DURABLE_TOPIC + ":TestSendWhileClosed";
try
{
using(IConnection connection = CreateConnection(TEST_CLIENT_AND_CONSUMER_ID))
@@ -55,7 +54,7 @@ public override void SetUp()

using(ISession session = connection.CreateSession(ackMode))
{
ITopic topic = session.GetTopic(TEST_DURABLE_TOPIC);
ITopic topic = (ITopic) CreateDestination(session, DestinationType.Topic);
IMessageProducer producer = session.CreateProducer(topic);

producer.DeliveryMode = MsgDeliveryMode.Persistent;
@@ -110,16 +109,14 @@ public override void SetUp()
AcknowledgementMode.DupsOkAcknowledge, AcknowledgementMode.Transactional)]
AcknowledgementMode ackMode)
{
string TEST_DURABLE_TOPIC = DURABLE_TOPIC + ":TestDurableConsumerSelectorChange";

try
{
using(IConnection connection = CreateConnection(TEST_CLIENT_AND_CONSUMER_ID))
{
connection.Start();
using(ISession session = connection.CreateSession(ackMode))
{
ITopic topic = session.GetTopic(TEST_DURABLE_TOPIC);
ITopic topic = (ITopic) CreateDestination(session, DestinationType.Topic);
IMessageProducer producer = session.CreateProducer(topic);
IMessageConsumer consumer = session.CreateDurableConsumer(topic, TEST_CLIENT_AND_CONSUMER_ID, "color='red'", false);

@@ -27,8 +27,6 @@ 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";
@@ -61,7 +59,7 @@ public class ForeignMessageTransformationTest : NMSTestSupport
connection.Start();
using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
{
IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
IDestination destination = CreateDestination(session, DestinationType.Topic);
using(IMessageConsumer consumer = session.CreateConsumer(destination))
using(IMessageProducer producer = session.CreateProducer(destination))
{
@@ -102,7 +100,7 @@ public class ForeignMessageTransformationTest : NMSTestSupport
connection.Start();
using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
{
IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
IDestination destination = CreateDestination(session, DestinationType.Topic);
using(IMessageConsumer consumer = session.CreateConsumer(destination))
using(IMessageProducer producer = session.CreateProducer(destination))
{
@@ -147,7 +145,7 @@ public class ForeignMessageTransformationTest : NMSTestSupport
connection.Start();
using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
{
IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
IDestination destination = CreateDestination(session, DestinationType.Topic);
using(IMessageConsumer consumer = session.CreateConsumer(destination))
using(IMessageProducer producer = session.CreateProducer(destination))
{
@@ -194,7 +192,7 @@ public class ForeignMessageTransformationTest : NMSTestSupport
connection.Start();
using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
{
IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
IDestination destination = CreateDestination(session, DestinationType.Topic);
using(IMessageConsumer consumer = session.CreateConsumer(destination))
using(IMessageProducer producer = session.CreateProducer(destination))
{
@@ -240,7 +238,7 @@ public class ForeignMessageTransformationTest : NMSTestSupport
connection.Start();
using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
{
IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
IDestination destination = CreateDestination(session, DestinationType.Topic);
using(IMessageConsumer consumer = session.CreateConsumer(destination))
using(IMessageProducer producer = session.CreateProducer(destination))
{

0 comments on commit d205dc2

Please sign in to comment.