optimize polaris load balancer test code format (#333)

pull/327/head
lepdou 2 years ago committed by GitHub
parent b4e780253d
commit 5cc9a5cf5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,5 +21,6 @@
- [Fix the current limiting effect is that other requests cannot be processed when queuing at a constant speed](https://github.com/Tencent/spring-cloud-tencent/pull/316)
- [Fix config file format misspell](https://github.com/Tencent/spring-cloud-tencent/pull/319)
- [UT: improve test coverage for load balancer unit test](https://github.com/Tencent/spring-cloud-tencent/pull/325)
& [optimize polaris load balancer test code format](https://github.com/Tencent/spring-cloud-tencent/pull/333)
- [feat:Add GitHub action of codecov.yml.](https://github.com/Tencent/spring-cloud-tencent/pull/328)
- [Feature: add spring cloud tencent logo](https://github.com/Tencent/spring-cloud-tencent/pull/329)

@ -60,8 +60,6 @@ import static org.mockito.Mockito.when;
*/
@RunWith(MockitoJUnitRunner.class)
public class PolarisLoadBalancerTest {
private static final String CLIENT_NAME = "polaris-test-server";
private static final String NS = "testNamespace";
private static final String[] HOST_LIST = new String[] {
@ -74,14 +72,11 @@ public class PolarisLoadBalancerTest {
@Mock
private RouterAPI routerAPI;
@Mock
private ConsumerAPI consumerAPI;
@Test
public void testPolarisLoadBalancer() {
//mock consumerAPI
when(consumerAPI.getHealthyInstances(any())).thenReturn(this.assembleInstanceResp());
@ -108,19 +103,14 @@ public class PolarisLoadBalancerTest {
consumerAPI, properties);
String host = balancer.choose(null);
System.out.println(host);
Assert.assertNotNull(host);
Assert.assertEquals("127.0.0.1:8080", host);
}
}
@Test
public void testExtendDiscoveryServiceInstance() {
//mock routerAPI for rule
when(routerAPI.processLoadBalance(any())).thenReturn(assembleProcessLoadBalanceResp());
PolarisWeightedRule rule = new PolarisWeightedRule(routerAPI);
@ -146,17 +136,14 @@ public class PolarisLoadBalancerTest {
consumerAPI, properties);
String host = balancer.choose(null);
System.out.println(host);
Assert.assertEquals("127.0.0.1:8080", host);
}
}
private ServerList<Server> assembleServerList() {
return new StaticServerList<>(Stream.of(HOST_LIST).map(this::convertServer).toArray(Server[]::new));
}
private ProcessLoadBalanceResponse assembleProcessLoadBalanceResp() {
ServiceInstances serviceInstances = assembleServiceInstances();
return new ProcessLoadBalanceResponse(serviceInstances.getInstances().get(0));
@ -183,5 +170,4 @@ public class PolarisLoadBalancerTest {
private Server convertServer(String host) {
return new Server("http", host, 8080);
}
}

Loading…
Cancel
Save