use of com.couchbase.client.core.msg.CancellationReason in project couchbase-jvm-clients by couchbase.
the class CircuitBreakerIntegrationTest method shouldTriggerWithTimeouts.
@Test
void shouldTriggerWithTimeouts() {
int threshold = collection.environment().ioConfig().kvCircuitBreakerConfig().volumeThreshold();
int timeouts = 0;
int cancellations = 0;
for (int i = 0; i < threshold * 3; i++) {
FailingGetRequestOnEncode request = new FailingGetRequestOnEncode("foo", Duration.ofMillis(1), collection.core().context(), new CollectionIdentifier(config().bucketname(), Optional.of(collection.scopeName()), Optional.of(collection.name())), FailFastRetryStrategy.INSTANCE);
collection.core().send(request);
try {
request.response().get();
fail();
} catch (ExecutionException ex) {
if (ex.getCause() instanceof TimeoutException) {
timeouts++;
} else if (ex.getCause() instanceof RequestCanceledException) {
cancellations++;
CancellationReason reason = ((RequestCanceledException) ex.getCause()).context().requestContext().request().cancellationReason();
assertEquals(reason.innerReason(), RetryReason.ENDPOINT_CIRCUIT_OPEN);
}
} catch (Throwable t) {
fail(t);
}
}
assertTrue(timeouts > 0);
assertTrue(cancellations > 0);
}
Aggregations