@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(); }
private CompletionStage<RestResponse> createCounter(RestRequest request) throws RestResponseException { NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder(); String counterName = request.variables().get("counterName"); String contents = request.contents().asString(); if (contents == null || contents.length() == 0) { responseBuilder.status(HttpResponseStatus.BAD_REQUEST); responseBuilder.entity("Configuration not provided"); return completedFuture(responseBuilder.build()); } CounterConfiguration configuration = createCounterConfiguration(contents); if (configuration == null) { responseBuilder.status(HttpResponseStatus.BAD_REQUEST).entity("Invalid configuration"); return completedFuture(responseBuilder.build()); } return counterManager.defineCounterAsync(counterName, configuration).thenApply(r -> responseBuilder.build()); }
CounterResource implements ResourceHandler { private CompletionStage<RestResponse> createCounter(RestRequest request) throws RestResponseException { NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder(); String counterName = request.variables().get("counterName"); String contents = request.contents().asString(); if (contents == null || contents.length() == 0) { responseBuilder.status(HttpResponseStatus.BAD_REQUEST); responseBuilder.entity("Configuration not provided"); return completedFuture(responseBuilder.build()); } CounterConfiguration configuration = createCounterConfiguration(contents); if (configuration == null) { responseBuilder.status(HttpResponseStatus.BAD_REQUEST).entity("Invalid configuration"); return completedFuture(responseBuilder.build()); } return counterManager.defineCounterAsync(counterName, configuration).thenApply(r -> responseBuilder.build()); } }
CounterResource implements ResourceHandler { private CompletionStage<RestResponse> createCounter(RestRequest request) throws RestResponseException { NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder(); String counterName = request.variables().get("counterName"); String contents = request.contents().asString(); if (contents == null || contents.length() == 0) { responseBuilder.status(HttpResponseStatus.BAD_REQUEST); responseBuilder.entity("Configuration not provided"); return completedFuture(responseBuilder.build()); } CounterConfiguration configuration = createCounterConfiguration(contents); if (configuration == null) { responseBuilder.status(HttpResponseStatus.BAD_REQUEST).entity("Invalid configuration"); return completedFuture(responseBuilder.build()); } return counterManager.defineCounterAsync(counterName, configuration).thenApply(r -> responseBuilder.build()); } CounterResource(InvocationHelper invocationHelper); }
CounterResource implements ResourceHandler { private CompletionStage<RestResponse> createCounter(RestRequest request) throws RestResponseException { NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder(); String counterName = request.variables().get("counterName"); String contents = request.contents().asString(); if (contents == null || contents.length() == 0) { responseBuilder.status(HttpResponseStatus.BAD_REQUEST); responseBuilder.entity("Configuration not provided"); return completedFuture(responseBuilder.build()); } CounterConfiguration configuration = createCounterConfiguration(contents); if (configuration == null) { responseBuilder.status(HttpResponseStatus.BAD_REQUEST).entity("Invalid configuration"); return completedFuture(responseBuilder.build()); } return counterManager.defineCounterAsync(counterName, configuration).thenApply(r -> responseBuilder.build()); } CounterResource(InvocationHelper invocationHelper); @Override Invocations getInvocations(); }
CounterResource implements ResourceHandler { private CompletionStage<RestResponse> createCounter(RestRequest request) throws RestResponseException { NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder(); String counterName = request.variables().get("counterName"); String contents = request.contents().asString(); if (contents == null || contents.length() == 0) { responseBuilder.status(HttpResponseStatus.BAD_REQUEST); responseBuilder.entity("Configuration not provided"); return completedFuture(responseBuilder.build()); } CounterConfiguration configuration = createCounterConfiguration(contents); if (configuration == null) { responseBuilder.status(HttpResponseStatus.BAD_REQUEST).entity("Invalid configuration"); return completedFuture(responseBuilder.build()); } return counterManager.defineCounterAsync(counterName, configuration).thenApply(r -> responseBuilder.build()); } CounterResource(InvocationHelper invocationHelper); @Override Invocations getInvocations();  }