Skip to content

Commit 65ebe9b

Browse files
committed
Ignoring header line in rabbitmqctl output
For tests.
1 parent cebcc8f commit 65ebe9b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Diff for: src/test/java/com/rabbitmq/tools/Host.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,21 @@ public int getPeerPort() {
239239

240240
public static List<ConnectionInfo> listConnections() throws IOException {
241241
String output = capture(rabbitmqctl("list_connections -q pid peer_port").getInputStream());
242+
// output (header line presence depends on broker version):
243+
// pid peer_port
244+
// <[email protected]> 58713
242245
String[] allLines = output.split("\n");
243246

244247
ArrayList<ConnectionInfo> result = new ArrayList<ConnectionInfo>();
245248
for (String line : allLines) {
246249
// line: <[email protected]> 58713
247250
String[] columns = line.split("\t");
248-
result.add(new ConnectionInfo(columns[0], Integer.valueOf(columns[1])));
251+
// can be also header line, so ignoring NumberFormatException
252+
try {
253+
result.add(new ConnectionInfo(columns[0], Integer.valueOf(columns[1])));
254+
} catch (NumberFormatException e) {
255+
// OK
256+
}
249257
}
250258
return result;
251259
}

0 commit comments

Comments
 (0)