Search in sources :

Example 1 with PutResponse

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

the class KVTest method testGetWithRev.

@Test
public void testGetWithRev() throws Exception {
    CompletableFuture<PutResponse> feature = kvClient.put(SAMPLE_KEY_3, SAMPLE_VALUE);
    PutResponse putResp = feature.get();
    kvClient.put(SAMPLE_KEY_3, SAMPLE_VALUE_2).get();
    GetOption option = GetOption.newBuilder().withRevision(putResp.getHeader().getRevision()).build();
    CompletableFuture<GetResponse> getFeature = kvClient.get(SAMPLE_KEY_3, option);
    GetResponse response = getFeature.get();
    assertThat(response.getKvs()).hasSize(1);
    assertThat(response.getKvs().get(0).getValue().toString(UTF_8)).isEqualTo(SAMPLE_VALUE.toString(UTF_8));
}
Also used : GetOption(io.etcd.jetcd.options.GetOption) PutResponse(io.etcd.jetcd.kv.PutResponse) GetResponse(io.etcd.jetcd.kv.GetResponse) Test(org.junit.jupiter.api.Test)

Example 2 with PutResponse

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

the class KVTest method testPut.

@Test
public void testPut() throws Exception {
    CompletableFuture<PutResponse> feature = kvClient.put(SAMPLE_KEY, SAMPLE_VALUE);
    PutResponse response = feature.get();
    assertThat(response.getHeader()).isNotNull();
    assertThat(!response.hasPrevKv()).isTrue();
}
Also used : PutResponse(io.etcd.jetcd.kv.PutResponse) Test(org.junit.jupiter.api.Test)

Example 3 with PutResponse

use of io.etcd.jetcd.kv.PutResponse 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 4 with PutResponse

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

the class ClientConnectionManagerTest method testHeaders.

@Test
public void testHeaders() throws InterruptedException, ExecutionException {
    final CountDownLatch latch = new CountDownLatch(1);
    final ClientBuilder builder = TestUtil.client(cluster).header("MyHeader1", "MyHeaderVal1").header("MyHeader2", "MyHeaderVal2").interceptor(new ClientInterceptor() {

        @Override
        public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
            return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) {

                @Override
                public void start(Listener<RespT> responseListener, Metadata headers) {
                    super.start(responseListener, headers);
                    assertThat(headers.get(Metadata.Key.of("MyHeader1", Metadata.ASCII_STRING_MARSHALLER))).isEqualTo("MyHeaderVal1");
                    assertThat(headers.get(Metadata.Key.of("MyHeader2", Metadata.ASCII_STRING_MARSHALLER))).isEqualTo("MyHeaderVal2");
                    latch.countDown();
                }
            };
        }
    });
    try (Client client = builder.build()) {
        CompletableFuture<PutResponse> future = client.getKVClient().put(bytesOf("sample_key"), bytesOf("sample_key"));
        latch.await(1, TimeUnit.MINUTES);
        future.get();
    }
}
Also used : Channel(io.grpc.Channel) ForwardingClientCall(io.grpc.ForwardingClientCall) Metadata(io.grpc.Metadata) CallOptions(io.grpc.CallOptions) CountDownLatch(java.util.concurrent.CountDownLatch) PutResponse(io.etcd.jetcd.kv.PutResponse) ClientCall(io.grpc.ClientCall) ForwardingClientCall(io.grpc.ForwardingClientCall) ClientInterceptor(io.grpc.ClientInterceptor) Client(io.etcd.jetcd.Client) ClientBuilder(io.etcd.jetcd.ClientBuilder) Test(org.junit.jupiter.api.Test)

Example 5 with PutResponse

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

the class WatchTest method testWatchFutureRevisionIsNotOverwrittenOnCreation.

@ParameterizedTest
@MethodSource("parameters")
public void testWatchFutureRevisionIsNotOverwrittenOnCreation(final Client client) throws Exception {
    final ByteSequence key = randomByteSequence();
    final ByteSequence value = randomByteSequence();
    final List<WatchResponse> events = Collections.synchronizedList(new ArrayList<>());
    PutResponse putResponse = client.getKVClient().put(key, value).get();
    long lastSeenRevision = putResponse.getHeader().getRevision();
    WatchOption watchOption = WatchOption.newBuilder().withRevision(lastSeenRevision + 1).build();
    try (Watcher watcher = client.getWatchClient().watch(key, watchOption, events::add)) {
        // resumes (recreates) the watch
        cluster.restart();
        // await().duration() would be better but it's broken
        Thread.sleep(2000);
        assertThat(events.isEmpty()).as("verify that received events list is empty").isTrue();
    }
}
Also used : Watcher(io.etcd.jetcd.Watch.Watcher) PutResponse(io.etcd.jetcd.kv.PutResponse) WatchResponse(io.etcd.jetcd.watch.WatchResponse) ByteSequence(io.etcd.jetcd.ByteSequence) TestUtil.randomByteSequence(io.etcd.jetcd.impl.TestUtil.randomByteSequence) WatchOption(io.etcd.jetcd.options.WatchOption) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

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