From ad680e710c07c5ebfc0d391be98dd60ed0ccbaf9 Mon Sep 17 00:00:00 2001 From: Tomas Restrepo Date: Fri, 18 May 2007 00:51:12 +0000 Subject: Merged revisions 537954-538078,538080-538083,538085-538097,538099-538108,538110-538239,538241-538881,538883-538906,538908-538911,538913-538921,538923-539191 via svnmerge from https://svn.apache.org/repos/asf/incubator/qpid/branches/M2 ........ r537954 | tomasr | 2007-05-14 14:10:59 -0500 (Mon, 14 May 2007) | 4 lines * QPID-487 (Contributed by Carlos Medina) Fix QpidConnectionInfo.ToString() * QPID-485 (Contributed by Carlos Medina) Fix AmqBrokerInfo.Equals() * QPID-456 Enforce virtual host names start with '/' ........ r538035 | tomasr | 2007-05-14 20:33:00 -0500 (Mon, 14 May 2007) | 6 lines * QPID-452 Improve message classes API * Add XML documentation to IChannel and IMessage * Add missing BrokerDetailTests * Add new tests for message creation and message factories * Fix wrong default encoding for text messages ........ r539178 | tomasr | 2007-05-17 18:50:50 -0500 (Thu, 17 May 2007) | 6 lines * QPID-492 Fix Race condition in message decoding * QPID-249 Make ServiceRequestingClient and ServiceProvidingClient a single, self contained test * Fix incorrect exception message in Qpid.Buffers, improve tests * Make ContentBody use an sliced buffer to avoid extra data copy * Remove useless tests in Qpid.Client (Blocking IO tests) ........ r539191 | tomasr | 2007-05-17 19:18:26 -0500 (Thu, 17 May 2007) | 1 line QPID-490 (Contributed by Carlos Medina) Implement PurgeQueue and DeleteQueue ........ git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@539198 13f79535-47bb-0310-9956-ffa450edef68 --- .../Qpid.Client.Tests/Channel/ChannelQueueTest.cs | 251 +++++++++++++++++++++ 1 file changed, 251 insertions(+) create mode 100644 qpid/dotnet/Qpid.Client.Tests/Channel/ChannelQueueTest.cs (limited to 'qpid/dotnet/Qpid.Client.Tests/Channel/ChannelQueueTest.cs') diff --git a/qpid/dotnet/Qpid.Client.Tests/Channel/ChannelQueueTest.cs b/qpid/dotnet/Qpid.Client.Tests/Channel/ChannelQueueTest.cs new file mode 100644 index 0000000000..88a056a245 --- /dev/null +++ b/qpid/dotnet/Qpid.Client.Tests/Channel/ChannelQueueTest.cs @@ -0,0 +1,251 @@ +/* + * + * 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.Net; +using System.Threading; +using log4net; +using Qpid.Client.Qms; +using Qpid.Messaging; +using NUnit.Framework; + +namespace Qpid.Client.Tests.Channel +{ + /// + /// Test the queue methods + /// + [TestFixture] + public class ChannelQueueTest + { + + private static ILog _logger = LogManager.GetLogger(typeof(ChannelQueueTest)); + + /// The default AMQ connection URL to use for tests. + const string DEFAULT_URI = "amqp://guest:guest@default/test?brokerlist='tcp://localhost:5672'"; + const string _routingKey = "ServiceQ1"; + + private ExceptionListenerDelegate _exceptionDelegate; + private AutoResetEvent _evt = new AutoResetEvent(false); + private Exception _lastException = null; + + private IMessageConsumer _consumer; + private IMessagePublisher _publisher; + private IChannel _channel; + private IConnection _connection; + + private string _queueName; + + [SetUp] + public virtual void Init() + { + _logger.Info("public virtual void Init(): called"); + + // Create a connection to the broker. + IConnectionInfo connectionInfo = QpidConnectionInfo.FromUrl(DEFAULT_URI); + _connection = new AMQConnection(connectionInfo); + _logger.Info("Starting..."); + + // Register this to listen for exceptions on the test connection. + _exceptionDelegate = new ExceptionListenerDelegate(OnException); + _connection.ExceptionListener += _exceptionDelegate; + + // Establish a session on the broker. + _channel = _connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge, 1); + + // Create a durable, non-temporary, non-exclusive queue. + _queueName = _channel.GenerateUniqueName(); + _channel.DeclareQueue(_queueName, true, false, false); + + _channel.Bind(_queueName, ExchangeNameDefaults.TOPIC, _routingKey); + + // Clear the most recent message and exception. + _lastException = null; + } + + [TearDown] + public virtual void ShutDown() + { + _logger.Info("public virtual void Shutdown(): called"); + + if (_connection != null) + { + _logger.Info("Disposing connection."); + _connection.Dispose(); + _logger.Info("Connection disposed."); + } + } + + [Test] + public void DeleteInExistentQueue() + { + try + { + _channel.DeleteQueue("Q1", false, false, true); + _logger.Info("queue deleted"); + } + catch (AMQException e) + { + _logger.Info(e.ToString()); + } + } + + [Test] + public void DeleteUsedQueue() + { + // Create the consumer + _consumer = _channel.CreateConsumerBuilder(_queueName) + .WithPrefetchLow(100) + .Create(); + _logger.Info("Consumer was created..."); + + // delete the queue + _channel.DeleteQueue(_queueName, false, true, true); + _logger.InfoFormat("Queue {0} was delete", _queueName); + + Assert.IsNull(_lastException); + } + + [Test] + public void DeleteUnUsedQueue() + { + // delete the queue + _channel.DeleteQueue(_queueName, true, true, true); + _logger.InfoFormat("Queue {0} was delete", _queueName); + + Assert.IsNull(_lastException); + } + + [Test] + public void DeleteNonEmptyQueue() + { + // Create the publisher + _publisher = _channel.CreatePublisherBuilder() + .WithExchangeName(ExchangeNameDefaults.TOPIC) + .WithRoutingKey(_routingKey) + .Create(); + _logger.Info("Publisher created..."); + SendTestMessage("Message 1"); + + try + { + _channel.DeleteQueue(_queueName, true, false, true); + } + catch (AMQException) + { + Assert.Fail("The test fails"); + } + } + + [Test] + public void DeleteEmptyQueue() + { + // Create the publisher + _publisher = _channel.CreatePublisherBuilder() + .WithExchangeName(ExchangeNameDefaults.TOPIC) + .WithRoutingKey(_routingKey) + .Create(); + _logger.Info("Publisher created..."); + + // delete an empty queue with ifEmpty = true + _channel.DeleteQueue(_queueName, false, true, true); + + Assert.IsNull(_lastException); + } + + [Test] + public void DeleteQueueWithResponse() + { + // Create the publisher + _publisher = _channel.CreatePublisherBuilder() + .WithExchangeName(ExchangeNameDefaults.TOPIC) + .WithRoutingKey(_routingKey) + .Create(); + _logger.Info("Publisher created..."); + + SendTestMessage("Message 1"); + SendTestMessage("Message 2"); + + // delete the queue, the server must respond + _channel.DeleteQueue(_queueName, false, false, false); + } + + [Test] + public void PurgeQueueWithResponse() + { + _publisher = _channel.CreatePublisherBuilder() + .WithExchangeName(ExchangeNameDefaults.TOPIC) + .WithRoutingKey(_routingKey) + .Create(); + _logger.Info("Pubisher created"); + + SendTestMessage("Message 1"); + SendTestMessage("Message 2"); + + _channel.PurgeQueue(_queueName, false); + } + + [Test] + public void PurgeQueueWithOutResponse() + { + _publisher = _channel.CreatePublisherBuilder() + .WithExchangeName(ExchangeNameDefaults.TOPIC) + .WithRoutingKey(_routingKey) + .Create(); + _logger.Info("Pubisher created"); + + SendTestMessage("Message 1"); + SendTestMessage("Message 2"); + + _channel.PurgeQueue(_queueName, true); + } + + + /// + /// Callback method to handle any exceptions raised by the test connection. /// + /// The connection exception. + public void OnException(Exception e) + { + // Preserve the most recent exception in case test cases need to examine it. + _lastException = e; + + // Notify any waiting threads that an exception event has occurred. + _evt.Set(); + } + + /// + /// Sends the specified message to the test publisher, and confirms that it was received by the test consumer or not + /// depending on whether or not the message should be received by the consumer. + /// + /// Any exceptions raised by the connection will cause an Assert failure exception to be raised. + /// + /// + /// The message to send. + private void SendTestMessage(string msg) + { + // create the IMessage object + IMessage msgSend = _channel.CreateTextMessage(msg); + + // send the message + _publisher.Send(msgSend); + _logger.InfoFormat("The messages \"{0}\" was sent", msg); + } + + } +} -- cgit v1.2.1