/** * Remove the key/value pair that corresponding to the specified key * @param key the key * @param resultHandler will be called on complete * @return reference to this, for fluency */ public io.vertx.rxjava.ext.consul.ConsulClient deleteValue(String key, Handler<AsyncResult<Void>> resultHandler) { delegate.deleteValue(key, resultHandler); return this; }
@Override public ConsulService deleteValue(String key, Handler<AsyncResult<Void>> resultHandler) { consulClient.deleteValue(key, resultHandler); return this; }
/** * Remove the key/value pair that corresponding to the specified key * @param key the key * @param resultHandler will be called on complete * @return reference to this, for fluency */ public io.vertx.rxjava.ext.consul.ConsulClient deleteValue(String key, Handler<AsyncResult<Void>> resultHandler) { delegate.deleteValue(key, resultHandler); return this; }
@Test public void clientCantDeleteUnknownKey(TestContext tc) { ctx.readClient().deleteValue("unknown", tc.asyncAssertFailure()); }
@Test public void readClientEmptyValue(TestContext tc) { String key = randomFooBarAlpha(); ctx.writeClient() .putValue(key, "", tc.asyncAssertSuccess(b -> { tc.assertTrue(b); ctx.readClient().getValue(key, tc.asyncAssertSuccess(pair -> { tc.assertEquals(key, pair.getKey()); tc.assertEquals("", pair.getValue()); ctx.writeClient().deleteValue(key, tc.asyncAssertSuccess()); })); })); }
@Test public void readClientCanReadOneValue(TestContext tc) { String key = randomFooBarUnicode(); String value = randomUnicodeString(10); ctx.writeClient() .putValue(key, value, tc.asyncAssertSuccess(b -> { tc.assertTrue(b); ctx.readClient().getValue(key, tc.asyncAssertSuccess(pair -> { tc.assertEquals(key, pair.getKey()); tc.assertEquals(value, pair.getValue()); ctx.writeClient().deleteValue(key, tc.asyncAssertSuccess()); })); })); }
private void blockingQuery(TestContext tc, BiConsumer<String, Handler<Long>> indexSupplier) { String key = randomFooBarAlpha(); String value = randomAlphaString(10); ctx.writeClient() .putValue(key, randomAlphaString(10), tc.asyncAssertSuccess(b1 -> { tc.assertTrue(b1); indexSupplier.accept(key, consulIndex -> { Async async = tc.async(2); vertx.setTimer(TimeUnit.SECONDS.toMillis(2), l -> { ctx.writeClient().putValue(key, value, tc.asyncAssertSuccess(b2 -> { tc.assertTrue(b2); ctx.readClient().getValueWithOptions(key, new BlockingQueryOptions().setIndex(consulIndex), tc.asyncAssertSuccess(kv -> { tc.assertTrue(kv.getModifyIndex() > consulIndex); tc.assertEquals(kv.getValue(), value); async.countDown(); })); ctx.readClient().getValuesWithOptions("foo/bar", new BlockingQueryOptions().setIndex(consulIndex), tc.asyncAssertSuccess(kv -> { tc.assertTrue(kv.getIndex() > consulIndex); tc.assertTrue(kv.getList().size() == 1); async.countDown(); })); })); }); async.handler(v -> ctx.writeClient().deleteValue(key, tc.asyncAssertSuccess())); }); })); } }
@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 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()); })); })); }
@Test public void watchExistingKey() throws InterruptedException { StateConsumer<String> consumer = new StateConsumer<>(); String key = ConsulContext.KEY_RW_PREFIX + randomAlphaString(10); String v1 = randomAlphaString(10); String v2 = randomAlphaString(10); assertTrue(getAsync(h -> ctx.writeClient().putValue(key, v1, h))); Watch<KeyValue> watch = Watch.key(key, vertx, ctx.readClientOptions()) .setHandler(kv -> { if (kv.succeeded()) { consumer.consume(kv.nextResult().isPresent() ? kv.nextResult().getValue() : EMPTY_MESSAGE); } else { consumer.consume(kv.cause().getMessage()); } }) .start(); consumer.await(v1); assertTrue(getAsync(h -> ctx.writeClient().putValue(key, v2, h))); consumer.await(v2); runAsync(h -> ctx.writeClient().deleteValue(key, h)); consumer.await(EMPTY_MESSAGE); consumer.check(); watch.stop(); }
@Test public void watchCreatedKey() throws InterruptedException { StateConsumer<String> consumer = new StateConsumer<>(); String key = ConsulContext.KEY_RW_PREFIX + randomAlphaString(10); String v1 = randomAlphaString(10); String v2 = randomAlphaString(10); Watch<KeyValue> watch = Watch.key(key, vertx, ctx.readClientOptions()) .setHandler(kv -> { if (kv.succeeded()) { consumer.consume(kv.nextResult().isPresent() ? kv.nextResult().getValue() : EMPTY_MESSAGE); } else { consumer.consume(kv.cause().getMessage()); } }) .start(); consumer.await(EMPTY_MESSAGE); assertTrue(getAsync(h -> ctx.writeClient().putValue(key, v1, h))); consumer.await(v1); assertTrue(getAsync(h -> ctx.writeClient().putValue(key, v2, h))); consumer.await(v2); runAsync(h -> ctx.writeClient().deleteValue(key, h)); consumer.await(EMPTY_MESSAGE); consumer.check(); watch.stop(); }
@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()); })); })); })); })); })); })); }