Search in sources :

Example 1 with LeaseTimeToLiveResponse

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);
}
Also used : LeaseTimeToLiveResponse(io.etcd.jetcd.lease.LeaseTimeToLiveResponse) Test(org.junit.jupiter.api.Test)

Example 2 with LeaseTimeToLiveResponse

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);
}
Also used : LeaseTimeToLiveResponse(io.etcd.jetcd.lease.LeaseTimeToLiveResponse) LeaseOption(io.etcd.jetcd.options.LeaseOption) PutOption(io.etcd.jetcd.options.PutOption) Test(org.junit.jupiter.api.Test)

Example 3 with LeaseTimeToLiveResponse

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);
}
Also used : LeaseTimeToLiveResponse(io.etcd.jetcd.lease.LeaseTimeToLiveResponse) LeaseTimeToLiveRequest(io.etcd.jetcd.api.LeaseTimeToLiveRequest)

Aggregations

LeaseTimeToLiveResponse (io.etcd.jetcd.lease.LeaseTimeToLiveResponse)3 Test (org.junit.jupiter.api.Test)2 LeaseTimeToLiveRequest (io.etcd.jetcd.api.LeaseTimeToLiveRequest)1 LeaseOption (io.etcd.jetcd.options.LeaseOption)1 PutOption (io.etcd.jetcd.options.PutOption)1