diff --git a/src/main/java/com/dispose/service/impl/TemplateServiceImpl.java b/src/main/java/com/dispose/service/impl/TemplateServiceImpl.java index a7386ee5..6857e12d 100644 --- a/src/main/java/com/dispose/service/impl/TemplateServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/TemplateServiceImpl.java @@ -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(); } diff --git a/src/test/java/com/dispose/test/dev/service/TemplateServiceTest.java b/src/test/java/com/dispose/test/dev/service/TemplateServiceTest.java index 1ad5cc58..510a5541 100644 --- a/src/test/java/com/dispose/test/dev/service/TemplateServiceTest.java +++ b/src/test/java/com/dispose/test/dev/service/TemplateServiceTest.java @@ -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));