use of io.etcd.jetcd.kv.GetResponse in project jetcd by coreos.
the class CommandGet method accept.
@Override
public void accept(Client client) throws Exception {
GetResponse getResponse = client.getKVClient().get(ByteSequence.from(key, UTF_8), GetOption.newBuilder().withRevision(rev).build()).get();
if (getResponse.getKvs().isEmpty()) {
// key does not exist
return;
}
LOGGER.info(key);
LOGGER.info(getResponse.getKvs().get(0).getValue().toString(UTF_8));
}
use of io.etcd.jetcd.kv.GetResponse in project jetcd by coreos.
the class KVNamespaceTest method assertExistentKey.
private static void assertExistentKey(KV kvClient, ByteSequence key, ByteSequence value) throws Exception {
CompletableFuture<GetResponse> getFeature = kvClient.get(key);
GetResponse response = getFeature.get();
assertThat(response.getKvs().size()).isEqualTo(1);
assertThat(response.getKvs().get(0).getKey()).isEqualTo(key);
assertThat(response.getKvs().get(0).getValue()).isEqualTo(value);
}
use of io.etcd.jetcd.kv.GetResponse in project jetcd by coreos.
the class KVImpl method get.
@Override
public CompletableFuture<GetResponse> get(ByteSequence key, GetOption option) {
checkNotNull(key, "key should not be null");
checkNotNull(option, "option should not be null");
return execute(() -> stub.range(Requests.mapRangeRequest(key, option, namespace)), response -> new GetResponse(response, namespace), Errors::isRetryable);
}
use of io.etcd.jetcd.kv.GetResponse in project dubbo by alibaba.
the class EtcdMetadataReportTest method testStoreConsumer.
@Test
public void testStoreConsumer() throws Exception {
String version = "1.0.0";
String group = null;
String application = "etc-metadata-report-consumer-test";
MetadataIdentifier consumerIdentifier = storeConsumer(etcdMetadataReport, TEST_SERVICE, version, group, application);
CompletableFuture<GetResponse> response = etcdClientForTest.getKVClient().get(ByteSequence.from(etcdMetadataReport.getNodeKey(consumerIdentifier), StandardCharsets.UTF_8));
String fileContent = response.get().getKvs().get(0).getValue().toString(StandardCharsets.UTF_8);
Assertions.assertNotNull(fileContent);
Assertions.assertEquals(fileContent, "{\"paramConsumerTest\":\"etcdConsumer\"}");
}
use of io.etcd.jetcd.kv.GetResponse in project jetcd by coreos.
the class KVTest method testTxnForCmpOpNotEqual.
@Test
public void testTxnForCmpOpNotEqual() throws Exception {
ByteSequence sampleKey = bytesOf("txn_key");
ByteSequence sampleValue = bytesOf("xyz");
ByteSequence cmpValue = bytesOf("abc");
ByteSequence putValue = bytesOf("XYZ");
ByteSequence putValueNew = bytesOf("ABC");
// put the original txn key value pair
kvClient.put(sampleKey, sampleValue).get();
// construct txn operation
Txn txn = kvClient.txn();
Cmp cmp = new Cmp(sampleKey, Cmp.Op.NOT_EQUAL, CmpTarget.value(cmpValue));
CompletableFuture<io.etcd.jetcd.kv.TxnResponse> txnResp = txn.If(cmp).Then(Op.put(sampleKey, putValue, PutOption.DEFAULT)).Else(Op.put(sampleKey, putValueNew, PutOption.DEFAULT)).commit();
txnResp.get();
// get the value
GetResponse getResp = kvClient.get(sampleKey).get();
assertThat(getResp.getKvs()).hasSize(1);
assertThat(getResp.getKvs().get(0).getValue().toString(UTF_8)).isEqualTo(putValue.toString(UTF_8));
}
Aggregations