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);
}
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);
}
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);
}
}
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);
}
}
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);
}
}
}
}
Aggregations