@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()); })); })); })); })); })); } }