REM:
1.修改策略模板匹配规则(修复带宽为0匹配不到模板)
2.修改模板选择service层测试。
This commit is contained in:
wangyiyun 2021-01-14 19:31:24 +08:00
parent 4d5b893eb1
commit 5d315f4689
2 changed files with 10 additions and 10 deletions

View File

@ -33,9 +33,12 @@ public class TemplateServiceImpl implements TemplateService {
// 判断类型是否一致
if (v.getType().equals(type)) {
// 当前带宽大于当前模板最小值
if (bandWidth > v.getBandMin()) {
if (bandWidth > v.getBandMin() || bandWidth == 0) {
// 模板最大值为-1或者带宽小于等于模板最小值返回模板名称
if (v.getBandMax() == -1 || bandWidth <= v.getBandMax()) {
if (v.getBandMax() == -1 && bandWidth != 0) {
log.debug("Template analyze: {}, {} match {}", type, bandWidth, v);
return v.getName();
} else if (bandWidth <= v.getBandMax() && bandWidth >= v.getBandMin()) {
log.debug("Template analyze: {}, {} match {}", type, bandWidth, v);
return v.getName();
}

View File

@ -32,32 +32,29 @@ public class TemplateServiceTest extends InitTestEnvironment {
public void getTemplateTest() {
Assert.assertEquals("Game_Server_10G", templateService.getTemplate("GAME",1600L));
Assert.assertEquals("Game_Server_10G", templateService.getTemplate("GAME", (long) 1500.5));
Assert.assertEquals("Game_Server_1G", templateService.getTemplate("GAME",1500L));
Assert.assertEquals("Game_Server_1G", templateService.getTemplate("GAME",(long) 1499.5));
Assert.assertEquals("Game_Server_1G", templateService.getTemplate("GAME", 1L));
Assert.assertEquals("Game_Server_1G", templateService.getTemplate("GAME", 100L));
Assert.assertEquals("Game_Server_1G", templateService.getTemplate("GAME", 1L));
Assert.assertEquals("Game_Server_1G", templateService.getTemplate("GAME", 0L));
Assert.assertNull(templateService.getTemplate("GAME",-1L));
log.info("GAME, 0L-----------template: {}", templateService.getTemplate("GAME", 0L));
log.info("GAME, 0.9-----------template: {}", templateService.getTemplate("GAME", (long) 0.9));
Assert.assertEquals("DNS_Server_10G", templateService.getTemplate("DNS",1600L));
Assert.assertEquals("DNS_Server_1G", templateService.getTemplate("DNS",1500L));
Assert.assertEquals("DNS_Server_1G", templateService.getTemplate("DNS",1L));
//Assert.assertEquals("Game_Server_1G", templateService.getTemplate("DNS",0L));
Assert.assertEquals("DNS_Server_1G", templateService.getTemplate("DNS",0L));
Assert.assertNull(templateService.getTemplate("DNS",-1L));
Assert.assertEquals("WEB_Server_10G", templateService.getTemplate("WEB",1600L));
Assert.assertEquals("WEB_Server_1G", templateService.getTemplate("WEB",1500L));
Assert.assertEquals("WEB_Server_1G", templateService.getTemplate("WEB",1L));
//Assert.assertEquals("Game_Server_1G", templateService.getTemplate("WEB",0L));
Assert.assertEquals("WEB_Server_1G", templateService.getTemplate("WEB",0L));
Assert.assertNull(templateService.getTemplate("WEB",-1L));
Assert.assertEquals("General_Server_10G", templateService.getTemplate("GENERAL",1600L));
Assert.assertEquals("General_Server_1G", templateService.getTemplate("GENERAL",1500L));
Assert.assertEquals("General_Server_100M", templateService.getTemplate("GENERAL",500L));
Assert.assertEquals("General_Server_100M", templateService.getTemplate("GENERAL",1L));
//Assert.assertEquals("General_Server_100M", templateService.getTemplate("GENERAL",0L));
Assert.assertEquals("General_Server_100M", templateService.getTemplate("GENERAL",0L));
Assert.assertNull(templateService.getTemplate("GENERAL",-1L));
Assert.assertNull(templateService.getTemplate("ALL",100L));