Refine search
@Override public void start() throws Exception { vertx.deployVerticle( "io.vertx.example.core.http.sharing.HttpServerVerticle", new DeploymentOptions().setInstances(2)); } }
@Test public void testRaceConditionWithWebsocketClientWorker() throws Exception { CompletableFuture<Context> fut = new CompletableFuture<>(); vertx.deployVerticle(new AbstractVerticle() { @Override public void start() throws Exception { fut.complete(context); } }, new DeploymentOptions().setWorker(true), ar -> { if (ar.failed()) { fut.completeExceptionally(ar.cause()); } }); testRaceConditionWithWebsocketClient(fut.get()); }
@Test public void testJsonOptions() { JsonObject config = new JsonObject().put("foo", "bar"); json.put("maxWorkerExecuteTime", maxWorkerExecuteTime); json.put("maxWorkerExecuteTimeUnit", maxWorkerExecuteTimeUnit); DeploymentOptions options = new DeploymentOptions(json); assertEquals(worker, options.isWorker()); assertEquals(isolationGroup, options.getIsolationGroup());
@Test(expected = IllegalArgumentException.class) public void testDeployInstanceSetExtraClasspath() throws Exception { vertx.deployVerticle(new MyVerticle(), new DeploymentOptions().setExtraClasspath(Arrays.asList("foo"))); }
@Test public void testToJson() { DeploymentOptions options = new DeploymentOptions(); JsonObject config = new JsonObject().put("foo", "bar"); Random rand = new Random(); options.setMaxWorkerExecuteTimeUnit(maxWorkerExecuteTimeUnit); JsonObject json = options.toJson(); DeploymentOptions copy = new DeploymentOptions(json); assertEquals(worker, copy.isWorker()); assertEquals(isolationGroup, copy.getIsolationGroup());
@Override public void start(Future<Void> startFuture) throws Exception { JsonObject options = new JsonObject().put("telnetOptions", new JsonObject(). put("host", "localhost"). put("port", 3000) ); vertx.deployVerticle("service:io.vertx.ext.shell", new DeploymentOptions().setConfig(options), ar -> { if (ar.succeeded()) { startFuture.succeeded(); } else { startFuture.fail(ar.cause()); } }); } }
@Test(expected = IllegalArgumentException.class) public void testDeployInstanceSetIsolatedClasses() throws Exception { vertx.deployVerticle(new MyVerticle(), new DeploymentOptions().setIsolatedClasses(Arrays.asList("foo"))); }
@Test public void testDefaultJsonOptions() { DeploymentOptions def = new DeploymentOptions(); DeploymentOptions json = new DeploymentOptions(new JsonObject()); assertEquals(def.getConfig(), json.getConfig()); assertEquals(def.isWorker(), json.isWorker()); assertEquals(def.getIsolationGroup(), json.getIsolationGroup()); assertEquals(def.isHa(), json.isHa()); assertEquals(def.getExtraClasspath(), json.getExtraClasspath()); assertEquals(def.getIsolatedClasses(), json.getIsolatedClasses()); assertEquals(def.getWorkerPoolName(), json.getWorkerPoolName()); assertEquals(def.getWorkerPoolSize(), json.getWorkerPoolSize()); assertEquals(def.getMaxWorkerExecuteTime(), json.getMaxWorkerExecuteTime()); assertEquals(def.getMaxWorkerExecuteTimeUnit(), json.getMaxWorkerExecuteTimeUnit()); }
@Override public void start(Future<Void> startFuture) throws Exception { JsonObject options = new JsonObject().put("httpOptions", new JsonObject(). put("host", "localhost"). put("port", 8080). put("authOptions", new JsonObject().put("provider", "shiro").put("config", new JsonObject().put("properties_path", "auth.properties"))) ); vertx.deployVerticle("service:io.vertx.ext.shell", new DeploymentOptions().setConfig(options), ar -> { if (ar.succeeded()) { startFuture.succeeded(); } else { startFuture.fail(ar.cause()); } }); } }
@Test(expected = IllegalArgumentException.class) public void testDeployInstanceSetIsolationGroup() throws Exception { vertx.deployVerticle(new MyVerticle(), new DeploymentOptions().setIsolationGroup("foo")); }
@Test public void testCopyOptions() { DeploymentOptions options = new DeploymentOptions(); JsonObject config = new JsonObject().put("foo", "bar"); Random rand = new Random(); options.setMaxWorkerExecuteTime(maxWorkerExecuteTime); options.setMaxWorkerExecuteTimeUnit(maxWorkerExecuteTimeUnit); DeploymentOptions copy = new DeploymentOptions(options); assertEquals(worker, copy.isWorker()); assertEquals(isolationGroup, copy.getIsolationGroup());
/** * Deploy verticles when the Spring application is ready. */ @EventListener void deployVerticles(ApplicationReadyEvent event) { vertx.deployVerticle(new HelloVerticle()); if (port != null) { JsonObject config = new JsonObject().put("port", port); vertx.deployVerticle(new HttpVerticle(), new DeploymentOptions().setConfig(config)); } } }
@Test(expected = IllegalArgumentException.class) public void testDeployInstanceSetInstances() throws Exception { vertx.deployVerticle(new MyVerticle(), new DeploymentOptions().setInstances(2)); }
@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));
public static void main(String[] args) { Vertx vertx = Vertx.vertx(); ApplicationContext context = new AnnotationConfigApplicationContext(ExampleApplication.class); VerticleFactory verticleFactory = context.getBean(SpringVerticleFactory.class); // The verticle factory is registered manually because it is created by the Spring container vertx.registerVerticleFactory(verticleFactory); // Scale the verticles on cores: create 4 instances during the deployment DeploymentOptions options = new DeploymentOptions().setInstances(4); vertx.deployVerticle(verticleFactory.prefix() + ":" + GreetingVerticle.class.getName(), options); }
@Test public void testCancelTimerWhenScheduledOnWorker() throws Exception { vertx.deployVerticle(new AbstractVerticle() { @Override public void start() throws Exception { long id = vertx.setTimer(100, id_ -> { fail(); }); Thread.sleep(200); assertTrue(vertx.cancelTimer(id)); testComplete(); } }, new DeploymentOptions().setWorker(true)); await(); } }
@Test public void testThreadPoolMetricsWithWorkerVerticleAndMultiThread() { testWithWorkerVerticle(new DeploymentOptions().setWorker(true).setMultiThreaded(true)); }
@Override public void start(Future<Void> startFuture) throws Exception { vertx.deployVerticle("java:" + OtherSourceVerticle.class.getName().replace('.', '/') + ".java", new DeploymentOptions(), ar -> { if (ar.succeeded()) { startFuture.complete((Void) null); } else { ar.cause().printStackTrace(); } }); } }
@Test public void testDeployClassNoDefaultPublicConstructor() throws Exception { class NoDefaultPublicConstructorVerticle extends AbstractVerticle { } vertx.deployVerticle(NoDefaultPublicConstructorVerticle.class, new DeploymentOptions(), onFailure(t -> { testComplete(); })); await(); }
@Override public void start(Future<Void> startFuture) throws Exception { JsonObject options = new JsonObject().put("sshOptions", new JsonObject(). put("host", "localhost"). put("port", 3000). put("keyPairOptions", new JsonObject(). put("path", "keystore.jks"). put("password", "wibble")). put("authOptions", new JsonObject().put("provider", "shiro").put("config", new JsonObject().put("properties_path", "auth.properties")) ) ); vertx.deployVerticle("service:io.vertx.ext.shell", new DeploymentOptions().setConfig(options), ar -> { if (ar.succeeded()) { startFuture.succeeded(); } else { startFuture.fail(ar.cause()); } }); } }