use of io.etcd.jetcd.kv.PutResponse in project jetcd by coreos.
the class KVTest method testGetWithRev.
@Test
public void testGetWithRev() throws Exception {
CompletableFuture<PutResponse> feature = kvClient.put(SAMPLE_KEY_3, SAMPLE_VALUE);
PutResponse putResp = feature.get();
kvClient.put(SAMPLE_KEY_3, SAMPLE_VALUE_2).get();
GetOption option = GetOption.newBuilder().withRevision(putResp.getHeader().getRevision()).build();
CompletableFuture<GetResponse> getFeature = kvClient.get(SAMPLE_KEY_3, option);
GetResponse response = getFeature.get();
assertThat(response.getKvs()).hasSize(1);
assertThat(response.getKvs().get(0).getValue().toString(UTF_8)).isEqualTo(SAMPLE_VALUE.toString(UTF_8));
}
use of io.etcd.jetcd.kv.PutResponse in project jetcd by coreos.
the class KVTest method testPut.
@Test
public void testPut() throws Exception {
CompletableFuture<PutResponse> feature = kvClient.put(SAMPLE_KEY, SAMPLE_VALUE);
PutResponse response = feature.get();
assertThat(response.getHeader()).isNotNull();
assertThat(!response.hasPrevKv()).isTrue();
}
use of io.etcd.jetcd.kv.PutResponse in project jetcd by coreos.
the class KVTest method testPutWithNotExistLease.
@Test
public void testPutWithNotExistLease() throws ExecutionException, InterruptedException {
PutOption option = PutOption.newBuilder().withLeaseId(99999).build();
CompletableFuture<PutResponse> future = kvClient.put(SAMPLE_KEY, SAMPLE_VALUE, option);
assertThatExceptionOfType(ExecutionException.class).isThrownBy(future::get).withMessageEndingWith("etcdserver: requested lease not found");
}
use of io.etcd.jetcd.kv.PutResponse in project jetcd by coreos.
the class ClientConnectionManagerTest method testHeaders.
@Test
public void testHeaders() throws InterruptedException, ExecutionException {
final CountDownLatch latch = new CountDownLatch(1);
final ClientBuilder builder = TestUtil.client(cluster).header("MyHeader1", "MyHeaderVal1").header("MyHeader2", "MyHeaderVal2").interceptor(new ClientInterceptor() {
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) {
@Override
public void start(Listener<RespT> responseListener, Metadata headers) {
super.start(responseListener, headers);
assertThat(headers.get(Metadata.Key.of("MyHeader1", Metadata.ASCII_STRING_MARSHALLER))).isEqualTo("MyHeaderVal1");
assertThat(headers.get(Metadata.Key.of("MyHeader2", Metadata.ASCII_STRING_MARSHALLER))).isEqualTo("MyHeaderVal2");
latch.countDown();
}
};
}
});
try (Client client = builder.build()) {
CompletableFuture<PutResponse> future = client.getKVClient().put(bytesOf("sample_key"), bytesOf("sample_key"));
latch.await(1, TimeUnit.MINUTES);
future.get();
}
}
use of io.etcd.jetcd.kv.PutResponse in project jetcd by coreos.
the class WatchTest method testWatchFutureRevisionIsNotOverwrittenOnCreation.
@ParameterizedTest
@MethodSource("parameters")
public void testWatchFutureRevisionIsNotOverwrittenOnCreation(final Client client) throws Exception {
final ByteSequence key = randomByteSequence();
final ByteSequence value = randomByteSequence();
final List<WatchResponse> events = Collections.synchronizedList(new ArrayList<>());
PutResponse putResponse = client.getKVClient().put(key, value).get();
long lastSeenRevision = putResponse.getHeader().getRevision();
WatchOption watchOption = WatchOption.newBuilder().withRevision(lastSeenRevision + 1).build();
try (Watcher watcher = client.getWatchClient().watch(key, watchOption, events::add)) {
// resumes (recreates) the watch
cluster.restart();
// await().duration() would be better but it's broken
Thread.sleep(2000);
assertThat(events.isEmpty()).as("verify that received events list is empty").isTrue();
}
}
Aggregations