@Override public AsyncInvoker async() { return webClient.async(); }
@Override public <R> Mono<R> method(String name, Entity<?> entity, Class<R> responseType) { return mono(webClient.async().method(name, entity, responseType)); }
@Override public <R> Mono<R> method(String name, Entity<?> entity, GenericType<R> genericType) { return mono(webClient.async().method(name, entity, genericType)); }
@Override public <T> Flux<T> flux(String name, Class<T> responseType) { Future<Response> futureResponse = webClient.async().method(name); return Flux.fromIterable(toIterable(futureResponse, responseType)); }
@Override public <T> Flux<T> flux(String name, Entity<?> entity, Class<T> responseType) { Future<Response> futureResponse = webClient.async().method(name, entity); return Flux.fromIterable(toIterable(futureResponse, responseType)); }
@Test public void testThatNewSpanIsCreatedWhenNotProvidedUsingAsyncClient() throws Exception { final WebClient client = createWebClient("/bookstore/books", openTracingClientProvider); final Future<Response> f = client.async().get(); final Response r = f.get(1, TimeUnit.SECONDS); assertEquals(Status.OK.getStatusCode(), r.getStatus()); assertThat(TestSender.getAllSpans().size(), equalTo(3)); assertThat(TestSender.getAllSpans().get(0).getOperationName(), equalTo("Get Books")); assertThat(TestSender.getAllSpans().get(1).getOperationName(), equalTo("GET /bookstore/books")); assertThat(TestSender.getAllSpans().get(2).getOperationName(), equalTo("GET " + client.getCurrentURI())); }
@Test public void testThatNewSpanIsCreatedWhenNotProvidedUsingAsyncClient() throws Exception { final WebClient client = createWebClient("/bookstore/books", braveClientProvider); final Future<Response> f = client.async().get(); final Response r = f.get(1, TimeUnit.SECONDS); assertEquals(Status.OK.getStatusCode(), r.getStatus()); assertThat(TestSpanReporter.getAllSpans().size(), equalTo(3)); assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books")); assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books")); assertThat(TestSpanReporter.getAllSpans().get(2).name(), equalTo("get " + client.getCurrentURI())); assertThatTraceHeadersArePresent(r, false); }
@Test public void testGetBookAsyncResponse404() throws Exception { String address = "http://localhost:" + PORT + "/bookstore/bookheaders/404"; WebClient wc = createWebClient(address); Future<Response> future = wc.async().get(Response.class); assertEquals(404, future.get().getStatus()); wc.close(); }
@Test public void testGetBookAsync404() throws Exception { String address = "http://localhost:" + PORT + "/bookstore/bookheaders/404"; WebClient wc = createWebClient(address); Future<Book> future = wc.async().get(Book.class); try { future.get(); fail("Exception expected"); } catch (ExecutionException ex) { assertTrue(ex.getCause() instanceof NotFoundException); } wc.close(); }
@Test public void testGetBookAsyncNoCallback() throws Exception { String address = "http://localhost:" + PORT + "/bookstore/bookheaders/simple"; WebClient wc = createWebClient(address); Future<Book> future = wc.async().get(Book.class); Book book = future.get(); assertEquals(124L, book.getId()); validateResponse(wc); }
@Test public void testPostBookAsync() throws Exception { String address = "http://localhost:" + PORT + "/bookstore/bookheaders/simple/async"; WebClient wc = createWebClientPost(address); Future<Book> future = wc.async().post(Entity.xml(new Book("Book", 126L)), Book.class); assertEquals(124L, future.get().getId()); validatePostResponse(wc, true, false); }
private void doTestGetBookAsync(String address, boolean asyncInvoker) throws InterruptedException, ExecutionException { WebClient wc = createWebClient(address); final Holder<Book> holder = new Holder<>(); InvocationCallback<Book> callback = createCallback(holder); Future<Book> future = asyncInvoker ? wc.async().get(callback) : wc.get(callback); Book book = future.get(); assertSame(book, holder.value); assertEquals(124L, book.getId()); validateResponse(wc); }
@Test public void testRetrieveBookCustomMethodAsync() throws Exception { String address = "http://localhost:" + PORT + "/bookstore/retrieve"; WebClient wc = WebClient.create(address); wc.accept("application/xml"); Future<Book> book = wc.async().method("RETRIEVE", Entity.xml(new Book("Retrieve", 123L)), Book.class); assertEquals("Retrieve", book.get().getName()); wc.close(); }