use of org.infinispan.client.rest.RestCounterClient in project infinispan by infinispan.
the class BackupManagerIT method createCounter.
private void createCounter(String name, Element type, Storage storage, RestClient client, long delta) {
String config = String.format("{\n" + " \"%s\":{\n" + " \"initial-value\":0,\n" + " \"storage\":\"%s\"\n" + " }\n" + "}", type, storage.toString());
RestCounterClient counterClient = client.counter(name);
RestResponse rsp = await(counterClient.create(RestEntity.create(MediaType.APPLICATION_JSON, config)));
assertEquals(200, rsp.getStatus());
if (delta != 0) {
rsp = await(counterClient.add(delta));
assertEquals(name, name.contains("strong") ? 200 : 204, rsp.getStatus());
assertNotNull(rsp.getBody());
}
}
use of org.infinispan.client.rest.RestCounterClient in project infinispan by infinispan.
the class RestOperations method testCounter.
@Test
public void testCounter() {
RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
builder.protocol(protocol);
RestClient client = SERVER_TEST.rest().withClientConfiguration(builder).create();
CounterConfiguration configuration = CounterConfiguration.builder(CounterType.WEAK).initialValue(5).concurrencyLevel(1).build();
AbstractCounterConfiguration config = ConvertUtil.configToParsedConfig("test-counter", configuration);
String configJson = AbstractRestResourceTest.counterConfigToJson(config);
RestCounterClient counter = client.counter("test");
RestResponse rsp = sync(counter.create(RestEntity.create(MediaType.APPLICATION_JSON, configJson)));
assertEquals(HttpResponseStatus.OK.code(), rsp.getStatus());
rsp = sync(counter.get());
assertEquals("5", rsp.getBody());
}
use of org.infinispan.client.rest.RestCounterClient in project infinispan by infinispan.
the class CounterResourceTest method testWeakCounterOps.
@Test
public void testWeakCounterOps() {
String name = "weak-test";
createCounter(name, CounterConfiguration.builder(CounterType.WEAK).initialValue(5).build());
RestCounterClient counterClient = client.counter(name);
CompletionStage<RestResponse> response = counterClient.increment();
assertThat(response).hasNoContent();
waitForCounterToReach(name, 6);
response = counterClient.increment();
assertThat(response).hasNoContent();
waitForCounterToReach(name, 7);
response = counterClient.decrement();
assertThat(response).hasNoContent();
waitForCounterToReach(name, 6);
response = counterClient.decrement();
assertThat(response).hasNoContent();
waitForCounterToReach(name, 5);
response = counterClient.add(10);
assertThat(response).hasNoContent();
waitForCounterToReach(name, 15);
response = counterClient.reset();
assertThat(response).hasNoContent();
waitForCounterToReach(name, 5);
}
use of org.infinispan.client.rest.RestCounterClient in project infinispan by infinispan.
the class CounterResourceTest method waitForCounterToReach.
private void waitForCounterToReach(String name, int i) {
RestCounterClient counterClient = client.counter(name);
eventually(() -> {
RestResponse r = join(counterClient.get());
assertThat(r).isOk();
long value = Long.parseLong(r.getBody());
return value == i;
});
}
use of org.infinispan.client.rest.RestCounterClient in project infinispan by infinispan.
the class CounterResourceTest method testWeakCounterLifecycle.
@Test
public void testWeakCounterLifecycle() {
CounterConfiguration counterConfig = CounterConfiguration.builder(CounterType.WEAK).initialValue(5).storage(Storage.VOLATILE).concurrencyLevel(6).build();
createCounter("sample-counter", counterConfig);
RestCounterClient counterClient = client.counter("sample-counter");
RestResponse response = join(counterClient.configuration(APPLICATION_JSON_TYPE));
Json jsonNode = Json.read(response.getBody());
Json config = jsonNode.at("weak-counter");
assertEquals(config.at("initial-value").asInteger(), 5);
assertEquals(config.at("storage").asString(), "VOLATILE");
assertEquals(config.at("concurrency-level").asInteger(), 6);
response = join(counterClient.delete());
assertThat(response).isOk();
response = join(counterClient.configuration());
assertThat(response).isNotFound();
}
Aggregations