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