@@ -68,31 +68,16 @@ public void start() throws InterruptedException, IOException {
68
68
this .stop ();
69
69
// Wait for the previous run to kill the prior process.
70
70
long timeLeft = this .maxWaitMilliseconds - (System .currentTimeMillis () - start );
71
- callWithRetry (() -> {
72
- System .out .println ("Checking if previous run for Dapr application has stopped ..." );
73
- try {
74
- this .listCommand .run ();
75
- throw new RuntimeException ("Previous run for app has not stopped yet!" );
76
- } catch (IllegalStateException e ) {
77
- // Success because we the list command did not find the app id.
78
- } catch (Exception e ) {
79
- throw new RuntimeException (e );
80
- }
81
- }, timeLeft );
71
+ System .out .println ("Checking if previous run for Dapr application has stopped ..." );
72
+ checkRunState (timeLeft , false );
82
73
83
74
System .out .println ("Starting dapr application ..." );
84
75
this .startCommand .run ();
85
76
this .started .set (true );
86
77
87
78
timeLeft = this .maxWaitMilliseconds - (System .currentTimeMillis () - start );
88
- callWithRetry (() -> {
89
- System .out .println ("Checking if Dapr application has started ..." );
90
- try {
91
- this .listCommand .run ();
92
- } catch (Exception e ) {
93
- throw new RuntimeException (e );
94
- }
95
- }, timeLeft );
79
+ System .out .println ("Checking if Dapr application has started ..." );
80
+ checkRunState (timeLeft , true );
96
81
97
82
if (this .ports .getAppPort () != null ) {
98
83
timeLeft = this .maxWaitMilliseconds - (System .currentTimeMillis () - start );
@@ -180,6 +165,25 @@ public String getAppName() {
180
165
return appName ;
181
166
}
182
167
168
+ public void checkRunState (long timeout , boolean shouldBeRunning ) throws InterruptedException {
169
+ callWithRetry (() -> {
170
+ try {
171
+ this .listCommand .run ();
172
+
173
+ if (!shouldBeRunning ) {
174
+ throw new RuntimeException ("Previous run for app has not stopped yet!" );
175
+ }
176
+ } catch (IllegalStateException e ) {
177
+ // Bad case if the app is supposed to be running.
178
+ if (shouldBeRunning ) {
179
+ throw e ;
180
+ }
181
+ } catch (Exception e ) {
182
+ throw new RuntimeException (e );
183
+ }
184
+ }, timeout );
185
+ }
186
+
183
187
private static String buildDaprCommand (
184
188
String appName , Class serviceClass , DaprPorts ports , DaprApiProtocol protocol , DaprApiProtocol appProtocol ) {
185
189
StringBuilder stringBuilder =
0 commit comments