use of org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier 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());
}
use of org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier in project dubbo by alibaba.
the class EtcdMetadataReportTest method testDoGetExportedURLs.
@Test
public void testDoGetExportedURLs() 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);
List<String> r = etcdMetadataReport.doGetExportedURLs(serviceMetadataIdentifier);
Assertions.assertTrue(r.size() == 1);
String fileContent = r.get(0);
Assertions.assertNotNull(fileContent);
Assertions.assertEquals(fileContent, url.toFullString());
}
use of org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier 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));
}
}
Aggregations