BargeJaxRsClient implements RaftClient { @Override public CompletableFuture<AppendEntriesResponse> appendEntries(AppendEntries request) { final CompletableFuture<AppendEntriesResponse> result = new CompletableFuture<>(); client.target(baseUri).path("/raft/entries") .request().async() .post(Entity.entity(request, MediaType.APPLICATION_JSON_TYPE), new InvocationCallback<Response>() { @Override public void completed(Response response) { result.complete(response.readEntity(AppendEntriesResponse.class)); } @Override public void failed(Throwable throwable) { result.completeExceptionally(throwable); } }); return result; } @SuppressWarnings("UnusedDeclaration")  BargeJaxRsClient(URI baseUri); @VisibleForTesting  BargeJaxRsClient(URI baseUri, Client client); @Override CompletableFuture<RequestVoteResponse> requestVote(RequestVote request); @Override CompletableFuture<AppendEntriesResponse> appendEntries(AppendEntries request);  }
@Test public void returnsFutureWithServerResponseWhenAppendingEntriesGivenServerAnswers() throws Exception { BargeJaxRsClient bargeJaxRsClient = new BargeJaxRsClient(getBaseUri(),client().register(Jackson.customJacksonProvider())); CompletableFuture<AppendEntriesResponse> future = bargeJaxRsClient.appendEntries(Model.entries); assertThat(future.get(1, TimeUnit.SECONDS)).isEqualTo(Model.entriesResponse); }