use of io.vertx.core.http.StreamResetException in project vert.x by eclipse.
the class Http2ClientTest method testServerResetClientStreamDuringResponse.
@Test
public void testServerResetClientStreamDuringResponse() throws Exception {
waitFor(2);
String chunk = TestUtils.randomAlphaString(1024);
Future<Void> doReset = Future.future();
server.requestHandler(req -> {
doReset.setHandler(onSuccess(v -> {
req.response().reset(8);
}));
req.response().setChunked(true).write(Buffer.buffer(chunk));
});
startServer();
Context ctx = vertx.getOrCreateContext();
Handler<Throwable> resetHandler = err -> {
assertOnIOContext(ctx);
assertTrue(err instanceof StreamResetException);
StreamResetException reset = (StreamResetException) err;
assertEquals(8, reset.getCode());
complete();
};
ctx.runOnContext(v -> {
client.post(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
resp.exceptionHandler(resetHandler);
resp.handler(buff -> {
doReset.complete();
});
}).exceptionHandler(resetHandler).setChunked(true).write(chunk);
});
await();
}
use of io.vertx.core.http.StreamResetException in project vert.x by eclipse.
the class Http2ClientTest method testResetActivePushPromise.
@Test
public void testResetActivePushPromise() throws Exception {
server.requestHandler(req -> {
req.response().push(HttpMethod.GET, "/wibble", ar -> {
assertTrue(ar.succeeded());
HttpServerResponse response = ar.result();
response.exceptionHandler(err -> {
if (err instanceof StreamResetException) {
assertEquals(Http2Error.CANCEL.code(), ((StreamResetException) err).getCode());
testComplete();
}
});
response.setChunked(true).write("some_content");
});
});
startServer();
HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
fail();
});
req.pushHandler(pushedReq -> {
pushedReq.handler(pushedResp -> {
pushedResp.handler(buff -> {
pushedReq.reset(Http2Error.CANCEL.code());
});
});
});
req.end();
await();
}
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();
}
Aggregations