public static io.vertx.ext.consul.ConsulClient putValueWithOptions(io.vertx.ext.consul.ConsulClient j_receiver, java.lang.String key, java.lang.String value, java.util.Map<String, Object> options, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Boolean>> resultHandler) { io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.putValueWithOptions(key, value, options != null ? new io.vertx.ext.consul.KeyValueOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null, resultHandler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Boolean>>() { public void handle(io.vertx.core.AsyncResult<java.lang.Boolean> ar) { resultHandler.handle(ar.map(event -> event)); } } : null)); return j_receiver; } public static io.vertx.ext.consul.ConsulClient transaction(io.vertx.ext.consul.ConsulClient j_receiver, java.util.Map<String, Object> request, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.Map<String, Object>>> resultHandler) {
@Override public ConsulClient putValueWithOptions(String key, String value, KeyValueOptions options, Handler<AsyncResult<Boolean>> resultHandler) { Query query = new Query(); if (options != null) { query.put("flags", Long.toUnsignedString(options.getFlags())) .put("acquire", options.getAcquireSession()) .put("release", options.getReleaseSession()); long cas = options.getCasIndex(); if (cas >= 0) { query.put("cas", cas); } } requestString(HttpMethod.PUT, "/v1/kv/" + urlEncode(key), query, value, resultHandler, (bool, headers) -> Boolean.valueOf(bool)); return this; }
@Test public void canSetAllFlags(TestContext tc) { String key = randomFooBarAlpha(); String value = randomAlphaString(10); KeyValueOptions opts = new KeyValueOptions().setFlags(-1); ctx.writeClient() .putValueWithOptions(key, value, opts, tc.asyncAssertSuccess(b -> { tc.assertTrue(b); ctx.readClient().getValue(key, tc.asyncAssertSuccess(pair -> { tc.assertEquals(key, pair.getKey()); tc.assertEquals(value, pair.getValue()); assertEquals(opts.getFlags(), pair.getFlags()); ctx.writeClient().deleteValue(key, tc.asyncAssertSuccess()); })); })); }
@Test public void checkAndSet(TestContext tc) { String key = randomFooBarAlpha(); ctx.writeClient() .putValue(key, randomAlphaString(10), tc.asyncAssertSuccess(b1 -> { tc.assertTrue(b1); ctx.readClient().getValue(key, tc.asyncAssertSuccess(pair1 -> { ctx.writeClient().putValue(key, randomAlphaString(10), tc.asyncAssertSuccess(b2 -> { tc.assertTrue(b2); ctx.readClient().getValue(key, tc.asyncAssertSuccess(pair2 -> { tc.assertTrue(pair1.getModifyIndex() < pair2.getModifyIndex()); ctx.writeClient().putValueWithOptions(key, randomAlphaString(10), new KeyValueOptions().setCasIndex(pair1.getModifyIndex()), tc.asyncAssertSuccess(b3 -> { tc.assertFalse(b3); ctx.writeClient().putValueWithOptions(key, randomAlphaString(10), new KeyValueOptions().setCasIndex(pair2.getModifyIndex()), tc.asyncAssertSuccess(b4 -> { tc.assertTrue(b4); ctx.writeClient().deleteValue(key, 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 writeClientHaveFullAccessToOneValue(TestContext tc) { String key = randomFooBarAlpha(); String value = randomAlphaString(10); KeyValueOptions opts = new KeyValueOptions().setFlags(randomLong()); ctx.writeClient() .putValueWithOptions(key, value, opts, tc.asyncAssertSuccess(b -> { tc.assertTrue(b); ctx.readClient().getValue(key, tc.asyncAssertSuccess(pair -> { tc.assertEquals(key, pair.getKey()); tc.assertEquals(value, pair.getValue()); assertEquals(opts.getFlags(), pair.getFlags()); ctx.writeClient().deleteValue(key, tc.asyncAssertSuccess()); })); })); }
public static io.vertx.ext.consul.ConsulService putValueWithOptions(io.vertx.ext.consul.ConsulService j_receiver, java.lang.String key, java.lang.String value, java.util.Map<String, Object> options, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Boolean>> resultHandler) { io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.putValueWithOptions(key, value, options != null ? new io.vertx.ext.consul.KeyValueOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null, resultHandler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Boolean>>() { public void handle(io.vertx.core.AsyncResult<java.lang.Boolean> ar) { resultHandler.handle(ar.map(event -> event)); } } : null)); return j_receiver; } public static io.vertx.ext.consul.ConsulService transaction(io.vertx.ext.consul.ConsulService j_receiver, java.util.Map<String, Object> request, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.Map<String, Object>>> resultHandler) {