Skip to content

Commit 315cd7b

Browse files
author
Matthew Sackman
committed
Merging bug 23027 onto default
2 parents 84694bf + 1481a28 commit 315cd7b

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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-2010 LShift
22+
// Ltd. Portions created by Cohesive Financial Technologies LLC are
23+
// Copyright (C) 2007-2010 Cohesive Financial Technologies
24+
// LLC. Portions created by Rabbit Technologies Ltd are Copyright
25+
// (C) 2007-2010 Rabbit Technologies Ltd.
26+
//
27+
// All Rights Reserved.
28+
//
29+
// Contributor(s): ______________________________________.
30+
//
31+
package com.rabbitmq.client.test.server;
32+
33+
import java.io.IOException;
34+
35+
import com.rabbitmq.client.Channel;
36+
import com.rabbitmq.client.Connection;
37+
import com.rabbitmq.client.QueueingConsumer;
38+
import com.rabbitmq.client.test.BrokerTestCase;
39+
import com.rabbitmq.tools.Host;
40+
41+
public class MemoryAlarms extends BrokerTestCase {
42+
43+
private static final String Q = "Restart";
44+
45+
private Connection connection2;
46+
private Channel channel2;
47+
48+
@Override
49+
protected void setUp() throws IOException {
50+
connectionFactory.setRequestedHeartbeat(1);
51+
super.setUp();
52+
if (connection2 == null) {
53+
connection2 = connectionFactory.newConnection();
54+
}
55+
channel2 = connection2.createChannel();
56+
}
57+
58+
@Override
59+
protected void tearDown() throws IOException {
60+
if (channel2 != null) {
61+
channel2.abort();
62+
channel2 = null;
63+
}
64+
if (connection2 != null) {
65+
connection2.abort();
66+
connection2 = null;
67+
}
68+
super.tearDown();
69+
connectionFactory.setRequestedHeartbeat(0);
70+
}
71+
72+
@Override
73+
protected void createResources() throws IOException {
74+
channel.queueDeclare(Q, false, false, false, null);
75+
}
76+
77+
@Override
78+
protected void releaseResources() throws IOException {
79+
channel.queueDelete(Q);
80+
}
81+
82+
protected void setMemoryAlarm() throws IOException, InterruptedException {
83+
Host.executeCommand("cd ../rabbitmq-test; make set-memory-alarm");
84+
}
85+
86+
protected void clearMemoryAlarm() throws IOException, InterruptedException {
87+
Host.executeCommand("cd ../rabbitmq-test; make clear-memory-alarm");
88+
}
89+
90+
public void testFlowControl() throws IOException, InterruptedException {
91+
basicPublishVolatile(Q);
92+
setMemoryAlarm();
93+
// non-publish actions only after an alarm should be fine
94+
assertNotNull(basicGet(Q));
95+
QueueingConsumer c = new QueueingConsumer(channel);
96+
String consumerTag = channel.basicConsume(Q, true, c);
97+
// publishes after an alarm should not go through
98+
basicPublishVolatile(Q);
99+
// the publish is async, so this is racy. This also tests we don't die
100+
// by heartbeat (3x heartbeat interval + epsilon)
101+
assertNull(c.nextDelivery(3100));
102+
// once the alarm has cleared the publishes should go through
103+
clearMemoryAlarm();
104+
assertNotNull(c.nextDelivery());
105+
// everything should be back to normal
106+
channel.basicCancel(consumerTag);
107+
basicPublishVolatile(Q);
108+
assertNotNull(basicGet(Q));
109+
}
110+
111+
}

test/src/com/rabbitmq/client/test/server/ServerTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public static TestSuite suite() {
4343
suite.addTest(PersisterRestartTests.suite());
4444
suite.addTestSuite(ExclusiveQueueDurability.class);
4545
suite.addTestSuite(AlternateExchangeEquivalence.class);
46+
suite.addTestSuite(MemoryAlarms.class);
4647
return suite;
4748
}
4849
}

0 commit comments

Comments
 (0)