Skip to content

Commit a90a964

Browse files
author
David R. MacIver
committed
add test case for queueing consumer shutdown from multiple threads. Verified that it fails with the old implementation and passes for the new one
1 parent 742c826 commit a90a964

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

test/src/com/rabbitmq/client/test/ClientTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public static TestSuite suite() {
4545
suite.addTest(BrokenFramesTest.suite());
4646
suite.addTest(ClonePropertiesTest.suite());
4747
suite.addTestSuite(Bug20004Test.class);
48+
suite.addTestSuite(QueueingConsumerShutdownTests.class);
4849
return suite;
4950
}
5051
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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 at
4+
// 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 the
8+
// License for the specific language governing rights and limitations
9+
// under the License.
10+
//
11+
// The Original Code is RabbitMQ.
12+
//
13+
// The Initial Developers of the Original Code are LShift Ltd,
14+
// Cohesive Financial Technologies LLC, and Rabbit Technologies Ltd.
15+
//
16+
// Portions created before 22-Nov-2008 00:00:00 GMT by LShift Ltd,
17+
// Cohesive Financial Technologies LLC, or Rabbit Technologies Ltd
18+
// are Copyright (C) 2007-2008 LShift Ltd, Cohesive Financial
19+
// Technologies LLC, and Rabbit Technologies Ltd.
20+
//
21+
// Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift
22+
// Ltd. Portions created by Cohesive Financial Technologies LLC are
23+
// Copyright (C) 2007-2009 Cohesive Financial Technologies
24+
// LLC. Portions created by Rabbit Technologies Ltd are Copyright
25+
// (C) 2007-2009 Rabbit Technologies Ltd.
26+
//
27+
// All Rights Reserved.
28+
//
29+
// Contributor(s): ______________________________________.
30+
//
31+
package com.rabbitmq.client.test;
32+
33+
import com.rabbitmq.client.*;
34+
import java.util.concurrent.atomic.AtomicInteger;
35+
import java.util.concurrent.CountDownLatch;
36+
import java.util.concurrent.TimeUnit;
37+
38+
public class QueueingConsumerShutdownTests extends BrokerTestCase{
39+
static final String QUEUE = "some-queue";
40+
static final int THREADS = 5;
41+
42+
public void testNThreadShutdown() throws Exception{
43+
Channel channel = connection.createChannel();
44+
final QueueingConsumer c = new QueueingConsumer(channel);
45+
channel.queueDeclare(QUEUE);
46+
channel.basicConsume(QUEUE, c);
47+
final AtomicInteger count = new AtomicInteger(THREADS);
48+
final CountDownLatch latch = new CountDownLatch(THREADS);
49+
50+
for(int i = 0; i < THREADS; i++){
51+
new Thread(){
52+
@Override public void run(){
53+
try {
54+
while(true){
55+
c.nextDelivery();
56+
}
57+
} catch (ShutdownSignalException sig) {
58+
count.decrementAndGet();
59+
} catch (Exception e) {
60+
throw new RuntimeException(e);
61+
} finally {
62+
latch.countDown();
63+
}
64+
}
65+
}.start();
66+
}
67+
68+
connection.close();
69+
70+
// Far longer than this could reasonably take
71+
assertTrue(latch.await(5, TimeUnit.SECONDS));
72+
assertEquals(0, count.get());
73+
}
74+
75+
76+
}

0 commit comments

Comments
 (0)