From 42b08afb918afb052abc421fc04c50b815b05533 Mon Sep 17 00:00:00 2001 From: Rupert Smith Date: Wed, 16 Jan 2008 17:02:05 +0000 Subject: Qpid-730 Added a durable subscription test. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/M2.1@612517 13f79535-47bb-0310-9956-ffa450edef68 --- .../Qpid.Buffer.Tests/Properties/AssemblyInfo.cs | 2 +- dotnet/Qpid.Buffer/Properties/AssemblyInfo.cs | 2 +- .../Qpid.Client.Tests/Properties/AssemblyInfo.cs | 2 +- .../Properties/AssemblyInfo.cs | 2 +- dotnet/Qpid.Client/Properties/AssemblyInfo.cs | 2 +- dotnet/Qpid.Codec/Properties/AssemblyInfo.cs | 2 +- .../Qpid.Common.Tests/Properties/AssemblyInfo.cs | 2 +- dotnet/Qpid.Common/Properties/AssemblyInfo.cs | 2 +- .../testcases/BaseMessagingTestFixture.cs | 30 ++-- .../testcases/DurableSubscriptionTest.cs | 154 +++++++++++++++++++++ .../testcases/MandatoryMessageTest.cs | 19 ++- dotnet/Qpid.Messaging/Properties/AssemblyInfo.cs | 2 +- dotnet/Qpid.Sasl.Tests/Properties/AssemblyInfo.cs | 2 +- dotnet/Qpid.Sasl/Properties/AssemblyInfo.cs | 2 +- dotnet/TestClient/Properties/AssemblyInfo.cs | 2 +- dotnet/TopicListener/Properties/AssemblyInfo.cs | 2 +- dotnet/TopicPublisher/Properties/AssemblyInfo.cs | 2 +- 17 files changed, 196 insertions(+), 35 deletions(-) create mode 100644 dotnet/Qpid.Integration.Tests/testcases/DurableSubscriptionTest.cs (limited to 'dotnet') diff --git a/dotnet/Qpid.Buffer.Tests/Properties/AssemblyInfo.cs b/dotnet/Qpid.Buffer.Tests/Properties/AssemblyInfo.cs index fbb1b0e430..52ec109908 100644 --- a/dotnet/Qpid.Buffer.Tests/Properties/AssemblyInfo.cs +++ b/dotnet/Qpid.Buffer.Tests/Properties/AssemblyInfo.cs @@ -6,7 +6,7 @@ using System.Runtime.InteropServices; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Apache.Qpid.Buffer.Tests")] -[assembly: AssemblyDescription("Built from svn revision number: 612420M")] +[assembly: AssemblyDescription("Built from svn revision number: 612420:612430M")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Apache Software Foundation")] [assembly: AssemblyProduct("Apache.Qpid.Buffer.Tests")] diff --git a/dotnet/Qpid.Buffer/Properties/AssemblyInfo.cs b/dotnet/Qpid.Buffer/Properties/AssemblyInfo.cs index d0ece92a3b..443f048cce 100644 --- a/dotnet/Qpid.Buffer/Properties/AssemblyInfo.cs +++ b/dotnet/Qpid.Buffer/Properties/AssemblyInfo.cs @@ -24,7 +24,7 @@ using System.Runtime.InteropServices; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Apache.Qpid.ByteBuffer")] -[assembly: AssemblyDescription("Built from svn revision number: 612420M")] +[assembly: AssemblyDescription("Built from svn revision number: 612420:612430M")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Apache Software Foundation")] [assembly: AssemblyProduct("Apache.Qpid.ByteBuffer")] diff --git a/dotnet/Qpid.Client.Tests/Properties/AssemblyInfo.cs b/dotnet/Qpid.Client.Tests/Properties/AssemblyInfo.cs index 5d3ea3a658..7d35b7be8f 100644 --- a/dotnet/Qpid.Client.Tests/Properties/AssemblyInfo.cs +++ b/dotnet/Qpid.Client.Tests/Properties/AssemblyInfo.cs @@ -27,7 +27,7 @@ using log4net.Config; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Apache.Qpid.Client.Tests")] -[assembly: AssemblyDescription("Built from svn revision number: 612420M")] +[assembly: AssemblyDescription("Built from svn revision number: 612420:612430M")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Apache Software Foundation")] [assembly: AssemblyProduct("Apache.Qpid.Client.Tests")] diff --git a/dotnet/Qpid.Client.Transport.Socket.Blocking/Properties/AssemblyInfo.cs b/dotnet/Qpid.Client.Transport.Socket.Blocking/Properties/AssemblyInfo.cs index ab00194a8d..2a3c84eae0 100644 --- a/dotnet/Qpid.Client.Transport.Socket.Blocking/Properties/AssemblyInfo.cs +++ b/dotnet/Qpid.Client.Transport.Socket.Blocking/Properties/AssemblyInfo.cs @@ -24,7 +24,7 @@ using System.Runtime.InteropServices; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Apache.Qpid.Transport.Blocking")] -[assembly: AssemblyDescription("Built from svn revision number: 612420M")] +[assembly: AssemblyDescription("Built from svn revision number: 612420:612430M")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Apache Software Foundation")] [assembly: AssemblyProduct("Apache.Qpid.Transport.Blocking")] diff --git a/dotnet/Qpid.Client/Properties/AssemblyInfo.cs b/dotnet/Qpid.Client/Properties/AssemblyInfo.cs index 6ee2cf7e35..8961a85e83 100644 --- a/dotnet/Qpid.Client/Properties/AssemblyInfo.cs +++ b/dotnet/Qpid.Client/Properties/AssemblyInfo.cs @@ -24,7 +24,7 @@ using System.Runtime.InteropServices; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Apache.Qpid.Client")] -[assembly: AssemblyDescription("Built from svn revision number: 612420M")] +[assembly: AssemblyDescription("Built from svn revision number: 612420:612430M")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Apache Software Foundation")] [assembly: AssemblyProduct("Apache.Qpid.Client")] diff --git a/dotnet/Qpid.Codec/Properties/AssemblyInfo.cs b/dotnet/Qpid.Codec/Properties/AssemblyInfo.cs index c26f837871..26f118f8f9 100644 --- a/dotnet/Qpid.Codec/Properties/AssemblyInfo.cs +++ b/dotnet/Qpid.Codec/Properties/AssemblyInfo.cs @@ -24,7 +24,7 @@ using System.Runtime.InteropServices; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Apache.Qpid.Codec")] -[assembly: AssemblyDescription("Built from svn revision number: 612420M")] +[assembly: AssemblyDescription("Built from svn revision number: 612420:612430M")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Apache Software Foundation")] [assembly: AssemblyProduct("Apache.Qpid.Codec")] diff --git a/dotnet/Qpid.Common.Tests/Properties/AssemblyInfo.cs b/dotnet/Qpid.Common.Tests/Properties/AssemblyInfo.cs index aecf1dcc03..ee049e5720 100644 --- a/dotnet/Qpid.Common.Tests/Properties/AssemblyInfo.cs +++ b/dotnet/Qpid.Common.Tests/Properties/AssemblyInfo.cs @@ -4,7 +4,7 @@ using System.Runtime.InteropServices; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Apache.Qpid.Common.Tests")] -[assembly: AssemblyDescription("Built from svn revision number: 612420M")] +[assembly: AssemblyDescription("Built from svn revision number: 612420:612430M")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Apache Software Foundation")] [assembly: AssemblyProduct("Apache.Qpid.Common.Tests")] diff --git a/dotnet/Qpid.Common/Properties/AssemblyInfo.cs b/dotnet/Qpid.Common/Properties/AssemblyInfo.cs index 12daf02b06..b6d1e49560 100644 --- a/dotnet/Qpid.Common/Properties/AssemblyInfo.cs +++ b/dotnet/Qpid.Common/Properties/AssemblyInfo.cs @@ -24,7 +24,7 @@ using System.Runtime.InteropServices; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Apache.Qpid.Common")] -[assembly: AssemblyDescription("Built from svn revision number: 612420M")] +[assembly: AssemblyDescription("Built from svn revision number: 612420:612430M")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Apache Software Foundation")] [assembly: AssemblyProduct("Apache.Qpid.Common")] diff --git a/dotnet/Qpid.Integration.Tests/testcases/BaseMessagingTestFixture.cs b/dotnet/Qpid.Integration.Tests/testcases/BaseMessagingTestFixture.cs index c208a1eb57..fec2ea948a 100644 --- a/dotnet/Qpid.Integration.Tests/testcases/BaseMessagingTestFixture.cs +++ b/dotnet/Qpid.Integration.Tests/testcases/BaseMessagingTestFixture.cs @@ -29,12 +29,12 @@ namespace Apache.Qpid.Integration.Tests.testcases { /// /// Provides a basis for writing Unit tests that communicate with an AMQ protocol broker. By default it creates a connection - /// to a message broker running on localhost on the standard AMQ port, 5672, using guest:guest login credentials, on the default exchange, - /// 'test' queue. + /// to a message broker running on localhost on the standard AMQ port, 5672, using guest:guest login credentials. It also + /// creates a standard auto-ack channel on this connection. /// public class BaseMessagingTestFixture { - private static ILog _logger = LogManager.GetLogger(typeof(BaseMessagingTestFixture)); + private static ILog log = LogManager.GetLogger(typeof(BaseMessagingTestFixture)); /// The default AMQ connection URL to use for tests. const string connectionUri = "amqp://guest:guest@default/test?brokerlist='tcp://localhost:5672'"; @@ -51,35 +51,27 @@ namespace Apache.Qpid.Integration.Tests.testcases [SetUp] public virtual void Init() { - _logger.Info("public virtual void Init(): called"); + log.Debug("public virtual void Init(): called"); - try - { - IConnectionInfo connectionInfo = QpidConnectionInfo.FromUrl(connectionUri); - _connection = new AMQConnection(connectionInfo); - _channel = _connection.CreateChannel(false, AcknowledgeMode.NoAcknowledge, 500, 300); - } - catch (QpidException e) - { - _logger.Error("Error initialisng test fixture: " + e, e); - throw e; - } + IConnectionInfo connectionInfo = QpidConnectionInfo.FromUrl(connectionUri); + _connection = new AMQConnection(connectionInfo); + _channel = _connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge, 500, 300); } /// - /// Disposes the test connection. This is called manually because the connection is a field so dispose will not be automatically + /// Disposes of the test connection. This is called manually because the connection is a field so dispose will not be automatically /// called on it. /// [TearDown] public virtual void Shutdown() { - _logger.Info("public virtual void Shutdown(): called"); + log.Debug("public virtual void Shutdown(): called"); if (_connection != null) { - _logger.Info("Disposing connection."); + log.Debug("Disposing connection."); _connection.Dispose(); - _logger.Info("Connection disposed."); + log.Debug("Connection disposed."); } } } diff --git a/dotnet/Qpid.Integration.Tests/testcases/DurableSubscriptionTest.cs b/dotnet/Qpid.Integration.Tests/testcases/DurableSubscriptionTest.cs new file mode 100644 index 0000000000..6af9add0aa --- /dev/null +++ b/dotnet/Qpid.Integration.Tests/testcases/DurableSubscriptionTest.cs @@ -0,0 +1,154 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +using System; +using System.Threading; +using log4net; +using NUnit.Framework; +using Apache.Qpid.Messaging; +using Apache.Qpid.Client.Qms; + +namespace Apache.Qpid.Integration.Tests.testcases +{ + /// + /// DurableSubscriptionTest checks that durable subscriptions work, by sending messages that can be picked up by + /// a subscription that is currently off-line, and checking that the subscriber gets all of its messages when it + /// does come on-line. + /// + ///

+ ///
CRC Card
Responsibilities Collaborations + ///
+ ///
+ ///

+ [TestFixture, Category("Integration")] + public class DurableSubscriptionTest : BaseMessagingTestFixture + { + /// Used for debugging purposes. + private static ILog log = LogManager.GetLogger(typeof(DurableSubscriptionTest)); + + /// Defines the name of the test topic to use with the tests. + public const string TEST_ROUTING_KEY = "durablesubtestkey"; + + [SetUp] + public override void Init() + { + base.Init(); + + _connection.Start(); + } + + [TearDown] + public override void Shutdown() + { + try + { + _connection.Stop(); + } + finally + { + base.Shutdown(); + } + } + + public void TestDurableSubscriptionNoAck() + { + TestDurableSubscription(AcknowledgeMode.NoAcknowledge); + } + + public void TestDurableSubscriptionAutoAck() + { + TestDurableSubscription(AcknowledgeMode.AutoAcknowledge); + } + + private void TestDurableSubscription(AcknowledgeMode ackMode) + { + // Create a topic with one producer and two consumers. + IChannel channel0 = _connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge, 1); + IMessagePublisher publisher = channel0.CreatePublisherBuilder() + .WithExchangeName(ExchangeNameDefaults.TOPIC) + .WithRoutingKey(TEST_ROUTING_KEY) + .Create(); + + IChannel channel1 = _connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge, 1); + string topicQueueName1 = channel1.GenerateUniqueName(); + channel1.DeclareQueue(topicQueueName1, false, true, true); + channel1.Bind(topicQueueName1, ExchangeNameDefaults.TOPIC, TEST_ROUTING_KEY); + IMessageConsumer consumer1 = channel1.CreateConsumerBuilder(topicQueueName1) + .Create(); + + IChannel channel2 = _connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge, 1); + string topicQueueName2 = channel2.GenerateUniqueName(); + channel2.DeclareQueue(topicQueueName2, false, true, true); + channel2.Bind(topicQueueName2, ExchangeNameDefaults.TOPIC, TEST_ROUTING_KEY); + IMessageConsumer consumer2 = channel2.CreateConsumerBuilder(topicQueueName2) + .WithSubscriptionName("TestSubscription") + .WithDurable(true) + .Create(); + + // Send messages and receive on both consumers. + publisher.Send(channel0.CreateTextMessage("A")); + + ConsumeNMessagesOnly(1, "A", consumer1); + ConsumeNMessagesOnly(1, "A", consumer2); + + // Detach one consumer. + consumer2.Dispose(); + + // Send message and receive on one consumer. + publisher.Send(channel0.CreateTextMessage("B")); + + ConsumeNMessagesOnly(1, "B", consumer1); + + // Re-attach consumer, check that it gets the messages that it missed. + IChannel channel3 = _connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge, 1); + //string topicQueueName3 = channe3.GenerateUniqueName(); + //channe3.DeclareQueue(topicQueueName3, false, true, true); + //channe3.Bind(topicQueueName3, ExchangeNameDefaults.TOPIC, TEST_ROUTING_KEY); + IMessageConsumer consumer3 = channel3.CreateConsumerBuilder(topicQueueName2) + .WithSubscriptionName("TestSubscription") + .WithDurable(true) + .Create(); + + ConsumeNMessagesOnly(1, "B", consumer3); + + // Clean up any open consumers at the end of the test. + consumer1.Dispose(); + consumer3.Dispose(); + } + + /// Consumes n messages, checking that the n+1th is not available within a timeout. + private void ConsumeNMessagesOnly(int n, string body, IMessageConsumer consumer) + { + IMessage msg; + + // Try to receive n messages. + for (int i = 0; i < n; i++) + { + msg = consumer.Receive(500); + Assert.IsNotNull(msg, "Consumer did not receive message number " + i); + Assert.AreEqual(body, ((ITextMessage)msg).Text, "Incorrect Message recevied on consumer1."); + } + + // Check that one more than n cannot be received. + msg = consumer.Receive(500); + Assert.IsNull(msg, "Consumer got more messages than the number requested (" + n + ")."); + } + } +} diff --git a/dotnet/Qpid.Integration.Tests/testcases/MandatoryMessageTest.cs b/dotnet/Qpid.Integration.Tests/testcases/MandatoryMessageTest.cs index b1e4dc330d..746d0597f3 100644 --- a/dotnet/Qpid.Integration.Tests/testcases/MandatoryMessageTest.cs +++ b/dotnet/Qpid.Integration.Tests/testcases/MandatoryMessageTest.cs @@ -47,7 +47,7 @@ namespace Apache.Qpid.Integration.Tests.testcases /// Defines the maximum time in milliseconds, to wait for redelivery to occurr. public const int TIMEOUT = 1000; - /// Condition used as a coordinate receipt of redelivery exception to the sending thread. + /// Condition used to coordinate receipt of redelivery exception to the sending thread. private ManualResetEvent errorEvent; /// Holds the last received error condition, for examination by the tests sending thread. @@ -59,8 +59,23 @@ namespace Apache.Qpid.Integration.Tests.testcases base.Init(); errorEvent = new ManualResetEvent(false); - lastErrorException = null; + lastErrorException = null; _connection.ExceptionListener = new ExceptionListenerDelegate(OnException); + + _connection.Start(); + } + + [TearDown] + public override void Shutdown() + { + try + { + _connection.Stop(); + } + finally + { + base.Shutdown(); + } } /// diff --git a/dotnet/Qpid.Messaging/Properties/AssemblyInfo.cs b/dotnet/Qpid.Messaging/Properties/AssemblyInfo.cs index 59b746d87d..c37a434f63 100644 --- a/dotnet/Qpid.Messaging/Properties/AssemblyInfo.cs +++ b/dotnet/Qpid.Messaging/Properties/AssemblyInfo.cs @@ -25,7 +25,7 @@ using System.Runtime.InteropServices; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Apache.Qpid.Messaging")] -[assembly: AssemblyDescription("Built from svn revision number: 612420M")] +[assembly: AssemblyDescription("Built from svn revision number: 612420:612430M")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Apache Software Foundation")] [assembly: AssemblyProduct("Apache.Qpid.Messaging")] diff --git a/dotnet/Qpid.Sasl.Tests/Properties/AssemblyInfo.cs b/dotnet/Qpid.Sasl.Tests/Properties/AssemblyInfo.cs index 4985b0fea6..e7111b35a0 100644 --- a/dotnet/Qpid.Sasl.Tests/Properties/AssemblyInfo.cs +++ b/dotnet/Qpid.Sasl.Tests/Properties/AssemblyInfo.cs @@ -6,7 +6,7 @@ using System.Runtime.InteropServices; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Apache.Qpid.Sasl.Tests")] -[assembly: AssemblyDescription("Built from svn revision number: 612420M")] +[assembly: AssemblyDescription("Built from svn revision number: 612420:612430M")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Apache Software Foundation")] [assembly: AssemblyProduct("Apache.Qpid.Sasl.Tests")] diff --git a/dotnet/Qpid.Sasl/Properties/AssemblyInfo.cs b/dotnet/Qpid.Sasl/Properties/AssemblyInfo.cs index 909edd82ab..e02c2c4df6 100644 --- a/dotnet/Qpid.Sasl/Properties/AssemblyInfo.cs +++ b/dotnet/Qpid.Sasl/Properties/AssemblyInfo.cs @@ -7,7 +7,7 @@ using System.Runtime.InteropServices; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Apache.Qpid.Sasl")] -[assembly: AssemblyDescription("Built from svn revision number: 612420M")] +[assembly: AssemblyDescription("Built from svn revision number: 612420:612430M")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Apache Software Foundation")] [assembly: AssemblyProduct("Apache.Qpid.Sasl")] diff --git a/dotnet/TestClient/Properties/AssemblyInfo.cs b/dotnet/TestClient/Properties/AssemblyInfo.cs index 2cd315daef..b0c86c526f 100644 --- a/dotnet/TestClient/Properties/AssemblyInfo.cs +++ b/dotnet/TestClient/Properties/AssemblyInfo.cs @@ -6,7 +6,7 @@ using System.Runtime.InteropServices; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("TestClient")] -[assembly: AssemblyDescription("Built from svn revision number: 612420M")] +[assembly: AssemblyDescription("Built from svn revision number: 612420:612430M")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Apache Software Foundation")] [assembly: AssemblyProduct("TestClient")] diff --git a/dotnet/TopicListener/Properties/AssemblyInfo.cs b/dotnet/TopicListener/Properties/AssemblyInfo.cs index fdaa83b10c..7bc870ac81 100644 --- a/dotnet/TopicListener/Properties/AssemblyInfo.cs +++ b/dotnet/TopicListener/Properties/AssemblyInfo.cs @@ -6,7 +6,7 @@ using System.Runtime.InteropServices; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("TopicListener")] -[assembly: AssemblyDescription("Built from svn revision number: 612420M")] +[assembly: AssemblyDescription("Built from svn revision number: 612420:612430M")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Apache Software Foundation")] [assembly: AssemblyProduct("TopicListener")] diff --git a/dotnet/TopicPublisher/Properties/AssemblyInfo.cs b/dotnet/TopicPublisher/Properties/AssemblyInfo.cs index 2282ddeb36..75ca2db1ae 100644 --- a/dotnet/TopicPublisher/Properties/AssemblyInfo.cs +++ b/dotnet/TopicPublisher/Properties/AssemblyInfo.cs @@ -6,7 +6,7 @@ using System.Runtime.InteropServices; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("TopicPublisher")] -[assembly: AssemblyDescription("Built from svn revision number: 612420M")] +[assembly: AssemblyDescription("Built from svn revision number: 612420:612430M")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Apache Software Foundation")] [assembly: AssemblyProduct("TopicPublisher")] -- cgit v1.2.1