Skip to content

Commit f682c3c

Browse files
committed
add tests for memory alarm induced flow control
1 parent e1758d2 commit f682c3c

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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 junit.framework.TestCase;
36+
37+
import com.rabbitmq.client.Channel;
38+
import com.rabbitmq.client.Connection;
39+
import com.rabbitmq.client.QueueingConsumer;
40+
import com.rabbitmq.client.test.BrokerTestCase;
41+
42+
import com.rabbitmq.tools.Host;
43+
44+
45+
public class MemoryAlarms extends BrokerTestCase {
46+
47+
private static final String Q = "Restart";
48+
49+
private Connection connection2;
50+
private Channel channel2;
51+
52+
@Override
53+
protected void setUp()
54+
throws IOException
55+
{
56+
super.setUp();
57+
if (connection2 == null) {
58+
connection2 = connectionFactory.newConnection();
59+
}
60+
channel2 = connection2.createChannel();
61+
}
62+
63+
@Override
64+
protected void tearDown()
65+
throws IOException
66+
{
67+
if (channel2 != null) {
68+
channel2.abort();
69+
channel2 = null;
70+
}
71+
if (connection2 != null) {
72+
connection2.abort();
73+
connection2 = null;
74+
}
75+
super.tearDown();
76+
}
77+
78+
@Override
79+
protected void createResources()
80+
throws IOException
81+
{
82+
channel.queueDeclare(Q, false, false, false, null);
83+
}
84+
85+
@Override
86+
protected void releaseResources()
87+
throws IOException
88+
{
89+
channel.queueDelete(Q);
90+
}
91+
92+
protected void setMemoryAlarm()
93+
throws IOException, InterruptedException
94+
{
95+
Host.executeCommand("cd ../rabbitmq-test; make set-memory-alarm");
96+
}
97+
98+
protected void clearMemoryAlarm()
99+
throws IOException, InterruptedException
100+
{
101+
Host.executeCommand("cd ../rabbitmq-test; make clear-memory-alarm");
102+
}
103+
104+
public void testFlowControl()
105+
throws IOException, InterruptedException
106+
{
107+
basicPublishVolatile(Q);
108+
setMemoryAlarm();
109+
//non-publish actions only after an alarm should be fine
110+
assertNotNull(basicGet(Q));
111+
QueueingConsumer c = new QueueingConsumer(channel);
112+
String consumerTag = channel.basicConsume(Q, true, c);
113+
//publishes after an alarm should not go through
114+
basicPublishVolatile(Q);
115+
assertNull(c.nextDelivery(10)); //the publish is async, so this is racy
116+
//once the alarm has cleared the publishes should go through
117+
clearMemoryAlarm();
118+
assertNotNull(c.nextDelivery());
119+
//everything should be back to normal
120+
channel.basicCancel(consumerTag);
121+
basicPublishVolatile(Q);
122+
assertNotNull(basicGet(Q));
123+
}
124+
125+
}

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)