Search in sources :

Example 6 with PutResponse

use of io.etcd.jetcd.kv.PutResponse in project jetcd by coreos.

the class WatchTest method getCompactedRevision.

private static long getCompactedRevision(final Client client, final ByteSequence key) throws Exception {
    final ByteSequence value = randomByteSequence();
    // Insert key twice to ensure we have at least two revisions
    client.getKVClient().put(key, value).get();
    final PutResponse putResponse = client.getKVClient().put(key, value).get();
    // Compact until latest revision
    client.getKVClient().compact(putResponse.getHeader().getRevision()).get();
    return putResponse.getHeader().getRevision() - 1;
}
Also used : PutResponse(io.etcd.jetcd.kv.PutResponse) ByteSequence(io.etcd.jetcd.ByteSequence) TestUtil.randomByteSequence(io.etcd.jetcd.impl.TestUtil.randomByteSequence)

Example 7 with PutResponse

use of io.etcd.jetcd.kv.PutResponse in project jetcd by coreos.

the class KVNamespaceTest method putKVWithAssertion.

/**
 * Put key-value pair and return whether has previous KV.
 */
private static boolean putKVWithAssertion(KV kvClient, ByteSequence key, ByteSequence value, ByteSequence prevValue) throws Exception {
    CompletableFuture<PutResponse> feature = kvClient.put(key, value, PutOption.newBuilder().withPrevKV().build());
    PutResponse response = feature.get();
    if (prevValue != null) {
        assertThat(response.hasPrevKv()).isTrue();
        assertThat(response.getPrevKv().getKey()).isEqualTo(key);
        assertThat(response.getPrevKv().getValue()).isEqualTo(prevValue);
    }
    return response.hasPrevKv();
}
Also used : PutResponse(io.etcd.jetcd.kv.PutResponse)

Example 8 with PutResponse

use of io.etcd.jetcd.kv.PutResponse in project jetcd by coreos.

the class KVImpl method put.

@Override
public CompletableFuture<PutResponse> put(ByteSequence key, ByteSequence value, PutOption option) {
    checkNotNull(key, "key should not be null");
    checkNotNull(value, "value should not be null");
    checkNotNull(option, "option should not be null");
    return execute(() -> stub.put(Requests.mapPutRequest(key, value, option, namespace)), response -> new PutResponse(response, namespace), Errors::isRetryable);
}
Also used : Errors(io.etcd.jetcd.support.Errors) PutResponse(io.etcd.jetcd.kv.PutResponse)

Example 9 with PutResponse

use of io.etcd.jetcd.kv.PutResponse in project jetcd by coreos.

the class KVTest method testGet.

@Test
public void testGet() throws Exception {
    CompletableFuture<PutResponse> feature = kvClient.put(SAMPLE_KEY_2, SAMPLE_VALUE_2);
    feature.get();
    CompletableFuture<GetResponse> getFeature = kvClient.get(SAMPLE_KEY_2);
    GetResponse response = getFeature.get();
    assertThat(response.getKvs()).hasSize(1);
    assertThat(response.getKvs().get(0).getValue().toString(UTF_8)).isEqualTo(SAMPLE_VALUE_2.toString(UTF_8));
    assertThat(!response.isMore()).isTrue();
}
Also used : PutResponse(io.etcd.jetcd.kv.PutResponse) GetResponse(io.etcd.jetcd.kv.GetResponse) Test(org.junit.jupiter.api.Test)

Example 10 with PutResponse

use of io.etcd.jetcd.kv.PutResponse in project jetcd by coreos.

the class LoadBalancerTest method testRoundRobinLoadBalancerFactory.

@Test
public void testRoundRobinLoadBalancerFactory() throws Exception {
    final List<URI> endpoints = cluster.clientEndpoints();
    final ClientBuilder builder = Client.builder().endpoints(endpoints).loadBalancerPolicy("round_robin");
    try (Client client = builder.build();
        KV kv = client.getKVClient()) {
        long lastMemberId = 0;
        long differences = 0;
        final String allEndpoints = endpoints.stream().map(URI::toString).collect(Collectors.joining(","));
        for (int i = 0; i < allEndpoints.length(); i++) {
            PutResponse response = kv.put(TestUtil.randomByteSequence(), TestUtil.randomByteSequence()).get();
            if (i > 0 && lastMemberId != response.getHeader().getMemberId()) {
                differences++;
            }
            lastMemberId = response.getHeader().getMemberId();
        }
        assertThat(differences).isNotEqualTo(lastMemberId);
    }
}
Also used : KV(io.etcd.jetcd.KV) Client(io.etcd.jetcd.Client) PutResponse(io.etcd.jetcd.kv.PutResponse) URI(java.net.URI) ClientBuilder(io.etcd.jetcd.ClientBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

PutResponse (io.etcd.jetcd.kv.PutResponse)10 Test (org.junit.jupiter.api.Test)6 ByteSequence (io.etcd.jetcd.ByteSequence)2 Client (io.etcd.jetcd.Client)2 ClientBuilder (io.etcd.jetcd.ClientBuilder)2 TestUtil.randomByteSequence (io.etcd.jetcd.impl.TestUtil.randomByteSequence)2 GetResponse (io.etcd.jetcd.kv.GetResponse)2 KV (io.etcd.jetcd.KV)1 Watcher (io.etcd.jetcd.Watch.Watcher)1 GetOption (io.etcd.jetcd.options.GetOption)1 PutOption (io.etcd.jetcd.options.PutOption)1 WatchOption (io.etcd.jetcd.options.WatchOption)1 Errors (io.etcd.jetcd.support.Errors)1 WatchResponse (io.etcd.jetcd.watch.WatchResponse)1 CallOptions (io.grpc.CallOptions)1 Channel (io.grpc.Channel)1 ClientCall (io.grpc.ClientCall)1 ClientInterceptor (io.grpc.ClientInterceptor)1 ForwardingClientCall (io.grpc.ForwardingClientCall)1 Metadata (io.grpc.Metadata)1