|
| 1 | +// This source code is dual-licensed under the Apache License, version |
| 2 | +// 2.0, and the Mozilla Public License, version 1.1. |
| 3 | +// |
| 4 | +// The APL v2.0: |
| 5 | +// |
| 6 | +//--------------------------------------------------------------------------- |
| 7 | +// Copyright (C) 2007-2011 VMware, Inc. |
| 8 | +// |
| 9 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | +// you may not use this file except in compliance with the License. |
| 11 | +// You may obtain a copy of the License at |
| 12 | +// |
| 13 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | +// |
| 15 | +// Unless required by applicable law or agreed to in writing, software |
| 16 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | +// See the License for the specific language governing permissions and |
| 19 | +// limitations under the License. |
| 20 | +//--------------------------------------------------------------------------- |
| 21 | +// |
| 22 | +// The MPL v1.1: |
| 23 | +// |
| 24 | +//--------------------------------------------------------------------------- |
| 25 | +// The contents of this file are subject to the Mozilla Public License |
| 26 | +// Version 1.1 (the "License"); you may not use this file except in |
| 27 | +// compliance with the License. You may obtain a copy of the License |
| 28 | +// at http://www.mozilla.org/MPL/ |
| 29 | +// |
| 30 | +// Software distributed under the License is distributed on an "AS IS" |
| 31 | +// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See |
| 32 | +// the License for the specific language governing rights and |
| 33 | +// limitations under the License. |
| 34 | +// |
| 35 | +// The Original Code is RabbitMQ. |
| 36 | +// |
| 37 | +// The Initial Developer of the Original Code is VMware, Inc. |
| 38 | +// Copyright (c) 2007-2011 VMware, Inc. All rights reserved. |
| 39 | +//--------------------------------------------------------------------------- |
| 40 | + |
| 41 | +using NUnit.Framework; |
| 42 | + |
| 43 | +using System; |
| 44 | +using System.IO; |
| 45 | +using System.Text; |
| 46 | +using System.Collections; |
| 47 | +using System.Threading; |
| 48 | + |
| 49 | +using RabbitMQ.Client; |
| 50 | +using RabbitMQ.Client.Impl; |
| 51 | +using RabbitMQ.Util; |
| 52 | + |
| 53 | +namespace RabbitMQ.Client.Unit |
| 54 | +{ |
| 55 | + [TestFixture] |
| 56 | + public class TestConsumerCancelNotify |
| 57 | + { |
| 58 | + |
| 59 | + Object lockObject = new Object(); |
| 60 | + bool notified = false; |
| 61 | + |
| 62 | + [Test] |
| 63 | + public void TestConsumerCancelNotification() |
| 64 | + { |
| 65 | + string queue = "queue_consumer_notify"; |
| 66 | + ConnectionFactory connFactory = new ConnectionFactory(); |
| 67 | + IConnection conn = connFactory.CreateConnection(); |
| 68 | + IModel chan = conn.CreateModel(); |
| 69 | + chan.QueueDeclare(queue, false, true, false, null); |
| 70 | + IBasicConsumer consumer = new CancelNotificationConsumer(chan, this); |
| 71 | + chan.BasicConsume(queue, false, consumer); |
| 72 | + |
| 73 | + chan.QueueDelete(queue); |
| 74 | + lock (lockObject) |
| 75 | + { |
| 76 | + if (!notified) |
| 77 | + { |
| 78 | + Monitor.Wait(lockObject); |
| 79 | + } |
| 80 | + Assert.IsTrue(notified); |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + public class CancelNotificationConsumer : QueueingBasicConsumer |
| 85 | + { |
| 86 | + TestConsumerCancelNotify testClass; |
| 87 | + |
| 88 | + public CancelNotificationConsumer(IModel model, TestConsumerCancelNotify tc) : base(model) |
| 89 | + { |
| 90 | + this.testClass = tc; |
| 91 | + } |
| 92 | + |
| 93 | + public override void HandleBasicCancel(string consumerTag) |
| 94 | + { |
| 95 | + lock (testClass.lockObject) |
| 96 | + { |
| 97 | + testClass.notified = true; |
| 98 | + Monitor.PulseAll(testClass.lockObject); |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | +} |
| 104 | + |
0 commit comments