Search in sources :

Example 1 with PutOption

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

Example 2 with PutOption

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);
}
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)

Aggregations

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