Search in sources :

Example 16 with GetResponse

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

the class KVNamespaceTest method assertExistentKVs.

private static void assertExistentKVs(KV kvClient, ByteSequence key, ByteSequence end, List<TestKeyValue> expectedKVs) throws Exception {
    CompletableFuture<GetResponse> getFuture = kvClient.get(key, GetOption.newBuilder().withRange(end).build());
    GetResponse getResponse = getFuture.get();
    assertThat(getResponse.getKvs().size()).isEqualTo(expectedKVs.size());
    for (KeyValue keyValue : getResponse.getKvs()) {
        boolean exist = false;
        for (TestKeyValue expectedKV : expectedKVs) {
            if (expectedKV.key.equals(keyValue.getKey())) {
                exist = true;
                assertThat(keyValue.getValue()).isEqualTo(expectedKV.value);
                break;
            }
        }
        assertThat(exist).isTrue();
    }
}
Also used : KeyValue(io.etcd.jetcd.KeyValue) GetResponse(io.etcd.jetcd.kv.GetResponse)

Example 17 with GetResponse

use of io.etcd.jetcd.kv.GetResponse in project dubbo by alibaba.

the class EtcdMetadataReportTest method testDoSaveMetadata.

@Test
public void testDoSaveMetadata() throws ExecutionException, InterruptedException {
    String version = "1.0.0";
    String group = null;
    String application = "etc-metadata-report-consumer-test";
    String revision = "90980";
    String protocol = "xxx";
    URL url = generateURL(TEST_SERVICE, version, group, application);
    ServiceMetadataIdentifier serviceMetadataIdentifier = new ServiceMetadataIdentifier(TEST_SERVICE, version, group, "provider", revision, protocol);
    etcdMetadataReport.doSaveMetadata(serviceMetadataIdentifier, url);
    CompletableFuture<GetResponse> response = etcdClientForTest.getKVClient().get(ByteSequence.from(etcdMetadataReport.getNodeKey(serviceMetadataIdentifier), StandardCharsets.UTF_8));
    String fileContent = response.get().getKvs().get(0).getValue().toString(StandardCharsets.UTF_8);
    Assertions.assertNotNull(fileContent);
    Assertions.assertEquals(fileContent, URL.encode(url.toFullString()));
}
Also used : ServiceMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier) GetResponse(io.etcd.jetcd.kv.GetResponse) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 18 with GetResponse

use of io.etcd.jetcd.kv.GetResponse in project dubbo by alibaba.

the class EtcdMetadataReportTest method testDoGetSubscribedURLs.

@Test
public void testDoGetSubscribedURLs() throws ExecutionException, InterruptedException {
    String version = "1.0.0";
    String group = null;
    String application = "etc-metadata-report-consumer-test";
    String revision = "90980";
    String protocol = "xxx";
    URL url = generateURL(TEST_SERVICE, version, group, application);
    SubscriberMetadataIdentifier subscriberMetadataIdentifier = new SubscriberMetadataIdentifier(application, revision);
    Gson gson = new Gson();
    String r = gson.toJson(Arrays.asList(url));
    etcdMetadataReport.doSaveSubscriberData(subscriberMetadataIdentifier, r);
    CompletableFuture<GetResponse> response = etcdClientForTest.getKVClient().get(ByteSequence.from(etcdMetadataReport.getNodeKey(subscriberMetadataIdentifier), StandardCharsets.UTF_8));
    String fileContent = etcdMetadataReport.doGetSubscribedURLs(subscriberMetadataIdentifier);
    Assertions.assertNotNull(fileContent);
    Assertions.assertEquals(fileContent, r);
}
Also used : SubscriberMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier) Gson(com.google.gson.Gson) GetResponse(io.etcd.jetcd.kv.GetResponse) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 19 with GetResponse

use of io.etcd.jetcd.kv.GetResponse in project dubbo by alibaba.

the class EtcdMetadataReportTest method testDoRemoveMetadata.

@Test
public void testDoRemoveMetadata() throws ExecutionException, InterruptedException {
    String version = "1.0.0";
    String group = null;
    String application = "etc-metadata-report-consumer-test";
    String revision = "90980";
    String protocol = "xxx";
    URL url = generateURL(TEST_SERVICE, version, group, application);
    ServiceMetadataIdentifier serviceMetadataIdentifier = new ServiceMetadataIdentifier(TEST_SERVICE, version, group, "provider", revision, protocol);
    etcdMetadataReport.doSaveMetadata(serviceMetadataIdentifier, url);
    CompletableFuture<GetResponse> response = etcdClientForTest.getKVClient().get(ByteSequence.from(etcdMetadataReport.getNodeKey(serviceMetadataIdentifier), StandardCharsets.UTF_8));
    String fileContent = response.get().getKvs().get(0).getValue().toString(StandardCharsets.UTF_8);
    Assertions.assertNotNull(fileContent);
    etcdMetadataReport.doRemoveMetadata(serviceMetadataIdentifier);
    response = etcdClientForTest.getKVClient().get(ByteSequence.from(etcdMetadataReport.getNodeKey(serviceMetadataIdentifier), StandardCharsets.UTF_8));
    Assertions.assertTrue(response.get().getKvs().isEmpty());
}
Also used : ServiceMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier) GetResponse(io.etcd.jetcd.kv.GetResponse) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 20 with GetResponse

use of io.etcd.jetcd.kv.GetResponse in project dubbo by alibaba.

the class EtcdMetadataReportTest method testDoSaveSubscriberData.

@Test
public void testDoSaveSubscriberData() throws ExecutionException, InterruptedException {
    String version = "1.0.0";
    String group = null;
    String application = "etc-metadata-report-consumer-test";
    String revision = "90980";
    String protocol = "xxx";
    URL url = generateURL(TEST_SERVICE, version, group, application);
    SubscriberMetadataIdentifier subscriberMetadataIdentifier = new SubscriberMetadataIdentifier(application, revision);
    Gson gson = new Gson();
    String r = gson.toJson(Arrays.asList(url));
    etcdMetadataReport.doSaveSubscriberData(subscriberMetadataIdentifier, r);
    CompletableFuture<GetResponse> response = etcdClientForTest.getKVClient().get(ByteSequence.from(etcdMetadataReport.getNodeKey(subscriberMetadataIdentifier), StandardCharsets.UTF_8));
    String fileContent = response.get().getKvs().get(0).getValue().toString(StandardCharsets.UTF_8);
    Assertions.assertNotNull(fileContent);
    Assertions.assertEquals(fileContent, r);
}
Also used : SubscriberMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier) Gson(com.google.gson.Gson) GetResponse(io.etcd.jetcd.kv.GetResponse) URL(org.apache.dubbo.common.URL) 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