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 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())); }
/** * Constructor from JSON * * @param options the JSON */ public SessionOptions(JsonObject options) { this.lockDelay = cutSeconds(options.getString(LOCK_KEY)); this.name = options.getString(NAME_KEY); this.node = options.getString(NODE_KEY); this.checks = listOf(options.getJsonArray(CHECKS_KEY)); this.behavior = SessionBehavior.of(options.getString(BEHAVIOR_KEY)); this.ttl = cutSeconds(options.getString(TTL_KEY)); }
private void checkSessionOptions(SessionOptions expected, SessionOptions actual) { assertEquals(expected.getBehavior(), actual.getBehavior()); assertEquals(expected.getChecks(), actual.getChecks()); assertEquals(expected.getLockDelay(), actual.getLockDelay()); assertEquals(expected.getName(), actual.getName()); assertEquals(expected.getNode(), actual.getNode()); assertEquals(expected.getTtl(), actual.getTtl()); }
@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()); })); })); }
@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()); })); })); })); })); })); } }
@Test public void unknownNode(TestContext tc) { ctx.writeClient().createSessionWithOptions(new SessionOptions().setNode("unknownNode"), tc.asyncAssertFailure()); }
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) {
@Override public ConsulClient createSessionWithOptions(SessionOptions options, Handler<AsyncResult<String>> idHandler) { String body = options == null ? null : options.toJson().encode(); requestObject(HttpMethod.PUT, "/v1/session/create", null, body, idHandler, (obj, headers) -> obj.getString("ID")); return this; }
@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()); })); })); }
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 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()); })); })); }