|
| 1 | +// The contents of this file are subject to the Mozilla Public License |
| 2 | +// Version 1.1 (the "License"); you may not use this file except in |
| 3 | +// compliance with the License. You may obtain a copy of the License |
| 4 | +// at http://www.mozilla.org/MPL/ |
| 5 | +// |
| 6 | +// Software distributed under the License is distributed on an "AS IS" |
| 7 | +// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See |
| 8 | +// the License for the specific language governing rights and |
| 9 | +// limitations under the License. |
| 10 | +// |
| 11 | +// The Original Code is RabbitMQ. |
| 12 | +// |
| 13 | +// The Initial Developer of the Original Code is VMware, Inc. |
| 14 | +// Copyright (c) 2007-2011 VMware, Inc. All rights reserved. |
| 15 | +// |
| 16 | + |
| 17 | +package com.rabbitmq.client.test.functional; |
| 18 | + |
| 19 | +import java.io.IOException; |
| 20 | + |
| 21 | +import com.rabbitmq.client.Consumer; |
| 22 | +import com.rabbitmq.client.QueueingConsumer; |
| 23 | +import com.rabbitmq.client.test.BrokerTestCase; |
| 24 | + |
| 25 | +public class ConsumerCancelNotificiation extends BrokerTestCase { |
| 26 | + |
| 27 | + private final String queue = "cancel_notification_queue"; |
| 28 | + |
| 29 | + private final Object lock = new Object(); |
| 30 | + |
| 31 | + private boolean notified = false; |
| 32 | + |
| 33 | + private void assertNotified(boolean expected, boolean wait) { |
| 34 | + synchronized (lock) { |
| 35 | + if (wait) { |
| 36 | + try { |
| 37 | + lock.wait(); |
| 38 | + } catch (InterruptedException e) { |
| 39 | + } |
| 40 | + } |
| 41 | + assertEquals(notified, expected); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + public void testConsumerCancellationNotification() throws IOException { |
| 46 | + channel.queueDeclare(queue, false, true, false, null); |
| 47 | + Consumer consumer = new QueueingConsumer(channel) { |
| 48 | + @Override |
| 49 | + public void handleCancelNotification() throws IOException { |
| 50 | + synchronized (lock) { |
| 51 | + notified = !notified; |
| 52 | + lock.notifyAll(); |
| 53 | + } |
| 54 | + } |
| 55 | + }; |
| 56 | + channel.basicConsume(queue, consumer); |
| 57 | + assertNotified(false, false); |
| 58 | + channel.queueDelete(queue); |
| 59 | + assertNotified(true, true); |
| 60 | + } |
| 61 | +} |
0 commit comments