use of java.util.concurrent.atomic.AtomicInteger in project vert.x by eclipse.
the class Http2ServerTest method testInvalidPostFileUpload.
@Test
public void testInvalidPostFileUpload() throws Exception {
server.requestHandler(req -> {
req.setExpectMultipart(true);
AtomicInteger errCount = new AtomicInteger();
req.exceptionHandler(err -> {
errCount.incrementAndGet();
});
req.endHandler(v -> {
assertTrue(errCount.get() > 0);
testComplete();
});
});
startServer();
String contentType = "multipart/form-data; boundary=a4e41223-a527-49b6-ac1c-315d76be757e";
String contentLength = "225";
String body = "--a4e41223-a527-49b6-ac1c-315d76be757e\r\n" + "Content-Disposition: form-data; name=\"file\"; filename=\"tmp-0.txt\"\r\n" + "Content-Type: image/gif; charset=ABCD\r\n" + "Content-Length: 12\r\n" + "\r\n" + "some-content\r\n" + "--a4e41223-a527-49b6-ac1c-315d76be757e--\r\n";
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
int id = request.nextStreamId();
request.encoder.writeHeaders(request.context, id, POST("/form").set("content-type", contentType).set("content-length", contentLength), 0, false, request.context.newPromise());
request.encoder.writeData(request.context, id, Buffer.buffer(body).getByteBuf(), 0, true, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
use of java.util.concurrent.atomic.AtomicInteger in project vert.x by eclipse.
the class Http2ServerTest method testServerSettings.
@Test
public void testServerSettings() throws Exception {
waitFor(2);
io.vertx.core.http.Http2Settings expectedSettings = TestUtils.randomHttp2Settings();
expectedSettings.setHeaderTableSize((int) io.vertx.core.http.Http2Settings.DEFAULT_HEADER_TABLE_SIZE);
server.close();
server = vertx.createHttpServer(serverOptions);
Context otherContext = vertx.getOrCreateContext();
server.connectionHandler(conn -> {
otherContext.runOnContext(v -> {
conn.updateSettings(expectedSettings, ar -> {
assertSame(otherContext, Vertx.currentContext());
io.vertx.core.http.Http2Settings ackedSettings = conn.settings();
assertEquals(expectedSettings.getMaxHeaderListSize(), ackedSettings.getMaxHeaderListSize());
assertEquals(expectedSettings.getMaxFrameSize(), ackedSettings.getMaxFrameSize());
assertEquals(expectedSettings.getInitialWindowSize(), ackedSettings.getInitialWindowSize());
assertEquals(expectedSettings.getMaxConcurrentStreams(), ackedSettings.getMaxConcurrentStreams());
assertEquals(expectedSettings.getHeaderTableSize(), ackedSettings.getHeaderTableSize());
assertEquals(expectedSettings.get(''), ackedSettings.get(7));
complete();
});
});
});
server.requestHandler(req -> {
fail();
});
startServer();
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
request.decoder.frameListener(new Http2FrameAdapter() {
AtomicInteger count = new AtomicInteger();
@Override
public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings newSettings) throws Http2Exception {
vertx.runOnContext(v -> {
switch(count.getAndIncrement()) {
case 0:
break;
case 1:
assertEquals((Long) expectedSettings.getMaxHeaderListSize(), newSettings.maxHeaderListSize());
assertEquals((Integer) expectedSettings.getMaxFrameSize(), newSettings.maxFrameSize());
assertEquals((Integer) expectedSettings.getInitialWindowSize(), newSettings.initialWindowSize());
assertEquals((Long) expectedSettings.getMaxConcurrentStreams(), newSettings.maxConcurrentStreams());
assertEquals(null, newSettings.headerTableSize());
complete();
break;
default:
fail();
}
});
}
});
});
fut.sync();
await();
}
use of java.util.concurrent.atomic.AtomicInteger in project vert.x by eclipse.
the class Http2ServerTest method testServerSendGoAwayNoError.
@Test
public void testServerSendGoAwayNoError() throws Exception {
waitFor(2);
AtomicReference<HttpServerRequest> first = new AtomicReference<>();
AtomicInteger status = new AtomicInteger();
AtomicInteger closed = new AtomicInteger();
AtomicBoolean done = new AtomicBoolean();
Context ctx = vertx.getOrCreateContext();
Handler<HttpServerRequest> requestHandler = req -> {
if (first.compareAndSet(null, req)) {
req.exceptionHandler(err -> {
assertTrue(done.get());
});
req.response().exceptionHandler(err -> {
assertTrue(done.get());
});
} else {
assertEquals(0, status.getAndIncrement());
req.exceptionHandler(err -> {
closed.incrementAndGet();
});
req.response().exceptionHandler(err -> {
closed.incrementAndGet();
});
HttpConnection conn = req.connection();
conn.shutdownHandler(v -> {
assertTrue(done.get());
});
conn.closeHandler(v -> {
assertTrue(done.get());
});
ctx.runOnContext(v1 -> {
conn.goAway(0, first.get().response().streamId());
vertx.setTimer(300, timerID -> {
assertEquals(1, status.getAndIncrement());
done.set(true);
complete();
});
});
}
};
testServerSendGoAway(requestHandler, 0);
}
use of java.util.concurrent.atomic.AtomicInteger in project vert.x by eclipse.
the class Http2ServerTest method testShutdown.
@Test
public void testShutdown() throws Exception {
waitFor(2);
AtomicReference<HttpServerRequest> first = new AtomicReference<>();
AtomicInteger status = new AtomicInteger();
Handler<HttpServerRequest> requestHandler = req -> {
if (first.compareAndSet(null, req)) {
req.exceptionHandler(err -> {
fail();
});
req.response().exceptionHandler(err -> {
fail();
});
} else {
assertEquals(0, status.getAndIncrement());
req.exceptionHandler(err -> {
fail();
});
req.response().exceptionHandler(err -> {
fail();
});
HttpConnection conn = req.connection();
conn.closeHandler(v -> {
assertEquals(2, status.getAndIncrement());
complete();
});
conn.shutdown();
vertx.setTimer(300, timerID -> {
assertEquals(1, status.getAndIncrement());
first.get().response().end();
req.response().end();
});
}
};
testServerSendGoAway(requestHandler, 0);
}
use of java.util.concurrent.atomic.AtomicInteger in project vert.x by eclipse.
the class HttpMetricsTest method testPushPromise.
@Test
public void testPushPromise() throws Exception {
waitFor(2);
int numBuffers = 10;
int contentLength = numBuffers * 1000;
server.requestHandler(req -> {
req.response().push(HttpMethod.GET, "/wibble", ar -> {
HttpServerResponse pushedResp = ar.result();
FakeHttpServerMetrics serverMetrics = FakeMetricsBase.getMetrics(server);
HttpServerMetric serverMetric = serverMetrics.getMetric(pushedResp);
assertNotNull(serverMetric);
pushedResp.putHeader("content-length", "" + contentLength);
AtomicInteger numBuffer = new AtomicInteger(numBuffers);
vertx.setPeriodic(1, timerID -> {
if (numBuffer.getAndDecrement() == 0) {
pushedResp.end();
assertNull(serverMetrics.getMetric(pushedResp));
vertx.cancelTimer(timerID);
complete();
} else {
pushedResp.write(TestUtils.randomBuffer(1000));
}
});
});
});
startServer();
client = vertx.createHttpClient(new HttpClientOptions().setProtocolVersion(HttpVersion.HTTP_2));
FakeHttpClientMetrics metrics = FakeMetricsBase.getMetrics(client);
HttpClientRequest req = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp -> {
});
req.pushHandler(pushedReq -> {
HttpClientMetric metric = metrics.getMetric(pushedReq);
assertNotNull(metric);
assertSame(pushedReq, metric.request);
pushedReq.handler(resp -> {
resp.endHandler(v -> {
assertNull(metrics.getMetric(pushedReq));
complete();
});
});
});
req.end();
await();
}
Aggregations