Search in sources :

Example 1 with RestURI

use of org.infinispan.client.rest.RestURI in project infinispan by infinispan.

the class HttpBenchmark method setup.

@Setup
public void setup() {
    RestURI uri = RestURI.create(this.uri);
    RestClientConfigurationBuilder builder = uri.toConfigurationBuilder();
    client = RestClient.forConfiguration(builder.build());
    cache = client.cache(cacheName);
    try (RestResponse response = uncheckedAwait(cache.exists())) {
        switch(response.getStatus()) {
            case RestResponse.OK:
            case RestResponse.NO_CONTENT:
                break;
            case RestResponse.NOT_FOUND:
                Util.close(client);
                throw new IllegalArgumentException("Could not find cache '" + cacheName + "'");
            case RestResponse.UNAUTHORIZED:
                Util.close(client);
                throw new SecurityException(response.getBody());
            default:
                Util.close(client);
                throw new RuntimeException(response.getBody());
        }
    }
    value = RestEntity.create(MediaType.APPLICATION_OCTET_STREAM, new byte[valueSize]);
    keySet = new ArrayList<>(keySetSize);
    // We always use the same seed to make things repeatable
    Random r = new Random(17);
    byte[] keyBytes = new byte[keySize / 2];
    for (int i = 0; i < keySetSize; i++) {
        r.nextBytes(keyBytes);
        String key = Util.toHexString(keyBytes);
        keySet.add(key);
        cache.put(key, value);
    }
    nextIndex = new AtomicInteger();
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) Random(java.util.Random) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RestResponse(org.infinispan.client.rest.RestResponse) RestURI(org.infinispan.client.rest.RestURI) Setup(org.openjdk.jmh.annotations.Setup)

Aggregations

Random (java.util.Random)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 RestResponse (org.infinispan.client.rest.RestResponse)1 RestURI (org.infinispan.client.rest.RestURI)1 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)1 Setup (org.openjdk.jmh.annotations.Setup)1