Skip to content

Commit 0369b9e

Browse files
committed
Use rabbitmqctl to restart broker in tests
Instead of make. This makes the build less dependant on the umbrella. [#156274540]
1 parent ad090c7 commit 0369b9e

File tree

3 files changed

+22
-34
lines changed

3 files changed

+22
-34
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ branches:
3131
before_script:
3232
- ./bin/before_build.sh
3333

34-
script: ./mvnw clean verify -P '!setup-test-node' -Dtravis-ci=true -Drabbitmqctl.bin='rabbitmq/sbin/rabbitmqctl' -Dtest-broker.A.nodename=rabbit@$(hostname) -Dtest-client-cert.password= -Dtest-tls-certs.dir=/tmp/tls-gen/basic
34+
script: ./mvnw clean verify -P '!setup-test-node' -Drabbitmqctl.bin='rabbitmq/sbin/rabbitmqctl' -Dtest-broker.A.nodename=rabbit@$(hostname) -Dtest-client-cert.password= -Dtest-tls-certs.dir=/tmp/tls-gen/basic
3535
cache:
3636
directories:
3737
- $HOME/.m2

src/test/java/com/rabbitmq/integration/tests/ConnectionForceCloseOnReceiveIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void onException(JMSException exception) {
5757

5858
Thread.sleep(ONE_SECOND);
5959

60-
Shell.invokeMakeTarget("stop-rabbit-on-node start-rabbit-on-node");
60+
Shell.restartNode();
6161

6262

6363
try {

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

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
/* Copyright (c) 2014 Pivotal Software, Inc. All rights reserved. */
22
package com.rabbitmq.jms.util;
33

4-
import java.io.*;
4+
import java.io.BufferedReader;
5+
import java.io.IOException;
6+
import java.io.InputStream;
7+
import java.io.InputStreamReader;
58

69
/**
710
* Shell is a test utility class for issuing shell commands from integration tests.
@@ -19,7 +22,7 @@ public static String executeSimpleCommand(String command) {
1922
process.waitFor();
2023
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
2124
String line = "";
22-
while ((line = reader.readLine())!= null) {
25+
while ((line = reader.readLine()) != null) {
2326
outputSb.append(line + "\n");
2427
}
2528
reader.close();
@@ -35,10 +38,8 @@ public static String executeControl(String cmd) {
3538
}
3639
*/
3740

38-
3941
public static String capture(InputStream is)
40-
throws IOException
41-
{
42+
throws IOException {
4243
BufferedReader br = new BufferedReader(new InputStreamReader(is));
4344
String line;
4445
StringBuilder buff = new StringBuilder();
@@ -48,19 +49,12 @@ public static String capture(InputStream is)
4849
return buff.toString();
4950
}
5051

51-
public static Process invokeMakeTarget(String command) throws IOException {
52-
File rabbitmqctl = new File(rabbitmqctlCommand());
53-
return executeCommand(makeCommand() +
54-
" -C \'" + rabbitmqDir() + "\'" +
55-
" RABBITMQCTL=\'" + rabbitmqctl.getAbsolutePath() + "\'" +
56-
" RABBITMQ_NODENAME=\'" + nodenameA() + "\'" +
57-
" RABBITMQ_NODE_PORT=" + node_portA() +
58-
" RABBITMQ_CONFIG_FILE=\'" + config_fileA() + "\'" +
59-
" " + command);
52+
public static void restartNode() throws IOException {
53+
executeCommand(rabbitmqctlCommand() + " -n " + nodenameA() + " stop_app");
54+
executeCommand(rabbitmqctlCommand() + " -n " + nodenameA() + " start_app");
6055
}
6156

62-
public static Process executeCommand(String command) throws IOException
63-
{
57+
public static Process executeCommand(String command) throws IOException {
6458
Process pr = executeCommandProcess(command);
6559

6660
int ev = waitForExitValue(pr);
@@ -76,17 +70,17 @@ public static Process executeCommand(String command) throws IOException
7670
}
7771

7872
private static int waitForExitValue(Process pr) {
79-
while(true) {
73+
while (true) {
8074
try {
8175
pr.waitFor();
8276
break;
83-
} catch (InterruptedException ignored) {}
77+
} catch (InterruptedException ignored) {
78+
}
8479
}
8580
return pr.exitValue();
8681
}
8782

88-
private static Process executeCommandProcess(String command) throws IOException
89-
{
83+
private static Process executeCommandProcess(String command) throws IOException {
9084
String[] finalCommand;
9185
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
9286
finalCommand = new String[4];
@@ -103,33 +97,27 @@ private static Process executeCommandProcess(String command) throws IOException
10397
return Runtime.getRuntime().exec(finalCommand);
10498
}
10599

106-
public static String makeCommand()
107-
{
100+
public static String makeCommand() {
108101
return System.getProperty("make.bin", "make");
109102
}
110103

111-
public static String nodenameA()
112-
{
104+
public static String nodenameA() {
113105
return System.getProperty("test-broker.A.nodename");
114106
}
115107

116-
public static String node_portA()
117-
{
108+
public static String node_portA() {
118109
return System.getProperty("test-broker.A.node_port");
119110
}
120111

121-
public static String config_fileA()
122-
{
112+
public static String config_fileA() {
123113
return System.getProperty("test-broker.A.config_file");
124114
}
125115

126-
public static String rabbitmqctlCommand()
127-
{
116+
public static String rabbitmqctlCommand() {
128117
return System.getProperty("rabbitmqctl.bin");
129118
}
130119

131-
public static String rabbitmqDir()
132-
{
120+
public static String rabbitmqDir() {
133121
return System.getProperty("rabbitmq.dir");
134122
}
135123
}

0 commit comments

Comments
 (0)