diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/integrated/Test_TestPlan.java b/Bench4Q-Master/src/test/java/org/bench4q/master/integrated/Test_TestPlan.java index 49fdcb81..697957c8 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/integrated/Test_TestPlan.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/integrated/Test_TestPlan.java @@ -4,6 +4,7 @@ import static org.junit.Assert.*; import java.util.Set; +import org.bench4q.master.domain.entity.Agent; import org.bench4q.master.domain.entity.RunningAgentDB; import org.bench4q.master.domain.entity.TestPlan; import org.bench4q.master.domain.entity.TestPlanScript; @@ -34,6 +35,13 @@ public class Test_TestPlan extends TestBase_MakeUpTestPlan { @Before public void prepare() { + if (this.getAgentRepository().loadEntities().size() == 0) { + Agent agent = new Agent(); + agent.setHostName("127.0.0.1"); + agent.setPort(6565); + agent.setMaxLoad(500); + this.getAgentService().addAgentToPool(agent); + } prepareForTestPlanRunning(); submitATestPlanWithOneScript(); } diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/TestBase_MakeUpTestPlan.java b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/TestBase_MakeUpTestPlan.java index 9f632dab..201d261a 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/TestBase_MakeUpTestPlan.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/TestBase_MakeUpTestPlan.java @@ -1,9 +1,12 @@ package org.bench4q.master.unitTest; +import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.UUID; +import org.apache.commons.io.FileUtils; import org.bench4q.master.domain.RunningScriptInterface; import org.bench4q.master.domain.entity.RunningAgentDB; import org.bench4q.master.domain.entity.TestPlan; @@ -58,7 +61,8 @@ public class TestBase_MakeUpTestPlan extends TestBase { // private static int EACH_SCRIPT_LOAD_MIDDLESCALE = 800; public static String Monitor_Host_Name = "133.133.12.3"; public static String monitor_port = "5556"; - + public static final String Test_User_Name = "admin"; + public static final String Test_User_Password = "test1"; public static final String Test_AGENT_HOSTNAME = "133.133.12.4"; public static final int TEST_PORT = 6565; @@ -206,6 +210,15 @@ public class TestBase_MakeUpTestPlan extends TestBase { } protected User getTestUser() { + if (this.userRepository.getUser(Test_User_Name) == null) { + User user = new User(); + user.setUserName(Test_User_Name); + user.setPassword(Test_User_Password); + this.userRepository.attatch(user); + } + if (this.testUser == null) { + this.testUser = this.userRepository.getUser(Test_User_Name); + } return testUser; } @@ -264,7 +277,7 @@ public class TestBase_MakeUpTestPlan extends TestBase { private UUID submitATestPlan(int i) { UUID testPlanRunId = UUID.randomUUID(); - User user = this.getUserRepository().getUser("admin"); + User user = this.getUserRepository().getUser(Test_User_Name); int scriptOne = getUserFirstScript(user); this.setScriptId(scriptOne); int scriptTwo = -1; @@ -337,6 +350,15 @@ public class TestBase_MakeUpTestPlan extends TestBase { } protected int getUserFirstScript(User user) { + if (this.getScriptService().loadScripts(getTestUser()).size() == 0) { + try { + this.scriptService.saveScript("test1", getTestUser().getId(), + FileUtils.readFileToString(new File( + "Scripts/homepage.xml")), null); + } catch (IOException e) { + e.printStackTrace(); + } + } return this.getScriptService().loadScripts(user).get(0).getId(); } @@ -375,11 +397,11 @@ public class TestBase_MakeUpTestPlan extends TestBase { RunningScriptModel model = new RunningScriptModel(); model.setScriptId(scriptID); model.setRequireLoad(EACH_SCRIPT_LOAD_SMALLSCALE); - ScheduleModel config = new ScheduleModel(); - config.getPoints().add(new PointModel(0, 0)); - config.getPoints().add(new PointModel(20, 10)); - config.getPoints().add(new PointModel(60, 10)); - model.setScheduleModel(config); + ScheduleModel schedule = new ScheduleModel(); + schedule.getPoints().add(new PointModel(0, 0)); + schedule.getPoints().add(new PointModel(20, 10)); + schedule.getPoints().add(new PointModel(60, 10)); + model.setScheduleModel(schedule); return model; } diff --git a/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/ScheduleModel.java b/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/ScheduleModel.java index 978f586a..ff93e9a2 100644 --- a/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/ScheduleModel.java +++ b/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/ScheduleModel.java @@ -37,6 +37,14 @@ public class ScheduleModel { return endTime - startTime; } + public int getMaxLoad() { + int result = 0; + for (PointModel pointModel : this.points) { + result = Math.max(result, pointModel.getLoad()); + } + return result; + } + @XmlRootElement public static class PointModel { private long time; diff --git a/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/RunningScriptModel.java b/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/RunningScriptModel.java index 26a16776..f570f689 100644 --- a/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/RunningScriptModel.java +++ b/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/RunningScriptModel.java @@ -17,7 +17,7 @@ public class RunningScriptModel { private int scriptId; private int requireLoad; private ScheduleModel scheduleModel; - private ScriptFilterOptionsModel scriptFilterOptionsModel; + private ScriptFilterOptionsModel scriptFilterOptionsModel = new ScriptFilterOptionsModel(); private RunScenarioModel scenarioModel; private String scriptName; private boolean finished; diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/model/WebScriptModel.java b/Bench4Q-Web/src/main/java/org/bench4q/web/model/WebScriptModel.java index 7548bffc..f1ced4f8 100644 --- a/Bench4Q-Web/src/main/java/org/bench4q/web/model/WebScriptModel.java +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/model/WebScriptModel.java @@ -1,28 +1,23 @@ package org.bench4q.web.model; - +import org.bench4q.share.models.agent.scriptrecord.ScheduleModel; public class WebScriptModel { private int id; - private int load; - private long warmup; - private long executeRange; - private long cooldown; + private ScheduleModel scheduleModel; private boolean isFilterTimer; private String filterTypeMatches = null; - - + public WebScriptModel() { } - public WebScriptModel(int id,int load,long warmup,long executeRange,long cooldown,String filterTypeMatches){ - this.id=id; - this.load=load; - this.warmup=warmup; - this.executeRange=executeRange; - this.cooldown=cooldown; + + public WebScriptModel(int id, int load, ScheduleModel scheduleModel, + String filterTypeMatches) { + this.id = id; + this.scheduleModel = scheduleModel; this.filterTypeMatches = filterTypeMatches; - } + public int getId() { return id; } @@ -31,49 +26,28 @@ public class WebScriptModel { this.id = id; } - public int getLoad() { - return load; - } - - public void setLoad(int load) { - this.load = load; - } - - public long getWarmup() { - return warmup; - } - - public void setWarmup(long warmup) { - this.warmup = warmup; - } - - public long getExecuteRange() { - return executeRange; - } - - public void setExecuteRange(long executeRange) { - this.executeRange = executeRange; - } - - public long getCooldown() { - return cooldown; - } - - public void setCooldown(long cooldown) { - this.cooldown = cooldown; - } public boolean isFilterTimer() { return isFilterTimer; } + public void setIsFilterTimer(boolean timer) { this.isFilterTimer = timer; } + + public ScheduleModel getScheduleModel() { + return scheduleModel; + } + + public void setScheduleModel(ScheduleModel scheduleModel) { + this.scheduleModel = scheduleModel; + } + public String getFilterTypeMatches() { return filterTypeMatches; } + public void setFilterTypeMatches(String filterTypeMatches) { this.filterTypeMatches = filterTypeMatches; } - } diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/service/TestPlanService.java b/Bench4Q-Web/src/main/java/org/bench4q/web/service/TestPlanService.java index 1af8a672..4181911c 100644 --- a/Bench4Q-Web/src/main/java/org/bench4q/web/service/TestPlanService.java +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/service/TestPlanService.java @@ -18,7 +18,6 @@ import org.bench4q.share.models.master.ScriptHandleModel; import org.bench4q.share.models.master.TestPlanModel; import org.bench4q.share.models.master.TestPlanResultModel; import org.bench4q.share.models.master.TestPlanScriptBriefResultModel; -import org.bench4q.share.models.master.TestScriptConfigModel; import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel; import org.bench4q.share.models.master.statistics.ScriptBriefResultModel; import org.bench4q.web.masterMessager.TestPlanMessager; @@ -62,24 +61,20 @@ public class TestPlanService { private List createRunningScriptModel( List scriptParam) { - + // TODO: You just remove the load List scriptList = new ArrayList(); - for (WebScriptModel scriptModel : scriptParam) { RunningScriptModel runnningScriptModel = new RunningScriptModel(); runnningScriptModel.setScriptId(scriptModel.getId()); - runnningScriptModel.setRequireLoad(scriptModel.getLoad()); ScriptFilterOptionsModel scriptFilterOptionsModel = new ScriptFilterOptionsModel(); - scriptFilterOptionsModel.setFilterTypeMatches(scriptModel.getFilterTypeMatches()); - scriptFilterOptionsModel.setFilterTimer(scriptModel.isFilterTimer()); - - TestScriptConfigModel testScriptConfig = new TestScriptConfigModel(); - testScriptConfig.setCoolDown(scriptModel.getCooldown()); - testScriptConfig.setExecuteRange(scriptModel.getExecuteRange()); - testScriptConfig.setWarmUp(scriptModel.getWarmup()); - runnningScriptModel.setConfig(testScriptConfig); + scriptFilterOptionsModel.setFilterTypeMatches(scriptModel + .getFilterTypeMatches()); + scriptFilterOptionsModel + .setFilterTimer(scriptModel.isFilterTimer()); runnningScriptModel - .setScriptFilterOptionsModel(scriptFilterOptionsModel); + .setScheduleModel(scriptModel.getScheduleModel()); + runnningScriptModel + .setScriptFilterOptionsModel(scriptFilterOptionsModel); scriptList.add(runnningScriptModel); } return scriptList; diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/validation/TestPlanValidate.java b/Bench4Q-Web/src/main/java/org/bench4q/web/validation/TestPlanValidate.java index a3709590..6b1ec816 100644 --- a/Bench4Q-Web/src/main/java/org/bench4q/web/validation/TestPlanValidate.java +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/validation/TestPlanValidate.java @@ -25,9 +25,9 @@ public class TestPlanValidate { private boolean isValidateScriptModel(WebScriptModel scriptModel) { if (scriptModel.getId() == 0) return false; - if (scriptModel.getLoad() == 0) + if (scriptModel.getScheduleModel().getMaxLoad() == 0) return false; - if (scriptModel.getExecuteRange() == 0) + if (scriptModel.getScheduleModel().getPoints().size() == 0) return false; return true; }