use of io.etcd.jetcd.Watch.Watcher in project jetcd by coreos.
the class WatchTest method testWatchOnPut.
@ParameterizedTest
@MethodSource("parameters")
public void testWatchOnPut(final Client client) throws Exception {
final ByteSequence key = randomByteSequence();
final ByteSequence value = randomByteSequence();
final AtomicReference<WatchResponse> ref = new AtomicReference<>();
try (Watcher watcher = client.getWatchClient().watch(key, ref::set)) {
client.getKVClient().put(key, value).get();
await().atMost(TIME_OUT_SECONDS, TimeUnit.SECONDS).untilAsserted(() -> assertThat(ref.get()).isNotNull());
assertThat(ref.get()).isNotNull();
assertThat(ref.get().getEvents().size()).isEqualTo(1);
assertThat(ref.get().getEvents().get(0).getEventType()).isEqualTo(EventType.PUT);
assertThat(ref.get().getEvents().get(0).getKeyValue().getKey()).isEqualTo(key);
}
}
use of io.etcd.jetcd.Watch.Watcher in project jetcd by coreos.
the class WatchTest method testWatchCompacted.
@ParameterizedTest
@MethodSource("parameters")
public void testWatchCompacted(final Client client) throws Exception {
final ByteSequence key = randomByteSequence();
final AtomicReference<Throwable> ref = new AtomicReference<>();
// Try to listen from previous revision on
final WatchOption options = WatchOption.newBuilder().withRevision(getCompactedRevision(client, key)).build();
final Watch wc = client.getWatchClient();
try (Watcher watcher = wc.watch(key, options, Watch.listener(TestUtil::noOpWatchResponseConsumer, ref::set))) {
await().atMost(TIME_OUT_SECONDS, TimeUnit.SECONDS).untilAsserted(() -> assertThat(ref.get()).isNotNull());
assertThat(ref.get().getClass()).isEqualTo(CompactedException.class);
}
}
Aggregations