Skip to content
Permalink
Browse files
Remove tests for non-persistent durable messages. All durable consume…
…r message tests must use persistent messages. (c.f., http://activemq.apache.org/why-do-i-not-receive-messages-on-my-durable-topic-subscription.html)

Added macro expansion for TIBCOHost, TIBCOBackupHost, MSMQHost, and MSMQBackupHost.
  • Loading branch information
Jim Gomes committed Jun 1, 2009
1 parent aa087fb commit 8789ad30f5cf23db94017d53ca556417c2cf1b12
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 37 deletions.
@@ -33,34 +33,44 @@ public class DurableTest : NMSTestSupport

#if !NET_1_1
[RowTest]
[Row(MsgDeliveryMode.Persistent)]
[Row(MsgDeliveryMode.NonPersistent)]
[Row(AcknowledgementMode.AutoAcknowledge)]
[Row(AcknowledgementMode.ClientAcknowledge)]
[Row(AcknowledgementMode.DupsOkAcknowledge)]
[Row(AcknowledgementMode.Transactional)]
#endif
public void TestDurableConsumerSelectorChange(MsgDeliveryMode deliveryMode)
public void TestDurableConsumerSelectorChange(AcknowledgementMode ackMode)
{
try
{
using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
{
connection.Start();
using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
using(ISession session = connection.CreateSession(ackMode))
{
ITopic topic = SessionUtil.GetTopic(session, DURABLE_TOPIC);
ITopic topic = session.GetTopic(DURABLE_TOPIC);
IMessageProducer producer = session.CreateProducer(topic);
IMessageConsumer consumer = session.CreateDurableConsumer(topic, CONSUMER_ID, "color='red'", false);

producer.DeliveryMode = deliveryMode;
producer.DeliveryMode = MsgDeliveryMode.Persistent;

// Send the messages
ITextMessage sendMessage = session.CreateTextMessage("1st");
sendMessage.Properties["color"] = "red";
producer.Send(sendMessage);
if(AcknowledgementMode.Transactional == ackMode)
{
session.Commit();
}

ITextMessage receiveMsg = consumer.Receive(receiveTimeout) as ITextMessage;
Assert.IsNotNull(receiveMsg, "Failed to retrieve 1st durable message.");
Assert.AreEqual("1st", receiveMsg.Text);
Assert.AreEqual(deliveryMode, receiveMsg.NMSDeliveryMode, "NMSDeliveryMode does not match");
Assert.AreEqual(MsgDeliveryMode.Persistent, receiveMsg.NMSDeliveryMode, "NMSDeliveryMode does not match");
receiveMsg.Acknowledge();
if(AcknowledgementMode.Transactional == ackMode)
{
session.Commit();
}

// Change the subscription.
consumer.Dispose();
@@ -72,13 +82,21 @@ public void TestDurableConsumerSelectorChange(MsgDeliveryMode deliveryMode)
sendMessage = session.CreateTextMessage("3rd");
sendMessage.Properties["color"] = "blue";
producer.Send(sendMessage);
if(AcknowledgementMode.Transactional == ackMode)
{
session.Commit();
}

// Selector should skip the 2nd message.
receiveMsg = consumer.Receive(receiveTimeout) as ITextMessage;
Assert.IsNotNull(receiveMsg, "Failed to retrieve durable message.");
Assert.AreEqual("3rd", receiveMsg.Text, "Retrieved the wrong durable message.");
Assert.AreEqual(deliveryMode, receiveMsg.NMSDeliveryMode, "NMSDeliveryMode does not match");
Assert.AreEqual(MsgDeliveryMode.Persistent, receiveMsg.NMSDeliveryMode, "NMSDeliveryMode does not match");
receiveMsg.Acknowledge();
if(AcknowledgementMode.Transactional == ackMode)
{
session.Commit();
}

// Make sure there are no pending messages.
Assert.IsNull(consumer.ReceiveNoWait(), "Wrong number of messages in durable subscription.");
@@ -97,25 +115,20 @@ public void TestDurableConsumerSelectorChange(MsgDeliveryMode deliveryMode)

#if !NET_1_1
[RowTest]
[Row(MsgDeliveryMode.Persistent, AcknowledgementMode.AutoAcknowledge)]
[Row(MsgDeliveryMode.Persistent, AcknowledgementMode.ClientAcknowledge)]
[Row(MsgDeliveryMode.Persistent, AcknowledgementMode.DupsOkAcknowledge)]
[Row(MsgDeliveryMode.Persistent, AcknowledgementMode.Transactional)]

[Row(MsgDeliveryMode.NonPersistent, AcknowledgementMode.AutoAcknowledge)]
[Row(MsgDeliveryMode.NonPersistent, AcknowledgementMode.ClientAcknowledge)]
[Row(MsgDeliveryMode.NonPersistent, AcknowledgementMode.DupsOkAcknowledge)]
[Row(MsgDeliveryMode.NonPersistent, AcknowledgementMode.Transactional)]
[Row(AcknowledgementMode.AutoAcknowledge)]
[Row(AcknowledgementMode.ClientAcknowledge)]
[Row(AcknowledgementMode.DupsOkAcknowledge)]
[Row(AcknowledgementMode.Transactional)]
#endif
public void TestDurableConsumer(MsgDeliveryMode deliveryMode, AcknowledgementMode ackMode)
public void TestDurableConsumer(AcknowledgementMode ackMode)
{
try
{
RegisterDurableConsumer(TEST_CLIENT_ID, DURABLE_TOPIC, CONSUMER_ID, DURABLE_SELECTOR, false);
RunTestDurableConsumer(deliveryMode, ackMode);
RunTestDurableConsumer(ackMode);
if(AcknowledgementMode.Transactional == ackMode)
{
RunTestDurableConsumer(deliveryMode, ackMode);
RunTestDurableConsumer(ackMode);
}
}
finally
@@ -124,9 +137,9 @@ public void TestDurableConsumer(MsgDeliveryMode deliveryMode, AcknowledgementMod
}
}

protected void RunTestDurableConsumer(MsgDeliveryMode deliveryMode, AcknowledgementMode ackMode)
protected void RunTestDurableConsumer(AcknowledgementMode ackMode)
{
SendDurableMessage(deliveryMode);
SendDurableMessage();

using(IConnection connection = CreateConnection(TEST_CLIENT_ID))
{
@@ -139,7 +152,7 @@ protected void RunTestDurableConsumer(MsgDeliveryMode deliveryMode, Acknowledgem
IMessage msg = consumer.Receive(receiveTimeout);
Assert.IsNotNull(msg, "Did not receive first durable message.");
msg.Acknowledge();
SendDurableMessage(deliveryMode);
SendDurableMessage();

msg = consumer.Receive(receiveTimeout);
Assert.IsNotNull(msg, "Did not receive second durable message.");
@@ -154,7 +167,7 @@ protected void RunTestDurableConsumer(MsgDeliveryMode deliveryMode, Acknowledgem
}
}

protected void SendDurableMessage(MsgDeliveryMode deliveryMode)
protected void SendDurableMessage()
{
using(IConnection connection = CreateConnection(SEND_CLIENT_ID))
{
@@ -166,7 +179,7 @@ protected void SendDurableMessage(MsgDeliveryMode deliveryMode)
{
ITextMessage message = session.CreateTextMessage("Durable Hello");

producer.DeliveryMode = deliveryMode;
producer.DeliveryMode = MsgDeliveryMode.Persistent;
producer.RequestTimeout = receiveTimeout;
producer.Send(message);
}
@@ -212,31 +212,55 @@ protected static string GetNodeValueAttribute(XmlElement parentNode, string node
/// <returns></returns>
public static string ReplaceEnvVar(string srcText)
{
// TODO: This should be refactored to be more generic and support full variable
// NOTE: Might be able to refactor to be more generic and support full variable
// names that can be pulled from the environment. Currently, we only support limited
// hard-coded variable names:
//
// "${activemqhost}" - defaults to "localhost".
// "${activemqbackuphost}" - defaults to "localhost".
// hard-coded variable names.

srcText = ReplaceEnvVar(srcText, "ActiveMQHost", "localhost");
srcText = ReplaceEnvVar(srcText, "ActiveMQBackupHost", "localhost");
string defaultBroker = GetEnvVar("NMSTestBroker", "localhost");

srcText = ReplaceEnvVar(srcText, "ActiveMQHost", defaultBroker);
srcText = ReplaceEnvVar(srcText, "ActiveMQBackupHost", defaultBroker);

srcText = ReplaceEnvVar(srcText, "TIBCOHost", defaultBroker);
srcText = ReplaceEnvVar(srcText, "TIBCOBackupHost", defaultBroker);

srcText = ReplaceEnvVar(srcText, "MSMQHost", defaultBroker);
srcText = ReplaceEnvVar(srcText, "MSMQBackupHost", defaultBroker);
return srcText;
}

/// <summary>
/// Replace the variable with environment variable.
/// </summary>
/// <param name="srcText"></param>
/// <param name="varName"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static string ReplaceEnvVar(string srcText, string varName, string defaultValue)
{
string replacementValue = GetEnvVar(varName, defaultValue);
return Regex.Replace(srcText, "\\${" + varName + "}", replacementValue, RegexOptions.IgnoreCase);
}

/// <summary>
/// Get environment variable value.
/// </summary>
/// <param name="varName"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static string GetEnvVar(string varName, string defaultValue)
{
#if (PocketPC||NETCF||NETCF_2_0)
string replacementValue = null;
string varValue = null;
#else
string replacementValue = Environment.GetEnvironmentVariable(varName);
string varValue = Environment.GetEnvironmentVariable(varName);
#endif
if(null == replacementValue)
if(null == varValue)
{
replacementValue = defaultValue;
varValue = defaultValue;
}

return Regex.Replace(srcText, "\\${" + varName + "}", replacementValue, RegexOptions.IgnoreCase);
return varValue;
}

/// <summary>

0 comments on commit 8789ad3

Please sign in to comment.