@Override public synchronized MessageConsumer<T> endHandler(Handler<Void> endHandler) { if (endHandler != null) { // We should use the HandlerHolder context to properly do this (needs small refactoring) Context endCtx = vertx.getOrCreateContext(); this.endHandler = v1 -> endCtx.runOnContext(v2 -> endHandler.handle(null)); } else { this.endHandler = null; } return this; }
private void callCompletionHandlerAsync(Handler<AsyncResult<Void>> completionHandler) { if (completionHandler != null) { vertx.runOnContext(v -> completionHandler.handle(Future.succeededFuture())); } }
private void checkDrained() { Handler<Void> handler = drainHandler; if (handler != null && credits >= maxSize / 2) { this.drainHandler = null; vertx.runOnContext(v -> handler.handle(null)); } }
private void testSucceededOtherwiseApplyFunction(AsyncResult<String> res, Future<String> f) { AsyncResult<String> ar = res.otherwise("whatever"); f.complete("foobar"); assertTrue(ar.succeeded()); assertFalse(ar.failed()); assertEquals("foobar", ar.result()); assertNull(ar.cause()); }
private void testUncompletedOtherwiseApplyFunction(AsyncResult<String> res) { AsyncResult<String> ar1 = res.otherwise(Throwable::getMessage); assertFalse(ar1.succeeded()); assertFalse(ar1.failed()); assertNull(ar1.result()); assertNull(ar1.cause()); }
private void testDeployClassNotFound(String className) throws Exception { vertx.deployVerticle(className, ar -> { assertTrue(ar.failed()); // No prefix or suffix so should be interpreted as a java class assertTrue(ar.cause() instanceof ClassNotFoundException); testComplete(); }); await(); }
@Test public void testAsyncDeployCalledSynchronously() throws Exception { MyAsyncVerticle verticle = new MyAsyncVerticle(f -> f.complete(null), f -> f.complete(null)); vertx.deployVerticle(verticle, ar -> { assertTrue(ar.succeeded()); testComplete(); }); await(); }
@Override public void start() throws Exception { vertx.deployVerticle(new AbstractVerticle() { }, id -> vertx.undeploy(id.result())); } };
protected <T> void addRegistration(boolean newAddress, String address, boolean replyHandler, boolean localOnly, Handler<AsyncResult<Void>> completionHandler) { completionHandler.handle(Future.succeededFuture()); }
@Override public HttpServerResponse push(HttpMethod method, String host, String path, MultiMap headers, Handler<AsyncResult<HttpServerResponse>> handler) { handler.handle(Future.failedFuture("Push promise is only supported with HTTP2")); return this; }
/** * Create a future that hasn't completed yet and that is passed to the {@code handler} before it is returned. * * @param handler the handler * @param <T> the result type * @return the future. */ static <T> Future<T> future(Handler<Future<T>> handler) { Future<T> fut = future(); handler.handle(fut); return fut; }
@Override public void start(Future<Void> startFuture) throws Exception { vertx.deployVerticle(verticleChild, onFailure(v -> { startFuture.complete(); })); } };
@Test public void testDeployWithConfig() throws Exception { MyVerticle verticle = new MyVerticle(); JsonObject config = generateJSONObject(); vertx.deployVerticle(verticle, new DeploymentOptions().setConfig(config), ar -> { assertDeployment(1, verticle, config, ar); testComplete(); }); await(); }
@Override public void resolve(String identifier, DeploymentOptions deploymentOptions, ClassLoader classLoader, Future<String> resolution) { vertx.runOnContext(v -> { // Async resolution resolution.complete("whatever"); }); } @Override
@Override public void start(Future<Void> startFuture) throws Exception { this.context.addCloseHook(closeable); startFuture.fail("Fail to deploy."); } };
@Test public void testDeployFromTestThread() throws Exception { MyVerticle verticle = new MyVerticle(); vertx.deployVerticle(verticle, ar -> { assertDeployment(1, verticle, null, ar); assertFalse(verticle.startContext.isWorkerContext()); assertTrue(verticle.startContext.isEventLoopContext()); testComplete(); }); await(); }
private void setEndTimer() { // Set another timer to trigger test complete - this is so if the first timer is called more than once we will // catch it vertx.setTimer(10, id -> testComplete()); }
@Override public void beforeStartingVertx(VertxOptions options) { beforeStartingVertxInvoked = true; this.options = options; if (clusterHost != null) { options.setClusterHost(clusterHost); options.setClusterPort(clusterPort); options.setClusterPublicHost(clusterPublicHost); options.setClusterPublicPort(clusterPublicPort); super.beforeStartingVertx(options); } }
private void testSucceededOtherwise(AsyncResult<String> res, Future<String> f) { AsyncResult<String> ar = res.otherwise(Throwable::getMessage); f.complete("foobar"); assertTrue(ar.succeeded()); assertFalse(ar.failed()); assertEquals("foobar", ar.result()); assertNull(ar.cause()); }
@Override public void connect(ConnectionListener<FakeConnection> listener, ContextInternal context, Handler<AsyncResult<ConnectResult<FakeConnection>>> handler) { handler.handle(Future.failedFuture(cause)); } };