fix:use 1.6.1 version of polaris-java and fix some bug.

pull/222/head
SkyeBeFreeman 3 years ago
parent cc52fa1818
commit 70f5261ecf

@ -1,5 +1,4 @@
# Change Log # Change Log
--- ---
- [fix:fix consul connect bug.](https://github.com/Tencent/spring-cloud-tencent/pull/217) - [fix:use 1.6.1 version of polaris-java and fix some bug.](https://github.com/Tencent/spring-cloud-tencent/pull/221)
- [fix:fix PolarisRegistration cannot get metadata bug.](https://github.com/Tencent/spring-cloud-tencent/pull/218)

@ -0,0 +1,5 @@
# Change Log
---
- [fix:fix consul connect bug.](https://github.com/Tencent/spring-cloud-tencent/pull/217)
- [fix:fix PolarisRegistration cannot get metadata bug.](https://github.com/Tencent/spring-cloud-tencent/pull/218)

@ -86,14 +86,11 @@
<properties> <properties>
<!-- Project revision --> <!-- Project revision -->
<revision>1.5.1-Hoxton.SR9</revision> <revision>1.5.2-Hoxton.SR9</revision>
<!-- Spring Cloud --> <!-- Spring Cloud -->
<spring.cloud.version>Hoxton.SR9</spring.cloud.version> <spring.cloud.version>Hoxton.SR9</spring.cloud.version>
<!-- Dependencies -->
<logback.version>1.2.7</logback.version>
<!-- Maven Plugin Versions --> <!-- Maven Plugin Versions -->
<jacoco.version>0.8.3</jacoco.version> <jacoco.version>0.8.3</jacoco.version>
<maven-source-plugin.version>3.2.0</maven-source-plugin.version> <maven-source-plugin.version>3.2.0</maven-source-plugin.version>
@ -109,15 +106,6 @@
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
<!-- Spring Cloud Dependencies -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring.cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Spring Cloud Tencent Dependencies --> <!-- Spring Cloud Tencent Dependencies -->
<dependency> <dependency>
<groupId>com.tencent.cloud</groupId> <groupId>com.tencent.cloud</groupId>
@ -127,10 +115,13 @@
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>
<!-- Spring Cloud Dependencies -->
<dependency> <dependency>
<groupId>ch.qos.logback</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>logback-classic</artifactId> <artifactId>spring-cloud-dependencies</artifactId>
<version>${logback.version}</version> <version>${spring.cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency> </dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>

@ -40,7 +40,7 @@ import static com.tencent.cloud.polaris.discovery.refresh.PolarisServiceStatusCh
*/ */
public class PolarisRefreshApplicationReadyEventListener implements ApplicationListener<ApplicationReadyEvent>, ApplicationEventPublisherAware { public class PolarisRefreshApplicationReadyEventListener implements ApplicationListener<ApplicationReadyEvent>, ApplicationEventPublisherAware {
private static final Logger LOG = LoggerFactory.getLogger(PolarisRefreshConfiguration.class); private static final Logger LOG = LoggerFactory.getLogger(PolarisRefreshApplicationReadyEventListener.class);
private static final int DELAY = 60; private static final int DELAY = 60;
private final PolarisDiscoveryHandler polarisDiscoveryHandler; private final PolarisDiscoveryHandler polarisDiscoveryHandler;
private final PolarisServiceStatusChangeListener polarisServiceStatusChangeListener; private final PolarisServiceStatusChangeListener polarisServiceStatusChangeListener;

@ -24,6 +24,8 @@ import java.util.concurrent.ConcurrentHashMap;
import com.tencent.cloud.common.util.ApplicationContextAwareUtils; import com.tencent.cloud.common.util.ApplicationContextAwareUtils;
import com.tencent.cloud.common.util.JacksonUtils; import com.tencent.cloud.common.util.JacksonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@ -38,6 +40,7 @@ public class MetadataContext {
* transitive context. * transitive context.
*/ */
public static final String FRAGMENT_TRANSITIVE = "transitive"; public static final String FRAGMENT_TRANSITIVE = "transitive";
private static final Logger LOG = LoggerFactory.getLogger(MetadataContext.class);
/** /**
* Namespace of local instance. * Namespace of local instance.
*/ */
@ -48,9 +51,6 @@ public class MetadataContext {
*/ */
public static String LOCAL_SERVICE; public static String LOCAL_SERVICE;
private final Map<String, Map<String, String>> fragmentContexts;
static { static {
String namespace = ApplicationContextAwareUtils String namespace = ApplicationContextAwareUtils
.getProperties("spring.cloud.polaris.namespace"); .getProperties("spring.cloud.polaris.namespace");
@ -60,6 +60,8 @@ public class MetadataContext {
} }
if (StringUtils.isEmpty(namespace)) { if (StringUtils.isEmpty(namespace)) {
LOG.error("namespace should not be blank. please configure spring.cloud.polaris.namespace or "
+ "spring.cloud.polaris.discovery.namespace");
throw new RuntimeException("namespace should not be blank. please configure spring.cloud.polaris.namespace or " throw new RuntimeException("namespace should not be blank. please configure spring.cloud.polaris.namespace or "
+ "spring.cloud.polaris.discovery.namespace"); + "spring.cloud.polaris.discovery.namespace");
} }
@ -75,12 +77,16 @@ public class MetadataContext {
} }
if (StringUtils.isEmpty(serviceName)) { if (StringUtils.isEmpty(serviceName)) {
LOG.error("service name should not be blank. please configure spring.cloud.polaris.service or "
+ "spring.cloud.polaris.discovery.service or spring.application.name");
throw new RuntimeException("service name should not be blank. please configure spring.cloud.polaris.service or " throw new RuntimeException("service name should not be blank. please configure spring.cloud.polaris.service or "
+ "spring.cloud.polaris.discovery.service or spring.application.name"); + "spring.cloud.polaris.discovery.service or spring.application.name");
} }
LOCAL_SERVICE = serviceName; LOCAL_SERVICE = serviceName;
} }
private final Map<String, Map<String, String>> fragmentContexts;
public MetadataContext() { public MetadataContext() {
this.fragmentContexts = new ConcurrentHashMap<>(); this.fragmentContexts = new ConcurrentHashMap<>();
} }

@ -40,8 +40,8 @@ public class ApplicationContextAwareUtils implements ApplicationContextAware {
return applicationContext; return applicationContext;
} }
public void setApplicationContext(ApplicationContext applicationContext) @Override
throws BeansException { public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
ApplicationContextAwareUtils.applicationContext = applicationContext; ApplicationContextAwareUtils.applicationContext = applicationContext;
} }

@ -69,7 +69,12 @@ public final class JacksonUtils {
public static Map<String, String> deserialize2Map(String jsonStr) { public static Map<String, String> deserialize2Map(String jsonStr) {
try { try {
if (StringUtils.hasText(jsonStr)) { if (StringUtils.hasText(jsonStr)) {
return OM.readValue(jsonStr, Map.class); Map<String, Object> temp = OM.readValue(jsonStr, Map.class);
Map<String, String> result = new HashMap<>();
temp.forEach((key, value) -> {
result.put(String.valueOf(key), String.valueOf(value));
});
return result;
} }
return new HashMap<>(); return new HashMap<>();
} }

@ -21,30 +21,55 @@ package com.tencent.cloud.common.util;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
/** /**
* test for {@link JacksonUtils} * Test for {@link JacksonUtils}.
*@author lepdou 2022-05-27 *
* @author lepdou, Haotian Zhang
*/ */
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
public class JacksonUtilsTest { public class JacksonUtilsTest {
@Test @Test
public void test() { public void testSerialize2Json() {
Map<String, String> sourceMap = new HashMap<>(); Map<String, String> sourceMap = new HashMap<>();
sourceMap.put("k1", "v1"); sourceMap.put("k1", "v1");
sourceMap.put("k2", "v2"); sourceMap.put("k2", "v2");
sourceMap.put("k3", "v3"); sourceMap.put("k3", "v3");
Map<String, String> map = JacksonUtils.deserialize2Map(JacksonUtils.serialize2Json(sourceMap)); String jsonStr = JacksonUtils.serialize2Json(sourceMap);
assertThat(jsonStr).isEqualTo("{\"k1\":\"v1\",\"k2\":\"v2\",\"k3\":\"v3\"}");
}
@Test
public void testDeserialize2Map() {
String jsonStr = "{\"k1\":\"v1\",\"k2\":\"v2\",\"k3\":\"v3\"}";
Map<String, String> map = JacksonUtils.deserialize2Map(jsonStr);
assertThat(map.size()).isEqualTo(3);
assertThat(map.get("k1")).isEqualTo("v1");
assertThat(map.get("k2")).isEqualTo("v2");
assertThat(map.get("k3")).isEqualTo("v3");
assertThat(JacksonUtils.deserialize2Map("")).isNotNull();
assertThat(JacksonUtils.deserialize2Map("")).isEmpty();
Assert.assertEquals(sourceMap.size(), map.size()); jsonStr = "{\"k1\":\"v1\",\"k2\":\"v2\",\"k3\":\"v3\"";
Assert.assertEquals(sourceMap.get("k1"), map.get("k1")); try {
Assert.assertEquals(sourceMap.get("k2"), map.get("k2")); JacksonUtils.deserialize2Map(jsonStr);
Assert.assertEquals(sourceMap.get("k3"), map.get("k3")); fail("RuntimeException should be thrown.");
}
catch (RuntimeException exception) {
assertThat(exception.getMessage()).isEqualTo("Json to map failed.");
}
catch (Throwable throwable) {
fail("RuntimeException should be thrown.");
}
} }
} }

@ -70,8 +70,9 @@
</developers> </developers>
<properties> <properties>
<revision>1.5.1-Hoxton.SR9</revision> <revision>1.5.2-Hoxton.SR9</revision>
<polaris.version>1.6.0</polaris.version> <polaris.version>1.6.1</polaris.version>
<logback.version>1.2.7</logback.version>
<mocktio.version>4.5.1</mocktio.version> <mocktio.version>4.5.1</mocktio.version>
<byte-buddy.version>1.12.10</byte-buddy.version> <byte-buddy.version>1.12.10</byte-buddy.version>
@ -146,6 +147,12 @@
<version>${revision}</version> <version>${revision}</version>
</dependency> </dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId> <artifactId>mockito-inline</artifactId>

@ -2,7 +2,8 @@
## Example Introduction ## Example Introduction
This example shows how to use ```spring-cloud-starter-tencent-metadata-transfer`` in Spring Cloud project for its features. This example shows how to use ```spring-cloud-starter-tencent-metadata-transfer``` in Spring Cloud project for its
features.
This example contains ```metadata-callee-service```、```metadata-caller-service```. This example contains ```metadata-callee-service```、```metadata-caller-service```.

@ -34,19 +34,19 @@ public class Person {
private int age; private int age;
String getName() { public String getName() {
return name; return name;
} }
void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
int getAge() { public int getAge() {
return age; return age;
} }
void setAge(int age) { public void setAge(int age) {
this.age = age; this.age = age;
} }

Loading…
Cancel
Save