You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ai...@apache.org on 2008/05/28 16:56:54 UTC
svn commit: r660966 -
/incubator/qpid/trunk/qpid/dotnet/Qpid.Integration.Tests/testcases/CommitRollbackTest.cs
Author: aidan
Date: Wed May 28 07:56:54 2008
New Revision: 660966
URL: http://svn.apache.org/viewvc?rev=660966&view=rev
Log:
QPID-1099 Add tests for publishing several messages transactionally and consuming them in an OnMessage handler
Modified:
incubator/qpid/trunk/qpid/dotnet/Qpid.Integration.Tests/testcases/CommitRollbackTest.cs
Modified: incubator/qpid/trunk/qpid/dotnet/Qpid.Integration.Tests/testcases/CommitRollbackTest.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/Qpid.Integration.Tests/testcases/CommitRollbackTest.cs?rev=660966&r1=660965&r2=660966&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/Qpid.Integration.Tests/testcases/CommitRollbackTest.cs (original)
+++ incubator/qpid/trunk/qpid/dotnet/Qpid.Integration.Tests/testcases/CommitRollbackTest.cs Wed May 28 07:56:54 2008
@@ -49,7 +49,19 @@
/// <summary>Defines the name of the test topic to use with the tests.</summary>
public const string TEST_ROUTING_KEY = "commitrollbacktestkey";
+
+ /// <summary>Used to count test messages received so far.</summary>
+ private int messageReceivedCount;
+
+ /// <summary>Used to hold the expected number of messages to receive.</summary>
+ private int expectedMessageCount;
+ /// <summary>Monitor used to signal succesfull receipt of all test messages.</summary>
+ AutoResetEvent finishedEvent;
+
+ /// <summary>Flag used to indicate that all messages really were received, and that the test did not just time out. </summary>
+ private bool allReceived;
+
[SetUp]
public override void Init()
{
@@ -60,6 +72,12 @@
true, false, null);
SetUpEndPoint(1, true, true, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, true, ExchangeNameDefaults.DIRECT,
true, false, null);
+
+ // Clear counts
+ messageReceivedCount = 0;
+ expectedMessageCount = 0;
+ finishedEvent = new AutoResetEvent(false);
+ allReceived = false;
}
[TearDown]
@@ -189,5 +207,55 @@
ConsumeNMessagesOnly(1, "F", testConsumer[1]);
}
+
+ [Test]
+ public void TestReceivePrePublished()
+ {
+ // Send messages
+ for (int i = 0; i < 10; ++i)
+ {
+ testProducer[0].Send(testChannel[0].CreateTextMessage("G"+i));
+ testChannel[0].Commit();
+ }
+
+ for (int i = 0; i < 10; ++i)
+ {
+ ConsumeNMessages(1, "G"+i, testConsumer[1]);
+ }
+ testChannel[1].Commit();
+ }
+
+ [Test]
+ public void TestReceivePrePublishedOnMessageHandler()
+ {
+ testConsumer[1].OnMessage += new MessageReceivedDelegate(OnMessage);
+ // Send messages
+ for (int i = 0; i < 10; ++i)
+ {
+ testProducer[0].Send(testChannel[0].CreateTextMessage("G"+i));
+ testChannel[0].Commit();
+ }
+ expectedMessageCount = 10;
+
+ finishedEvent.WaitOne(new TimeSpan(0, 0, 0, 30), false);
+
+ // Check that all messages really were received.
+ Assert.IsTrue(allReceived, "All messages were not received, only got: " + messageReceivedCount + " but wanted " + expectedMessageCount);
+
+ testChannel[1].Commit();
+ }
+
+ /// <summary> Atomically increments the message count on every message, and signals once all messages in the test are received. </summary>
+ public void OnMessage(IMessage m)
+ {
+ int newCount = Interlocked.Increment(ref messageReceivedCount);
+
+ if (newCount >= expectedMessageCount)
+ {
+ allReceived = true;
+ finishedEvent.Set();
+ }
+ }
+
}
}