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 65aa544 commit c216018
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 29 deletions.
13 changes: 7 additions & 6 deletions src/main/java/example/Examples.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
35 changes: 15 additions & 20 deletions src/test/java/io/vertx/core/ProgrammaticZKClusterManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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<Vertx> vertx1 = new AtomicReference<>();
AtomicReference<Vertx> 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 -> {
Expand All @@ -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());
Expand Down Expand Up @@ -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<Vertx> vertx1 = new AtomicReference<>();
AtomicReference<Vertx> 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 -> {
Expand All @@ -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());
Expand Down Expand Up @@ -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<Vertx> 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 -> {
Expand Down Expand Up @@ -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<Vertx> vertx1 = new AtomicReference<>();
AtomicReference<Vertx> 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 -> {
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c216018

Please sign in to comment.