Skip to content

Commit c07515b

Browse files
committed
Update to run test suite against broker in docker container
1 parent 75eb1cc commit c07515b

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/test/java/com/rabbitmq/jms/util/Shell.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
public class Shell {
1919

20+
private static final String DOCKER_PREFIX = "DOCKER:";
21+
2022
public static String executeSimpleCommand(String command) {
2123
StringBuffer outputSb = new StringBuffer();
2224

@@ -48,13 +50,13 @@ public static String capture(InputStream is)
4850
}
4951

5052
public static void restartNode() throws IOException {
51-
executeCommand(rabbitmqctlCommand() + " -n " + nodenameA() + " stop_app");
52-
executeCommand(rabbitmqctlCommand() + " -n " + nodenameA() + " start_app");
53+
executeCommand(rabbitmqctlCommand() + rabbitmqctlNodenameArgument() + " stop_app");
54+
executeCommand(rabbitmqctlCommand() + rabbitmqctlNodenameArgument() + " start_app");
5355
}
5456

5557
public static List<Binding> listBindings(boolean includeDefaults) throws IOException {
5658
List<Binding> bindings = new ArrayList<>();
57-
Process process = executeCommand(rabbitmqctlCommand() + " -n " + nodenameA() + " list_bindings source_name destination_name routing_key --quiet");
59+
Process process = executeCommand(rabbitmqctlCommand() + rabbitmqctlNodenameArgument() + " list_bindings source_name destination_name routing_key --quiet");
5860
String output = capture(process.getInputStream());
5961
String[] lines = output.split("\n");
6062
if (lines.length > 0) {
@@ -116,8 +118,29 @@ public static String nodenameA() {
116118
return System.getProperty("test-broker.A.nodename");
117119
}
118120

121+
private static String rabbitmqctlNodenameArgument() {
122+
return isOnDocker() ? "" : " -n \'" + nodenameA() + "\'";
123+
}
124+
125+
public static boolean isOnDocker() {
126+
String rabbitmqCtl = System.getProperty("rabbitmqctl.bin");
127+
if (rabbitmqCtl == null) {
128+
throw new IllegalStateException("Please define the rabbitmqctl.bin system property");
129+
}
130+
return rabbitmqCtl.startsWith(DOCKER_PREFIX);
131+
}
132+
119133
public static String rabbitmqctlCommand() {
120-
return System.getProperty("rabbitmqctl.bin");
134+
String rabbitmqCtl = System.getProperty("rabbitmqctl.bin");
135+
if (rabbitmqCtl == null) {
136+
throw new IllegalStateException("Please define the rabbitmqctl.bin system property");
137+
}
138+
if (rabbitmqCtl.startsWith("DOCKER:")) {
139+
String containerId = rabbitmqCtl.split(":")[1];
140+
return "docker exec " + containerId + " rabbitmqctl";
141+
} else {
142+
return rabbitmqCtl;
143+
}
121144
}
122145

123146
public static class Binding {

0 commit comments

Comments
 (0)