From 831649f6424871791fa5fac2a5a7403cf4ae45e9 Mon Sep 17 00:00:00 2001 From: Aidan Skinner Date: Wed, 28 May 2008 14:56:54 +0000 Subject: QPID-1099 Add tests for publishing several messages transactionally and consuming them in an OnMessage handler git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@660966 13f79535-47bb-0310-9956-ffa450edef68 --- .../testcases/CommitRollbackTest.cs | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/qpid/dotnet/Qpid.Integration.Tests/testcases/CommitRollbackTest.cs b/qpid/dotnet/Qpid.Integration.Tests/testcases/CommitRollbackTest.cs index 3224d2cbd2..72074da809 100644 --- a/qpid/dotnet/Qpid.Integration.Tests/testcases/CommitRollbackTest.cs +++ b/qpid/dotnet/Qpid.Integration.Tests/testcases/CommitRollbackTest.cs @@ -49,7 +49,19 @@ namespace Apache.Qpid.Integration.Tests.testcases /// Defines the name of the test topic to use with the tests. public const string TEST_ROUTING_KEY = "commitrollbacktestkey"; + + /// Used to count test messages received so far. + private int messageReceivedCount; + + /// Used to hold the expected number of messages to receive. + private int expectedMessageCount; + /// Monitor used to signal succesfull receipt of all test messages. + AutoResetEvent finishedEvent; + + /// Flag used to indicate that all messages really were received, and that the test did not just time out. + private bool allReceived; + [SetUp] public override void Init() { @@ -60,6 +72,12 @@ namespace Apache.Qpid.Integration.Tests.testcases 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 @@ namespace Apache.Qpid.Integration.Tests.testcases 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(); + } + + /// Atomically increments the message count on every message, and signals once all messages in the test are received. + public void OnMessage(IMessage m) + { + int newCount = Interlocked.Increment(ref messageReceivedCount); + + if (newCount >= expectedMessageCount) + { + allReceived = true; + finishedEvent.Set(); + } + } + } } -- cgit v1.2.1