Skip to content

Commit e720e63

Browse files
committed
Ignoring header line in rabbitmqctl output
For tests. (cherry picked from commit 65ebe9b)
1 parent d855cf1 commit e720e63

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,21 @@ public int getPeerPort() {
242242

243243
public static List<ConnectionInfo> listConnections() throws IOException {
244244
String output = capture(rabbitmqctl("list_connections -q pid peer_port").getInputStream());
245+
// output (header line presence depends on broker version):
246+
// pid peer_port
247+
// <[email protected]> 58713
245248
String[] allLines = output.split("\n");
246249

247250
ArrayList<ConnectionInfo> result = new ArrayList<ConnectionInfo>();
248251
for (String line : allLines) {
249252
// line: <[email protected]> 58713
250253
String[] columns = line.split("\t");
251-
result.add(new ConnectionInfo(columns[0], Integer.valueOf(columns[1])));
254+
// can be also header line, so ignoring NumberFormatException
255+
try {
256+
result.add(new ConnectionInfo(columns[0], Integer.valueOf(columns[1])));
257+
} catch (NumberFormatException e) {
258+
// OK
259+
}
252260
}
253261
return result;
254262
}

0 commit comments

Comments
 (0)