use of org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier in project dubbo by alibaba.
the class ZookeeperMetadataReportTest method testDoRemoveMetadata.
@Test
public void testDoRemoveMetadata() throws ExecutionException, InterruptedException {
String interfaceName = "org.apache.dubbo.metadata.store.zookeeper.ZookeeperMetadataReport4TstService";
String version = "1.0.0";
String group = null;
String application = "etc-metadata-report-consumer-test";
String revision = "90980";
String protocol = "xxx";
URL url = generateURL(interfaceName, version, group, application);
ServiceMetadataIdentifier serviceMetadataIdentifier = new ServiceMetadataIdentifier(interfaceName, version, group, "provider", revision, protocol);
zookeeperMetadataReport.doSaveMetadata(serviceMetadataIdentifier, url);
String fileContent = zookeeperMetadataReport.zkClient.getContent(zookeeperMetadataReport.getNodePath(serviceMetadataIdentifier));
Assertions.assertNotNull(fileContent);
zookeeperMetadataReport.doRemoveMetadata(serviceMetadataIdentifier);
fileContent = zookeeperMetadataReport.zkClient.getContent(zookeeperMetadataReport.getNodePath(serviceMetadataIdentifier));
Assertions.assertNull(fileContent);
}
use of org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier in project dubbo by alibaba.
the class ZookeeperMetadataReportTest method testDoSaveMetadata.
@Test
public void testDoSaveMetadata() throws ExecutionException, InterruptedException {
String interfaceName = "org.apache.dubbo.metadata.store.zookeeper.ZookeeperMetadataReport4TstService";
String version = "1.0.0";
String group = null;
String application = "etc-metadata-report-consumer-test";
String revision = "90980";
String protocol = "xxx";
URL url = generateURL(interfaceName, version, group, application);
ServiceMetadataIdentifier serviceMetadataIdentifier = new ServiceMetadataIdentifier(interfaceName, version, group, "provider", revision, protocol);
zookeeperMetadataReport.doSaveMetadata(serviceMetadataIdentifier, url);
String fileContent = zookeeperMetadataReport.zkClient.getContent(zookeeperMetadataReport.getNodePath(serviceMetadataIdentifier));
Assertions.assertNotNull(fileContent);
Assertions.assertEquals(fileContent, URL.encode(url.toFullString()));
}
use of org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier in project dubbo by alibaba.
the class ZookeeperMetadataReportTest method testDoGetExportedURLs.
@Test
public void testDoGetExportedURLs() throws ExecutionException, InterruptedException {
String interfaceName = "org.apache.dubbo.metadata.store.zookeeper.ZookeeperMetadataReport4TstService";
String version = "1.0.0";
String group = null;
String application = "etc-metadata-report-consumer-test";
String revision = "90980";
String protocol = "xxx";
URL url = generateURL(interfaceName, version, group, application);
ServiceMetadataIdentifier serviceMetadataIdentifier = new ServiceMetadataIdentifier(interfaceName, version, group, "provider", revision, protocol);
zookeeperMetadataReport.doSaveMetadata(serviceMetadataIdentifier, url);
List<String> r = zookeeperMetadataReport.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 testLocalDataCenterMetadataReport.
@Test
public void testLocalDataCenterMetadataReport() {
URL url = mockURL.addParameter("strategy", "local");
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());
MetadataReport localReport = null, failoverReport = null;
for (FailoverMetadataReport.MetadataReportHolder holder : report.getProxyReports()) {
if (holder.url.getBackupAddress().contains(url.getAddress())) {
localReport = holder.report;
} else {
failoverReport = holder.report;
}
}
Assertions.assertNotNull(localReport);
Assertions.assertNotNull(failoverReport);
MetadataIdentifier identifier = new MetadataIdentifier("helloService", null, null, null, "test");
ServiceDefinition definition = new ServiceDefinition();
definition.setCanonicalName("helloService");
report.storeProviderMetadata(identifier, definition);
// assert local metadata report write already.
Assertions.assertNotNull(report.getServiceDefinition(identifier));
Assertions.assertNotNull(localReport.getServiceDefinition(identifier));
Assertions.assertNull(failoverReport.getServiceDefinition(identifier));
HashMap parameterMap = new HashMap();
report.storeConsumerMetadata(identifier, parameterMap);
// assert local metadata report write already.
Assertions.assertEquals(parameterMap, ((MockMetadataReport) localReport).consumerMetadata.get(identifier));
Assertions.assertNotEquals(parameterMap, ((MockMetadataReport) failoverReport).consumerMetadata.get(identifier));
SubscriberMetadataIdentifier subscribeIdentifier = new SubscriberMetadataIdentifier("test", "1.0");
MetadataInfo metadataInfo = new MetadataInfo(subscribeIdentifier.getApplication(), subscribeIdentifier.getRevision(), null);
report.publishAppMetadata(subscribeIdentifier, metadataInfo);
// assert all metadata report write already.
Assertions.assertEquals(metadataInfo, report.getAppMetadata(subscribeIdentifier, null));
Assertions.assertEquals(metadataInfo, localReport.getAppMetadata(subscribeIdentifier, null));
Assertions.assertNotEquals(metadataInfo, failoverReport.getAppMetadata(subscribeIdentifier, null));
report.registerServiceAppMapping("helloService", "test", null);
Set<String> appNames = report.getServiceAppMapping("helloService", null, null);
// assert local metadata report write already.
Assertions.assertEquals(appNames, report.getServiceAppMapping("helloService", null, null));
Assertions.assertEquals(appNames, localReport.getServiceAppMapping("helloService", null, null));
Assertions.assertNotEquals(appNames, failoverReport.getServiceAppMapping("helloService", null, null));
ServiceMetadataIdentifier serviceIdentifier = new ServiceMetadataIdentifier("helloService", null, null, null, "1.0", "dubbo");
report.saveServiceMetadata(serviceIdentifier, url);
// assert local metadata report write already.
Assertions.assertNotNull(report.getExportedURLs(serviceIdentifier));
Assertions.assertNotNull(localReport.getExportedURLs(serviceIdentifier));
Assertions.assertNull(failoverReport.getExportedURLs(serviceIdentifier));
Set<String> urls = new HashSet<>();
urls.add(url.toFullString());
report.saveSubscribedData(subscribeIdentifier, urls);
// assert local metadata report write already.
Assertions.assertEquals(new ArrayList<>(urls), report.getSubscribedURLs(subscribeIdentifier));
Assertions.assertEquals(new ArrayList<>(urls), localReport.getSubscribedURLs(subscribeIdentifier));
Assertions.assertNotEquals(new ArrayList<>(urls), failoverReport.getSubscribedURLs(subscribeIdentifier));
}
use of org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier 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()));
}
Aggregations