fix instance's weight hard code to 100 bug (#801)

pull/804/head
lepdou 2 years ago committed by GitHub
parent b3feb94b73
commit a15e2ceaa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -22,3 +22,4 @@
- [Fix issue: prompt no registration if web dependence was not imported.](https://github.com/Tencent/spring-cloud-tencent/pull/777) - [Fix issue: prompt no registration if web dependence was not imported.](https://github.com/Tencent/spring-cloud-tencent/pull/777)
- [set reporter.enabled default to true](https://github.com/Tencent/spring-cloud-tencent/pull/786) - [set reporter.enabled default to true](https://github.com/Tencent/spring-cloud-tencent/pull/786)
- [fix:fix nacos enabled condition bugs.](https://github.com/Tencent/spring-cloud-tencent/pull/794) - [fix:fix nacos enabled condition bugs.](https://github.com/Tencent/spring-cloud-tencent/pull/794)
- [fix:fix instance's weight hard code to 100 bug.](https://github.com/Tencent/spring-cloud-tencent/pull/801)

@ -47,7 +47,6 @@ import org.springframework.util.CollectionUtils;
public final class LoadBalancerUtils { public final class LoadBalancerUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(LoadBalancerUtils.class); private static final Logger LOGGER = LoggerFactory.getLogger(LoadBalancerUtils.class);
private static final int DEFAULT_WEIGHT = 100;
private static final int WAIT_TIME = 3; private static final int WAIT_TIME = 3;
private LoadBalancerUtils() { private LoadBalancerUtils() {
@ -104,7 +103,6 @@ public final class LoadBalancerUtils {
instance.setId(serviceInstance.getInstanceId()); instance.setId(serviceInstance.getInstanceId());
instance.setHost(serviceInstance.getHost()); instance.setHost(serviceInstance.getHost());
instance.setPort(serviceInstance.getPort()); instance.setPort(serviceInstance.getPort());
instance.setWeight(DEFAULT_WEIGHT);
instance.setMetadata(serviceInstance.getMetadata()); instance.setMetadata(serviceInstance.getMetadata());
if (serviceInstance instanceof PolarisServiceInstance) { if (serviceInstance instanceof PolarisServiceInstance) {
@ -112,6 +110,7 @@ public final class LoadBalancerUtils {
instance.setRegion(polarisServiceInstance.getPolarisInstance().getRegion()); instance.setRegion(polarisServiceInstance.getPolarisInstance().getRegion());
instance.setZone(polarisServiceInstance.getPolarisInstance().getZone()); instance.setZone(polarisServiceInstance.getPolarisInstance().getZone());
instance.setCampus(polarisServiceInstance.getPolarisInstance().getCampus()); instance.setCampus(polarisServiceInstance.getPolarisInstance().getCampus());
instance.setWeight(polarisServiceInstance.getPolarisInstance().getWeight());
} }
return instance; return instance;

@ -23,7 +23,9 @@ import java.util.List;
import com.tencent.cloud.common.metadata.MetadataContext; import com.tencent.cloud.common.metadata.MetadataContext;
import com.tencent.cloud.common.metadata.MetadataContextHolder; import com.tencent.cloud.common.metadata.MetadataContextHolder;
import com.tencent.cloud.common.pojo.PolarisServiceInstance;
import com.tencent.cloud.common.util.ApplicationContextAwareUtils; import com.tencent.cloud.common.util.ApplicationContextAwareUtils;
import com.tencent.polaris.api.pojo.DefaultInstance;
import com.tencent.polaris.api.pojo.Instance; import com.tencent.polaris.api.pojo.Instance;
import com.tencent.polaris.api.pojo.ServiceInstances; import com.tencent.polaris.api.pojo.ServiceInstances;
import org.junit.AfterClass; import org.junit.AfterClass;
@ -36,7 +38,6 @@ import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.ServiceInstance;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
@ -80,11 +81,17 @@ public class LoadBalancerUtilsTest {
@Test @Test
public void testTransferNotEmptyInstances() { public void testTransferNotEmptyInstances() {
int instanceSize = 100; int instanceSize = 100;
int weight = 50;
List<ServiceInstance> instances = new ArrayList<>(); List<ServiceInstance> instances = new ArrayList<>();
for (int i = 0; i < instanceSize; i++) { for (int i = 0; i < instanceSize; i++) {
instances.add(new DefaultServiceInstance("ins" + i, testNamespaceAndService, "127.0.0." + i, DefaultInstance instance = new DefaultInstance();
8080, false)); instance.setService(testNamespaceAndService);
instance.setId("ins" + i);
instance.setPort(8080);
instance.setHost("127.0.0." + i);
instance.setWeight(weight);
instances.add(new PolarisServiceInstance(instance));
} }
ServiceInstances serviceInstances = LoadBalancerUtils.transferServersToServiceInstances(Flux.just(instances)); ServiceInstances serviceInstances = LoadBalancerUtils.transferServersToServiceInstances(Flux.just(instances));
@ -100,7 +107,7 @@ public class LoadBalancerUtilsTest {
Assert.assertEquals("ins" + i, instance.getId()); Assert.assertEquals("ins" + i, instance.getId());
Assert.assertEquals("127.0.0." + i, instance.getHost()); Assert.assertEquals("127.0.0." + i, instance.getHost());
Assert.assertEquals(8080, instance.getPort()); Assert.assertEquals(8080, instance.getPort());
Assert.assertEquals(100, instance.getWeight()); Assert.assertEquals(weight, instance.getWeight());
} }
} }
} }

Loading…
Cancel
Save