Skip to content
Permalink
Browse files
Fix message comparison in the test.
  • Loading branch information
Jim Gomes committed Aug 16, 2010
1 parent 72e029f commit 712edafa21ae20492bc9ca43f31d14d47a2e235c
Showing 1 changed file with 39 additions and 24 deletions.
@@ -23,7 +23,7 @@ namespace Apache.NMS.Test
{
[TestFixture]
public class TempDestinationTest : NMSTestSupport
{
{
private IConnection connection;
private IList connections = ArrayList.Synchronized(new ArrayList());

@@ -35,13 +35,13 @@ public override void SetUp()
this.connection = CreateConnection();
this.connections.Add(connection);
}

[TearDown]
public override void TearDown()
{
foreach(IConnection conn in this.connections)
{
try
{
try
{
conn.Close();
}
@@ -56,17 +56,17 @@ public override void TearDown()
}

[Test]
public void TestTempDestOnlyConsumedByLocalConn()
public void TestTempDestOnlyConsumedByLocalConn()
{
connection.Start();

ISession tempSession = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
ITemporaryQueue queue = tempSession.CreateTemporaryQueue();
IMessageProducer producer = tempSession.CreateProducer(queue);
producer.DeliveryMode = (MsgDeliveryMode.NonPersistent);
ITextMessage message = tempSession.CreateTextMessage("First");
producer.Send(message);

// temp destination should not be consume when using another connection
IConnection otherConnection = CreateConnection();
connections.Add(otherConnection);
@@ -83,72 +83,87 @@ public void TestTempDestOnlyConsumedByLocalConn()
}

[Test]
public void TestTempQueueHoldsMessagesWithConsumers()
public void TestTempQueueHoldsMessagesWithConsumers()
{
ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
ITemporaryQueue queue = session.CreateTemporaryQueue();
IMessageConsumer consumer = session.CreateConsumer(queue);
connection.Start();

IMessageProducer producer = session.CreateProducer(queue);
producer.DeliveryMode = (MsgDeliveryMode.NonPersistent);
ITextMessage message = session.CreateTextMessage("Hello");
producer.Send(message);

IMessage message2 = consumer.Receive(TimeSpan.FromMilliseconds(1000));
Assert.IsNotNull(message2);
Assert.IsTrue(message2 is ITextMessage, "Expected message to be a ITextMessage");
Assert.IsTrue(((ITextMessage)message2).Text == message.Text, "Expected message to be a '" + message.Text + "'");
}

[Test]
public void TestTempQueueHoldsMessagesWithoutConsumers()
public void TestTempQueueHoldsMessagesWithoutConsumers()
{
ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
ITemporaryQueue queue = session.CreateTemporaryQueue();
IMessageProducer producer = session.CreateProducer(queue);
producer.DeliveryMode = MsgDeliveryMode.NonPersistent;
ITextMessage message = session.CreateTextMessage("Hello");
producer.Send(message);

connection.Start();
IMessageConsumer consumer = session.CreateConsumer(queue);
IMessage message2 = consumer.Receive(TimeSpan.FromMilliseconds(3000));
Assert.IsNotNull(message2);
Assert.IsTrue(message2 is ITextMessage, "Expected message to be a ITextMessage");
Assert.IsTrue(((ITextMessage)message2).Text == message.Text, "Expected message to be a '" + message.Text + "'");
}

[Test]
public void TestTmpQueueWorksUnderLoad()
public void TestTmpQueueWorksUnderLoad()
{
int count = 500;
int dataSize = 1024;

ArrayList list = new ArrayList(count);
ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
ITemporaryQueue queue = session.CreateTemporaryQueue();
IBytesMessage message;
IBytesMessage message2;
IMessageProducer producer = session.CreateProducer(queue);
producer.DeliveryMode = MsgDeliveryMode.NonPersistent;

byte[] data = new byte[dataSize];
for(int i = 0; i < count; i++)

byte[] srcdata = new byte[dataSize];
srcdata[0] = (byte) 'B';
srcdata[1] = (byte) 'A';
srcdata[2] = (byte) 'D';
srcdata[3] = (byte) 'W';
srcdata[4] = (byte) 'O';
srcdata[5] = (byte) 'L';
srcdata[6] = (byte) 'F';
for(int i = 0; i < count; i++)
{
IBytesMessage message = session.CreateBytesMessage();
message.WriteBytes(data);
message = session.CreateBytesMessage();
message.WriteBytes(srcdata);
message.Properties.SetInt("c", i);
producer.Send(message);
list.Add(message);
}

connection.Start();
byte[] data = new byte[dataSize];
byte[] data2 = new byte[dataSize];
IMessageConsumer consumer = session.CreateConsumer(queue);
for(int i = 0; i < count; i++)
{
IMessage message2 = consumer.Receive(TimeSpan.FromMilliseconds(2000));
Assert.IsTrue(message2 != null);
message2 = consumer.Receive(TimeSpan.FromMilliseconds(2000)) as IBytesMessage;
Assert.IsNotNull(message2);
Assert.AreEqual(i, message2.Properties.GetInt("c"));
Assert.IsTrue(message2.Equals(list[i]));
message = list[i] as IBytesMessage;
Assert.IsNotNull(message);
message.ReadBytes(data);
message2.ReadBytes(data2);
Assert.AreEqual(data, data2);
}
}
}

0 comments on commit 712edaf

Please sign in to comment.