use of io.etcd.jetcd.lease.LeaseTimeToLiveResponse in project jetcd by coreos.
the class LeaseTest method testTimeToLive.
@Test
public void testTimeToLive() throws ExecutionException, InterruptedException {
long ttl = 5;
long leaseID = leaseClient.grant(ttl).get().getID();
LeaseTimeToLiveResponse resp = leaseClient.timeToLive(leaseID, LeaseOption.DEFAULT).get();
assertThat(resp.getTTl()).isGreaterThan(0);
assertThat(resp.getGrantedTTL()).isEqualTo(ttl);
}
use of io.etcd.jetcd.lease.LeaseTimeToLiveResponse 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);
}
use of io.etcd.jetcd.lease.LeaseTimeToLiveResponse in project jetcd by coreos.
the class LeaseImpl method timeToLive.
@Override
public CompletableFuture<LeaseTimeToLiveResponse> timeToLive(long leaseId, LeaseOption option) {
checkNotNull(option, "LeaseOption should not be null");
LeaseTimeToLiveRequest leaseTimeToLiveRequest = LeaseTimeToLiveRequest.newBuilder().setID(leaseId).setKeys(option.isAttachedKeys()).build();
return execute(() -> this.stub.leaseTimeToLive(leaseTimeToLiveRequest), LeaseTimeToLiveResponse::new);
}
Aggregations