Test:add sct-stater-polaris-router juint. (#767)
Co-authored-by: dongyinuo <45160106+dongyinuo@users.noreply.github.com>pull/757/head
parent
bed6f384b5
commit
517637be9e
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the BSD 3-Clause License (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://opensource.org/licenses/BSD-3-Clause
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software distributed
|
||||||
|
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||||
|
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.tencent.cloud.polaris.router.config;
|
||||||
|
|
||||||
|
import com.tencent.cloud.common.metadata.config.MetadataAutoConfiguration;
|
||||||
|
import com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration;
|
||||||
|
import com.tencent.cloud.polaris.router.feign.RouterLabelFeignInterceptor;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
|
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test for {@link FeignAutoConfiguration}.
|
||||||
|
* @author dongyinuo
|
||||||
|
*/
|
||||||
|
public class FeignAutoConfigurationTest {
|
||||||
|
|
||||||
|
private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
|
||||||
|
.withConfiguration(AutoConfigurations.of(
|
||||||
|
MetadataAutoConfiguration.class,
|
||||||
|
RouterAutoConfiguration.class,
|
||||||
|
PolarisContextAutoConfiguration.class,
|
||||||
|
FeignAutoConfiguration.class));
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void routerLabelInterceptor() {
|
||||||
|
contextRunner.run(context -> {
|
||||||
|
assertThat(context).hasSingleBean(FeignAutoConfiguration.class);
|
||||||
|
assertThat(context).hasSingleBean(RouterLabelFeignInterceptor.class);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the BSD 3-Clause License (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://opensource.org/licenses/BSD-3-Clause
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software distributed
|
||||||
|
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||||
|
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.tencent.cloud.polaris.router.config;
|
||||||
|
|
||||||
|
|
||||||
|
import com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration;
|
||||||
|
import com.tencent.cloud.polaris.loadbalancer.config.PolarisLoadBalancerAutoConfiguration;
|
||||||
|
import com.tencent.cloud.polaris.router.PolarisRouterServiceInstanceListSupplier;
|
||||||
|
import com.tencent.polaris.router.api.core.RouterAPI;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||||
|
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||||
|
import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient;
|
||||||
|
import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClient;
|
||||||
|
import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryProperties;
|
||||||
|
import org.springframework.cloud.client.discovery.simple.reactive.SimpleReactiveDiscoveryClient;
|
||||||
|
import org.springframework.cloud.client.discovery.simple.reactive.SimpleReactiveDiscoveryProperties;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test for {@link LoadBalancerConfiguration}.
|
||||||
|
* @author dongyinuo
|
||||||
|
*/
|
||||||
|
public class LoadBalancerConfigurationTest {
|
||||||
|
|
||||||
|
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLoadBalancerConfiguration() {
|
||||||
|
contextRunner.withConfiguration(AutoConfigurations.of(
|
||||||
|
PolarisLoadBalancerAutoConfiguration.class,
|
||||||
|
PolarisContextAutoConfiguration.class,
|
||||||
|
LoadBalancerConfiguration.class))
|
||||||
|
.run(context -> {
|
||||||
|
assertThat(context).hasSingleBean(LoadBalancerConfiguration.class);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPolarisReactiveSupportConfiguration() {
|
||||||
|
contextRunner.withConfiguration(AutoConfigurations.of(
|
||||||
|
LoadBalancerConfiguration.PolarisReactiveSupportConfiguration.class,
|
||||||
|
PolarisLoadBalancerAutoConfiguration.class,
|
||||||
|
PolarisContextAutoConfiguration.class))
|
||||||
|
.withBean(SimpleReactiveDiscoveryProperties.class)
|
||||||
|
.withBean(SimpleReactiveDiscoveryClient.class)
|
||||||
|
.run(context -> {
|
||||||
|
assertThat(context).hasSingleBean(LoadBalancerConfiguration.PolarisReactiveSupportConfiguration.class);
|
||||||
|
assertThat(context).hasSingleBean(RouterAPI.class);
|
||||||
|
assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class);
|
||||||
|
assertThat(context).hasSingleBean(PolarisRouterServiceInstanceListSupplier.class);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPolarisBlockingSupportConfiguration() {
|
||||||
|
contextRunner.withConfiguration(AutoConfigurations.of(
|
||||||
|
PolarisLoadBalancerAutoConfiguration.class,
|
||||||
|
PolarisContextAutoConfiguration.class,
|
||||||
|
LoadBalancerConfiguration.PolarisBlockingSupportConfiguration.class
|
||||||
|
))
|
||||||
|
.withBean(SimpleDiscoveryProperties.class)
|
||||||
|
.withBean(SimpleDiscoveryClient.class)
|
||||||
|
.run(context -> {
|
||||||
|
assertThat(context).hasSingleBean(LoadBalancerConfiguration.PolarisBlockingSupportConfiguration.class);
|
||||||
|
assertThat(context).hasSingleBean(DiscoveryClient.class);
|
||||||
|
assertThat(context).hasSingleBean(RouterAPI.class);
|
||||||
|
assertThat(context).hasSingleBean(PolarisRouterServiceInstanceListSupplier.class);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the BSD 3-Clause License (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://opensource.org/licenses/BSD-3-Clause
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software distributed
|
||||||
|
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||||
|
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.tencent.cloud.polaris.router.config;
|
||||||
|
|
||||||
|
import com.tencent.cloud.common.metadata.config.MetadataAutoConfiguration;
|
||||||
|
import com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
|
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test for {@link RouterAutoConfiguration }.
|
||||||
|
* @author dongyinuo
|
||||||
|
*/
|
||||||
|
public class RouterAutoConfigurationTests {
|
||||||
|
|
||||||
|
private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
|
||||||
|
.withConfiguration(AutoConfigurations.of(
|
||||||
|
TestRestTemplatesConfiguration.class,
|
||||||
|
MetadataAutoConfiguration.class,
|
||||||
|
RouterAutoConfiguration.class,
|
||||||
|
PolarisContextAutoConfiguration.class,
|
||||||
|
RouterAutoConfiguration.RouterLabelRestTemplateConfig.class));
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRouterLabelRestTemplateConfig() {
|
||||||
|
contextRunner.run(context -> {
|
||||||
|
assertThat(context).hasSingleBean(RouterAutoConfiguration.RouterLabelRestTemplateConfig.class);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
static class TestRestTemplatesConfiguration {
|
||||||
|
@Bean
|
||||||
|
public RestTemplate restTemplate() {
|
||||||
|
return new RestTemplate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the BSD 3-Clause License (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://opensource.org/licenses/BSD-3-Clause
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software distributed
|
||||||
|
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||||
|
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.tencent.cloud.polaris.router.config.properties;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test for {@link PolarisMetadataRouterProperties}.
|
||||||
|
*/
|
||||||
|
public class PolarisMetadataRouterPropertiesTest {
|
||||||
|
|
||||||
|
PolarisMetadataRouterProperties properties;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
properties = new PolarisMetadataRouterProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isEnabled() {
|
||||||
|
assertThat(properties.isEnabled()).isEqualTo(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setEnabled() {
|
||||||
|
properties.setEnabled(false);
|
||||||
|
assertThat(properties.isEnabled()).isEqualTo(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testToString() {
|
||||||
|
assertThat(properties.toString())
|
||||||
|
.isEqualTo("PolarisMetadataRouterProperties{enabled=true}");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the BSD 3-Clause License (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://opensource.org/licenses/BSD-3-Clause
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software distributed
|
||||||
|
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||||
|
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.tencent.cloud.polaris.router.config.properties;
|
||||||
|
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test for {@link PolarisNearByRouterProperties}.
|
||||||
|
*/
|
||||||
|
public class PolarisNearByRouterPropertiesTest {
|
||||||
|
|
||||||
|
PolarisNearByRouterProperties properties;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
properties = new PolarisNearByRouterProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isEnabled() {
|
||||||
|
assertThat(properties.isEnabled()).isEqualTo(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setEnabled() {
|
||||||
|
properties.setEnabled(false);
|
||||||
|
assertThat(properties.isEnabled()).isEqualTo(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testToString() {
|
||||||
|
assertThat(properties.toString())
|
||||||
|
.isEqualTo("PolarisNearByRouterProperties{enabled=true}");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the BSD 3-Clause License (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://opensource.org/licenses/BSD-3-Clause
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software distributed
|
||||||
|
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||||
|
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.tencent.cloud.polaris.router.config.properties;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test for {@link PolarisRuleBasedRouterProperties}.
|
||||||
|
*/
|
||||||
|
public class PolarisRuleBasedRouterPropertiesTest {
|
||||||
|
|
||||||
|
PolarisRuleBasedRouterProperties properties;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
properties = new PolarisRuleBasedRouterProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isEnabled() {
|
||||||
|
assertThat(properties.isEnabled()).isEqualTo(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setEnabled() {
|
||||||
|
properties.setEnabled(false);
|
||||||
|
assertThat(properties.isEnabled()).isEqualTo(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testToString() {
|
||||||
|
assertThat(properties.toString())
|
||||||
|
.isEqualTo("PolarisNearByRouterProperties{enabled=true}");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the BSD 3-Clause License (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://opensource.org/licenses/BSD-3-Clause
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software distributed
|
||||||
|
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||||
|
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.tencent.cloud.polaris.router.endpoint;
|
||||||
|
|
||||||
|
import com.tencent.cloud.polaris.context.ServiceRuleManager;
|
||||||
|
import com.tencent.polaris.client.api.SDKContext;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
|
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test for {@link PolarisRouterEndpointAutoConfiguration}.
|
||||||
|
* @author dongyinuo
|
||||||
|
*/
|
||||||
|
public class PolarisRouterEndpointAutoConfigurationTests {
|
||||||
|
|
||||||
|
private ServiceRuleManager serviceRuleManager;
|
||||||
|
|
||||||
|
private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
|
||||||
|
.withConfiguration(AutoConfigurations.of(
|
||||||
|
TestServiceRuleManagerConfiguration.class,
|
||||||
|
PolarisRouterEndpointAutoConfiguration.class))
|
||||||
|
.withPropertyValues("endpoints.polaris-router.enabled=true");
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void polarisRouterEndpoint() {
|
||||||
|
contextRunner.run(context -> {
|
||||||
|
assertThat(context).hasSingleBean(PolarisRouterEndpointAutoConfiguration.class);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
static class TestServiceRuleManagerConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ServiceRuleManager serviceRuleManager(SDKContext sdkContext) {
|
||||||
|
return new ServiceRuleManager(sdkContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public SDKContext sdkContext() {
|
||||||
|
return SDKContext.initContext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the BSD 3-Clause License (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://opensource.org/licenses/BSD-3-Clause
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software distributed
|
||||||
|
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||||
|
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.tencent.cloud.polaris.router.resttemplate;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.springframework.cloud.client.DefaultServiceInstance;
|
||||||
|
import org.springframework.cloud.client.ServiceInstance;
|
||||||
|
import org.springframework.cloud.client.loadbalancer.LoadBalancerRequest;
|
||||||
|
import org.springframework.http.HttpRequest;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test for {@link PolarisLoadBalancerRequest}.
|
||||||
|
* @author dongyinuo
|
||||||
|
*/
|
||||||
|
public class PolarisLoadBalancerRequestTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() throws Exception {
|
||||||
|
String calleeService = "calleeService";
|
||||||
|
HttpRequest request = new RouterLabelRestTemplateInterceptorTest.MockedHttpRequest("http://" + calleeService + "/user/get");
|
||||||
|
MockLoadBalancerRequest mockLoadBalancerRequest = new MockLoadBalancerRequest();
|
||||||
|
PolarisLoadBalancerRequest<ServiceInstance> polarisLoadBalancerRequest = new PolarisLoadBalancerRequest<>(request, mockLoadBalancerRequest);
|
||||||
|
|
||||||
|
DefaultServiceInstance serviceInstance = new DefaultServiceInstance();
|
||||||
|
serviceInstance.setServiceId(calleeService);
|
||||||
|
ServiceInstance apply = polarisLoadBalancerRequest.apply(serviceInstance);
|
||||||
|
assertThat(apply.getServiceId()).isEqualTo(calleeService);
|
||||||
|
assertThat(polarisLoadBalancerRequest.getRequest()).isEqualTo(request);
|
||||||
|
assertThat(polarisLoadBalancerRequest.getDelegate()).isEqualTo(mockLoadBalancerRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
static class MockLoadBalancerRequest implements LoadBalancerRequest {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object apply(ServiceInstance instance) throws Exception {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue