use of org.infinispan.counter.exception.CounterException in project infinispan by infinispan.
the class TestCounterNotificationManager method add.
private List<UserListener<?>> add(String counterName, List<UserListener<?>> list, UserListener<?> listener) {
if (list == null) {
CounterListenerOp op = createListener(client.protocolVersion(), counterName, listenerId.getBytes());
TestResponse response = client.execute(op);
switch(response.getStatus()) {
case Success:
break;
case OperationNotExecuted:
break;
case KeyDoesNotExist:
throw new CounterException("Counter " + counterName + " doesn't exist");
default:
throw new IllegalStateException("Unknown status " + response.getStatus());
}
list = new CopyOnWriteArrayList<>();
}
list.add(listener);
return list;
}
use of org.infinispan.counter.exception.CounterException in project infinispan by infinispan.
the class TestCounterNotificationManager method remove.
private void remove(String counterName, UserListener<?> listener) {
userListenerList.computeIfPresent(counterName, (name, list) -> {
list.remove(listener);
if (list.isEmpty()) {
CounterListenerOp op = removeListener(client.protocolVersion(), counterName, listenerId.getBytes());
TestResponse response = client.execute(op);
switch(response.getStatus()) {
case Success:
break;
case OperationNotExecuted:
break;
case KeyDoesNotExist:
throw new CounterException("Counter " + counterName + " doesn't exist");
default:
throw new IllegalStateException("Unknown status " + response.getStatus());
}
return null;
}
return list;
});
}
use of org.infinispan.counter.exception.CounterException in project infinispan by infinispan.
the class TestWeakCounter method executeOp.
private CompletableFuture<Void> executeOp(CounterOp op) {
TestResponse response = client.execute(op);
CompletableFuture<Void> future = new CompletableFuture<>();
switch(response.getStatus()) {
case Success:
future.complete(null);
break;
case OperationNotExecuted:
future.complete(null);
break;
case KeyDoesNotExist:
future.completeExceptionally(new IllegalStateException("Counter Not Found!"));
break;
case ServerError:
future.completeExceptionally(new CounterException(((TestErrorResponse) response).msg));
break;
default:
future.completeExceptionally(new Exception("unknown response " + response));
}
return future;
}
use of org.infinispan.counter.exception.CounterException 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;
}
use of org.infinispan.counter.exception.CounterException in project infinispan by infinispan.
the class TestWeakCounter method getValue.
@Override
public long getValue() {
CounterOp op = new CounterOp(client.protocolVersion(), COUNTER_GET, name);
TestResponse response = client.execute(op);
switch(response.getStatus()) {
case Success:
return ((CounterValueTestResponse) response).getValue();
case ServerError:
throw new CounterException(((TestErrorResponse) response).msg);
default:
throw new CounterException("unknown response " + response);
}
}
Aggregations