From 5cc9a5cf5d33f4c58e8d6b8c1a1520f4871bff71 Mon Sep 17 00:00:00 2001 From: lepdou Date: Tue, 28 Jun 2022 20:25:56 +0800 Subject: [PATCH] optimize polaris load balancer test code format (#333) --- CHANGELOG.md | 1 + .../loadbalancer/PolarisLoadBalancerTest.java | 16 +--------------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f98236df..812cb131f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/spring-cloud-tencent-polaris-loadbalancer/src/test/java/com/tencent/cloud/polaris/loadbalancer/PolarisLoadBalancerTest.java b/spring-cloud-tencent-polaris-loadbalancer/src/test/java/com/tencent/cloud/polaris/loadbalancer/PolarisLoadBalancerTest.java index be8456e2d..e9d8580d3 100644 --- a/spring-cloud-tencent-polaris-loadbalancer/src/test/java/com/tencent/cloud/polaris/loadbalancer/PolarisLoadBalancerTest.java +++ b/spring-cloud-tencent-polaris-loadbalancer/src/test/java/com/tencent/cloud/polaris/loadbalancer/PolarisLoadBalancerTest.java @@ -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 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); } - }