Search in sources :

Example 1 with InstanceParameter

use of com.tencent.polaris.test.mock.discovery.NamingService.InstanceParameter in project polaris-java by polarismesh.

the class CircuitBreakerTest method before.

@Before
public void before() {
    try {
        namingServer = NamingServer.startNamingServer(10081);
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    }
    ServiceKey serviceKey = new ServiceKey(NAMESPACE_TEST, SERVICE_CIRCUIT_BREAKER);
    InstanceParameter parameter = new InstanceParameter();
    parameter.setHealthy(true);
    parameter.setIsolated(false);
    parameter.setWeight(100);
    namingServer.getNamingService().batchAddInstances(serviceKey, 10010, MAX_COUNT, parameter);
}
Also used : InstanceParameter(com.tencent.polaris.test.mock.discovery.NamingService.InstanceParameter) ServiceKey(com.tencent.polaris.api.pojo.ServiceKey) IOException(java.io.IOException) Before(org.junit.Before)

Example 2 with InstanceParameter

use of com.tencent.polaris.test.mock.discovery.NamingService.InstanceParameter in project polaris-java by polarismesh.

the class ServiceDynamicRuleTest method before.

@Before
public void before() {
    try {
        namingServer = NamingServer.startNamingServer(10081);
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    }
    ServiceKey serviceKey = new ServiceKey(NAMESPACE_PRODUCTION, RULE_ROUTER_SERVICE);
    InstanceParameter parameter = new InstanceParameter();
    parameter.setWeight(100);
    parameter.setHealthy(true);
    parameter.setIsolated(false);
    Map<String, String> metadata = new HashMap<>();
    metadata.put("env", "base");
    parameter.setMetadata(metadata);
    namingServer.getNamingService().batchAddInstances(serviceKey, 10001, MATCH_META_COUNT, parameter);
    parameter.setMetadata(null);
    namingServer.getNamingService().batchAddInstances(serviceKey, 10010, 8, parameter);
    Map<String, MatchString> data = new HashMap<>();
    data.put("env", MatchString.newBuilder().setType(MatchStringType.EXACT).setValue(StringValue.newBuilder().setValue("base").build()).build());
    Map<String, MatchString> srcData = new HashMap<>();
    srcData.put("uid", MatchString.newBuilder().setType(MatchStringType.EXACT).setValue(StringValue.newBuilder().setValue("144115217417489762").build()).build());
    Routing routing = Routing.newBuilder().addInbounds(Route.newBuilder().addDestinations(Destination.newBuilder().putAllMetadata(data).setWeight(UInt32Value.newBuilder().setValue(100).build()).build()).addSources(Source.newBuilder().setNamespace(StringValue.newBuilder().setValue("*").build()).setService(StringValue.newBuilder().setValue("*").build()).putAllMetadata(srcData).build()).build()).build();
    namingServer.getNamingService().setRouting(serviceKey, routing);
}
Also used : MatchString(com.tencent.polaris.client.pb.ModelProto.MatchString) HashMap(java.util.HashMap) InstanceParameter(com.tencent.polaris.test.mock.discovery.NamingService.InstanceParameter) ServiceKey(com.tencent.polaris.api.pojo.ServiceKey) Routing(com.tencent.polaris.client.pb.RoutingProto.Routing) IOException(java.io.IOException) MatchString(com.tencent.polaris.client.pb.ModelProto.MatchString) Before(org.junit.Before)

Example 3 with InstanceParameter

use of com.tencent.polaris.test.mock.discovery.NamingService.InstanceParameter in project polaris-java by polarismesh.

the class ServiceExpireTest method before.

@Before
public void before() {
    try {
        namingServer = NamingServer.startNamingServer(10081);
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    }
    InstanceParameter parameter = new InstanceParameter();
    parameter.setHealthy(true);
    parameter.setIsolated(false);
    parameter.setWeight(100);
    for (int i = 0; i < 2; i++) {
        namingServer.getNamingService().batchAddInstances(new ServiceKey(NAMESPACE_TEST, SERVICES[i]), 10100, 10, parameter);
    }
}
Also used : InstanceParameter(com.tencent.polaris.test.mock.discovery.NamingService.InstanceParameter) ServiceKey(com.tencent.polaris.api.pojo.ServiceKey) IOException(java.io.IOException) Before(org.junit.Before)

Example 4 with InstanceParameter

use of com.tencent.polaris.test.mock.discovery.NamingService.InstanceParameter in project polaris-java by polarismesh.

the class ConsumerTest method testGetNotExistsService.

@Test
public void testGetNotExistsService() {
    Configuration configuration = TestUtils.configWithEnvAddress();
    try (ConsumerAPI consumerAPI = DiscoveryAPIFactory.createConsumerAPIByConfig(configuration)) {
        for (int i = 0; i < 10; i++) {
            GetOneInstanceRequest request = new GetOneInstanceRequest();
            request.setNamespace(NAMESPACE_TEST);
            request.setService(NOT_EXISTS_SERVICE);
            InstancesResponse oneInstance = consumerAPI.getOneInstance(request);
            Assert.assertFalse(oneInstance.isServiceExist());
        }
        // 把实例加上去,可以重新获取
        InstanceParameter parameter = new InstanceParameter();
        parameter.setHealthy(true);
        parameter.setIsolated(false);
        parameter.setWeight(100);
        namingServer.getNamingService().batchAddInstances(new ServiceKey(NAMESPACE_TEST, NOT_EXISTS_SERVICE), 10100, 10, parameter);
        GetOneInstanceRequest request = new GetOneInstanceRequest();
        request.setNamespace(NAMESPACE_TEST);
        request.setService(NOT_EXISTS_SERVICE);
        InstancesResponse oneInstance = consumerAPI.getOneInstance(request);
        Assert.assertEquals(1, oneInstance.getInstances().length);
    }
}
Also used : Configuration(com.tencent.polaris.api.config.Configuration) GetOneInstanceRequest(com.tencent.polaris.api.rpc.GetOneInstanceRequest) InstanceParameter(com.tencent.polaris.test.mock.discovery.NamingService.InstanceParameter) ServiceKey(com.tencent.polaris.api.pojo.ServiceKey) ConsumerAPI(com.tencent.polaris.api.core.ConsumerAPI) InstancesResponse(com.tencent.polaris.api.rpc.InstancesResponse) Test(org.junit.Test)

Example 5 with InstanceParameter

use of com.tencent.polaris.test.mock.discovery.NamingService.InstanceParameter in project polaris-java by polarismesh.

the class ConsumerTest method before.

@Before
public void before() {
    try {
        namingServer = NamingServer.startNamingServer(10081);
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    }
    for (ValidParam validParam : validParams.values()) {
        InstanceParameter instanceParameter = new InstanceParameter();
        instanceParameter.setHealthy(true);
        instanceParameter.setIsolated(false);
        instanceParameter.setWeight(100);
        ServiceKey serviceKey = new ServiceKey(NAMESPACE_TEST, validParam.getServiceName());
        List<Node> nodes = namingServer.getNamingService().batchAddInstances(serviceKey, 10000, validParam.getCountAll(), instanceParameter);
        if (validParam.getCountAll() > validParam.getCountHealth()) {
            int abnormalCount = validParam.getCountAll() - validParam.getCountHealth();
            int unhealthyCount = abnormalCount / 2;
            int isolatedCount = abnormalCount - unhealthyCount;
            for (int i = 0; i < unhealthyCount; i++) {
                namingServer.getNamingService().setInstanceHealthyStatus(serviceKey, nodes.get(i), false, null, null);
            }
            for (int i = 0; i < isolatedCount; i++) {
                namingServer.getNamingService().setInstanceHealthyStatus(serviceKey, nodes.get(nodes.size() - 1 - i), null, true, null);
            }
        }
        if (validParam.getCountAll() > validParam.getCountHasWeight()) {
            int weightZeroCount = validParam.getCountAll() - validParam.getCountHasWeight();
            for (int i = 0; i < weightZeroCount; i++) {
                namingServer.getNamingService().setInstanceHealthyStatus(serviceKey, nodes.get(i), null, null, 0);
            }
        }
    }
}
Also used : 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)

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