Search in sources :

Example 1 with CounterOutOfBoundsException

use of org.infinispan.counter.exception.CounterOutOfBoundsException in project infinispan by infinispan.

the class TestStrongCounter method executeOp.

private <T> CompletableFuture<T> executeOp(CounterOp op, BiConsumer<CompletableFuture<T>, TestResponse> responseHandler, BooleanSupplier canReachUpperBound) {
    TestResponse response = client.execute(op);
    CompletableFuture<T> future = new CompletableFuture<>();
    switch(response.getStatus()) {
        case Success:
            responseHandler.accept(future, response);
            break;
        case OperationNotExecuted:
            responseHandler.accept(future, response);
            break;
        case KeyDoesNotExist:
            future.completeExceptionally(new IllegalStateException("Counter Not Found!"));
            break;
        case ServerError:
            future.completeExceptionally(new CounterException(((TestErrorResponse) response).msg));
            break;
        case NotExecutedWithPrevious:
            future.completeExceptionally(canReachUpperBound.getAsBoolean() ? new CounterOutOfBoundsException(format(FORMAT_MESSAGE, UPPER_BOUND)) : new CounterOutOfBoundsException(format(FORMAT_MESSAGE, LOWER_BOUND)));
            break;
        default:
            future.completeExceptionally(new Exception("unknown response " + response));
    }
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) COUNTER_RESET(org.infinispan.server.hotrod.HotRodOperation.COUNTER_RESET) COUNTER_GET(org.infinispan.server.hotrod.HotRodOperation.COUNTER_GET) TestResponse(org.infinispan.server.hotrod.test.TestResponse) CounterValueTestResponse(org.infinispan.server.hotrod.counter.response.CounterValueTestResponse) CounterOutOfBoundsException(org.infinispan.counter.exception.CounterOutOfBoundsException) TestErrorResponse(org.infinispan.server.hotrod.test.TestErrorResponse) CounterException(org.infinispan.counter.exception.CounterException) CounterException(org.infinispan.counter.exception.CounterException) CounterOutOfBoundsException(org.infinispan.counter.exception.CounterOutOfBoundsException)

Aggregations

CompletableFuture (java.util.concurrent.CompletableFuture)1 CounterException (org.infinispan.counter.exception.CounterException)1 CounterOutOfBoundsException (org.infinispan.counter.exception.CounterOutOfBoundsException)1 COUNTER_GET (org.infinispan.server.hotrod.HotRodOperation.COUNTER_GET)1 COUNTER_RESET (org.infinispan.server.hotrod.HotRodOperation.COUNTER_RESET)1 CounterValueTestResponse (org.infinispan.server.hotrod.counter.response.CounterValueTestResponse)1 TestErrorResponse (org.infinispan.server.hotrod.test.TestErrorResponse)1 TestResponse (org.infinispan.server.hotrod.test.TestResponse)1