diff options
author | Aidan Skinner <aidan@apache.org> | 2008-05-28 14:56:54 +0000 |
---|---|---|
committer | Aidan Skinner <aidan@apache.org> | 2008-05-28 14:56:54 +0000 |
commit | 831649f6424871791fa5fac2a5a7403cf4ae45e9 (patch) | |
tree | 910629a3a5f0aa445d2dbd2f7a2c80fa0ef4d438 /qpid/dotnet/Qpid.Integration.Tests | |
parent | 8e430931619f5778a15b56b7b6042eac18899637 (diff) | |
download | qpid-python-831649f6424871791fa5fac2a5a7403cf4ae45e9.tar.gz |
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
Diffstat (limited to 'qpid/dotnet/Qpid.Integration.Tests')
-rw-r--r-- | qpid/dotnet/Qpid.Integration.Tests/testcases/CommitRollbackTest.cs | 68 |
1 files changed, 68 insertions, 0 deletions
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 /// <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 @@ 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();
+ }
+
+ /// <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();
+ }
+ }
+
}
}
|