Skip to content

Commit 708c92c

Browse files
committed
Merge branch '4.1.x-stable' into 4.2.x-stable
2 parents 295688c + 21eb5f0 commit 708c92c

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

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

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.rabbitmq.client.impl.nio.NioParams;
2121
import com.rabbitmq.tools.Host;
2222
import org.junit.After;
23+
import org.junit.Assume;
2324
import org.junit.Before;
2425
import org.junit.Rule;
2526
import org.junit.rules.TestRule;
@@ -37,6 +38,7 @@
3738
import java.util.concurrent.TimeoutException;
3839

3940
import static org.junit.Assert.*;
41+
import static org.junit.Assume.*;
4042

4143
public class BrokerTestCase {
4244

@@ -81,6 +83,7 @@ protected boolean isAutomaticRecoveryEnabled() {
8183

8284
@Before public void setUp()
8385
throws IOException, TimeoutException {
86+
assumeTrue(shouldRun());
8487
openConnection();
8588
openChannel();
8689

@@ -89,14 +92,26 @@ protected boolean isAutomaticRecoveryEnabled() {
8992

9093
@After public void tearDown()
9194
throws IOException, TimeoutException {
92-
closeChannel();
93-
closeConnection();
95+
if(shouldRun()) {
96+
closeChannel();
97+
closeConnection();
98+
99+
openConnection();
100+
openChannel();
101+
releaseResources();
102+
closeChannel();
103+
closeConnection();
104+
}
105+
}
94106

95-
openConnection();
96-
openChannel();
97-
releaseResources();
98-
closeChannel();
99-
closeConnection();
107+
/**
108+
* Whether to run the test or not.
109+
* Subclasses can check whether some broker features
110+
* are available or not, and choose not to run the test.
111+
* @return
112+
*/
113+
protected boolean shouldRun() throws IOException {
114+
return true;
100115
}
101116

102117
/**

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public class TopicPermissions extends BrokerTestCase {
3434
String notProtectedTopic = "not.protected.topic";
3535
String noneTopicExchange = "not.a.topic";
3636

37+
@Override
38+
protected boolean shouldRun() throws IOException {
39+
return Host.isRabbitMqCtlCommandAvailable("set_topic_permissions");
40+
}
41+
3742
@Override
3843
protected void createResources() throws IOException, TimeoutException {
3944
channel.exchangeDeclare(protectedTopic, BuiltinExchangeType.TOPIC);

src/test/java/com/rabbitmq/tools/Host.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ private static Process executeCommandProcess(String command) throws IOException
9191
return Runtime.getRuntime().exec(finalCommand);
9292
}
9393

94+
public static boolean isRabbitMqCtlCommandAvailable(String command) throws IOException {
95+
Process process = rabbitmqctl("help");
96+
String stdout = capture(process.getInputStream());
97+
return stdout.contains(command);
98+
}
99+
94100
public static Process rabbitmqctl(String command) throws IOException {
95101
return executeCommand(rabbitmqctlCommand() +
96102
" -n \'" + nodenameA() + "\'" +

0 commit comments

Comments
 (0)