Commit f2803837 by Nepxion

测试用例,增加Route接口

parent 57562afd
...@@ -11,6 +11,7 @@ package com.nepxion.discovery.plugin.example.controller; ...@@ -11,6 +11,7 @@ package com.nepxion.discovery.plugin.example.controller;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -32,10 +33,10 @@ public class DiscoveryController { ...@@ -32,10 +33,10 @@ public class DiscoveryController {
private RestTemplate restTemplate; private RestTemplate restTemplate;
@Value("${" + PluginConstant.SPRING_APPLICATION_NAME + "}") @Value("${" + PluginConstant.SPRING_APPLICATION_NAME + "}")
private String serviceId; private String aServiceId;
@Value("${" + PluginConstant.EUREKA_METADATA_VERSION + "}") @Value("${" + PluginConstant.EUREKA_METADATA_VERSION + "}")
private String eurekaVersion; private String aEurekaVersion;
@RequestMapping(path = "/instances", method = RequestMethod.GET) @RequestMapping(path = "/instances", method = RequestMethod.GET)
public List<ServiceInstance> instances() { public List<ServiceInstance> instances() {
...@@ -51,13 +52,18 @@ public class DiscoveryController { ...@@ -51,13 +52,18 @@ public class DiscoveryController {
List<ServiceInstance> bInstances = instances(); List<ServiceInstance> bInstances = instances();
// 获取C服务的实例列表 // 获取C服务的实例列表
List<ServiceInstance> cInstances = (List<ServiceInstance>) restTemplate.getForEntity("http://discovery-springcloud-example-b/instances", List.class); List<Map<String, ?>> cInstances = restTemplate.getForEntity("http://discovery-springcloud-example-b/instances", List.class).getBody();
String aInfo = aServiceId.toLowerCase() + "[" + aEurekaVersion + "]";
for (ServiceInstance bInstance : bInstances) { for (ServiceInstance bInstance : bInstances) {
String aInfo = serviceId + "[" + eurekaVersion + "]"; String bServiceId = bInstance.getServiceId().toLowerCase();
String bInfo = bInstance.getServiceId() + "[" + bInstance.getMetadata().get(PluginConstant.EUREKA_METADATA_VERSION) + "]"; String bEurekaVersion = bInstance.getMetadata().get(PluginConstant.VERSION);
for (ServiceInstance cInstance : cInstances) { String bInfo = bServiceId + "[" + bEurekaVersion + "]";
String cInfo = cInstance.getServiceId() + "[" + cInstance.getMetadata().get(PluginConstant.EUREKA_METADATA_VERSION) + "]"; for (Map<String, ?> cInstance : cInstances) {
String cServiceId = cInstance.get("serviceId").toString().toLowerCase();
String cEurekaVersion = ((Map<String, String>) cInstance.get("metadata")).get(PluginConstant.VERSION);
String cInfo = cServiceId + "[" + cEurekaVersion + "]";
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
routes.add(stringBuilder.append(aInfo).append("->").append(bInfo).append("->").append(cInfo).toString()); routes.add(stringBuilder.append(aInfo).append("->").append(bInfo).append("->").append(cInfo).toString());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment