public static io.vertx.ext.consul.ConsulClient createSessionWithOptions(io.vertx.ext.consul.ConsulClient j_receiver, java.util.Map<String, Object> options, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>> idHandler) { io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.createSessionWithOptions(options != null ? new io.vertx.ext.consul.SessionOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null, idHandler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>() { public void handle(io.vertx.core.AsyncResult<java.lang.String> ar) { idHandler.handle(ar.map(event -> event)); } } : null)); return j_receiver; } public static io.vertx.ext.consul.ConsulClient infoSession(io.vertx.ext.consul.ConsulClient j_receiver, java.lang.String id, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.Map<String, Object>>> resultHandler) {
public static io.vertx.ext.consul.ConsulService createSessionWithOptions(io.vertx.ext.consul.ConsulService j_receiver, java.util.Map<String, Object> options, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>> idHandler) { io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.createSessionWithOptions(options != null ? new io.vertx.ext.consul.SessionOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null, idHandler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>>() { public void handle(io.vertx.core.AsyncResult<java.lang.String> ar) { idHandler.handle(ar.map(event -> event)); } } : null)); return j_receiver; } public static io.vertx.ext.consul.ConsulService infoSession(io.vertx.ext.consul.ConsulService j_receiver, java.lang.String id, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.Map<String, Object>>> resultHandler) {
@Test public void testSessionOptions() { SessionOptions opts = randomSessionOptions(); checkSessionOptions(opts, new SessionOptions(opts)); checkSessionOptions(opts, new SessionOptions(opts.toJson())); SessionOptions nullChecks = opts.setChecks(null); checkSessionOptions(nullChecks, new SessionOptions(nullChecks)); checkSessionOptions(nullChecks, new SessionOptions(nullChecks.toJson())); }
@Test public void unknownNode(TestContext tc) { ctx.writeClient().createSessionWithOptions(new SessionOptions().setNode("unknownNode"), tc.asyncAssertFailure()); }
@Test public void createSessionWithOptionsWithDefaultLockDelay(TestContext tc) { SessionOptions opt = new SessionOptions() .setBehavior(SessionBehavior.DELETE) .setName("optName") .setTtl(442); ctx.writeClient().createSessionWithOptions(opt, tc.asyncAssertSuccess(id -> { ctx.writeClient().infoSession(id, tc.asyncAssertSuccess(session -> { List<String> checks = session.getChecks(); tc.assertEquals(1, checks.size()); tc.assertTrue("serfHealth".equals(checks.get(0))); tc.assertEquals(15L, session.getLockDelay()); tc.assertEquals(ctx.nodeName(), session.getNode()); ctx.writeClient().destroySession(id, tc.asyncAssertSuccess()); })); })); }
@Test public void createSessionWithOptionsWithZeroLockDelay(TestContext tc) { SessionOptions opt = new SessionOptions() .setBehavior(SessionBehavior.DELETE) .setLockDelay(0L) .setName("optName") .setTtl(442); ctx.writeClient().createSessionWithOptions(opt, tc.asyncAssertSuccess(id -> { ctx.writeClient().infoSession(id, tc.asyncAssertSuccess(session -> { List<String> checks = session.getChecks(); tc.assertEquals(1, checks.size()); tc.assertTrue("serfHealth".equals(checks.get(0))); tc.assertEquals(0L, session.getLockDelay()); tc.assertEquals(ctx.nodeName(), session.getNode()); ctx.writeClient().destroySession(id, tc.asyncAssertSuccess()); })); })); }
@Test public void createSessionWithOptions(TestContext tc) { SessionOptions opt = new SessionOptions() .setBehavior(SessionBehavior.DELETE) .setLockDelay(42) .setName("optName") .setTtl(442); ctx.writeClient().createSessionWithOptions(opt, tc.asyncAssertSuccess(id -> { ctx.writeClient().infoSession(id, tc.asyncAssertSuccess(session -> { List<String> checks = session.getChecks(); tc.assertEquals(1, checks.size()); tc.assertTrue("serfHealth".equals(checks.get(0))); tc.assertEquals(opt.getLockDelay(), session.getLockDelay()); tc.assertEquals(ctx.nodeName(), session.getNode()); ctx.writeClient().destroySession(id, tc.asyncAssertSuccess()); })); })); }
public static SessionOptions randomSessionOptions() { return new SessionOptions() .setBehavior(randomElement(SessionBehavior.values())) .setChecks(randomStringList(2)) .setLockDelay(randomPositiveInt()) .setName(randomAlphaString(10)) .setNode(randomAlphaString(10)) .setTtl(10 + (randomPositiveInt() % 100)); }
@Test public void deleteBehavior(TestContext tc) { ctx.writeClient().createSessionWithOptions(new SessionOptions().setTtl(442).setBehavior(SessionBehavior.DELETE), tc.asyncAssertSuccess(id -> { ctx.writeClient().putValueWithOptions("foo/bar", "value1", new KeyValueOptions().setAcquireSession(id), tc.asyncAssertSuccess(b -> { tc.assertTrue(b); ctx.writeClient().getValue("foo/bar", tc.asyncAssertSuccess(pair -> { tc.assertEquals("value1", pair.getValue()); tc.assertEquals(id, pair.getSession()); ctx.writeClient().destroySession(id, tc.asyncAssertSuccess(v -> { ctx.writeClient().getValue("foo/bar", tc.asyncAssertSuccess(notfound -> { tc.assertFalse(notfound.isPresent()); })); })); })); })); })); } }