use of com.tencent.polaris.test.mock.discovery.NamingService.InstanceParameter in project polaris-java by polarismesh.
the class MetadataRouterTest method before.
@Before
public void before() {
try {
namingServer = NamingServer.startNamingServer(10081);
} catch (IOException e) {
Assert.fail(e.getMessage());
}
/**
* 该服务下有四个实例
* 1. 127.0.0.1:80 不健康 Env-set:1-0
* 2. 127.0.0.1:70 健康 Env-set:1-0
* 3. 127.0.0.1:100 健康 Env-set:1-0
* 4. 127.0.0.1:90 健康
*/
ServiceKey serviceKey = new ServiceKey(NAMESPACE_PRODUCTION, METADATA_SERVICE);
InstanceParameter parameter = new InstanceParameter();
parameter.setWeight(100);
parameter.setHealthy(false);
parameter.setIsolated(false);
Map<String, String> metadata = new HashMap<>();
metadata.put("Env-set", "1-0");
parameter.setMetadata(metadata);
namingServer.getNamingService().addInstance(serviceKey, new Node("127.0.0.1", 80), parameter);
parameter.setHealthy(true);
namingServer.getNamingService().addInstance(serviceKey, new Node("127.0.0.1", 70), parameter);
namingServer.getNamingService().addInstance(serviceKey, new Node("127.0.0.1", 100), parameter);
parameter.setMetadata(null);
namingServer.getNamingService().addInstance(serviceKey, new Node("127.0.0.1", 90), parameter);
/**
* 该服务下有两个实例
* 1. 127.0.0.1:80 不健康 Env-set:1-0
* 2. 127.0.0.1:81 不健康
*/
ServiceKey serviceKey1 = new ServiceKey(NAMESPACE_PRODUCTION, METADATA_SERVICE_1);
parameter.setMetadata(metadata);
parameter.setHealthy(false);
namingServer.getNamingService().addInstance(serviceKey1, new Node("127.0.0.1", 80), parameter);
parameter.setMetadata(null);
namingServer.getNamingService().addInstance(serviceKey1, new Node("127.0.0.1", 81), parameter);
}
use of com.tencent.polaris.test.mock.discovery.NamingService.InstanceParameter in project polaris-java by polarismesh.
the class NamingServer method startNamingServer.
public static NamingServer startNamingServer(int port) throws IOException {
NamingServer namingServer = new NamingServer(port);
namingServer.start();
Node node = new Node("127.0.0.1", port);
InstanceParameter parameter = new InstanceParameter();
parameter.setHealthy(true);
parameter.setIsolated(false);
parameter.setProtocol("grpc");
parameter.setWeight(100);
// 注册系统集群地址
namingServer.getNamingService().addInstance(new ServiceKey("Polaris", "polaris.discover"), node, parameter);
namingServer.getNamingService().addInstance(new ServiceKey("Polaris", "polaris.healthcheck"), node, parameter);
return namingServer;
}
Aggregations