|
2 | 2 |
|
3 | 3 | import io.vertx.core.Future; |
4 | 4 | import io.vertx.core.buffer.Buffer; |
5 | | -import io.vertx.core.http.HttpClientRequest; |
6 | | -import io.vertx.core.http.HttpMethod; |
7 | | -import io.vertx.core.http.ServerWebSocket; |
| 5 | +import io.vertx.core.http.*; |
8 | 6 | import io.vertx.core.net.SocketAddress; |
9 | 7 | import io.vertx.ext.unit.Async; |
10 | 8 | import io.vertx.ext.unit.TestContext; |
@@ -49,31 +47,33 @@ private SocketAddress backend(TestContext ctx, Async async) { |
49 | 47 | * @param wsHit if interceptor changes the WebSocket packet |
50 | 48 | */ |
51 | 49 | private void testWithInterceptor(TestContext ctx, ProxyInterceptor interceptor, boolean httpHit, boolean wsHit) { |
52 | | - Async latch = ctx.async(4); |
| 50 | + Async latch = ctx.async(3); |
53 | 51 | SocketAddress backend = backend(ctx, latch); |
54 | 52 |
|
55 | 53 | startProxy(proxy -> { |
56 | 54 | proxy.origin(backend); |
57 | | - if (interceptor != null) proxy.addInterceptor(interceptor); |
| 55 | + if (interceptor != null) { |
| 56 | + proxy.addInterceptor(interceptor); |
| 57 | + }; |
58 | 58 | }); |
59 | 59 |
|
60 | | - vertx.createHttpClient().request(HttpMethod.GET, 8080, "localhost", "/http") |
61 | | - .compose(HttpClientRequest::send) |
62 | | - .onComplete(ctx.asyncAssertSuccess(resp -> { |
63 | | - resp.body().onSuccess(body -> { |
64 | | - ctx.assertEquals(body.toString().endsWith("/updated"), httpHit); |
| 60 | + HttpClientAgent httpClient = vertx.createHttpClient(); |
| 61 | + WebSocketClient webSocketClient = vertx.createWebSocketClient(); |
| 62 | + |
| 63 | + Buffer body = httpClient |
| 64 | + .request(HttpMethod.GET, 8080, "localhost", "/http") |
| 65 | + .compose(req -> req.send() |
| 66 | + .expecting(HttpResponseExpectation.SC_OK)) |
| 67 | + .compose(HttpClientResponse::body).await(); |
| 68 | + ctx.assertEquals(body.toString().endsWith("/updated"), httpHit); |
| 69 | + webSocketClient.connect(8080, "localhost", "/ws") |
| 70 | + .onComplete(ctx.asyncAssertSuccess(webSocket -> { |
| 71 | + webSocket.handler(buffer -> { |
| 72 | + ctx.assertEquals(buffer.toString().endsWith("/updated"), wsHit); |
65 | 73 | latch.countDown(); |
66 | | - |
67 | | - vertx.createWebSocketClient().connect(8080, "localhost", "/ws") |
68 | | - .onComplete(ctx.asyncAssertSuccess(webSocket -> { |
69 | | - webSocket.handler(buffer -> { |
70 | | - ctx.assertEquals(buffer.toString().endsWith("/updated"), wsHit); |
71 | | - latch.countDown(); |
72 | | - webSocket.close(); |
73 | | - }); |
74 | | - webSocket.write(Buffer.buffer("hello")); |
75 | | - })); |
| 74 | + webSocket.close(); |
76 | 75 | }); |
| 76 | + webSocket.write(Buffer.buffer("hello")); |
77 | 77 | })); |
78 | 78 | latch.await(5000); |
79 | 79 | } |
|
0 commit comments