@@ -45,10 +45,10 @@ public class AssertTool extends ToolBase {
4545 private static Long timeoutMs = 1000L ;
4646
4747 private static final Option IS_NOT_ROOT_OPTION =
48- Option .builder ().desc ("Asserts that we are NOT the root user." ).longOpt ("not-root" ).build ();
48+ Option .builder ().desc ("Asserts that we are NOT the root user." ).longOpt ("not-root" ).get ();
4949
5050 private static final Option IS_ROOT_OPTION =
51- Option .builder ().desc ("Asserts that we are the root user." ).longOpt ("root" ).build ();
51+ Option .builder ().desc ("Asserts that we are the root user." ).longOpt ("root" ).get ();
5252
5353 private static final OptionGroup ROOT_OPTION =
5454 new OptionGroup ().addOption (IS_NOT_ROOT_OPTION ).addOption (IS_ROOT_OPTION );
@@ -59,15 +59,15 @@ public class AssertTool extends ToolBase {
5959 .longOpt ("not-started" )
6060 .hasArg ()
6161 .argName ("url" )
62- .build ();
62+ .get ();
6363
6464 private static final Option IS_RUNNING_ON_OPTION =
6565 Option .builder ()
6666 .desc ("Asserts that Solr is running on a certain URL. Default timeout is 1000ms." )
6767 .longOpt ("started" )
6868 .hasArg ()
6969 .argName ("url" )
70- .build ();
70+ .get ();
7171
7272 private static final OptionGroup RUNNING_OPTION =
7373 new OptionGroup ().addOption (IS_NOT_RUNNING_ON_OPTION ).addOption (IS_RUNNING_ON_OPTION );
@@ -78,23 +78,23 @@ public class AssertTool extends ToolBase {
7878 .longOpt ("same-user" )
7979 .hasArg ()
8080 .argName ("directory" )
81- .build ();
81+ .get ();
8282
8383 private static final Option DIRECTORY_EXISTS_OPTION =
8484 Option .builder ()
8585 .desc ("Asserts that directory <directory> exists." )
8686 .longOpt ("exists" )
8787 .hasArg ()
8888 .argName ("directory" )
89- .build ();
89+ .get ();
9090
9191 private static final Option DIRECTORY_NOT_EXISTS_OPTION =
9292 Option .builder ()
9393 .desc ("Asserts that directory <directory> does NOT exist." )
9494 .longOpt ("not-exists" )
9595 .hasArg ()
9696 .argName ("directory" )
97- .build ();
97+ .get ();
9898
9999 private static final OptionGroup DIRECTORY_OPTION =
100100 new OptionGroup ().addOption (DIRECTORY_EXISTS_OPTION ).addOption (DIRECTORY_NOT_EXISTS_OPTION );
@@ -106,7 +106,7 @@ public class AssertTool extends ToolBase {
106106 .longOpt ("cloud" )
107107 .hasArg ()
108108 .argName ("url" )
109- .build ();
109+ .get ();
110110
111111 private static final Option IS_NOT_CLOUD_OPTION =
112112 Option .builder ()
@@ -115,7 +115,7 @@ public class AssertTool extends ToolBase {
115115 .longOpt ("not-cloud" )
116116 .hasArg ()
117117 .argName ("url" )
118- .build ();
118+ .get ();
119119
120120 private static final OptionGroup CLOUD_OPTION =
121121 new OptionGroup ().addOption (IS_CLOUD_OPTION ).addOption (IS_NOT_CLOUD_OPTION );
@@ -126,7 +126,7 @@ public class AssertTool extends ToolBase {
126126 .longOpt ("message" )
127127 .hasArg ()
128128 .argName ("message" )
129- .build ();
129+ .get ();
130130
131131 private static final Option TIMEOUT_OPTION =
132132 Option .builder ()
@@ -135,13 +135,13 @@ public class AssertTool extends ToolBase {
135135 .hasArg ()
136136 .type (Long .class )
137137 .argName ("ms" )
138- .build ();
138+ .get ();
139139
140140 private static final Option EXIT_CODE_OPTION =
141141 Option .builder ()
142142 .desc ("Return an exit code instead of printing error message on assert fail." )
143143 .longOpt ("exitcode" )
144- .build ();
144+ .get ();
145145
146146 public AssertTool (ToolRuntime runtime ) {
147147 super (runtime );
@@ -292,9 +292,10 @@ public int assertSolrNotRunning(String url, String credentials) throws Exception
292292 status .waitToSeeSolrUp (url , credentials , 1 , TimeUnit .SECONDS );
293293 try {
294294 log .debug ("Solr still up. Waiting before trying again to see if it was stopped" );
295- Thread .sleep (1000L );
295+ TimeUnit . MILLISECONDS .sleep (1000L );
296296 } catch (InterruptedException interrupted ) {
297- timeout = 0 ; // stop looping
297+ Thread .currentThread ().interrupt ();
298+ break ;
298299 }
299300 } catch (Exception se ) {
300301 if (CLIUtils .exceptionIsAuthRelated (se )) {
@@ -312,7 +313,7 @@ public int assertSolrNotRunning(String url, String credentials) throws Exception
312313 }
313314
314315 public int assertSolrRunningInCloudMode (String url , String credentials ) throws Exception {
315- if (! isSolrRunningOn (url , credentials )) {
316+ if (isSolrStoppedOn (url , credentials )) {
316317 return exitOrException (
317318 "Solr is not running on url "
318319 + url
@@ -328,7 +329,7 @@ public int assertSolrRunningInCloudMode(String url, String credentials) throws E
328329 }
329330
330331 public int assertSolrNotRunningInCloudMode (String url , String credentials ) throws Exception {
331- if (! isSolrRunningOn (url , credentials )) {
332+ if (isSolrStoppedOn (url , credentials )) {
332333 return exitOrException (
333334 "Solr is not running on url "
334335 + url
@@ -344,8 +345,9 @@ public int assertSolrNotRunningInCloudMode(String url, String credentials) throw
344345 }
345346
346347 public static int sameUser (String directory ) throws Exception {
347- if (Files .exists (Path .of (directory ))) {
348- String userForDir = userForDir (Path .of (directory ));
348+ Path path = Path .of (directory );
349+ if (Files .exists (path )) {
350+ String userForDir = userForDir (path );
349351 if (!currentUser ().equals (userForDir )) {
350352 return exitOrException ("Must run as user " + userForDir + ". We are " + currentUser ());
351353 }
@@ -405,16 +407,16 @@ private static int exitOrException(String msg) throws AssertionFailureException
405407 }
406408 }
407409
408- private boolean isSolrRunningOn (String url , String credentials ) throws Exception {
410+ private boolean isSolrStoppedOn (String url , String credentials ) throws Exception {
409411 StatusTool status = new StatusTool (runtime );
410412 try {
411413 status .waitToSeeSolrUp (url , credentials , timeoutMs , TimeUnit .MILLISECONDS );
412- return true ;
414+ return false ;
413415 } catch (Exception se ) {
414416 if (CLIUtils .exceptionIsAuthRelated (se )) {
415417 throw se ;
416418 }
417- return false ;
419+ return true ;
418420 }
419421 }
420422
0 commit comments