use of java.util.concurrent.atomic.AtomicInteger in project vert.x by eclipse.
the class Http1xTest method testConnectionClose.
private void testConnectionClose(Handler<HttpClientRequest> clientRequest, Handler<NetSocket> connectHandler) throws Exception {
client.close();
server.close();
NetServerOptions serverOptions = new NetServerOptions();
CountDownLatch serverLatch = new CountDownLatch(1);
vertx.createNetServer(serverOptions).connectHandler(connectHandler).listen(8080, result -> {
if (result.succeeded()) {
serverLatch.countDown();
} else {
fail();
}
});
awaitLatch(serverLatch);
HttpClientOptions clientOptions = new HttpClientOptions().setDefaultHost("localhost").setDefaultPort(8080).setKeepAlive(true).setPipelining(false);
client = vertx.createHttpClient(clientOptions);
int requests = 11;
AtomicInteger count = new AtomicInteger(requests);
for (int i = 0; i < requests; i++) {
HttpClientRequest req = client.get("/", resp -> {
resp.bodyHandler(buffer -> {
});
resp.endHandler(v -> {
if (count.decrementAndGet() == 0) {
complete();
}
});
resp.exceptionHandler(th -> {
fail();
});
}).exceptionHandler(th -> {
fail();
});
clientRequest.handle(req);
}
await();
}
use of java.util.concurrent.atomic.AtomicInteger in project vert.x by eclipse.
the class Http2ClientTest method testUnknownFrame.
@Test
public void testUnknownFrame() throws Exception {
Buffer expectedSend = TestUtils.randomBuffer(500);
Buffer expectedRecv = TestUtils.randomBuffer(500);
server.requestHandler(req -> {
req.customFrameHandler(frame -> {
assertEquals(10, frame.type());
assertEquals(253, frame.flags());
assertEquals(expectedSend, frame.payload());
req.response().writeCustomFrame(12, 134, expectedRecv).end();
});
});
startServer();
AtomicInteger status = new AtomicInteger();
HttpClientRequest req = client.request(HttpMethod.GET, DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
Context ctx = Vertx.currentContext();
assertEquals(0, status.getAndIncrement());
resp.customFrameHandler(frame -> {
assertOnIOContext(ctx);
assertEquals(1, status.getAndIncrement());
assertEquals(12, frame.type());
assertEquals(134, frame.flags());
assertEquals(expectedRecv, frame.payload());
});
resp.endHandler(v -> {
assertEquals(2, status.getAndIncrement());
testComplete();
});
});
req.sendHead(version -> {
assertSame(HttpVersion.HTTP_2, version);
req.writeCustomFrame(10, 253, expectedSend);
req.end();
});
await();
}
use of java.util.concurrent.atomic.AtomicInteger in project vert.x by eclipse.
the class Http2ClientTest method testResponseBody.
private void testResponseBody(String expected) throws Exception {
server.requestHandler(req -> {
HttpServerResponse resp = req.response();
resp.end(expected);
});
startServer();
client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
AtomicInteger count = new AtomicInteger();
Buffer content = Buffer.buffer();
resp.handler(buff -> {
content.appendBuffer(buff);
count.incrementAndGet();
});
resp.endHandler(v -> {
assertTrue(count.get() > 0);
assertEquals(expected, content.toString());
testComplete();
});
}).exceptionHandler(err -> fail()).end();
await();
}
use of java.util.concurrent.atomic.AtomicInteger in project vert.x by eclipse.
the class Http2ClientTest method testPost.
private void testPost(String expected) throws Exception {
Buffer content = Buffer.buffer();
AtomicInteger count = new AtomicInteger();
server.requestHandler(req -> {
assertEquals(HttpMethod.POST, req.method());
req.handler(buff -> {
content.appendBuffer(buff);
count.getAndIncrement();
});
req.endHandler(v -> {
assertTrue(count.get() > 0);
req.response().end();
});
});
startServer();
client.post(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
resp.endHandler(v -> {
assertEquals(expected, content.toString());
testComplete();
});
}).exceptionHandler(err -> {
fail();
}).end(expected);
await();
}
use of java.util.concurrent.atomic.AtomicInteger in project vert.x by eclipse.
the class Http2ClientTest 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);
});
});
server.requestHandler(req -> {
req.response().end();
});
startServer();
AtomicInteger count = new AtomicInteger();
client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
complete();
}).connectionHandler(conn -> {
conn.remoteSettingsHandler(settings -> {
switch(count.getAndIncrement()) {
case 0:
break;
case 1:
assertEquals(expectedSettings.getMaxHeaderListSize(), settings.getMaxHeaderListSize());
assertEquals(expectedSettings.getMaxFrameSize(), settings.getMaxFrameSize());
assertEquals(expectedSettings.getInitialWindowSize(), settings.getInitialWindowSize());
assertEquals(expectedSettings.getMaxConcurrentStreams(), settings.getMaxConcurrentStreams());
assertEquals(expectedSettings.getHeaderTableSize(), settings.getHeaderTableSize());
assertEquals(expectedSettings.get(''), settings.get(7));
complete();
break;
}
});
}).end();
await();
}
Aggregations