Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the documentation of a test. #284

Merged
merged 3 commits into from
Jun 8, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,36 @@ public void start_wontStartStopped() throws Exception {
public void start() throws Exception {
Vertx wcVertx = null;
try {
// Start a server.
int port = 8080;
server.start(port);

// Define a request handler.
Router r = server.createRouter();
String body = "/s1/foo handler";
r.get("/foo").handler((rc) -> {
rc.response().end(body);
});
server.mountSubRouter("/s1", r);

// Create a web client.
wcVertx = Vertx.vertx();
WebClient client = WebClient.create(wcVertx);
// fixme: Async API converted to blocking looks ugly as fuck
CompletableFuture<AsyncResult<HttpResponse<Buffer>>> f = new CompletableFuture<>();

// A future to receive the response to a request below.
CompletableFuture<AsyncResult<HttpResponse<Buffer>>> futureResponse =
new CompletableFuture<>();

// Send an asynchronous GET request, that will put the response into the future.
client.get(port, "localhost", "/s1/foo")
.send(f::complete);
.send(futureResponse::complete);

int timeout = 3;
AsyncResult<HttpResponse<Buffer>> ar = f.get(timeout, TimeUnit.SECONDS);
AsyncResult<HttpResponse<Buffer>> ar = futureResponse.get(timeout, TimeUnit.SECONDS);
assertTrue("Did not receive response in " + timeout + " seconds",
f.isDone());
futureResponse.isDone());
if (ar.succeeded()) {
// Check the result.
HttpResponse<Buffer> response = ar.result();

assertThat(response.statusCode(), equalTo(200));
Expand Down