protected Set<Deployment> takeDeploymentSnapshot(int pos) { Set<Deployment> snapshot = new ConcurrentHashSet<>(); VertxInternal v = (VertxInternal) vertices[pos]; for (String depID : v.deploymentIDs()) { snapshot.add(v.getDeployment(depID)); } return snapshot; }
protected void takeDeploymentSnapshots() { for (int i = 0; i < vertices.length; i++) { VertxInternal v = (VertxInternal) vertices[i]; if (!v.isKilled()) { deploymentSnapshots[i] = takeDeploymentSnapshot(i); } } }
protected void checkDeployments() { int totalDeployed = 0; for (int i = 0; i < vertices.length; i++) { VertxInternal v = (VertxInternal) vertices[i]; if (!v.isKilled()) { totalDeployed += checkHasDeployments(i, i); } } assertEquals(totDeployed, totalDeployed); }
protected void kill(int pos) { // Save the deploymentIDs first takeDeploymentSnapshots(); VertxInternal v = (VertxInternal) vertices[pos]; killedNode = pos; v.executeBlocking( fut -> { v.simulateKill(); fut.complete(); }, ar -> { assertTrue(ar.succeeded()); }); }
@Test public void testCacheDirDeletedOnVertxClose() { VertxInternal vertx2 = (VertxInternal) vertx(); File file = vertx2.resolveFile(webRoot + "/somefile.html"); assertTrue(file.exists()); File cacheDir = file.getParentFile().getParentFile(); assertTrue(cacheDir.exists()); vertx2.close( onSuccess( v -> { assertFalse(cacheDir.exists()); testComplete(); })); await(); }
private synchronized void connect() { if (!connecting) { // We defer actual connection until the first part of body is written or end is called // This gives the user an opportunity to set an exception handler before connecting so // they can capture any exceptions on connection client.getConnection( port, host, conn -> { synchronized (this) { if (exceptionOccurred) { // The request already timed out before it has left the pool waiter queue // So return it conn.close(); } else if (!conn.isClosed()) { connected(conn); } else { // The connection has been closed - closed connections can be in the pool // Get another connection - Note that we DO NOT call connectionClosed() on the pool // at this point // that is done asynchronously in the connection closeHandler() connect(); } } }, exceptionHandler, vertx.getOrCreateContext()); connecting = true; } }
public NetSocketImpl( VertxInternal vertx, Channel channel, ContextImpl context, SSLHelper helper, boolean client, TCPMetrics metrics, Object metric) { super(vertx, channel, context, metrics); this.helper = helper; this.client = client; this.writeHandlerID = UUID.randomUUID().toString(); this.metric = metric; Handler<Message<Buffer>> writeHandler = msg -> write(msg.body()); registration = vertx.eventBus().<Buffer>localConsumer(writeHandlerID).handler(writeHandler); }