use of io.vertx.core.net.NetClient in project vert.x by eclipse.
the class MetricsTest method testHTTP2ConnectionCloseBeforePrefaceIsReceived.
@Test
public void testHTTP2ConnectionCloseBeforePrefaceIsReceived() throws Exception {
// Let the server close the connection with an idle timeout
HttpServerOptions options = Http2TestBase.createHttp2ServerOptions(HttpTestBase.DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST).setIdleTimeout(1);
HttpServer server = vertx.createHttpServer(options);
server.requestHandler(req -> {
}).listen().toCompletionStage().toCompletableFuture().get(20, TimeUnit.SECONDS);
FakeHttpServerMetrics metrics = FakeVertxMetrics.getMetrics(server);
NetClient client = vertx.createNetClient(new NetClientOptions().setSslEngineOptions(new JdkSSLEngineOptions()).setUseAlpn(true).setSsl(true).setTrustStoreOptions(Trust.SERVER_JKS.get()).setApplicationLayerProtocols(Collections.singletonList("h2")));
CountDownLatch latch = new CountDownLatch(1);
client.connect(HttpTestBase.DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, onSuccess(so -> {
assertEquals("h2", so.applicationLayerProtocol());
so.closeHandler(v -> latch.countDown());
}));
awaitLatch(latch);
assertEquals(0, metrics.connectionCount());
}
use of io.vertx.core.net.NetClient in project vert.x by eclipse.
the class TransportTest method testNetServer.
private void testNetServer(VertxOptions options) {
vertx = Vertx.vertx(options);
NetServer server = vertx.createNetServer();
server.connectHandler(so -> {
so.handler(buff -> {
assertEquals("ping", buff.toString());
so.write("pong");
});
so.closeHandler(v -> {
testComplete();
});
});
server.listen(1234, onSuccess(v -> {
NetClient client = vertx.createNetClient();
client.connect(1234, "localhost", onSuccess(so -> {
so.write("ping");
so.handler(buff -> {
assertEquals("pong", buff.toString());
so.close();
});
}));
}));
await();
}
use of io.vertx.core.net.NetClient in project vert.x by eclipse.
the class TransportTest method testDomainSocketClient.
@Test
public void testDomainSocketClient() throws Exception {
File sock = TestUtils.tmpFile(".sock");
vertx = Vertx.vertx();
NetClient client = vertx.createNetClient();
client.connect(SocketAddress.domainSocketAddress(sock.getAbsolutePath()), onFailure(err -> {
assertEquals(err.getClass(), IllegalArgumentException.class);
testComplete();
}));
await();
}
use of io.vertx.core.net.NetClient in project vertx-tcp-eventbus-bridge by vert-x3.
the class TcpEventBusBridgeInteropTest method testSendMessageWithDuplicateReplyID.
@Test
public void testSendMessageWithDuplicateReplyID(TestContext context) {
// replies must always return to the same origin
NetClient client = vertx.createNetClient();
final Async async = context.async();
client.connect(7000, "localhost", conn -> {
context.assertFalse(conn.failed());
NetSocket socket = conn.result();
vertx.eventBus().consumer("third-party-receiver", msg -> context.fail());
final FrameParser parser = new FrameParser(parse -> {
context.assertTrue(parse.succeeded());
client.close();
async.complete();
});
socket.handler(parser);
FrameHelper.sendFrame("send", "hello", "third-party-receiver", new JsonObject().put("value", "vert.x"), socket);
});
}
use of io.vertx.core.net.NetClient in project vertx-tcp-eventbus-bridge by vert-x3.
the class TcpEventBusBridgeHookTest method testRegister.
@Test
public void testRegister(TestContext context) {
final JsonObject payload = new JsonObject().put("value", "Francesco");
// 0. Start the bridge
// 1. Check if REGISTER hook is called
// 2. Check if REGISTERED hook is called
// 3. Try to send a message while managing REGISTERED event
// 4. Check if client receives the message
Async bridgeStart = context.async();
Async register = context.async();
Async registered = context.async();
Async request = context.async();
TcpEventBusBridge bridge = TcpEventBusBridge.create(vertx, new BridgeOptions().addInboundPermitted(new PermittedOptions()).addOutboundPermitted(new PermittedOptions()), new NetServerOptions(), be -> {
if (be.type() == BridgeEventType.REGISTER) {
context.assertNotNull(be.socket());
context.assertEquals(address, be.getRawMessage().getString("address"));
register.complete();
} else if (be.type() == BridgeEventType.REGISTERED) {
context.assertNotNull(be.socket());
context.assertEquals(address, be.getRawMessage().getString("address"));
// The client should be able to receive this message
vertx.eventBus().send(address, payload);
registered.complete();
}
be.complete(true);
});
bridge.listen(7000, res -> {
context.assertTrue(res.succeeded());
bridgeStart.complete();
});
bridgeStart.await();
NetClient client = vertx.createNetClient();
client.connect(7000, "localhost", conn -> {
context.assertFalse(conn.failed());
NetSocket socket = conn.result();
// 1 reply will arrive
// MESSAGE for address
final FrameParser parser = new FrameParser(parse -> {
context.assertTrue(parse.succeeded());
JsonObject frame = parse.result();
context.assertNotEquals("err", frame.getString("type"));
context.assertEquals("Francesco", frame.getJsonObject("body").getString("value"));
client.close();
request.complete();
});
socket.handler(parser);
FrameHelper.sendFrame("register", address, null, socket);
});
register.await();
registered.await();
request.await();
}
Aggregations