use of io.vertx.core.http.StreamResetException in project vert.x by eclipse.
the class Http2ClientTest method testServerResetClientStreamDuringRequest.
@Test
public void testServerResetClientStreamDuringRequest() throws Exception {
String chunk = TestUtils.randomAlphaString(1024);
server.requestHandler(req -> {
req.handler(buf -> {
req.response().reset(8);
});
});
startServer();
client.post(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
fail();
}).exceptionHandler(err -> {
Context ctx = Vertx.currentContext();
assertOnIOContext(ctx);
assertTrue(err instanceof StreamResetException);
StreamResetException reset = (StreamResetException) err;
assertEquals(8, reset.getCode());
testComplete();
}).setChunked(true).write(chunk);
await();
}
use of io.vertx.core.http.StreamResetException in project vert.x by eclipse.
the class Http2ClientTest method testResetPushPromiseNoHandler.
@Test
public void testResetPushPromiseNoHandler() throws Exception {
server.requestHandler(req -> {
req.response().push(HttpMethod.GET, "/wibble", ar -> {
assertTrue(ar.succeeded());
HttpServerResponse resp = ar.result();
resp.setChunked(true).write("content");
resp.exceptionHandler(err -> {
assertTrue(err instanceof StreamResetException);
assertEquals(Http2Error.CANCEL.code(), ((StreamResetException) err).getCode());
testComplete();
});
});
});
startServer();
HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
});
req.end();
await();
}
use of io.vertx.core.http.StreamResetException in project vert.x by eclipse.
the class Http2ServerTest method testNetSocketHandleReset.
@Test
public void testNetSocketHandleReset() throws Exception {
server.requestHandler(req -> {
NetSocket socket = req.netSocket();
AtomicInteger status = new AtomicInteger();
socket.exceptionHandler(err -> {
assertTrue(err instanceof StreamResetException);
StreamResetException ex = (StreamResetException) err;
assertEquals(0, ex.getCode());
assertEquals(0, status.getAndIncrement());
});
socket.endHandler(v -> {
fail();
});
socket.closeHandler(v -> {
assertEquals(1, status.getAndIncrement());
testComplete();
});
});
startServer();
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
int id = request.nextStreamId();
request.decoder.frameListener(new Http2EventAdapter() {
int count = 0;
@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception {
int c = count++;
vertx.runOnContext(v -> {
assertEquals(0, c);
});
request.encoder.writeRstStream(ctx, streamId, 0, ctx.newPromise());
request.context.flush();
}
});
request.encoder.writeHeaders(request.context, id, GET("/"), 0, false, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
use of io.vertx.core.http.StreamResetException in project vert.x by eclipse.
the class Http2ServerTest method testClientResetServerStream.
@Test
public void testClientResetServerStream() throws Exception {
Context ctx = vertx.getOrCreateContext();
Future<Void> bufReceived = Future.future();
AtomicInteger resetCount = new AtomicInteger();
server.requestHandler(req -> {
req.handler(buf -> {
bufReceived.complete();
});
req.exceptionHandler(err -> {
assertOnIOContext(ctx);
assertTrue(err instanceof StreamResetException);
assertEquals(10L, ((StreamResetException) err).getCode());
assertEquals(0, resetCount.getAndIncrement());
});
req.response().exceptionHandler(err -> {
assertOnIOContext(ctx);
assertTrue(err instanceof StreamResetException);
assertEquals(10L, ((StreamResetException) err).getCode());
assertEquals(1, resetCount.getAndIncrement());
});
req.endHandler(v -> {
assertOnIOContext(ctx);
assertEquals(2, resetCount.get());
testComplete();
});
});
startServer(ctx);
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
int id = request.nextStreamId();
Http2ConnectionEncoder encoder = request.encoder;
encoder.writeHeaders(request.context, id, GET("/"), 0, false, request.context.newPromise());
encoder.writeData(request.context, id, Buffer.buffer("hello").getByteBuf(), 0, false, request.context.newPromise());
bufReceived.setHandler(ar -> {
encoder.writeRstStream(request.context, id, 10, request.context.newPromise());
request.context.flush();
});
});
fut.sync();
await();
}
use of io.vertx.core.http.StreamResetException 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();
}
Aggregations