Skip to content

Commit 3646e36

Browse files
committed
Use rabbitmqctl to start/stop rabbit application on node
Instead of using make. This way only HA tests need make to run. (cherry picked from commit 9177ae2)
1 parent e65478e commit 3646e36

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ protected void restart()
143143

144144
protected void bareRestart()
145145
throws IOException {
146-
Host.invokeMakeTarget(
147-
"stop-rabbit-on-node start-rabbit-on-node");
146+
Host.stopRabbitOnNode();
147+
Host.startRabbitOnNode();
148148
}
149149

150150
public void openConnection()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ protected void releaseResources() throws IOException {
5858
}
5959

6060
closeConnection();
61-
Host.invokeMakeTarget("stop-rabbit-on-node");
61+
Host.stopRabbitOnNode();
6262
Thread.sleep(5000);
63-
Host.invokeMakeTarget("start-rabbit-on-node");
63+
Host.startRabbitOnNode();
6464
openConnection();
6565
openChannel();
6666

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

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
import java.util.ArrayList;
2525
import java.util.List;
2626

27+
import com.rabbitmq.client.Connection;
28+
import com.rabbitmq.client.ConnectionFactory;
2729
import com.rabbitmq.client.impl.NetworkConnection;
30+
import com.rabbitmq.client.test.TestUtils;
2831

2932
public class Host {
3033

@@ -128,9 +131,34 @@ public static Process invokeMakeTarget(String command) throws IOException {
128131
" " + command);
129132
}
130133

131-
public static String systemHostname() throws IOException {
132-
Process process = executeCommandIgnoringErrors("hostname");
133-
return capture(process.getInputStream()).trim();
134+
public static void startRabbitOnNode() throws IOException {
135+
rabbitmqctl("eval 'rabbit:start().'");
136+
tryConnectFor(10_000);
137+
}
138+
139+
public static void stopRabbitOnNode() throws IOException {
140+
rabbitmqctl("eval 'rabbit:stop().'");
141+
}
142+
143+
public static void tryConnectFor(int timeoutInMs) throws IOException {
144+
int waitTime = 100;
145+
int totalWaitTime = 0;
146+
while (totalWaitTime <= timeoutInMs) {
147+
try {
148+
Thread.sleep(waitTime);
149+
} catch (InterruptedException e) {
150+
throw new RuntimeException(e);
151+
}
152+
totalWaitTime += waitTime;
153+
ConnectionFactory connectionFactory = TestUtils.connectionFactory();
154+
try (Connection ignored = connectionFactory.newConnection()) {
155+
return;
156+
157+
} catch (Exception e) {
158+
// retrying
159+
}
160+
}
161+
throw new IOException("Could not connect to broker for " + timeoutInMs + " ms");
134162
}
135163

136164
public static String makeCommand()

0 commit comments

Comments
 (0)