fix:fix consul connect bug.

pull/217/head
SkyeBeFreeman 3 years ago
parent 887b715822
commit f0a9d99746

@ -1,15 +1,4 @@
# Change Log
---
- [Feature: Support parse ratelimit rule expression labels.](https://github.com/Tencent/spring-cloud-tencent/pull/183)
- [Feature: Router support request label.](https://github.com/Tencent/spring-cloud-tencent/pull/165)
- [Feature: Support router expression label](https://github.com/Tencent/spring-cloud-tencent/pull/190)
- [Add metadata transfer example.](https://github.com/Tencent/spring-cloud-tencent/pull/184)
- [Feature: Support metadata router.](https://github.com/Tencent/spring-cloud-tencent/pull/191)
- [Feature: Misc optimize metadata router.](https://github.com/Tencent/spring-cloud-tencent/pull/192)
- [Feature:Support near by router.](https://github.com/Tencent/spring-cloud-tencent/pull/196)
- [Feature: Load application.yml and application-${profile}.yml from polaris server.](https://github.com/Tencent/spring-cloud-tencent/pull/199)
- [feat:add rate limit of unirate.](https://github.com/Tencent/spring-cloud-tencent/pull/197)
- [test:add junit test to polaris-circuitbreaker.](https://github.com/Tencent/spring-cloud-tencent/pull/202)
- [test:add junit test to polaris-discovery.](https://github.com/Tencent/spring-cloud-tencent/pull/205)
- [Example:set example polaris address to demo environment.](https://github.com/Tencent/spring-cloud-tencent/pull/206)
- [fix:fix consul connect bug.](https://github.com/Tencent/spring-cloud-tencent/pull/217)

@ -0,0 +1,15 @@
# Change Log
---
- [Feature: Support parse ratelimit rule expression labels.](https://github.com/Tencent/spring-cloud-tencent/pull/183)
- [Feature: Router support request label.](https://github.com/Tencent/spring-cloud-tencent/pull/165)
- [Feature: Support router expression label](https://github.com/Tencent/spring-cloud-tencent/pull/190)
- [Add metadata transfer example.](https://github.com/Tencent/spring-cloud-tencent/pull/184)
- [Feature: Support metadata router.](https://github.com/Tencent/spring-cloud-tencent/pull/191)
- [Feature: Misc optimize metadata router.](https://github.com/Tencent/spring-cloud-tencent/pull/192)
- [Feature:Support near by router.](https://github.com/Tencent/spring-cloud-tencent/pull/196)
- [Feature: Load application.yml and application-${profile}.yml from polaris server.](https://github.com/Tencent/spring-cloud-tencent/pull/199)
- [feat:add rate limit of unirate.](https://github.com/Tencent/spring-cloud-tencent/pull/197)
- [test:add junit test to polaris-circuitbreaker.](https://github.com/Tencent/spring-cloud-tencent/pull/202)
- [test:add junit test to polaris-discovery.](https://github.com/Tencent/spring-cloud-tencent/pull/205)
- [Example:set example polaris address to demo environment.](https://github.com/Tencent/spring-cloud-tencent/pull/206)

@ -86,7 +86,7 @@
<properties>
<!-- Project revision -->
<revision>1.5.0-Hoxton.SR9</revision>
<revision>1.5.1-Hoxton.SR9-SNAPSHOT</revision>
<!-- Spring Cloud -->
<spring.cloud.version>Hoxton.SR9</spring.cloud.version>

@ -73,6 +73,22 @@ public class ConsulContextProperties {
@Value("${spring.cloud.consul.discovery.prefer-ip-address:#{'false'}}")
private boolean preferIpAddress;
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
public boolean isEnabled() {
return enabled;
}

@ -20,16 +20,16 @@ package com.tencent.cloud.polaris.extend.consul;
import java.util.List;
import java.util.Map;
import com.tencent.cloud.polaris.DiscoveryPropertiesAutoConfiguration;
import com.tencent.cloud.polaris.context.PolarisContextAutoConfiguration;
import com.tencent.polaris.client.api.SDKContext;
import com.tencent.polaris.factory.config.global.ServerConnectorConfigImpl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import static com.tencent.polaris.plugins.connector.common.constant.ConsulConstant.MetadataMapKey.INSTANCE_ID_KEY;
import static com.tencent.polaris.plugins.connector.common.constant.ConsulConstant.MetadataMapKey.IP_ADDRESS_KEY;
@ -44,47 +44,47 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Haotian Zhang
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ConsulContextPropertiesTest.TestApplication.class)
@ActiveProfiles("test")
public class ConsulContextPropertiesTest {
@Autowired
private ConsulContextProperties consulContextProperties;
@Autowired
private SDKContext sdkContext;
@Test
public void testDefaultInitialization() {
assertThat(consulContextProperties).isNotNull();
assertThat(consulContextProperties.isEnabled()).isTrue();
assertThat(consulContextProperties.getHost()).isEqualTo("127.0.0.1");
assertThat(consulContextProperties.getPort()).isEqualTo(8500);
assertThat(consulContextProperties.isRegister()).isTrue();
assertThat(consulContextProperties.isDiscoveryEnabled()).isTrue();
}
@Test
public void testModify() {
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner().withConfiguration(
AutoConfigurations.of(PolarisContextAutoConfiguration.class,
ConsulContextPropertiesTest.TestConfiguration.class,
DiscoveryPropertiesAutoConfiguration.class))
.withPropertyValues("spring.cloud.consul.discovery.register=true")
.withPropertyValues("spring.cloud.consul.discovery.enabled=true")
.withPropertyValues("spring.application.name=" + SERVICE_PROVIDER)
.withPropertyValues("spring.cloud.consul.discovery.instance-id=ins-test")
.withPropertyValues("spring.cloud.consul.discovery.prefer-ip-address=true")
.withPropertyValues("spring.cloud.consul.discovery.ip-address=" + HOST);
applicationContextRunner.run(context -> {
assertThat(context).hasSingleBean(SDKContext.class);
SDKContext sdkContext = context.getBean(SDKContext.class);
com.tencent.polaris.api.config.Configuration configuration = sdkContext.getConfig();
List<ServerConnectorConfigImpl> serverConnectorConfigs = configuration.getGlobal().getServerConnectors();
Map<String, String> metadata = null;
for (ServerConnectorConfigImpl serverConnectorConfig : serverConnectorConfigs) {
if (serverConnectorConfig.getId().equals("consul")) {
metadata = serverConnectorConfig.getMetadata();
}
assertThat(sdkContext).isNotNull();
com.tencent.polaris.api.config.Configuration configuration = sdkContext.getConfig();
List<ServerConnectorConfigImpl> serverConnectorConfigs = configuration.getGlobal().getServerConnectors();
Map<String, String> metadata = null;
for (ServerConnectorConfigImpl serverConnectorConfig : serverConnectorConfigs) {
if (serverConnectorConfig.getId().equals("consul")) {
metadata = serverConnectorConfig.getMetadata();
}
assertThat(metadata).isNotNull();
assertThat(metadata.get(SERVICE_NAME_KEY)).isEqualTo(SERVICE_PROVIDER);
assertThat(metadata.get(INSTANCE_ID_KEY)).isEqualTo("ins-test");
assertThat(metadata.get(PREFER_IP_ADDRESS_KEY)).isEqualTo("true");
assertThat(metadata.get(IP_ADDRESS_KEY)).isEqualTo(HOST);
});
}
assertThat(metadata).isNotNull();
assertThat(metadata.get(SERVICE_NAME_KEY)).isEqualTo(SERVICE_PROVIDER);
assertThat(metadata.get(INSTANCE_ID_KEY)).isEqualTo("ins-test");
assertThat(metadata.get(PREFER_IP_ADDRESS_KEY)).isEqualTo("true");
assertThat(metadata.get(IP_ADDRESS_KEY)).isEqualTo(HOST);
}
@Configuration
static class TestConfiguration {
@SpringBootApplication
protected static class TestApplication {
@Bean
public ConsulContextProperties consulContextProperties() {
ConsulContextProperties consulContextProperties = new ConsulContextProperties();
consulContextProperties.setEnabled(true);
return consulContextProperties;
}
}
}

@ -0,0 +1,24 @@
server:
port: 48084
spring:
application:
name: java_provider_test
cloud:
polaris:
address: grpc://127.0.0.1:8091
namespace: Test
enabled: true
discovery:
enabled: true
register: true
consul:
port: 8500
host: 127.0.0.1
enabled: true
discovery:
enabled: true
register: true
instance-id: ins-test
service-name: ${spring.application.name}
ip-address: 127.0.0.1
prefer-ip-address: true

@ -70,7 +70,7 @@
</developers>
<properties>
<revision>1.5.0-Hoxton.SR9</revision>
<revision>1.5.1-Hoxton.SR9-SNAPSHOT</revision>
<polaris.version>1.6.0</polaris.version>
<mocktio.version>4.5.1</mocktio.version>
<byte-buddy.version>1.12.10</byte-buddy.version>

Loading…
Cancel
Save