feat: support traffic warmup lane router (#1785)
Co-authored-by: Haotian Zhang <skyebefreeman@qq.com>pull/1791/head
parent
8e8c222a7f
commit
7f23a5f6a9
@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 Tencent. 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 com.tencent.polaris.plugins.router.lane.BaseLaneMode;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the configuration for lane router.
|
||||||
|
*
|
||||||
|
* @author Yuwei Fu
|
||||||
|
*/
|
||||||
|
@ConfigurationProperties(prefix = "spring.cloud.polaris.router.lane-router")
|
||||||
|
public class PolarisLaneRouterProperties {
|
||||||
|
|
||||||
|
private BaseLaneMode baseLaneMode = BaseLaneMode.ONLY_UNTAGGED_INSTANCE;
|
||||||
|
|
||||||
|
public BaseLaneMode getBaseLaneMode() {
|
||||||
|
return baseLaneMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBaseLaneMode(BaseLaneMode baseLaneMode) {
|
||||||
|
this.baseLaneMode = baseLaneMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "PolarisLaneRouterProperties{" +
|
||||||
|
"baseLaneMode=" + baseLaneMode +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 Tencent. 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 com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration;
|
||||||
|
import com.tencent.cloud.polaris.router.config.RouterConfigModifierAutoConfiguration;
|
||||||
|
import com.tencent.polaris.plugins.router.lane.BaseLaneMode;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.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 PolarisLaneRouterProperties}.
|
||||||
|
*/
|
||||||
|
public class PolarisLaneRouterPropertiesTest {
|
||||||
|
private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
|
||||||
|
.withConfiguration(AutoConfigurations.of(
|
||||||
|
PolarisContextAutoConfiguration.class,
|
||||||
|
RouterConfigModifierAutoConfiguration.class
|
||||||
|
))
|
||||||
|
.withPropertyValues("spring.application.name=test");
|
||||||
|
|
||||||
|
PolarisLaneRouterProperties properties;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
properties = new PolarisLaneRouterProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDefaultValues() {
|
||||||
|
contextRunner.run(context -> {
|
||||||
|
PolarisLaneRouterProperties props = context.getBean(PolarisLaneRouterProperties.class);
|
||||||
|
assertThat(props.getBaseLaneMode()).isEqualTo(BaseLaneMode.ONLY_UNTAGGED_INSTANCE);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBaseLaneModePropertyBinding() {
|
||||||
|
contextRunner
|
||||||
|
.withPropertyValues("spring.cloud.polaris.router.lane-router.base-lane-mode=" + BaseLaneMode.EXCLUDE_ENABLED_LANE_INSTANCE.name())
|
||||||
|
.run(context -> {
|
||||||
|
PolarisLaneRouterProperties props = context.getBean(PolarisLaneRouterProperties.class);
|
||||||
|
assertThat(props.getBaseLaneMode()).isEqualTo(BaseLaneMode.EXCLUDE_ENABLED_LANE_INSTANCE);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetBaseLaneMode() {
|
||||||
|
assertThat(properties.getBaseLaneMode()).isEqualTo(BaseLaneMode.ONLY_UNTAGGED_INSTANCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetBaseLaneMode() {
|
||||||
|
properties.setBaseLaneMode(BaseLaneMode.EXCLUDE_ENABLED_LANE_INSTANCE);
|
||||||
|
assertThat(properties.getBaseLaneMode()).isEqualTo(BaseLaneMode.EXCLUDE_ENABLED_LANE_INSTANCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in new issue