Search in sources :

Example 6 with GetResponse

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));
}
Also used : GetResponse(io.etcd.jetcd.kv.GetResponse)

Example 7 with GetResponse

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);
}
Also used : GetResponse(io.etcd.jetcd.kv.GetResponse)

Example 8 with GetResponse

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);
}
Also used : Errors(io.etcd.jetcd.support.Errors) GetResponse(io.etcd.jetcd.kv.GetResponse)

Example 9 with GetResponse

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\"}");
}
Also used : MetadataIdentifier(org.apache.dubbo.metadata.report.identifier.MetadataIdentifier) ServiceMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier) SubscriberMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier) GetResponse(io.etcd.jetcd.kv.GetResponse) Test(org.junit.jupiter.api.Test)

Example 10 with GetResponse

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));
}
Also used : Cmp(io.etcd.jetcd.op.Cmp) Txn(io.etcd.jetcd.Txn) TxnResponse(io.etcd.jetcd.kv.TxnResponse) GetResponse(io.etcd.jetcd.kv.GetResponse) ByteSequence(io.etcd.jetcd.ByteSequence) Test(org.junit.jupiter.api.Test)

Aggregations

GetResponse (io.etcd.jetcd.kv.GetResponse)21 Test (org.junit.jupiter.api.Test)16 ByteSequence (io.etcd.jetcd.ByteSequence)7 TxnResponse (io.etcd.jetcd.kv.TxnResponse)4 Cmp (io.etcd.jetcd.op.Cmp)4 URL (org.apache.dubbo.common.URL)4 ServiceMetadataIdentifier (org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier)4 SubscriberMetadataIdentifier (org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier)4 Gson (com.google.gson.Gson)3 Txn (io.etcd.jetcd.Txn)3 TestUtil.randomString (io.etcd.jetcd.impl.TestUtil.randomString)3 DeleteResponse (io.etcd.jetcd.kv.DeleteResponse)3 PutResponse (io.etcd.jetcd.kv.PutResponse)2 Op (io.etcd.jetcd.op.Op)2 GetOption (io.etcd.jetcd.options.GetOption)2 MetadataIdentifier (org.apache.dubbo.metadata.report.identifier.MetadataIdentifier)2 Client (io.etcd.jetcd.Client)1 KeyValue (io.etcd.jetcd.KeyValue)1 DeleteOption (io.etcd.jetcd.options.DeleteOption)1 Errors (io.etcd.jetcd.support.Errors)1