use of io.etcd.jetcd.api.WatchResponse in project jetcd by coreos.
the class WatchUnitTest method testWatcherListenForMultiplePuts.
@Test
public void testWatcherListenForMultiplePuts() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(2);
List<io.etcd.jetcd.watch.WatchResponse> responses = new ArrayList<>();
Watch.Listener listener = Watch.listener(r -> {
responses.add(r);
latch.countDown();
});
try (Watch.Watcher watcher = watchClient.watch(KEY, listener)) {
WatchResponse createdResponse = createWatchResponse(0);
responseObserverRef.get().onNext(createdResponse);
WatchResponse resp1 = WatchResponse.newBuilder().setWatchId(0).addEvents(Event.newBuilder().setType(EventType.PUT).setKv(io.etcd.jetcd.api.KeyValue.newBuilder().setModRevision(2).build()).build()).build();
WatchResponse resp2 = WatchResponse.newBuilder().setWatchId(0).addEvents(Event.newBuilder().setType(EventType.PUT).setKv(io.etcd.jetcd.api.KeyValue.newBuilder().setModRevision(3).build()).build()).build();
responseObserverRef.get().onNext(resp1);
responseObserverRef.get().onNext(resp2);
latch.await(4, TimeUnit.SECONDS);
assertThat(responses).hasSize(2);
assertEqualOnWatchResponses(responses.get(0), new io.etcd.jetcd.watch.WatchResponse(resp1));
assertEqualOnWatchResponses(responses.get(1), new io.etcd.jetcd.watch.WatchResponse(resp2));
}
}
use of io.etcd.jetcd.api.WatchResponse in project jetcd by coreos.
the class WatchUnitTest method testWatcherCreateOnCompactionError.
@Test
public void testWatcherCreateOnCompactionError() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<Throwable> ref = new AtomicReference<>();
Watch.Listener listener = Watch.listener(r -> {
}, t -> {
ref.set(t);
latch.countDown();
});
try (Watch.Watcher watcher = watchClient.watch(KEY, listener)) {
WatchResponse createdResponse = createWatchResponse(0);
responseObserverRef.get().onNext(createdResponse);
WatchResponse compactedResponse = WatchResponse.newBuilder().setCanceled(true).setCompactRevision(2).build();
responseObserverRef.get().onNext(compactedResponse);
latch.await(4, TimeUnit.SECONDS);
assertThat(ref.get()).isNotNull();
assertThat(ref.get()).isInstanceOf(EtcdException.class).hasFieldOrPropertyWithValue("compactedRevision", 2L);
}
}
use of io.etcd.jetcd.api.WatchResponse in project jetcd by coreos.
the class WatchUnitTest method testWatcherCreateOnCancellationWithNoReason.
@Test
public void testWatcherCreateOnCancellationWithNoReason() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<Throwable> ref = new AtomicReference<>();
Watch.Listener listener = Watch.listener(r -> {
}, t -> {
ref.set(t);
latch.countDown();
});
try (Watch.Watcher watcher = watchClient.watch(KEY, listener)) {
WatchResponse createdResponse = createWatchResponse(0);
responseObserverRef.get().onNext(createdResponse);
WatchResponse canceledResponse = WatchResponse.newBuilder().setCanceled(true).build();
responseObserverRef.get().onNext(canceledResponse);
latch.await(4, TimeUnit.SECONDS);
assertThat(ref.get()).isNotNull();
assertThat(ref.get()).isInstanceOf(EtcdException.class).hasMessageContaining("etcdserver: mvcc: required revision is a future revision");
}
}
use of io.etcd.jetcd.api.WatchResponse in project jetcd by coreos.
the class WatchUnitTest method testWatcherWithRequireLeaderErrsOutOnNoLeader.
@Test
public void testWatcherWithRequireLeaderErrsOutOnNoLeader() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<Throwable> ref = new AtomicReference<>();
Watch.Listener listener = Watch.listener(r -> {
}, t -> {
ref.set(t);
latch.countDown();
});
try (Watch.Watcher watcher = watchClient.watch(KEY, listener)) {
WatchResponse createdResponse = createWatchResponse(0);
responseObserverRef.get().onNext(createdResponse);
responseObserverRef.get().onError(Status.UNAVAILABLE.withDescription(Errors.NO_LEADER_ERROR_MESSAGE).asRuntimeException());
latch.await(4, TimeUnit.SECONDS);
assertThat(ref.get()).isNotNull();
assertThat(ref.get()).isNotNull();
assertThat(ref.get()).isInstanceOf(EtcdException.class).hasMessageContaining(Errors.NO_LEADER_ERROR_MESSAGE);
final WatchImpl.WatcherImpl wimpl = (WatchImpl.WatcherImpl) watcher;
assertThat(wimpl.isClosed()).isTrue();
}
}
use of io.etcd.jetcd.api.WatchResponse in project jetcd by coreos.
the class WatchUnitTest method testWatcherCreateOnCancellationWithReason.
@Test
public void testWatcherCreateOnCancellationWithReason() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<Throwable> ref = new AtomicReference<>();
Watch.Listener listener = Watch.listener(r -> {
}, t -> {
ref.set(t);
latch.countDown();
});
try (Watch.Watcher watcher = watchClient.watch(KEY, listener)) {
WatchResponse createdResponse = createWatchResponse(0);
responseObserverRef.get().onNext(createdResponse);
WatchResponse canceledResponse = WatchResponse.newBuilder().setCanceled(true).setCancelReason("bad reason").build();
responseObserverRef.get().onNext(canceledResponse);
latch.await(4, TimeUnit.SECONDS);
assertThat(ref.get()).isNotNull();
assertThat(ref.get()).isInstanceOf(EtcdException.class).hasMessageContaining(canceledResponse.getCancelReason());
}
}
Aggregations