From c2160183fa02f4a6e0b29affa41c8c18a1db8ae3 Mon Sep 17 00:00:00 2001 From: Julien Viet Date: Mon, 20 Nov 2023 15:20:13 +0100 Subject: [PATCH] Update to vertx builder changes --- src/main/java/example/Examples.java | 13 +++---- .../ProgrammaticZKClusterManagerTest.java | 35 ++++++++----------- .../core/eventbus/ZKFaultToleranceTest.java | 2 +- .../impl/ZKDiscoveryImplClusteredTest.java | 4 +-- 4 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/main/java/example/Examples.java b/src/main/java/example/Examples.java index 32c07af..08389dd 100644 --- a/src/main/java/example/Examples.java +++ b/src/main/java/example/Examples.java @@ -14,8 +14,9 @@ public class Examples { public void example1() { ClusterManager mgr = new ZookeeperClusterManager(); - VertxOptions options = new VertxOptions().setClusterManager(mgr); - Vertx.clusteredVertx(options).onComplete(res -> { + Vertx.builder() + .withClusterManager(mgr) + .buildClustered().onComplete(res -> { if (res.succeeded()) { Vertx vertx = res.result(); } else { @@ -34,9 +35,10 @@ public void example2() { ClusterManager mgr = new ZookeeperClusterManager(zkConfig); - VertxOptions options = new VertxOptions().setClusterManager(mgr); - Vertx.clusteredVertx(options).onComplete(res -> { + Vertx.builder() + .withClusterManager(mgr) + .buildClustered().onComplete(res -> { if (res.succeeded()) { Vertx vertx = res.result(); } else { @@ -47,8 +49,7 @@ public void example2() { public void example3(CuratorFramework curator) { ClusterManager mgr = new ZookeeperClusterManager(curator); - VertxOptions options = new VertxOptions().setClusterManager(mgr); - Vertx.clusteredVertx(options).onComplete(res -> { + Vertx.builder().withClusterManager(mgr).buildClustered().onComplete(res -> { if (res.succeeded()) { Vertx vertx = res.result(); } else { diff --git a/src/test/java/io/vertx/core/ProgrammaticZKClusterManagerTest.java b/src/test/java/io/vertx/core/ProgrammaticZKClusterManagerTest.java index b9d3c57..29f0907 100644 --- a/src/test/java/io/vertx/core/ProgrammaticZKClusterManagerTest.java +++ b/src/test/java/io/vertx/core/ProgrammaticZKClusterManagerTest.java @@ -44,8 +44,7 @@ public class ProgrammaticZKClusterManagerTest extends AsyncTestBase { private void testProgrammatic(ZookeeperClusterManager mgr, JsonObject config) throws Exception { mgr.setConfig(config); assertEquals(config, mgr.getConfig()); - VertxOptions options = new VertxOptions().setClusterManager(mgr); - Vertx.clusteredVertx(options).onComplete(res -> { + Vertx.builder().withClusterManager(mgr).buildClustered().onComplete(res -> { assertTrue(res.succeeded()); assertNotNull(mgr.getCuratorFramework()); res.result().close().onComplete(res2 -> { @@ -75,8 +74,7 @@ public void testProgrammaticSetWithConstructor() throws Exception { public void testProgrammaticSetRetryPolicyDefault() throws Exception { JsonObject config = zkCluster.getDefaultConfig(); ZookeeperClusterManager mgr = new ZookeeperClusterManager(config); - VertxOptions options = new VertxOptions().setClusterManager(mgr); - Vertx.clusteredVertx(options).onComplete(res -> { + Vertx.builder().withClusterManager(mgr).buildClustered().onComplete(res -> { assertTrue(res.succeeded()); assertNotNull(mgr.getCuratorFramework()); assertTrue(mgr.getCuratorFramework().getZookeeperClient().getRetryPolicy() instanceof ExponentialBackoffRetry); @@ -90,8 +88,7 @@ public void testProgrammaticSetRetryPolicy() throws Exception { config.put("retry", new JsonObject().put("policy","one_time")); ZookeeperClusterManager mgr = new ZookeeperClusterManager(config); - VertxOptions options = new VertxOptions().setClusterManager(mgr); - Vertx.clusteredVertx(options).onComplete(res -> { + Vertx.builder().withClusterManager(mgr).buildClustered().onComplete(res -> { assertTrue(res.succeeded()); assertNotNull(mgr.getCuratorFramework()); assertTrue(mgr.getCuratorFramework().getZookeeperClient().getRetryPolicy() instanceof RetryOneTime); @@ -129,13 +126,11 @@ public void testEventBusWhenUsingACustomCurator() throws Exception { ZookeeperClusterManager mgr1 = new ZookeeperClusterManager(curator1); ZookeeperClusterManager mgr2 = new ZookeeperClusterManager(curator2); - VertxOptions options1 = new VertxOptions().setClusterManager(mgr1); - VertxOptions options2 = new VertxOptions().setClusterManager(mgr2); AtomicReference vertx1 = new AtomicReference<>(); AtomicReference vertx2 = new AtomicReference<>(); - Vertx.clusteredVertx(options1).onComplete(res -> { + Vertx.builder().withClusterManager(mgr1).buildClustered().onComplete(res -> { assertTrue(res.succeeded()); assertNotNull(mgr1.getCuratorFramework()); res.result().eventBus().consumer("news", message -> { @@ -148,7 +143,7 @@ public void testEventBusWhenUsingACustomCurator() throws Exception { assertWaitUntil(() -> vertx1.get() != null); - Vertx.clusteredVertx(options2).onComplete(res -> { + Vertx.builder().withClusterManager(mgr2).buildClustered().onComplete(res -> { assertTrue(res.succeeded()); assertNotNull(mgr2.getCuratorFramework()); vertx2.set(res.result()); @@ -190,15 +185,15 @@ public void testSharedDataUsingCustomCurator() throws Exception { ZookeeperClusterManager mgr1 = new ZookeeperClusterManager(curator1); ZookeeperClusterManager mgr2 = new ZookeeperClusterManager(curator2); - VertxOptions options1 = new VertxOptions().setClusterManager(mgr1); + VertxOptions options1 = new VertxOptions(); options1.getEventBusOptions().setHost("127.0.0.1"); - VertxOptions options2 = new VertxOptions().setClusterManager(mgr2); + VertxOptions options2 = new VertxOptions(); options2.getEventBusOptions().setHost("127.0.0.1"); AtomicReference vertx1 = new AtomicReference<>(); AtomicReference vertx2 = new AtomicReference<>(); - Vertx.clusteredVertx(options1).onComplete(res -> { + Vertx.builder().with(options1).withClusterManager(mgr1).buildClustered().onComplete(res -> { assertTrue(res.succeeded()); assertNotNull(mgr1.getCuratorFramework()); res.result().sharedData().getClusterWideMap("mymap1").onComplete(ar -> { @@ -210,7 +205,7 @@ public void testSharedDataUsingCustomCurator() throws Exception { assertWaitUntil(() -> vertx1.get() != null); - Vertx.clusteredVertx(options2).onComplete(res -> { + Vertx.builder().with(options2).withClusterManager(mgr2).buildClustered().onComplete(res -> { assertTrue(res.succeeded()); assertNotNull(mgr2.getCuratorFramework()); vertx2.set(res.result()); @@ -248,12 +243,12 @@ public void testThatExternalCuratorCanBeShutdown() { String nodeID = UUID.randomUUID().toString(); ZookeeperClusterManager mgr = new ZookeeperClusterManager(curator, nodeID); - VertxOptions options = new VertxOptions().setClusterManager(mgr); + VertxOptions options = new VertxOptions(); options.getEventBusOptions().setHost("127.0.0.1"); AtomicReference vertx1 = new AtomicReference<>(); - Vertx.clusteredVertx(options).onComplete(res -> { + Vertx.builder().with(options).withClusterManager(mgr).buildClustered().onComplete(res -> { assertTrue(res.succeeded()); assertNotNull(mgr.getCuratorFramework()); res.result().sharedData().getClusterWideMap("mymap1").onComplete(ar -> { @@ -315,15 +310,15 @@ public void testSharedDataUsingCustomCuratorFrameworks() throws Exception { ZookeeperClusterManager mgr1 = new ZookeeperClusterManager(curator1); ZookeeperClusterManager mgr2 = new ZookeeperClusterManager(curator2); - VertxOptions options1 = new VertxOptions().setClusterManager(mgr1); + VertxOptions options1 = new VertxOptions(); options1.getEventBusOptions().setHost("127.0.0.1"); - VertxOptions options2 = new VertxOptions().setClusterManager(mgr2); + VertxOptions options2 = new VertxOptions(); options2.getEventBusOptions().setHost("127.0.0.1"); AtomicReference vertx1 = new AtomicReference<>(); AtomicReference vertx2 = new AtomicReference<>(); - Vertx.clusteredVertx(options1).onComplete(res -> { + Vertx.builder().with(options1).withClusterManager(mgr1).buildClustered().onComplete(res -> { assertTrue(res.succeeded()); assertNotNull(mgr1.getCuratorFramework()); res.result().sharedData().getClusterWideMap("mymap1").onComplete(ar -> { @@ -335,7 +330,7 @@ public void testSharedDataUsingCustomCuratorFrameworks() throws Exception { assertWaitUntil(() -> vertx1.get() != null); - Vertx.clusteredVertx(options2).onComplete(res -> { + Vertx.builder().with(options2).withClusterManager(mgr2).buildClustered().onComplete(res -> { assertTrue(res.succeeded()); assertNotNull(mgr2.getCuratorFramework()); vertx2.set(res.result()); diff --git a/src/test/java/io/vertx/core/eventbus/ZKFaultToleranceTest.java b/src/test/java/io/vertx/core/eventbus/ZKFaultToleranceTest.java index 194dcd1..8b63383 100644 --- a/src/test/java/io/vertx/core/eventbus/ZKFaultToleranceTest.java +++ b/src/test/java/io/vertx/core/eventbus/ZKFaultToleranceTest.java @@ -41,7 +41,7 @@ protected void startNodes(int numNodes, VertxOptions options) { for (int i = 0; i < numNodes; i++) { int index = i; options.getEventBusOptions().setHost("localhost").setPort(0); - clusteredVertx(options.setClusterManager(getClusterManager()), ar -> { + clusteredVertx(options, ar -> { try { if (ar.failed()) { ar.cause().printStackTrace(); diff --git a/src/test/java/io/vertx/servicediscovery/impl/ZKDiscoveryImplClusteredTest.java b/src/test/java/io/vertx/servicediscovery/impl/ZKDiscoveryImplClusteredTest.java index 5cca31f..1cb5fd1 100644 --- a/src/test/java/io/vertx/servicediscovery/impl/ZKDiscoveryImplClusteredTest.java +++ b/src/test/java/io/vertx/servicediscovery/impl/ZKDiscoveryImplClusteredTest.java @@ -31,9 +31,9 @@ public class ZKDiscoveryImplClusteredTest extends DiscoveryImplTestBase { @Before public void setUp() { - VertxOptions options = new VertxOptions().setClusterManager(zkClustered.getClusterManager()); + VertxOptions options = new VertxOptions(); options.getEventBusOptions().setHost("localhost").setPort(0); - Vertx.clusteredVertx(options).onComplete(ar -> { + Vertx.builder().with(options).withClusterManager(zkClustered.getClusterManager()).buildClustered().onComplete(ar -> { vertx = ar.result(); }); await().until(() -> vertx != null);