parent
b943800a02
commit
52a048a89a
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
this.filterTypeMatches = filterTypeMatches;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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,22 +61,18 @@ public class TestPlanService {
|
|||
|
||||
private List<RunningScriptModel> createRunningScriptModel(
|
||||
List<WebScriptModel> scriptParam) {
|
||||
|
||||
// TODO: You just remove the load
|
||||
List<RunningScriptModel> scriptList = new ArrayList<RunningScriptModel>();
|
||||
|
||||
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
|
||||
.setScheduleModel(scriptModel.getScheduleModel());
|
||||
runnningScriptModel
|
||||
.setScriptFilterOptionsModel(scriptFilterOptionsModel);
|
||||
scriptList.add(runnningScriptModel);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue