From b7b0592067f98b48ca6d2c6fe72b01fe7f1f48ec Mon Sep 17 00:00:00 2001 From: Haotian Zhang <928016560@qq.com> Date: Thu, 5 Mar 2026 15:15:50 +0800 Subject: [PATCH] feat: Update config server IP to 127.0.0.1 and adjust tests Signed-off-by: Haotian Zhang <928016560@qq.com> --- CHANGELOG.md | 1 + .../polaris/config/ConfigurationModifier.java | 2 +- .../config/ConfigurationModifierTest.java | 24 +++++++++---------- .../src/main/resources/application.yml | 2 +- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 472b8c435..3a433c1ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,3 +2,4 @@ --- - [feat: Add config address to report client url conversion.](https://github.com/Tencent/spring-cloud-tencent/pull/1795) +- [feat: Update config server IP to 127.0.0.1 and adjust tests.](https://github.com/Tencent/spring-cloud-tencent/pull/1796) diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/ConfigurationModifier.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/ConfigurationModifier.java index 0202486b1..89b8307d1 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/ConfigurationModifier.java +++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/ConfigurationModifier.java @@ -211,7 +211,7 @@ public class ConfigurationModifier implements PolarisConfigurationConfigModifier } if (ipPort.length != 2) { - throw new IllegalArgumentException("Config server address (" + address + ") is wrong, please check address like grpc://183.47.111.8:8091."); + throw new IllegalArgumentException("Config server address (" + address + ") is wrong, please check address like grpc://127.0.0.1:8091."); } LOGGER.info("[SCT] Check config server ipPort: {}", Arrays.asList(ipPort)); diff --git a/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/ConfigurationModifierTest.java b/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/ConfigurationModifierTest.java index 4ae0d3a1b..a9ccd2cec 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/ConfigurationModifierTest.java +++ b/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/ConfigurationModifierTest.java @@ -107,18 +107,18 @@ class ConfigurationModifierTest { /** * Test resolvePolarisAddressFromConfigAddress with a single address containing port. - * Scenario: pass a single config address "grpc://192.168.1.100:8093". + * Scenario: pass a single config address "grpc://127.0.0.1:8093". * Expect: the port should be replaced with 8091. */ @DisplayName("resolvePolarisAddressFromConfigAddress should replace port with 8091 for single address") @Test void testResolvePolarisAddressFromConfigAddress_SingleAddress() throws Exception { // Arrange - String configAddress = "grpc://192.168.1.100:8093"; + String configAddress = "grpc://127.0.0.1:8093"; try (MockedStatic mockedAddressUtils = Mockito.mockStatic(AddressUtils.class)) { mockedAddressUtils.when(() -> AddressUtils.parseAddressList(anyString())) - .thenReturn(Collections.singletonList("192.168.1.100:8093")); + .thenReturn(Collections.singletonList("127.0.0.1:8093")); // Act List result = invokeResolvePolarisAddressFromConfigAddress(configAddress); @@ -126,7 +126,7 @@ class ConfigurationModifierTest { // Assert assertThat(result).isNotNull(); assertThat(result).hasSize(1); - assertThat(result.get(0)).isEqualTo("192.168.1.100:8091"); + assertThat(result.get(0)).isEqualTo("127.0.0.1:8091"); } } @@ -139,11 +139,11 @@ class ConfigurationModifierTest { @Test void testResolvePolarisAddressFromConfigAddress_MultipleAddresses() throws Exception { // Arrange - String configAddress = "grpc://10.0.1.1:8093,grpc://10.0.1.2:8094"; + String configAddress = "grpc://127.0.0.1:8093,grpc://127.0.0.1:8094"; try (MockedStatic mockedAddressUtils = Mockito.mockStatic(AddressUtils.class)) { mockedAddressUtils.when(() -> AddressUtils.parseAddressList(anyString())) - .thenReturn(Arrays.asList("10.0.1.1:8093", "10.0.1.2:8094")); + .thenReturn(Arrays.asList("127.0.0.1:8093", "127.0.0.1:8094")); // Act List result = invokeResolvePolarisAddressFromConfigAddress(configAddress); @@ -151,8 +151,8 @@ class ConfigurationModifierTest { // Assert assertThat(result).isNotNull(); assertThat(result).hasSize(2); - assertThat(result.get(0)).isEqualTo("10.0.1.1:8091"); - assertThat(result.get(1)).isEqualTo("10.0.1.2:8091"); + assertThat(result.get(0)).isEqualTo("127.0.0.1:8091"); + assertThat(result.get(1)).isEqualTo("127.0.0.1:8091"); } } @@ -190,11 +190,11 @@ class ConfigurationModifierTest { @Test void testResolvePolarisAddressFromConfigAddress_BlankAddressSkipped() throws Exception { // Arrange - String configAddress = "grpc://172.16.0.1:8093, ,grpc://172.16.0.2:9090"; + String configAddress = "grpc://127.0.0.1:8093, ,grpc://127.0.0.1:9090"; try (MockedStatic mockedAddressUtils = Mockito.mockStatic(AddressUtils.class)) { mockedAddressUtils.when(() -> AddressUtils.parseAddressList(anyString())) - .thenReturn(Arrays.asList("172.16.0.1:8093", " ", "172.16.0.2:9090")); + .thenReturn(Arrays.asList("127.0.0.1:8093", " ", "127.0.0.1:9090")); // Act List result = invokeResolvePolarisAddressFromConfigAddress(configAddress); @@ -202,8 +202,8 @@ class ConfigurationModifierTest { // Assert assertThat(result).isNotNull(); assertThat(result).hasSize(2); - assertThat(result.get(0)).isEqualTo("172.16.0.1:8091"); - assertThat(result.get(1)).isEqualTo("172.16.0.2:8091"); + assertThat(result.get(0)).isEqualTo("127.0.0.1:8091"); + assertThat(result.get(1)).isEqualTo("127.0.0.1:8091"); } } diff --git a/spring-cloud-tencent-examples/polaris-router-grayrelease-lane-example/router-grayrelease-lane-callee-service/src/main/resources/application.yml b/spring-cloud-tencent-examples/polaris-router-grayrelease-lane-example/router-grayrelease-lane-callee-service/src/main/resources/application.yml index c5c4c4072..213717a9c 100644 --- a/spring-cloud-tencent-examples/polaris-router-grayrelease-lane-example/router-grayrelease-lane-callee-service/src/main/resources/application.yml +++ b/spring-cloud-tencent-examples/polaris-router-grayrelease-lane-example/router-grayrelease-lane-callee-service/src/main/resources/application.yml @@ -23,7 +23,7 @@ spring: # enabled: true # address: 127.0.0.1:9091 config: - address: grpc://9.134.5.52:8093 + address: grpc://119.91.66.223:8093 auto-refresh: true groups: - name: ${spring.application.name}