Search in sources :

Example 6 with RestCounterClient

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");
}
Also used : RestCounterClient(org.infinispan.client.rest.RestCounterClient) RestResponse(org.infinispan.client.rest.RestResponse) Test(org.testng.annotations.Test)

Example 7 with RestCounterClient

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();
}
Also used : RestCounterClient(org.infinispan.client.rest.RestCounterClient) RestResponse(org.infinispan.client.rest.RestResponse)

Example 8 with RestCounterClient

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);
}
Also used : RestCounterClient(org.infinispan.client.rest.RestCounterClient) RestResponse(org.infinispan.client.rest.RestResponse)

Aggregations

RestCounterClient (org.infinispan.client.rest.RestCounterClient)8 RestResponse (org.infinispan.client.rest.RestResponse)8 Test (org.testng.annotations.Test)3 CounterConfiguration (org.infinispan.counter.api.CounterConfiguration)2 AbstractCounterConfiguration (org.infinispan.counter.configuration.AbstractCounterConfiguration)2 RestClient (org.infinispan.client.rest.RestClient)1 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)1 Json (org.infinispan.commons.dataconversion.internal.Json)1 AbstractRestResourceTest (org.infinispan.rest.resources.AbstractRestResourceTest)1 Test (org.junit.Test)1