1515
1616package com .rabbitmq .perf .it ;
1717
18- import com .rabbitmq .client .impl .NetworkConnection ;
19-
2018import java .io .BufferedReader ;
2119import java .io .IOException ;
2220import java .io .InputStream ;
@@ -96,10 +94,21 @@ public static void startBrokerApp() throws IOException {
9694 }
9795
9896 public static String rabbitmqctlCommand () {
99- return System .getProperty ("rabbitmqctl.bin" );
97+ String rabbitmqCtl = System .getProperty ("rabbitmqctl.bin" );
98+ if (rabbitmqCtl == null ) {
99+ throw new IllegalStateException ("Please define the rabbitmqctl.bin system property" );
100+ }
101+ if (rabbitmqCtl .startsWith ("DOCKER:" )) {
102+ String containerId = rabbitmqCtl .split (":" )[1 ];
103+ return "docker exec " + containerId + " rabbitmqctl" ;
104+ } else if ("sudo_rabbitmqctl" .equals (rabbitmqCtl )) {
105+ return "sudo rabbitmqctl" ;
106+ } else {
107+ return rabbitmqCtl ;
108+ }
100109 }
101110
102- public static void closeConnection (String pid ) throws IOException {
111+ private static void closeConnection (String pid ) throws IOException {
103112 rabbitmqctl ("close_connection '" + pid + "' 'Closed via rabbitmqctl'" );
104113 }
105114
@@ -109,24 +118,21 @@ public static void closeAllConnections(List<ConnectionInfo> connectionInfos) thr
109118 }
110119 }
111120
112- public static void closeAllConnections () throws IOException {
113- closeAllConnections (listConnections ());
114- }
115-
116121 public static List <ConnectionInfo > listConnections () throws IOException {
117122 String output = capture (rabbitmqctl ("list_connections -q pid peer_port" ).getInputStream ());
118123 // output (header line presence depends on broker version):
119124 // pid peer_port
120125121126 String [] allLines = output .split ("\n " );
122127
123- List <ConnectionInfo > result = new ArrayList <ConnectionInfo >();
128+ List <ConnectionInfo > result = new ArrayList <>();
124129 for (String line : allLines ) {
125130 // line: <[email protected] > 58713 126131 String [] columns = line .split ("\t " );
127132 // can be also header line, so ignoring NumberFormatException
128133 try {
129- result .add (new ConnectionInfo (columns [0 ], Integer .valueOf (columns [1 ])));
134+ Integer .valueOf (columns [1 ]);
135+ result .add (new ConnectionInfo (columns [0 ]));
130136 } catch (NumberFormatException e ) {
131137 // OK
132138 }
@@ -160,33 +166,17 @@ public static List<String> listQueues() throws IOException {
160166 .collect (Collectors .toList ());
161167 }
162168
163- private static Host .ConnectionInfo findConnectionInfoFor (List <ConnectionInfo > xs , NetworkConnection c ) {
164- Host .ConnectionInfo result = null ;
165- for (Host .ConnectionInfo ci : xs ) {
166- if (c .getLocalPort () == ci .getPeerPort ()) {
167- result = ci ;
168- break ;
169- }
170- }
171- return result ;
172- }
173-
174169 public static class ConnectionInfo {
175170
176171 private final String pid ;
177- private final int peerPort ;
178172
179- public ConnectionInfo (String pid , int peerPort ) {
173+ public ConnectionInfo (String pid ) {
180174 this .pid = pid ;
181- this .peerPort = peerPort ;
182175 }
183176
184177 public String getPid () {
185178 return pid ;
186179 }
187180
188- public int getPeerPort () {
189- return peerPort ;
190- }
191181 }
192182}
0 commit comments