use of com.tencent.polaris.api.config.Configuration in project polaris-java by polarismesh.
the class ConsumerTest method commonTestSyncGetOneInstance.
public void commonTestSyncGetOneInstance(Operation operation) {
ValidParam validParam = validParams.get(operation);
Configuration configuration = TestUtils.configWithEnvAddress();
try (ConsumerAPI consumerAPI = DiscoveryAPIFactory.createConsumerAPIByConfig(configuration)) {
for (int i = 0; i < ITERATE_COUNT; i++) {
GetOneInstanceRequest request = new GetOneInstanceRequest();
request.setNamespace(NAMESPACE_TEST);
request.setService(validParam.getServiceName());
InstancesResponse instancesResponse = consumerAPI.getOneInstance(request);
Assert.assertEquals(1, instancesResponse.getInstances().length);
Instance instance = instancesResponse.getInstances()[0];
Assert.assertTrue(instance.isHealthy());
Assert.assertFalse(instance.isIsolated());
Assert.assertEquals(100, instance.getWeight());
}
}
}
use of com.tencent.polaris.api.config.Configuration in project polaris-java by polarismesh.
the class GetServicesTest method testRoundTrip.
@Test
public void testRoundTrip() {
Configuration configuration = TestUtils.configWithEnvAddress();
try (ConsumerAPI consumerAPI = DiscoveryAPIFactory.createConsumerAPIByConfig(configuration)) {
for (int i = 0; i < 5; i++) {
namingServer.getNamingService().addService(new ServiceKey(NAMESPACE_TEST, "get_services_test_" + i));
}
ServicesResponse response = consumerAPI.getServices(GetServicesRequest.builder().namespace(NAMESPACE_TEST).build());
Assert.assertFalse(CollectionUtils.isEmpty(response.getServices()));
Assert.assertEquals(5, response.getServices().size());
}
}
use of com.tencent.polaris.api.config.Configuration in project polaris-java by polarismesh.
the class MetadataRouterTest method testFailoverNoneScene.
@Test
public void testFailoverNoneScene() {
Configuration configuration = TestUtils.configWithEnvAddress();
try (ConsumerAPI consumer = DiscoveryAPIFactory.createConsumerAPIByConfig(configuration)) {
// 该服务下有四个实例,只有一个80端口实例满足metadata路由,但是不健康,降级策略采用默认不降级
for (int i = 0; i < 10; i++) {
GetOneInstanceRequest getInstances2 = new GetOneInstanceRequest();
getInstances2.setNamespace(NAMESPACE_PRODUCTION);
getInstances2.setService(METADATA_SERVICE);
Map<String, String> map = new HashMap<>();
map.put("Env-set", "1-1");
getInstances2.setMetadata(map);
InstancesResponse ins = null;
try {
ins = consumer.getOneInstance(getInstances2);
} catch (PolarisException e) {
Assert.assertEquals(ErrorCode.METADATA_MISMATCH, e.getCode());
}
}
}
}
use of com.tencent.polaris.api.config.Configuration in project polaris-java by polarismesh.
the class MetadataRouterTest method testFailoverAllScene.
@Test
public void testFailoverAllScene() {
Configuration configuration = TestUtils.configWithEnvAddress();
try (ConsumerAPI consumer = DiscoveryAPIFactory.createConsumerAPIByConfig(configuration)) {
// 但是不健康,降级策略采用默认返回所有健康实例,其中80端口实例为不健康,故80端口的实例不会返回
for (int i = 0; i < 10; i++) {
GetOneInstanceRequest getInstances2 = new GetOneInstanceRequest();
getInstances2.setNamespace("Production");
getInstances2.setService(METADATA_SERVICE);
Map<String, String> map = new HashMap<>();
map.put("Env-set", "1-1");
getInstances2.setMetadata(map);
getInstances2.setMetadataFailoverType(MetadataFailoverType.METADATAFAILOVERALL);
InstancesResponse ins = null;
try {
ins = consumer.getOneInstance(getInstances2);
} catch (PolarisException e) {
e.printStackTrace();
}
Assert.assertNotEquals(80, ins.getInstances()[0].getPort());
}
}
}
use of com.tencent.polaris.api.config.Configuration in project polaris-java by polarismesh.
the class MetadataRouterTest method testFailoverNotKeyScene.
@Test
public void testFailoverNotKeyScene() {
// 传入Env-set:1-1 ,应该返回第4个实例,因为前三个都包含Env-set这个key
Configuration configuration = TestUtils.configWithEnvAddress();
try (ConsumerAPI consumer = DiscoveryAPIFactory.createConsumerAPIByConfig(configuration)) {
for (int i = 0; i < 10; i++) {
GetOneInstanceRequest getInstances2 = new GetOneInstanceRequest();
getInstances2.setNamespace("Production");
getInstances2.setService(METADATA_SERVICE);
Map<String, String> map = new HashMap<>();
map.put("Env-set", "1-1");
getInstances2.setMetadata(map);
// TODO: 通过配置文件来设置该配置
getInstances2.setMetadataFailoverType(MetadataFailoverType.METADATAFAILOVERNOTKEY);
InstancesResponse ins = null;
try {
ins = consumer.getOneInstance(getInstances2);
} catch (PolarisException e) {
Assert.fail(e.getMessage());
}
Assert.assertEquals(90, ins.getInstances()[0].getPort());
Assert.assertEquals("127.0.0.1", ins.getInstances()[0].getHost());
}
}
}
Aggregations