From 312e45e2acdca0206a801280c06f2b00dc103f33 Mon Sep 17 00:00:00 2001 From: Julien Viet Date: Mon, 20 Nov 2023 15:06:18 +0100 Subject: [PATCH] Update to vertx builder changes --- src/main/java/examples/Examples.java | 29 ++--- ...ogrammaticHazelcastClusterManagerTest.java | 119 ++++++++++-------- .../HazelcastDiscoveryImplClusteredTest.java | 6 +- 3 files changed, 86 insertions(+), 68 deletions(-) diff --git a/src/main/java/examples/Examples.java b/src/main/java/examples/Examples.java index 92bade31..202c242f 100644 --- a/src/main/java/examples/Examples.java +++ b/src/main/java/examples/Examples.java @@ -40,10 +40,10 @@ public void example1() { ClusterManager mgr = new HazelcastClusterManager(); - VertxOptions options = new VertxOptions().setClusterManager(mgr); - Vertx - .clusteredVertx(options) + .builder() + .withClusterManager(mgr) + .buildClustered() .onComplete(res -> { if (res.succeeded()) { Vertx vertx = res.result(); @@ -61,10 +61,10 @@ public void example2() { ClusterManager mgr = new HazelcastClusterManager(hazelcastConfig); - VertxOptions options = new VertxOptions().setClusterManager(mgr); - Vertx - .clusteredVertx(options) + .builder() + .withClusterManager(mgr) + .buildClustered() .onComplete(res -> { if (res.succeeded()) { Vertx vertx = res.result(); @@ -81,10 +81,10 @@ public void customizeDefaultConfig() { ClusterManager mgr = new HazelcastClusterManager(hazelcastConfig); - VertxOptions options = new VertxOptions().setClusterManager(mgr); - Vertx - .clusteredVertx(options) + .builder() + .withClusterManager(mgr) + .buildClustered() .onComplete(res -> { if (res.succeeded()) { Vertx vertx = res.result(); @@ -96,9 +96,10 @@ public void customizeDefaultConfig() { public void example3(HazelcastInstance hazelcastInstance) { ClusterManager mgr = new HazelcastClusterManager(hazelcastInstance); - VertxOptions options = new VertxOptions().setClusterManager(mgr); Vertx - .clusteredVertx(options) + .builder() + .withClusterManager(mgr) + .buildClustered() .onComplete(res -> { if (res.succeeded()) { Vertx vertx = res.result(); @@ -124,10 +125,10 @@ public void liteMemberConfig() { ClusterManager mgr = new HazelcastClusterManager(hazelcastConfig); - VertxOptions options = new VertxOptions().setClusterManager(mgr); - Vertx - .clusteredVertx(options) + .builder() + .withClusterManager(mgr) + .buildClustered() .onComplete(res -> { if (res.succeeded()) { Vertx vertx = res.result(); diff --git a/src/test/java/io/vertx/core/ProgrammaticHazelcastClusterManagerTest.java b/src/test/java/io/vertx/core/ProgrammaticHazelcastClusterManagerTest.java index bf8d4cbb..c6682c1f 100644 --- a/src/test/java/io/vertx/core/ProgrammaticHazelcastClusterManagerTest.java +++ b/src/test/java/io/vertx/core/ProgrammaticHazelcastClusterManagerTest.java @@ -90,14 +90,16 @@ private Config createConfig() { private void testProgrammatic(HazelcastClusterManager mgr, Config config) throws Exception { mgr.setConfig(config); assertEquals(config, mgr.getConfig()); - VertxOptions options = new VertxOptions().setClusterManager(mgr); - Vertx.clusteredVertx(options).onComplete(res -> { - assertTrue(res.succeeded()); - assertNotNull(mgr.getHazelcastInstance()); - res.result().close().onComplete(res2 -> { - assertTrue(res2.succeeded()); - testComplete(); - }); + Vertx + .builder() + .withClusterManager(mgr) + .buildClustered().onComplete(res -> { + assertTrue(res.succeeded()); + assertNotNull(mgr.getHazelcastInstance()); + res.result().close().onComplete(res2 -> { + assertTrue(res2.succeeded()); + testComplete(); + }); }); await(); } @@ -109,33 +111,39 @@ public void testEventBusWhenUsingACustomHazelcastInstance() throws Exception { HazelcastClusterManager mgr1 = new HazelcastClusterManager(instance1); HazelcastClusterManager mgr2 = new HazelcastClusterManager(instance2); - 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 -> { - assertTrue(res.succeeded()); - assertNotNull(mgr1.getHazelcastInstance()); - res.result().eventBus().consumer("news", message -> { - assertNotNull(message); - assertTrue(message.body().equals("hello")); - testComplete(); + Vertx.builder() + .with(options1) + .withClusterManager(mgr1) + .buildClustered().onComplete(res -> { + assertTrue(res.succeeded()); + assertNotNull(mgr1.getHazelcastInstance()); + res.result().eventBus().consumer("news", message -> { + assertNotNull(message); + assertTrue(message.body().equals("hello")); + testComplete(); + }); + vertx1.set(res.result()); }); - vertx1.set(res.result()); - }); assertWaitUntil(() -> vertx1.get() != null); - Vertx.clusteredVertx(options2).onComplete(res -> { - assertTrue(res.succeeded()); - assertNotNull(mgr2.getHazelcastInstance()); - vertx2.set(res.result()); - res.result().eventBus().send("news", "hello"); - }); + Vertx.builder() + .with(options2) + .withClusterManager(mgr2) + .buildClustered().onComplete(res -> { + assertTrue(res.succeeded()); + assertNotNull(mgr2.getHazelcastInstance()); + vertx2.set(res.result()); + res.result().eventBus().send("news", "hello"); + }); await(); @@ -159,37 +167,43 @@ public void testSharedDataUsingCustomHazelcast() throws Exception { HazelcastClusterManager mgr1 = new HazelcastClusterManager(instance1); HazelcastClusterManager mgr2 = new HazelcastClusterManager(instance2); - 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 -> { - assertTrue(res.succeeded()); - assertNotNull(mgr1.getHazelcastInstance()); - res.result().sharedData().getClusterWideMap("mymap1").onComplete(ar -> { - ar.result().put("news", "hello").onComplete(v -> { - vertx1.set(res.result()); + Vertx.builder() + .with(options1) + .withClusterManager(mgr1) + .buildClustered().onComplete(res -> { + assertTrue(res.succeeded()); + assertNotNull(mgr1.getHazelcastInstance()); + res.result().sharedData().getClusterWideMap("mymap1").onComplete(ar -> { + ar.result().put("news", "hello").onComplete(v -> { + vertx1.set(res.result()); + }); }); }); - }); assertWaitUntil(() -> vertx1.get() != null); - Vertx.clusteredVertx(options2).onComplete(res -> { - assertTrue(res.succeeded()); - assertNotNull(mgr2.getHazelcastInstance()); - vertx2.set(res.result()); - res.result().sharedData().getClusterWideMap("mymap1").onComplete(ar -> { - ar.result().get("news").onComplete(r -> { - assertEquals("hello", r.result()); - testComplete(); + Vertx.builder() + .with(options2) + .withClusterManager(mgr2) + .buildClustered().onComplete(res -> { + assertTrue(res.succeeded()); + assertNotNull(mgr2.getHazelcastInstance()); + vertx2.set(res.result()); + res.result().sharedData().getClusterWideMap("mymap1").onComplete(ar -> { + ar.result().get("news").onComplete(r -> { + assertEquals("hello", r.result()); + testComplete(); + }); }); }); - }); await(); @@ -215,20 +229,23 @@ public void testThatExternalHZInstanceCanBeShutdown() { String nodeID = instance.getCluster().getLocalMember().getAttribute("__vertx.nodeId"); HazelcastClusterManager mgr = new HazelcastClusterManager(createConfig()); - 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 -> { - assertTrue(res.succeeded()); - assertNotNull(mgr.getHazelcastInstance()); - res.result().sharedData().getClusterWideMap("mymap1").onComplete(ar -> { - ar.result().put("news", "hello").onComplete(v -> { - vertx1.set(res.result()); + Vertx.builder() + .with(options) + .withClusterManager(mgr) + .buildClustered().onComplete(res -> { + assertTrue(res.succeeded()); + assertNotNull(mgr.getHazelcastInstance()); + res.result().sharedData().getClusterWideMap("mymap1").onComplete(ar -> { + ar.result().put("news", "hello").onComplete(v -> { + vertx1.set(res.result()); + }); }); }); - }); assertWaitUntil(() -> vertx1.get() != null); int size = mgr.getNodes().size(); diff --git a/src/test/java/io/vertx/servicediscovery/impl/HazelcastDiscoveryImplClusteredTest.java b/src/test/java/io/vertx/servicediscovery/impl/HazelcastDiscoveryImplClusteredTest.java index 093c9fee..f566e9492 100644 --- a/src/test/java/io/vertx/servicediscovery/impl/HazelcastDiscoveryImplClusteredTest.java +++ b/src/test/java/io/vertx/servicediscovery/impl/HazelcastDiscoveryImplClusteredTest.java @@ -46,9 +46,9 @@ public class HazelcastDiscoveryImplClusteredTest extends DiscoveryImplTestBase { public void setUp() { Random random = new Random(); System.setProperty("vertx.hazelcast.test.group.name", new BigInteger(128, random).toString(32)); - VertxOptions options = new VertxOptions() - .setClusterManager(new HazelcastClusterManager()); - Vertx.clusteredVertx(options).onComplete(ar -> { + Vertx.builder() + .withClusterManager(new HazelcastClusterManager()) + .buildClustered().onComplete(ar -> { vertx = ar.result(); }); await().until(() -> vertx != null);