Search in sources :

Example 1 with CancellationReason

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);
}
Also used : CancellationReason(com.couchbase.client.core.msg.CancellationReason) RequestCanceledException(com.couchbase.client.core.error.RequestCanceledException) ExecutionException(java.util.concurrent.ExecutionException) CollectionIdentifier(com.couchbase.client.core.io.CollectionIdentifier) TimeoutException(com.couchbase.client.core.error.TimeoutException) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

RequestCanceledException (com.couchbase.client.core.error.RequestCanceledException)1 TimeoutException (com.couchbase.client.core.error.TimeoutException)1 CollectionIdentifier (com.couchbase.client.core.io.CollectionIdentifier)1 CancellationReason (com.couchbase.client.core.msg.CancellationReason)1 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)1 ExecutionException (java.util.concurrent.ExecutionException)1 Test (org.junit.jupiter.api.Test)1