use of io.vertx.core.http.HttpClientRequest in project java-chassis by ServiceComb.
the class TestVertxDeleteMethod method testCreateRequest.
@Test
public void testCreateRequest() {
HttpClient client = Mockito.mock(HttpClient.class);
IpPort ipPort = Mockito.mock(IpPort.class);
Mockito.when(ipPort.getPort()).thenReturn(23);
Mockito.when(ipPort.getHostOrIp()).thenReturn("test");
Invocation invocation = Mockito.mock(Invocation.class);
RestOperationMeta operation = Mockito.mock(RestOperationMeta.class);
AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
HttpClientRequest obj = (HttpClientRequest) VertxDeleteMethod.INSTANCE.createRequest(client, invocation, ipPort, "testCall", operation, asyncResp);
Assert.assertNull(obj);
}
use of io.vertx.core.http.HttpClientRequest in project vert.x by eclipse.
the class Http2ClientTest method testClientResetServerStreamDuringRequest.
@Test
public void testClientResetServerStreamDuringRequest() throws Exception {
Future<Void> bufReceived = Future.future();
server.requestHandler(req -> {
req.handler(buf -> {
bufReceived.complete();
});
req.exceptionHandler(err -> {
assertTrue(err instanceof StreamResetException);
});
req.response().exceptionHandler(err -> {
assertTrue(err instanceof StreamResetException);
assertEquals(10L, ((StreamResetException) err).getCode());
testComplete();
});
});
startServer();
HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
fail();
}).setChunked(true).write(Buffer.buffer("hello"));
bufReceived.setHandler(ar -> {
req.reset(10);
});
await();
}
use of io.vertx.core.http.HttpClientRequest in project vert.x by eclipse.
the class Http2ClientTest method testSendingGoAwayDiscardsTheConnection.
@Test
public void testSendingGoAwayDiscardsTheConnection() throws Exception {
AtomicInteger reqCount = new AtomicInteger();
server.requestHandler(req -> {
switch(reqCount.getAndIncrement()) {
case 0:
req.response().setChunked(true).write("some-data");
break;
case 1:
req.response().end();
break;
default:
fail();
}
});
startServer();
HttpClientRequest req1 = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath");
req1.handler(resp1 -> {
req1.connection().goAway(0);
client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp2 -> {
testComplete();
}).setTimeout(5000).exceptionHandler(this::fail).end();
}).end();
await();
}
use of io.vertx.core.http.HttpClientRequest in project vert.x by eclipse.
the class Http2ClientTest method testReceivingGoAwayDiscardsTheConnection.
@Test
public void testReceivingGoAwayDiscardsTheConnection() throws Exception {
AtomicInteger reqCount = new AtomicInteger();
server.requestHandler(req -> {
switch(reqCount.getAndIncrement()) {
case 0:
req.connection().goAway(0);
break;
case 1:
req.response().end();
break;
default:
fail();
}
});
startServer();
HttpClientRequest req1 = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath");
req1.connectionHandler(conn -> {
AtomicInteger gaCount = new AtomicInteger();
conn.goAwayHandler(ga -> {
if (gaCount.getAndIncrement() == 0) {
client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp2 -> {
testComplete();
}).setTimeout(5000).exceptionHandler(this::fail).end();
}
});
});
req1.handler(resp1 -> {
fail();
}).end();
await();
}
use of io.vertx.core.http.HttpClientRequest in project vert.x by eclipse.
the class Http2ClientTest method testHeaders.
@Test
public void testHeaders() throws Exception {
AtomicInteger reqCount = new AtomicInteger();
server.requestHandler(req -> {
assertEquals("https", req.scheme());
assertEquals(HttpMethod.GET, req.method());
assertEquals("/somepath", req.path());
assertEquals(DEFAULT_HTTPS_HOST_AND_PORT, req.host());
assertEquals("foo_request_value", req.getHeader("Foo_request"));
assertEquals("bar_request_value", req.getHeader("bar_request"));
assertEquals(2, req.headers().getAll("juu_request").size());
assertEquals("juu_request_value_1", req.headers().getAll("juu_request").get(0));
assertEquals("juu_request_value_2", req.headers().getAll("juu_request").get(1));
reqCount.incrementAndGet();
HttpServerResponse resp = req.response();
resp.putHeader("content-type", "text/plain");
resp.putHeader("Foo_response", "foo_value");
resp.putHeader("bar_response", "bar_value");
resp.putHeader("juu_response", (List<String>) Arrays.asList("juu_value_1", "juu_value_2"));
resp.end();
});
startServer();
HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath");
req.handler(resp -> {
Context ctx = vertx.getOrCreateContext();
assertOnIOContext(ctx);
assertEquals(3, req.streamId());
assertEquals(1, reqCount.get());
assertEquals(HttpVersion.HTTP_2, resp.version());
assertEquals(200, resp.statusCode());
assertEquals("OK", resp.statusMessage());
assertEquals("text/plain", resp.getHeader("content-type"));
assertEquals("200", resp.getHeader(":status"));
assertEquals("foo_value", resp.getHeader("foo_response"));
assertEquals("bar_value", resp.getHeader("bar_response"));
assertEquals(2, resp.headers().getAll("juu_response").size());
assertEquals("juu_value_1", resp.headers().getAll("juu_response").get(0));
assertEquals("juu_value_2", resp.headers().getAll("juu_response").get(1));
resp.endHandler(v -> {
assertOnIOContext(ctx);
testComplete();
});
}).putHeader("Foo_request", "foo_request_value").putHeader("bar_request", "bar_request_value").putHeader("juu_request", Arrays.<CharSequence>asList("juu_request_value_1", "juu_request_value_2")).exceptionHandler(err -> fail()).end();
await();
}
Aggregations