mirror of https://github.com/dapr/java-sdk.git
Adjust latency and jitter for Toxi proxy to stabilize SDK resiliency IT (#1070)
This commit is contained in:
parent
3dadc0be06
commit
a4ec275353
|
@ -38,7 +38,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
/**
|
/**
|
||||||
* Test SDK resiliency.
|
* Test SDK resiliency.
|
||||||
*/
|
*/
|
||||||
public class ActorSdkResiliencytIT extends BaseIT {
|
public class ActorSdkResiliencyIT extends BaseIT {
|
||||||
|
|
||||||
private static final ActorId ACTOR_ID = new ActorId(UUID.randomUUID().toString());
|
private static final ActorId ACTOR_ID = new ActorId(UUID.randomUUID().toString());
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ public class ActorSdkResiliencytIT extends BaseIT {
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void init() throws Exception {
|
public static void init() throws Exception {
|
||||||
daprRun = startDaprApp(
|
daprRun = startDaprApp(
|
||||||
ActorSdkResiliencytIT.class.getSimpleName(),
|
ActorSdkResiliencyIT.class.getSimpleName(),
|
||||||
DemoActorService.SUCCESS_MESSAGE,
|
DemoActorService.SUCCESS_MESSAGE,
|
||||||
DemoActorService.class,
|
DemoActorService.class,
|
||||||
true,
|
true,
|
|
@ -36,20 +36,18 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
/**
|
/**
|
||||||
* Test SDK resiliency.
|
* Test SDK resiliency.
|
||||||
*/
|
*/
|
||||||
public class SdkResiliencytIT extends BaseIT {
|
public class SdkResiliencyIT extends BaseIT {
|
||||||
|
|
||||||
private static final int NUM_ITERATIONS = 35;
|
private static final int NUM_ITERATIONS = 35;
|
||||||
|
|
||||||
private static final Duration TIMEOUT = Duration.ofMillis(100);
|
private static final Duration TIMEOUT = Duration.ofMillis(100);
|
||||||
|
|
||||||
private static final Duration LATENCY = TIMEOUT.dividedBy(2);
|
private static final Duration LATENCY = TIMEOUT.dividedBy(3);
|
||||||
|
|
||||||
private static final Duration JITTER = TIMEOUT.multipliedBy(2);
|
private static final Duration JITTER = TIMEOUT.multipliedBy(3);
|
||||||
|
|
||||||
private static final int MAX_RETRIES = -1; // Infinity
|
private static final int MAX_RETRIES = -1; // Infinity
|
||||||
|
|
||||||
private static DaprRun daprRun;
|
|
||||||
|
|
||||||
private static DaprClient daprClient;
|
private static DaprClient daprClient;
|
||||||
|
|
||||||
private static ToxiProxyRun toxiProxyRun;
|
private static ToxiProxyRun toxiProxyRun;
|
||||||
|
@ -64,7 +62,7 @@ public class SdkResiliencytIT extends BaseIT {
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void init() throws Exception {
|
public static void init() throws Exception {
|
||||||
daprRun = startDaprApp(SdkResiliencytIT.class.getSimpleName(), 5000);
|
DaprRun daprRun = startDaprApp(SdkResiliencyIT.class.getSimpleName(), 5000);
|
||||||
daprClient = new DaprClientBuilder().build();
|
daprClient = new DaprClientBuilder().build();
|
||||||
daprClient.waitForSidecar(8000).block();
|
daprClient.waitForSidecar(8000).block();
|
||||||
|
|
||||||
|
@ -113,7 +111,7 @@ public class SdkResiliencytIT extends BaseIT {
|
||||||
@Test
|
@Test
|
||||||
public void retryAndTimeout() {
|
public void retryAndTimeout() {
|
||||||
AtomicInteger toxiClientErrorCount = new AtomicInteger();
|
AtomicInteger toxiClientErrorCount = new AtomicInteger();
|
||||||
AtomicInteger retryOneClientErrorCount = new AtomicInteger();
|
AtomicInteger retryOnceClientErrorCount = new AtomicInteger();
|
||||||
|
|
||||||
while (true){
|
while (true){
|
||||||
for (int i = 0; i < NUM_ITERATIONS; i++) {
|
for (int i = 0; i < NUM_ITERATIONS; i++) {
|
||||||
|
@ -129,7 +127,7 @@ public class SdkResiliencytIT extends BaseIT {
|
||||||
daprRetriesOnceClient.saveState(STATE_STORE_NAME, key, value).block();
|
daprRetriesOnceClient.saveState(STATE_STORE_NAME, key, value).block();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// This call should fail sometimes. So, we count.
|
// This call should fail sometimes. So, we count.
|
||||||
retryOneClientErrorCount.incrementAndGet();
|
retryOnceClientErrorCount.incrementAndGet();
|
||||||
}
|
}
|
||||||
|
|
||||||
// We retry forever so that the call below should always work.
|
// We retry forever so that the call below should always work.
|
||||||
|
@ -140,17 +138,29 @@ public class SdkResiliencytIT extends BaseIT {
|
||||||
}
|
}
|
||||||
|
|
||||||
// We should have at least one success per client, otherwise retry.
|
// We should have at least one success per client, otherwise retry.
|
||||||
if(toxiClientErrorCount.get() < NUM_ITERATIONS && retryOneClientErrorCount.get() < NUM_ITERATIONS){
|
if(toxiClientErrorCount.get() < NUM_ITERATIONS && retryOnceClientErrorCount.get() < NUM_ITERATIONS){
|
||||||
// This assertion makes sure that toxicity is on
|
// This assertion makes sure that toxicity is on
|
||||||
assertTrue(toxiClientErrorCount.get() > 0);
|
assertTrue(toxiClientErrorCount.get() > 0, "Toxi client error count is 0");
|
||||||
assertTrue(retryOneClientErrorCount.get() > 0);
|
assertTrue(retryOnceClientErrorCount.get() > 0, "Retry once client error count is 0");
|
||||||
// A client without retries should have more errors than a client with one retry.
|
// A client without retries should have more errors than a client with one retry.
|
||||||
assertTrue(toxiClientErrorCount.get() > retryOneClientErrorCount.get());
|
|
||||||
|
String failureMessage = formatFailureMessage(toxiClientErrorCount, retryOnceClientErrorCount);
|
||||||
|
assertTrue(toxiClientErrorCount.get() > retryOnceClientErrorCount.get(), failureMessage);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
toxiClientErrorCount.set(0);
|
toxiClientErrorCount.set(0);
|
||||||
retryOneClientErrorCount.set(0);
|
retryOnceClientErrorCount.set(0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String formatFailureMessage(
|
||||||
|
AtomicInteger toxiClientErrorCount,
|
||||||
|
AtomicInteger retryOnceClientErrorCount
|
||||||
|
) {
|
||||||
|
return String.format(
|
||||||
|
"Toxi client error count: %d, Retry once client error count: %d",
|
||||||
|
toxiClientErrorCount.get(),
|
||||||
|
retryOnceClientErrorCount.get()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue