private CompletionStage<RestResponse> createCounter(RestRequest request) throws RestResponseException {
      NettyRestResponse.Builder responseBuilder = invocationHelper.newResponse(request);
      String counterName = request.variables().get("counterName");

      String contents = request.contents().asString();

      if (contents == null || contents.isEmpty()) {
         throw Log.REST.missingContent();
      }
      CounterConfiguration configuration = createCounterConfiguration(contents);
      if (configuration == null) {
         throw Log.REST.invalidContent();
      }

      return invocationHelper.getCounterManager()
            .defineCounterAsync(counterName, configuration)
            .thenApply(created -> created ?
                  responseBuilder.build() :
                  responseBuilder.status(NOT_MODIFIED)
                        .entity("Unable to create counter: " + counterName)
                        .build());
   }
@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);
   }