Search in sources :

Example 6 with SubscriberMetadataIdentifier

use of org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier 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 7 with SubscriberMetadataIdentifier

use of org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier 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)

Example 8 with SubscriberMetadataIdentifier

use of org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier in project dubbo by alibaba.

the class FailoverMetadataReportTest method testReadWriteAllMetadataReport.

@Test
public void testReadWriteAllMetadataReport() {
    URL url = mockURL.addParameter("strategy", "all");
    FailoverMetadataReport report = getFailoverReport(url);
    Assertions.assertNotNull(report.getProxyReports(), "metadata reports should not be null.");
    Assertions.assertEquals(2, report.getProxyReports().size(), "expect 2 metadata report, actual " + report.getProxyReports().size());
    MetadataIdentifier identifier = new MetadataIdentifier("helloService", null, null, null, "test");
    ServiceDefinition definition = new ServiceDefinition();
    definition.setCanonicalName("helloService");
    report.storeProviderMetadata(identifier, definition);
    Assertions.assertNotNull(report.getServiceDefinition(identifier));
    // assert all metadata report write already.
    for (FailoverMetadataReport.MetadataReportHolder holder : report.getProxyReports()) {
        Assertions.assertNotNull(holder.report.getServiceDefinition(identifier));
    }
    HashMap parameterMap = new HashMap();
    report.storeConsumerMetadata(identifier, parameterMap);
    // assert all metadata report write already.
    for (FailoverMetadataReport.MetadataReportHolder holder : report.getProxyReports()) {
        Assertions.assertEquals(parameterMap, ((MockMetadataReport) holder.report).consumerMetadata.get(identifier));
    }
    SubscriberMetadataIdentifier subscribeIdentifier = new SubscriberMetadataIdentifier("test", "1.0");
    MetadataInfo metadataInfo = new MetadataInfo(subscribeIdentifier.getApplication(), subscribeIdentifier.getRevision(), null);
    report.publishAppMetadata(subscribeIdentifier, metadataInfo);
    Assertions.assertEquals(metadataInfo, report.getAppMetadata(subscribeIdentifier, null));
    // assert all metadata report write already.
    for (FailoverMetadataReport.MetadataReportHolder holder : report.getProxyReports()) {
        Assertions.assertEquals(metadataInfo, holder.report.getAppMetadata(subscribeIdentifier, null));
    }
    report.registerServiceAppMapping("helloService", "test", null);
    Set<String> appNames = report.getServiceAppMapping("helloService", null, null);
    Assertions.assertEquals(appNames, report.getServiceAppMapping("helloService", null, null));
    // assert all metadata report write already.
    for (FailoverMetadataReport.MetadataReportHolder holder : report.getProxyReports()) {
        Assertions.assertEquals(appNames, holder.report.getServiceAppMapping("helloService", null, null));
    }
    ServiceMetadataIdentifier serviceIdentifier = new ServiceMetadataIdentifier("helloService", null, null, null, "1.0", "dubbo");
    report.saveServiceMetadata(serviceIdentifier, url);
    Assertions.assertNotNull(report.getExportedURLs(serviceIdentifier));
    // assert all metadata report write already.
    for (FailoverMetadataReport.MetadataReportHolder holder : report.getProxyReports()) {
        Assertions.assertNotNull(holder.report.getExportedURLs(serviceIdentifier));
    }
    report.saveSubscribedData(subscribeIdentifier, new HashSet<>());
    Assertions.assertNotNull(report.getSubscribedURLs(subscribeIdentifier));
    // assert all metadata report write already.
    for (FailoverMetadataReport.MetadataReportHolder holder : report.getProxyReports()) {
        Assertions.assertNotNull(holder.report.getSubscribedURLs(subscribeIdentifier));
    }
}
Also used : MetadataInfo(org.apache.dubbo.metadata.MetadataInfo) HashMap(java.util.HashMap) URL(org.apache.dubbo.common.URL) ServiceMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier) SubscriberMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier) MetadataIdentifier(org.apache.dubbo.metadata.report.identifier.MetadataIdentifier) SubscriberMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier) ServiceMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier) ServiceDefinition(org.apache.dubbo.metadata.definition.model.ServiceDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

SubscriberMetadataIdentifier (org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier)8 URL (org.apache.dubbo.common.URL)6 Test (org.junit.jupiter.api.Test)6 Gson (com.google.gson.Gson)4 MetadataInfo (org.apache.dubbo.metadata.MetadataInfo)3 MetadataReport (org.apache.dubbo.metadata.report.MetadataReport)3 GetResponse (io.etcd.jetcd.kv.GetResponse)2 HashMap (java.util.HashMap)2 ServiceDefinition (org.apache.dubbo.metadata.definition.model.ServiceDefinition)2 MetadataIdentifier (org.apache.dubbo.metadata.report.identifier.MetadataIdentifier)2 ServiceMetadataIdentifier (org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier)2 HashSet (java.util.HashSet)1