11/* Copyright (c) 2014 Pivotal Software, Inc. All rights reserved. */
22package com .rabbitmq .jms .util ;
33
4- import java .io .*;
4+ import java .io .BufferedReader ;
5+ import java .io .IOException ;
6+ import java .io .InputStream ;
7+ import java .io .InputStreamReader ;
58
69/**
710 * Shell is a test utility class for issuing shell commands from integration tests.
@@ -19,7 +22,7 @@ public static String executeSimpleCommand(String command) {
1922 process .waitFor ();
2023 BufferedReader reader = new BufferedReader (new InputStreamReader (process .getInputStream ()));
2124 String line = "" ;
22- while ((line = reader .readLine ())!= null ) {
25+ while ((line = reader .readLine ()) != null ) {
2326 outputSb .append (line + "\n " );
2427 }
2528 reader .close ();
@@ -35,10 +38,8 @@ public static String executeControl(String cmd) {
3538 }
3639 */
3740
38-
3941 public static String capture (InputStream is )
40- throws IOException
41- {
42+ throws IOException {
4243 BufferedReader br = new BufferedReader (new InputStreamReader (is ));
4344 String line ;
4445 StringBuilder buff = new StringBuilder ();
@@ -48,19 +49,12 @@ public static String capture(InputStream is)
4849 return buff .toString ();
4950 }
5051
51- public static Process invokeMakeTarget (String command ) throws IOException {
52- File rabbitmqctl = new File (rabbitmqctlCommand ());
53- return executeCommand (makeCommand () +
54- " -C \' " + rabbitmqDir () + "\' " +
55- " RABBITMQCTL=\' " + rabbitmqctl .getAbsolutePath () + "\' " +
56- " RABBITMQ_NODENAME=\' " + nodenameA () + "\' " +
57- " RABBITMQ_NODE_PORT=" + node_portA () +
58- " RABBITMQ_CONFIG_FILE=\' " + config_fileA () + "\' " +
59- " " + command );
52+ public static void restartNode () throws IOException {
53+ executeCommand (rabbitmqctlCommand () + " -n " + nodenameA () + " stop_app" );
54+ executeCommand (rabbitmqctlCommand () + " -n " + nodenameA () + " start_app" );
6055 }
6156
62- public static Process executeCommand (String command ) throws IOException
63- {
57+ public static Process executeCommand (String command ) throws IOException {
6458 Process pr = executeCommandProcess (command );
6559
6660 int ev = waitForExitValue (pr );
@@ -76,17 +70,17 @@ public static Process executeCommand(String command) throws IOException
7670 }
7771
7872 private static int waitForExitValue (Process pr ) {
79- while (true ) {
73+ while (true ) {
8074 try {
8175 pr .waitFor ();
8276 break ;
83- } catch (InterruptedException ignored ) {}
77+ } catch (InterruptedException ignored ) {
78+ }
8479 }
8580 return pr .exitValue ();
8681 }
8782
88- private static Process executeCommandProcess (String command ) throws IOException
89- {
83+ private static Process executeCommandProcess (String command ) throws IOException {
9084 String [] finalCommand ;
9185 if (System .getProperty ("os.name" ).toLowerCase ().contains ("windows" )) {
9286 finalCommand = new String [4 ];
@@ -103,33 +97,27 @@ private static Process executeCommandProcess(String command) throws IOException
10397 return Runtime .getRuntime ().exec (finalCommand );
10498 }
10599
106- public static String makeCommand ()
107- {
100+ public static String makeCommand () {
108101 return System .getProperty ("make.bin" , "make" );
109102 }
110103
111- public static String nodenameA ()
112- {
104+ public static String nodenameA () {
113105 return System .getProperty ("test-broker.A.nodename" );
114106 }
115107
116- public static String node_portA ()
117- {
108+ public static String node_portA () {
118109 return System .getProperty ("test-broker.A.node_port" );
119110 }
120111
121- public static String config_fileA ()
122- {
112+ public static String config_fileA () {
123113 return System .getProperty ("test-broker.A.config_file" );
124114 }
125115
126- public static String rabbitmqctlCommand ()
127- {
116+ public static String rabbitmqctlCommand () {
128117 return System .getProperty ("rabbitmqctl.bin" );
129118 }
130119
131- public static String rabbitmqDir ()
132- {
120+ public static String rabbitmqDir () {
133121 return System .getProperty ("rabbitmq.dir" );
134122 }
135123}
0 commit comments