use of org.infinispan.client.rest.RestCounterClient in project infinispan by infinispan.
the class CounterResourceTest method testStrongCounterOps.
@Test
public void testStrongCounterOps() {
String name = "strong-test";
createCounter(name, CounterConfiguration.builder(CounterType.BOUNDED_STRONG).lowerBound(0).upperBound(100).initialValue(0).build());
RestCounterClient counterClient = client.counter(name);
CompletionStage<RestResponse> response = counterClient.increment();
assertThat(response).hasReturnedText("1");
response = counterClient.increment();
assertThat(response).hasReturnedText("2");
response = counterClient.decrement();
assertThat(response).hasReturnedText("1");
response = counterClient.decrement();
assertThat(response).hasReturnedText("0");
response = counterClient.add(35);
assertThat(response).hasReturnedText("35");
waitForCounterToReach(name, 35);
response = counterClient.compareAndSet(5, 32);
assertThat(response).hasReturnedText("false");
response = counterClient.compareAndSet(35, 50);
assertThat(response).hasReturnedText("true");
waitForCounterToReach(name, 50);
response = counterClient.compareAndSwap(50, 90);
assertThat(response).hasReturnedText("50");
response = counterClient.get();
assertThat(response).hasReturnedText("90");
}
use of org.infinispan.client.rest.RestCounterClient in project infinispan by infinispan.
the class MultiResourceTest method callCounterOp.
private void callCounterOp(String name, String op) {
RestCounterClient counterClient = client.counter(name);
RestResponse response = null;
switch(op) {
case "increment":
response = join(counterClient.increment());
break;
case "decrement":
response = join(counterClient.decrement());
break;
default:
Assert.fail("Invalid operation " + op);
}
ResponseAssertion.assertThat(response).isOk();
}
use of org.infinispan.client.rest.RestCounterClient in project infinispan by infinispan.
the class MultiResourceTest method doCounterReadAndWrite.
private CompletableFuture<Boolean> doCounterReadAndWrite(CountDownLatch startLatch, String counterName) {
return CompletableFuture.supplyAsync(() -> {
try {
startLatch.await();
callCounterOp(counterName, "increment");
callCounterOp(counterName, "increment");
callCounterOp(counterName, "increment");
callCounterOp(counterName, "increment");
callCounterOp(counterName, "increment");
callCounterOp(counterName, "decrement");
callCounterOp(counterName, "decrement");
callCounterOp(counterName, "decrement");
RestCounterClient counterClient = client.counter(counterName);
eventually(() -> {
RestResponse r = join(counterClient.get());
ResponseAssertion.assertThat(r).isOk();
long value = Long.parseLong(r.getBody());
return value == 2;
});
return true;
} catch (Throwable e) {
e.printStackTrace();
return false;
}
}, service);
}
Aggregations