Skip to content

Commit

Permalink
Update to vertx builder changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Nov 20, 2023
1 parent 5323a6e commit 312e45e
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 68 deletions.
29 changes: 15 additions & 14 deletions src/main/java/examples/Examples.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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<Vertx> vertx1 = new AtomicReference<>();
AtomicReference<Vertx> 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();

Expand All @@ -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<Vertx> vertx1 = new AtomicReference<>();
AtomicReference<Vertx> 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();

Expand All @@ -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<Vertx> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 312e45e

Please sign in to comment.