Search in sources :

Example 6 with InstanceParameter

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);
}
Also used : HashMap(java.util.HashMap) InstanceParameter(com.tencent.polaris.test.mock.discovery.NamingService.InstanceParameter) Node(com.tencent.polaris.client.pojo.Node) ServiceKey(com.tencent.polaris.api.pojo.ServiceKey) IOException(java.io.IOException) Before(org.junit.Before)

Example 7 with InstanceParameter

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;
}
Also used : Node(com.tencent.polaris.client.pojo.Node) InstanceParameter(com.tencent.polaris.test.mock.discovery.NamingService.InstanceParameter) ServiceKey(com.tencent.polaris.api.pojo.ServiceKey)

Aggregations

ServiceKey (com.tencent.polaris.api.pojo.ServiceKey)7 InstanceParameter (com.tencent.polaris.test.mock.discovery.NamingService.InstanceParameter)7 IOException (java.io.IOException)5 Before (org.junit.Before)5 Node (com.tencent.polaris.client.pojo.Node)3 HashMap (java.util.HashMap)2 Configuration (com.tencent.polaris.api.config.Configuration)1 ConsumerAPI (com.tencent.polaris.api.core.ConsumerAPI)1 GetOneInstanceRequest (com.tencent.polaris.api.rpc.GetOneInstanceRequest)1 InstancesResponse (com.tencent.polaris.api.rpc.InstancesResponse)1 MatchString (com.tencent.polaris.client.pb.ModelProto.MatchString)1 Routing (com.tencent.polaris.client.pb.RoutingProto.Routing)1 Test (org.junit.Test)1