use of io.etcd.jetcd.options.PutOption 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.options.PutOption in project jetcd by coreos.
the class LeaseTest method testTimeToLiveWithKeys.
@Test
public void testTimeToLiveWithKeys() throws ExecutionException, InterruptedException {
long ttl = 5;
long leaseID = leaseClient.grant(ttl).get().getID();
PutOption putOption = PutOption.newBuilder().withLeaseId(leaseID).build();
kvClient.put(KEY_2, VALUE, putOption).get();
LeaseOption leaseOption = LeaseOption.newBuilder().withAttachedKeys().build();
LeaseTimeToLiveResponse resp = leaseClient.timeToLive(leaseID, leaseOption).get();
assertThat(resp.getTTl()).isGreaterThan(0);
assertThat(resp.getGrantedTTL()).isEqualTo(ttl);
assertThat(resp.getKeys().size()).isEqualTo(1);
assertThat(resp.getKeys().get(0)).isEqualTo(KEY_2);
}
Aggregations