@Test public void testFailedDeployRunsContextShutdownHook() throws Exception { AtomicBoolean closeHookCalledBeforeDeployFailure = new AtomicBoolean(false); Closeable closeable = completionHandler -> { closeHookCalledBeforeDeployFailure.set(true); completionHandler.handle(Future.succeededFuture()); }; Verticle v = new AbstractVerticle() { @Override public void start(Future<Void> startFuture) throws Exception { this.context.addCloseHook(closeable); startFuture.fail("Fail to deploy."); } }; vertx.deployVerticle(v, asyncResult -> { assertTrue(closeHookCalledBeforeDeployFailure.get()); assertTrue(asyncResult.failed()); assertNull(asyncResult.result()); testComplete(); }); await(); }
@Test public void testUndeploy() throws Exception { MyVerticle verticle = new MyVerticle(); vertx.deployVerticle(verticle, ar -> { assertTrue(ar.succeeded()); vertx.undeploy(ar.result(), ar2 -> { assertTrue(ar2.succeeded()); assertNull(ar2.result()); assertFalse(vertx.deploymentIDs().contains(ar.result())); assertEquals(verticle.startContext, verticle.stopContext); Context currentContext = Vertx.currentContext(); assertNotSame(currentContext, verticle.startContext); testComplete(); }); }); await(); }
@Test public void testMultipleFailedDeploys() throws InterruptedException { int instances = 10; DeploymentOptions options = new DeploymentOptions(); options.setInstances(instances); AtomicBoolean called = new AtomicBoolean(false); vertx.deployVerticle(() -> { Verticle v = new AbstractVerticle() { @Override public void start(final Future<Void> startFuture) throws Exception { startFuture.fail("Fail to deploy."); } }; return v; }, options, asyncResult -> { assertTrue(asyncResult.failed()); assertNull(asyncResult.result()); if (!called.compareAndSet(false, true)) { fail("Completion handler called more than once"); } vertx.setTimer(30, id -> { testComplete(); }); }); await(); }
@Test public void testOptions() { DeploymentOptions options = new DeploymentOptions(); assertNull(options.getConfig()); JsonObject config = new JsonObject().put("foo", "bar").put("obj", new JsonObject().put("quux", 123)); assertEquals(options, options.setConfig(config)); assertEquals(options, options.setWorker(true)); assertTrue(options.isWorker()); assertNull(options.getIsolationGroup()); String rand = TestUtils.randomUnicodeString(1000); assertEquals(options, options.setIsolationGroup(rand)); assertEquals(options, options.setHa(true)); assertTrue(options.isHa()); assertNull(options.getExtraClasspath()); List<String> cp = Arrays.asList("foo", "bar"); assertEquals(options, options.setExtraClasspath(cp)); assertNull(options.getIsolatedClasses()); List<String> isol = Arrays.asList("com.foo.MyClass", "org.foo.*"); assertEquals(options, options.setIsolatedClasses(isol));
@Test public void testFailedDeployRunsContextShutdownHook() throws Exception { AtomicBoolean closeHookCalledBeforeDeployFailure = new AtomicBoolean(false); Closeable closeable = completionHandler -> { closeHookCalledBeforeDeployFailure.set(true); completionHandler.handle(Future.succeededFuture()); }; Verticle v = new AbstractVerticle() { @Override public void start(Future<Void> startFuture) throws Exception { this.context.addCloseHook(closeable); startFuture.fail("Fail to deploy."); } }; vertx.deployVerticle(v, asyncResult -> { assertTrue(closeHookCalledBeforeDeployFailure.get()); assertTrue(asyncResult.failed()); assertNull(asyncResult.result()); testComplete(); }); await(); }
@Test public void testUndeploy() throws Exception { MyVerticle verticle = new MyVerticle(); vertx.deployVerticle(verticle, ar -> { assertTrue(ar.succeeded()); vertx.undeploy(ar.result(), ar2 -> { assertTrue(ar2.succeeded()); assertNull(ar2.result()); assertFalse(vertx.deploymentIDs().contains(ar.result())); assertEquals(verticle.startContext, verticle.stopContext); Context currentContext = Vertx.currentContext(); assertNotSame(currentContext, verticle.startContext); testComplete(); }); }); await(); }
@Test public void testMultipleFailedDeploys() throws InterruptedException { int instances = 10; DeploymentOptions options = new DeploymentOptions(); options.setInstances(instances); AtomicBoolean called = new AtomicBoolean(false); vertx.deployVerticle(() -> { Verticle v = new AbstractVerticle() { @Override public void start(final Future<Void> startFuture) throws Exception { startFuture.fail("Fail to deploy."); } }; return v; }, options, asyncResult -> { assertTrue(asyncResult.failed()); assertNull(asyncResult.result()); if (!called.compareAndSet(false, true)) { fail("Completion handler called more than once"); } vertx.setTimer(30, id -> { testComplete(); }); }); await(); }
@Test public void testOptions() { DeploymentOptions options = new DeploymentOptions(); assertNull(options.getConfig()); JsonObject config = new JsonObject().put("foo", "bar").put("obj", new JsonObject().put("quux", 123)); assertEquals(options, options.setConfig(config)); assertEquals(options, options.setMultiThreaded(true)); assertTrue(options.isMultiThreaded()); assertNull(options.getIsolationGroup()); String rand = TestUtils.randomUnicodeString(1000); assertEquals(options, options.setIsolationGroup(rand)); assertEquals(options, options.setHa(true)); assertTrue(options.isHa()); assertNull(options.getExtraClasspath()); List<String> cp = Arrays.asList("foo", "bar"); assertEquals(options, options.setExtraClasspath(cp)); assertNull(options.getIsolatedClasses()); List<String> isol = Arrays.asList("com.foo.MyClass", "org.foo.*"); assertEquals(options, options.setIsolatedClasses(isol));