File tree Expand file tree Collapse file tree 3 files changed +33
-7
lines changed
src/test/java/com/rabbitmq Expand file tree Collapse file tree 3 files changed +33
-7
lines changed Original file line number Diff line number Diff line change 2020import com .rabbitmq .client .impl .nio .NioParams ;
2121import com .rabbitmq .tools .Host ;
2222import org .junit .After ;
23+ import org .junit .Assume ;
2324import org .junit .Before ;
2425import org .junit .Rule ;
2526import org .junit .rules .TestRule ;
3738import java .util .concurrent .TimeoutException ;
3839
3940import static org .junit .Assert .*;
41+ import static org .junit .Assume .*;
4042
4143public class BrokerTestCase {
4244
@@ -81,6 +83,7 @@ protected boolean isAutomaticRecoveryEnabled() {
8183
8284 @ Before public void setUp ()
8385 throws IOException , TimeoutException {
86+ assumeTrue (shouldRun ());
8487 openConnection ();
8588 openChannel ();
8689
@@ -89,14 +92,26 @@ protected boolean isAutomaticRecoveryEnabled() {
8992
9093 @ After public void tearDown ()
9194 throws IOException , TimeoutException {
92- closeChannel ();
93- closeConnection ();
95+ if (shouldRun ()) {
96+ closeChannel ();
97+ closeConnection ();
98+
99+ openConnection ();
100+ openChannel ();
101+ releaseResources ();
102+ closeChannel ();
103+ closeConnection ();
104+ }
105+ }
94106
95- openConnection ();
96- openChannel ();
97- releaseResources ();
98- closeChannel ();
99- closeConnection ();
107+ /**
108+ * Whether to run the test or not.
109+ * Subclasses can check whether some broker features
110+ * are available or not, and choose not to run the test.
111+ * @return
112+ */
113+ protected boolean shouldRun () throws IOException {
114+ return true ;
100115 }
101116
102117 /**
Original file line number Diff line number Diff line change @@ -34,6 +34,11 @@ public class TopicPermissions extends BrokerTestCase {
3434 String notProtectedTopic = "not.protected.topic" ;
3535 String noneTopicExchange = "not.a.topic" ;
3636
37+ @ Override
38+ protected boolean shouldRun () throws IOException {
39+ return Host .isRabbitMqCtlCommandAvailable ("set_topic_permissions" );
40+ }
41+
3742 @ Override
3843 protected void createResources () throws IOException , TimeoutException {
3944 channel .exchangeDeclare (protectedTopic , BuiltinExchangeType .TOPIC );
Original file line number Diff line number Diff line change @@ -91,6 +91,12 @@ private static Process executeCommandProcess(String command) throws IOException
9191 return Runtime .getRuntime ().exec (finalCommand );
9292 }
9393
94+ public static boolean isRabbitMqCtlCommandAvailable (String command ) throws IOException {
95+ Process process = rabbitmqctl ("help" );
96+ String stdout = capture (process .getInputStream ());
97+ return stdout .contains (command );
98+ }
99+
94100 public static Process rabbitmqctl (String command ) throws IOException {
95101 return executeCommand (rabbitmqctlCommand () +
96102 " -n \' " + nodenameA () + "\' " +
You can’t perform that action at this time.
0 commit comments