protected void startServer(Context context) throws Exception { startServer(testAddress, context, server); }
protected void startServer(Context context, NetServer server) throws Exception { startServer(testAddress, context, server); } }
protected void startServer(SocketAddress remoteAddress, Context context) throws Exception { startServer(remoteAddress, context, server); }
protected void startServer() throws Exception { startServer(testAddress, vertx.getOrCreateContext()); }
protected void startServer(SocketAddress remoteAddress) throws Exception { startServer(remoteAddress, vertx.getOrCreateContext()); }
protected void startServer(SocketAddress remoteAddress, NetServer server) throws Exception { startServer(remoteAddress, vertx.getOrCreateContext(), server); }
protected void startServer(NetServer server) throws Exception { startServer(testAddress, vertx.getOrCreateContext(), server); }
@Test public void testClosingVertxCloseSharedServers() throws Exception { int numServers = 2; Vertx vertx = Vertx.vertx(getOptions()); List<NetServerImpl> servers = new ArrayList<>(); for (int i = 0;i < numServers;i++) { NetServer server = vertx.createNetServer().connectHandler(so -> { fail(); }); startServer(server); servers.add((NetServerImpl) server); } CountDownLatch latch = new CountDownLatch(1); vertx.close(onSuccess(v -> { latch.countDown(); })); awaitLatch(latch); servers.forEach(server -> { assertTrue(server.isClosed()); }); }
@Test public void testWriteHandlerSuccess() throws Exception { CompletableFuture<Void> close = new CompletableFuture<>(); server.connectHandler(socket -> { socket.pause(); close.thenAccept(v -> { socket.resume(); }); }); startServer(); client.connect(testAddress, onSuccess(so -> { writeUntilFull(so, v -> { so.write(Buffer.buffer("lost buffer"), onSuccess(ack -> testComplete())); close.complete(null); }); })); await(); }
@Test // This tests using NetSocket.writeHandlerID (on the server side) // Send some data and make sure it is fanned out to all connections public void testFanout() throws Exception { int numConnections = 10; Set<String> connections = new ConcurrentHashSet<>(); server.connectHandler(socket -> { connections.add(socket.writeHandlerID()); if (connections.size() == numConnections) { for (String actorID : connections) { vertx.eventBus().publish(actorID, Buffer.buffer("some data")); } } socket.closeHandler(v -> { connections.remove(socket.writeHandlerID()); }); }); startServer(); CountDownLatch receivedLatch = new CountDownLatch(numConnections); for (int i = 0; i < numConnections; i++) { client.connect(testAddress, onSuccess(socket -> { socket.handler(data -> { receivedLatch.countDown(); }); })); } assertTrue(receivedLatch.await(10, TimeUnit.SECONDS)); testComplete(); }
@Test public void testWriteHandlerFailure() throws Exception { CompletableFuture<Void> close = new CompletableFuture<>(); server.connectHandler(socket -> { socket.pause(); close.thenAccept(v -> { socket.close(); }); }); startServer(); client.connect(testAddress, onSuccess(so -> { writeUntilFull(so, v -> { so.write(Buffer.buffer("lost buffer"), onFailure(err -> { testComplete(); })); close.complete(null); }); })); await(); }
startServer(); AtomicInteger done = new AtomicInteger(); for (int i = 0;i < num;i++) {
}); }); startServer(); client.connect(testAddress, "localhost", onSuccess(so -> { so.pause();
@Test public void testWorkerClient() throws Exception { String expected = TestUtils.randomAlphaString(2000); server.connectHandler(so -> { so.write(expected).close(); }); startServer(); vertx.deployVerticle(new AbstractVerticle() { @Override public void start() throws Exception { NetClient client = vertx.createNetClient(); client.connect(testAddress, onSuccess(so ->{ Buffer received = Buffer.buffer(); so.handler(received::appendBuffer); so.closeHandler(v -> { assertEquals(expected, received.toString()); testComplete(); }); try { Thread.sleep(500); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } })); } }, new DeploymentOptions().setWorker(true)); await(); }
startServer(SocketAddress.inetSocketAddress(1234, "localhost")); HttpClient client = vertx.createHttpClient(clientOptions); client.getNow(1234, "localhost", "/somepath", onSuccess(resp -> {
protected void startServer(Context context) throws Exception { startServer(testAddress, context, server); }
.createNetServer(new NetServerOptions().setIdleTimeout(200).setIdleTimeoutUnit(TimeUnit.MILLISECONDS)) .connectHandler((idleOnServer ? sender : receiver)::accept); startServer(); client.close(); client = vertx.createNetClient(new NetClientOptions().setIdleTimeout(200).setIdleTimeoutUnit(TimeUnit.MILLISECONDS));
}); }); startServer(); client.connect(testAddress, onSuccess(so -> { NetSocketInternal soi = (NetSocketInternal) so;
startServer(); client.connect(testAddress, onSuccess(so -> { vertx.setTimer(1000, id -> {
protected void startServer(NetServer server) throws Exception { startServer(testAddress, vertx.getOrCreateContext(), server); }