Skip to content

Commit 47f0e5d

Browse files
author
Matthew Sackman
committed
Added test
1 parent 03afbbe commit 47f0e5d

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
}

test/src/com/rabbitmq/client/test/functional/FunctionalTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public static TestSuite suite() {
5454
suite.addTestSuite(DefaultExchange.class);
5555
suite.addTestSuite(UnbindAutoDeleteExchange.class);
5656
suite.addTestSuite(Confirm.class);
57+
suite.addTestSuite(ConsumerCancelNotificiation.class);
5758
suite.addTestSuite(UnexpectedFrames.class);
5859
suite.addTestSuite(PerQueueTTL.class);
5960
suite.addTestSuite(SaslMechanisms.class);

0 commit comments

Comments
 (0)