mirror of https://github.com/dapr/java-sdk.git
Fix instability due to race condition on stop. (#265)
This commit is contained in:
parent
53adaa9ce8
commit
1ca2751828
|
@ -49,16 +49,6 @@ public abstract class BaseIT {
|
||||||
return run;
|
return run;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static DaprRun restartDaprApp(DaprRun run) throws Exception {
|
|
||||||
DaprRun.Builder builder = DAPR_RUN_BUILDERS.get(run.getAppName());
|
|
||||||
run.stop();
|
|
||||||
DaprRun newRun = builder.build();
|
|
||||||
DAPR_RUNS.add(newRun);
|
|
||||||
newRun.start();
|
|
||||||
newRun.use();
|
|
||||||
return newRun;
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void cleanUp() throws Exception {
|
public static void cleanUp() throws Exception {
|
||||||
for (DaprRun app : DAPR_RUNS) {
|
for (DaprRun app : DAPR_RUNS) {
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class Command {
|
||||||
// Waits for success to happen within 1 minute.
|
// Waits for success to happen within 1 minute.
|
||||||
finished.tryAcquire(SUCCESS_WAIT_TIMEOUT_MINUTES, TimeUnit.MINUTES);
|
finished.tryAcquire(SUCCESS_WAIT_TIMEOUT_MINUTES, TimeUnit.MINUTES);
|
||||||
if (!success.get()) {
|
if (!success.get()) {
|
||||||
System.out.println("TEST WARNING: Could find success criteria for command: " + command);
|
throw new IllegalStateException("Could not find success criteria for command: " + command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,8 @@ public class DaprRun {
|
||||||
|
|
||||||
private final Command startCommand;
|
private final Command startCommand;
|
||||||
|
|
||||||
|
private final Command listCommand;
|
||||||
|
|
||||||
private final Command stopCommand;
|
private final Command stopCommand;
|
||||||
|
|
||||||
private DaprRun(String testName,
|
private DaprRun(String testName,
|
||||||
|
@ -41,6 +43,9 @@ public class DaprRun {
|
||||||
this.appName = String.format("%s_%s", testName, serviceClass.getSimpleName());
|
this.appName = String.format("%s_%s", testName, serviceClass.getSimpleName());
|
||||||
this.startCommand =
|
this.startCommand =
|
||||||
new Command(successMessage, buildDaprCommand(this.appName, serviceClass, ports));
|
new Command(successMessage, buildDaprCommand(this.appName, serviceClass, ports));
|
||||||
|
this.listCommand = new Command(
|
||||||
|
this.appName,
|
||||||
|
"dapr list");
|
||||||
this.stopCommand = new Command(
|
this.stopCommand = new Command(
|
||||||
"app stopped successfully",
|
"app stopped successfully",
|
||||||
"dapr stop --app-id " + this.appName);
|
"dapr stop --app-id " + this.appName);
|
||||||
|
@ -60,7 +65,17 @@ public class DaprRun {
|
||||||
this.started.set(true);
|
this.started.set(true);
|
||||||
|
|
||||||
long timeLeft = this.maxWaitMilliseconds - (System.currentTimeMillis() - start);
|
long timeLeft = this.maxWaitMilliseconds - (System.currentTimeMillis() - start);
|
||||||
|
callWithRetry(() -> {
|
||||||
|
System.out.println("Checking if Dapr is listening on HTTP port ...");
|
||||||
|
try {
|
||||||
|
this.listCommand.run();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}, timeLeft);
|
||||||
|
|
||||||
if (this.ports.getAppPort() != null) {
|
if (this.ports.getAppPort() != null) {
|
||||||
|
timeLeft = this.maxWaitMilliseconds - (System.currentTimeMillis() - start);
|
||||||
callWithRetry(() -> {
|
callWithRetry(() -> {
|
||||||
System.out.println("Checking if app is listening on port ...");
|
System.out.println("Checking if app is listening on port ...");
|
||||||
assertListeningOnPort(this.ports.getAppPort());
|
assertListeningOnPort(this.ports.getAppPort());
|
||||||
|
@ -89,11 +104,11 @@ public class DaprRun {
|
||||||
System.out.println("Stopping dapr application ...");
|
System.out.println("Stopping dapr application ...");
|
||||||
try {
|
try {
|
||||||
this.stopCommand.run();
|
this.stopCommand.run();
|
||||||
} catch (RuntimeException e) {
|
|
||||||
System.out.println("Could not stop app: " + this.appName);
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("Dapr application stopped.");
|
System.out.println("Dapr application stopped.");
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
System.out.println("Could not stop app " + this.appName + ": " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void use() {
|
public void use() {
|
||||||
|
|
|
@ -77,9 +77,9 @@ public class ActorTurnBasedConcurrencyIT extends BaseIT {
|
||||||
MyActorService.SUCCESS_MESSAGE,
|
MyActorService.SUCCESS_MESSAGE,
|
||||||
MyActorService.class,
|
MyActorService.class,
|
||||||
true,
|
true,
|
||||||
10000);
|
60000);
|
||||||
|
|
||||||
Thread.sleep(2000);
|
Thread.sleep(3000);
|
||||||
String actorType="MyActorTest";
|
String actorType="MyActorTest";
|
||||||
logger.debug("Creating proxy builder");
|
logger.debug("Creating proxy builder");
|
||||||
|
|
||||||
|
|
|
@ -36,44 +36,25 @@ public class MethodInvokeIT extends BaseIT {
|
||||||
/**
|
/**
|
||||||
* Run of a Dapr application.
|
* Run of a Dapr application.
|
||||||
*/
|
*/
|
||||||
private static DaprRun daprRun = null;
|
private DaprRun daprRun = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* Flag to determine if there is a context change based on parameters.
|
|
||||||
*/
|
|
||||||
private static Boolean wasGrpc;
|
|
||||||
|
|
||||||
@Parameter
|
@Parameter
|
||||||
public boolean useGrpc;
|
public boolean useGrpc;
|
||||||
|
|
||||||
@BeforeClass
|
@Before
|
||||||
public static void initClass() throws Exception {
|
public void init() throws Exception {
|
||||||
System.out.println("Working Directory = " + System.getProperty("user.dir"));
|
|
||||||
|
|
||||||
daprRun = startDaprApp(
|
daprRun = startDaprApp(
|
||||||
MethodInvokeIT.class.getSimpleName(),
|
MethodInvokeIT.class.getSimpleName(),
|
||||||
MethodInvokeService.SUCCESS_MESSAGE,
|
MethodInvokeService.SUCCESS_MESSAGE,
|
||||||
MethodInvokeService.class,
|
MethodInvokeService.class,
|
||||||
true,
|
true,
|
||||||
60000);
|
60000);
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void init() throws Exception {
|
|
||||||
if (wasGrpc != null) {
|
|
||||||
if (wasGrpc.booleanValue() != this.useGrpc) {
|
|
||||||
// Context change.
|
|
||||||
daprRun = super.restartDaprApp(daprRun);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.useGrpc) {
|
if (this.useGrpc) {
|
||||||
daprRun.switchToGRPC();
|
daprRun.switchToGRPC();
|
||||||
} else {
|
} else {
|
||||||
daprRun.switchToHTTP();
|
daprRun.switchToHTTP();
|
||||||
}
|
}
|
||||||
|
|
||||||
wasGrpc = this.useGrpc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue