use of io.vertx.core.http.HttpServerRequest in project vert.x by eclipse.
the class Http2ServerTest method testServerClose.
@Test
public void testServerClose() throws Exception {
waitFor(2);
AtomicInteger status = new AtomicInteger();
Handler<HttpServerRequest> requestHandler = req -> {
HttpConnection conn = req.connection();
conn.shutdownHandler(v -> {
assertEquals(0, status.getAndIncrement());
});
conn.closeHandler(v -> {
assertEquals(1, status.getAndIncrement());
complete();
});
conn.close();
};
server.requestHandler(requestHandler);
startServer();
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
request.channel.closeFuture().addListener(v1 -> {
vertx.runOnContext(v2 -> {
complete();
});
});
request.decoder.frameListener(new Http2EventAdapter() {
@Override
public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData) throws Http2Exception {
vertx.runOnContext(v -> {
assertEquals(0, errorCode);
});
}
});
Http2ConnectionEncoder encoder = request.encoder;
int id = request.nextStreamId();
encoder.writeHeaders(request.context, id, GET("/"), 0, true, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
use of io.vertx.core.http.HttpServerRequest in project vert.x by eclipse.
the class Http2ServerTest method testClientSendGoAwayNoError.
@Test
public void testClientSendGoAwayNoError() throws Exception {
Future<Void> abc = Future.future();
Context ctx = vertx.getOrCreateContext();
Handler<HttpServerRequest> requestHandler = req -> {
HttpConnection conn = req.connection();
AtomicInteger numShutdown = new AtomicInteger();
AtomicBoolean completed = new AtomicBoolean();
conn.shutdownHandler(v -> {
assertOnIOContext(ctx);
numShutdown.getAndIncrement();
vertx.setTimer(100, timerID -> {
completed.set(true);
testComplete();
});
});
conn.goAwayHandler(ga -> {
assertOnIOContext(ctx);
assertEquals(0, numShutdown.get());
req.response().end();
});
conn.closeHandler(v -> {
assertTrue(completed.get());
});
abc.complete();
};
server.requestHandler(requestHandler);
startServer(ctx);
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
Http2ConnectionEncoder encoder = request.encoder;
int id = request.nextStreamId();
encoder.writeHeaders(request.context, id, GET("/"), 0, true, request.context.newPromise());
request.context.flush();
abc.setHandler(ar -> {
encoder.writeGoAway(request.context, id, 0, Unpooled.EMPTY_BUFFER, request.context.newPromise());
request.context.flush();
});
});
fut.sync();
await();
}
use of io.vertx.core.http.HttpServerRequest in project vert.x by eclipse.
the class HttpRequestStreamTest method testClosingServerClosesRequestStreamEndHandler.
@Test
public void testClosingServerClosesRequestStreamEndHandler() {
this.server = vertx.createHttpServer(new HttpServerOptions().setPort(HttpTestBase.DEFAULT_HTTP_PORT));
ReadStream<HttpServerRequest> stream = server.requestStream();
AtomicBoolean closed = new AtomicBoolean();
stream.endHandler(v -> closed.set(true));
stream.handler(req -> {
});
server.listen(ar -> {
assertTrue(ar.succeeded());
assertFalse(closed.get());
server.close(v -> {
assertTrue(ar.succeeded());
assertTrue(closed.get());
testComplete();
});
});
await();
}
use of io.vertx.core.http.HttpServerRequest in project java-chassis by ServiceComb.
the class TestRestVertxHttpRequest method testGetQueryParams.
@Test
public void testGetQueryParams() {
boolean status = true;
try {
HttpServerRequest httpServerRequest = Mockito.mock(HttpServerRequest.class);
Deencapsulation.setField(instance, "request", httpServerRequest);
MultiMap multiMap = Mockito.mock(MultiMap.class);
Mockito.when(httpServerRequest.params()).thenReturn(multiMap);
List<String> stringList = new ArrayList<String>();
stringList.add("sters");
Set<String> stringSet = new HashSet<String>();
stringSet.add("sters");
Mockito.when(multiMap.names()).thenReturn(stringSet);
Mockito.when(multiMap.getAll("key")).thenReturn(stringList);
Assert.assertNotNull(instance.getQueryParams());
} catch (Exception ex) {
status = false;
}
Assert.assertTrue(status);
}
use of io.vertx.core.http.HttpServerRequest in project java-chassis by ServiceComb.
the class TestRestVertxHttpRequest method testGetQueryParamisNull.
@Test
public void testGetQueryParamisNull() {
boolean status = true;
try {
HttpServerRequest httpServerRequest = Mockito.mock(HttpServerRequest.class);
Deencapsulation.setField(instance, "request", httpServerRequest);
MultiMap multiMap = Mockito.mock(MultiMap.class);
Mockito.when(httpServerRequest.params()).thenReturn(multiMap);
List<String> stringList = null;
Mockito.when(multiMap.getAll("key")).thenReturn(stringList);
String[] str = instance.getQueryParam("key");
Assert.assertNull(str);
} catch (Exception ex) {
status = false;
}
Assert.assertTrue(status);
}
Aggregations