add the support about muti-script testplan
This commit is contained in:
parent
a890978271
commit
cf3cf083a1
|
@ -1,12 +1,13 @@
|
|||
package org.bench4q.master.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.api.model.AgentBriefModel;
|
||||
import org.bench4q.master.api.model.RunningScriptModel;
|
||||
import org.bench4q.master.api.model.TestPlanModel;
|
||||
import org.bench4q.master.api.model.RunTestPlanResultModel;
|
||||
import org.bench4q.master.communication.agent.RunScenarioResultModel;
|
||||
import org.bench4q.master.service.ScriptService;
|
||||
import org.bench4q.master.service.UserService;
|
||||
import org.bench4q.master.testPlan.TestPlanRunner;
|
||||
|
@ -43,23 +44,25 @@ public class TestPlanController extends BaseController {
|
|||
public RunTestPlanResultModel runTestPlanWithScriptId(
|
||||
@RequestParam int scriptId, @RequestParam int requireLoad) {
|
||||
// TODO:add the scriptId-requireLoad to taskList, and return a UUID
|
||||
List<RunningScriptModel> list = new ArrayList<RunningScriptModel>();
|
||||
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
return buildTestPlanResponseModel(false,
|
||||
"you don't have the powe to RunTestPlan", null);
|
||||
}
|
||||
|
||||
return buildTestPlanResponseModel(true, "",
|
||||
this.testPlanRunner._runTestPlanWithScriptId(scriptId,
|
||||
requireLoad));
|
||||
list.add(this.testPlanRunner._runTestPlanWithScriptId(scriptId,
|
||||
requireLoad));
|
||||
|
||||
return buildTestPlanResponseModel(true, "", list);
|
||||
}
|
||||
|
||||
public static RunTestPlanResultModel buildTestPlanResponseModel(
|
||||
boolean success, String failCause, List<RunScenarioResultModel> list) {
|
||||
boolean success, String failCause, List<RunningScriptModel> list) {
|
||||
RunTestPlanResultModel resultModel = new RunTestPlanResultModel();
|
||||
resultModel.setSuccess(success);
|
||||
resultModel.setFailCause(failCause);
|
||||
resultModel.setRunScenarioResultModels(list);
|
||||
resultModel.setRunningScriptModels(list);
|
||||
return resultModel;
|
||||
}
|
||||
|
||||
|
@ -79,20 +82,18 @@ public class TestPlanController extends BaseController {
|
|||
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
return _buildTestPlanResponseModel(false,
|
||||
"you don't have this power", null, null);
|
||||
"you don't have this power", null);
|
||||
}
|
||||
return _buildTestPlanResponseModel(true, "",
|
||||
this.testPlanRunner.runTestPlanWithModel(testPlanModel), null);
|
||||
this.testPlanRunner.runTestPlanWithModel(testPlanModel));
|
||||
}
|
||||
|
||||
private RunTestPlanResultModel _buildTestPlanResponseModel(boolean success,
|
||||
String failCause, UUID testPlanId,
|
||||
List<RunScenarioResultModel> runScenarioResultModels) {
|
||||
String failCause, UUID testPlanId) {
|
||||
RunTestPlanResultModel result = new RunTestPlanResultModel();
|
||||
result.setSuccess(success);
|
||||
result.setFailCause(failCause);
|
||||
result.setTestPlanId(testPlanId);
|
||||
result.setRunScenarioResultModels(runScenarioResultModels);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,14 +7,12 @@ import javax.xml.bind.annotation.XmlElement;
|
|||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.bench4q.master.communication.agent.RunScenarioResultModel;
|
||||
|
||||
@XmlRootElement(name = "RunTestPlanResultModel")
|
||||
public class RunTestPlanResultModel {
|
||||
private boolean success;
|
||||
private String failCause;
|
||||
private UUID testPlanId;
|
||||
private List<RunScenarioResultModel> runScenarioResultModels;
|
||||
private List<RunningScriptModel> runningScriptContextModels;
|
||||
|
||||
@XmlElement(name = "testPlanId")
|
||||
public UUID getTestPlanId() {
|
||||
|
@ -43,15 +41,15 @@ public class RunTestPlanResultModel {
|
|||
this.failCause = failCause;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "ScenarioRuningMessage")
|
||||
@XmlElement(name = "agentRunId")
|
||||
public List<RunScenarioResultModel> getRunScenarioResultModels() {
|
||||
return runScenarioResultModels;
|
||||
@XmlElementWrapper(name = "ContentList")
|
||||
@XmlElement(name = "RunningScriptContextModel")
|
||||
public List<RunningScriptModel> getRunningScriptContextModels() {
|
||||
return runningScriptContextModels;
|
||||
}
|
||||
|
||||
public void setRunScenarioResultModels(
|
||||
List<RunScenarioResultModel> runScenarioResultModels) {
|
||||
this.runScenarioResultModels = runScenarioResultModels;
|
||||
public void setRunningScriptModels(
|
||||
List<RunningScriptModel> runningScriptContextModels) {
|
||||
this.runningScriptContextModels = runningScriptContextModels;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package org.bench4q.master.api.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "RunningScripModel")
|
||||
public class RunningScriptModel {
|
||||
private int scriptId;
|
||||
private int requireLoad;
|
||||
private List<UUID> agentRunIds;
|
||||
|
||||
@XmlElement
|
||||
public int getScriptId() {
|
||||
return scriptId;
|
||||
}
|
||||
|
||||
public void setScriptId(int scriptId) {
|
||||
this.scriptId = scriptId;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public int getRequireLoad() {
|
||||
return requireLoad;
|
||||
}
|
||||
|
||||
public void setRequireLoad(int requireLoad) {
|
||||
this.requireLoad = requireLoad;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "AgentRunIdList")
|
||||
@XmlElement(name = "agentRunId")
|
||||
public List<UUID> getAgentRunIds() {
|
||||
return agentRunIds;
|
||||
}
|
||||
|
||||
public void setAgentRunIds(List<UUID> agentRunIds) {
|
||||
this.agentRunIds = agentRunIds;
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package org.bench4q.master.api.model;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "ScriptIdRequireLoad")
|
||||
public class ScriptIdRequireLoadModel {
|
||||
private int scriptId;
|
||||
private int requireLoad;
|
||||
|
||||
@XmlElement
|
||||
public int getScriptId() {
|
||||
return scriptId;
|
||||
}
|
||||
|
||||
public void setScriptId(int scriptId) {
|
||||
this.scriptId = scriptId;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public int getRequireLoad() {
|
||||
return requireLoad;
|
||||
}
|
||||
|
||||
public void setRequireLoad(int requireLoad) {
|
||||
this.requireLoad = requireLoad;
|
||||
}
|
||||
|
||||
}
|
|
@ -10,16 +10,16 @@ import org.springframework.stereotype.Component;
|
|||
@Component
|
||||
@XmlRootElement(name = "testPlanModel")
|
||||
public class TestPlanModel {
|
||||
private List<ScriptIdRequireLoadModel> scriptIdRequireLoads;
|
||||
private List<RunningScriptModel> scriptIdRequireLoads;
|
||||
|
||||
@XmlElementWrapper(name = "scriptIdRequireLoads")
|
||||
@XmlElement
|
||||
public List<ScriptIdRequireLoadModel> getScriptIdRequireLoads() {
|
||||
public List<RunningScriptModel> getScriptIdRequireLoads() {
|
||||
return scriptIdRequireLoads;
|
||||
}
|
||||
|
||||
public void setScriptIdRequireLoads(
|
||||
List<ScriptIdRequireLoadModel> scriptIdRequireLoads) {
|
||||
List<RunningScriptModel> scriptIdRequireLoads) {
|
||||
this.scriptIdRequireLoads = scriptIdRequireLoads;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.bench4q.master.service;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import org.bench4q.master.entity.db.Agent;
|
||||
import org.bench4q.master.helper.SessionHelper;
|
||||
|
@ -167,4 +168,31 @@ public class AgentService {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void resetAgents() {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = sessionHelper.openSession()
|
||||
.beginTransaction();
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Agent> agents = session.createCriteria(Agent.class).list();
|
||||
if (agents.size() == 0) {
|
||||
return;
|
||||
}
|
||||
Iterator<Agent> iterator = agents.iterator();
|
||||
Agent agent;
|
||||
while (iterator.hasNext()) {
|
||||
agent = iterator.next();
|
||||
agent.setRemainLoad(agent.getMaxLoad());
|
||||
}
|
||||
transaction.commit();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ import javax.xml.bind.Marshaller;
|
|||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
import org.bench4q.master.api.model.AgentBriefModel;
|
||||
import org.bench4q.master.api.model.ScriptIdRequireLoadModel;
|
||||
import org.bench4q.master.api.model.RunningScriptModel;
|
||||
import org.bench4q.master.api.model.TestPlanModel;
|
||||
import org.bench4q.master.communication.AgentStateService;
|
||||
import org.bench4q.master.communication.HttpRequester;
|
||||
|
@ -118,14 +118,14 @@ public class TestPlanRunner implements Runnable {
|
|||
}
|
||||
}
|
||||
|
||||
public List<RunScenarioResultModel> runTestWithRunScenarioModel(
|
||||
RunScenarioModel runScenarioModel, int requireLoad)
|
||||
public RunningScriptModel runTestWithRunScenarioModel(
|
||||
RunScenarioModel runScenarioModel, int requireLoad, int scriptId)
|
||||
throws JAXBException {
|
||||
// TODO: is it needed to be synchronized, but i think it is;
|
||||
Iterator<Agent> iterator;
|
||||
Agent agent;
|
||||
List<RunScenarioResultModel> resulList = new ArrayList<RunScenarioResultModel>();
|
||||
RunScenarioResultModel runScenarioResultModel = new RunScenarioResultModel();
|
||||
List<UUID> runIdList = new ArrayList<UUID>();
|
||||
int min;
|
||||
// TODO:i think this should be done by HA and Ballancer, now i just do
|
||||
// the ballance in the testPlanRunner by monopolized
|
||||
|
@ -136,11 +136,9 @@ public class TestPlanRunner implements Runnable {
|
|||
if (!_isAlive(agent)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_isMonopolized(agent)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
min = _getMin(requireLoad, agent.getRemainLoad());
|
||||
|
||||
runScenarioModel.setPoolSize(min);
|
||||
|
@ -148,21 +146,26 @@ public class TestPlanRunner implements Runnable {
|
|||
this.getAgentService().getLoadFromAgent(agent.getHostName(), min);
|
||||
runScenarioResultModel = this.sendScriptContentToAgent(
|
||||
agent.getHostName(), agent.getPort(),
|
||||
this.makeRunScenarioModelToString(runScenarioModel));
|
||||
|
||||
HostNameAndLoad hostLoad = new HostNameAndLoad();
|
||||
hostLoad.setHostName(agent.getHostName());
|
||||
hostLoad.setLoad(min);
|
||||
|
||||
this.runningAgentInfo.addToRunIdHostLoadMap(
|
||||
runScenarioResultModel.getRunId(), hostLoad);
|
||||
this.marshalRunScenarioModelToString(runScenarioModel));
|
||||
|
||||
this.runningAgentInfo.addToRunIdHostLoadMap(runScenarioResultModel
|
||||
.getRunId(), new HostNameAndLoad(agent.getHostName(), min));
|
||||
resulList.add(runScenarioResultModel);
|
||||
runIdList.add(runScenarioResultModel.getRunId());
|
||||
requireLoad -= min;
|
||||
}
|
||||
return resulList;
|
||||
if (requireLoad > 0) {
|
||||
return null;
|
||||
}
|
||||
return _buildRunningScriptModel(runIdList, scriptId);
|
||||
|
||||
}
|
||||
|
||||
private RunningScriptModel _buildRunningScriptModel(List<UUID> agentRunIds,
|
||||
int scriptId) {
|
||||
RunningScriptModel result = new RunningScriptModel();
|
||||
result.setAgentRunIds(agentRunIds);
|
||||
result.setScriptId(scriptId);
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean _isAlive(Agent agent) {
|
||||
|
@ -179,8 +182,8 @@ public class TestPlanRunner implements Runnable {
|
|||
: remainLoadByStart;
|
||||
}
|
||||
|
||||
public String makeRunScenarioModelToString(RunScenarioModel runScenarioModel)
|
||||
throws JAXBException {
|
||||
public String marshalRunScenarioModelToString(
|
||||
RunScenarioModel runScenarioModel) throws JAXBException {
|
||||
Marshaller marshaller;
|
||||
marshaller = JAXBContext.newInstance(runScenarioModel.getClass())
|
||||
.createMarshaller();
|
||||
|
@ -295,18 +298,18 @@ public class TestPlanRunner implements Runnable {
|
|||
}
|
||||
|
||||
private void doRunTestPlan(TestPlanModel testPlanModel) {
|
||||
|
||||
Iterator<ScriptIdRequireLoadModel> iterator = testPlanModel
|
||||
List<RunningScriptModel> result = new ArrayList<RunningScriptModel>();
|
||||
Iterator<RunningScriptModel> iterator = testPlanModel
|
||||
.getScriptIdRequireLoads().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
ScriptIdRequireLoadModel sModel = iterator.next();
|
||||
this._runTestPlanWithScriptId(sModel.getScriptId(),
|
||||
sModel.getRequireLoad());
|
||||
RunningScriptModel sModel = iterator.next();
|
||||
result.add(this._runTestPlanWithScriptId(sModel.getScriptId(),
|
||||
sModel.getRequireLoad()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<RunScenarioResultModel> _runTestPlanWithScriptId(int scriptId,
|
||||
public RunningScriptModel _runTestPlanWithScriptId(int scriptId,
|
||||
int requireLoad) {
|
||||
RunScenarioModel runScenarioModel = this.scriptService
|
||||
.getRunSceniroModelByScriptId(scriptId);
|
||||
|
@ -314,9 +317,15 @@ public class TestPlanRunner implements Runnable {
|
|||
return null;
|
||||
}
|
||||
try {
|
||||
List<RunScenarioResultModel> list = runTestWithRunScenarioModel(
|
||||
runScenarioModel, requireLoad);
|
||||
return list;
|
||||
RunningScriptModel result = this.runTestWithRunScenarioModel(
|
||||
runScenarioModel, requireLoad, scriptId);
|
||||
if (result == null) {
|
||||
result = new RunningScriptModel();
|
||||
result.setAgentRunIds(null);
|
||||
result.setScriptId(-1);
|
||||
}
|
||||
result.setRequireLoad(requireLoad);
|
||||
return result;
|
||||
} catch (JAXBException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.util.HashMap;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
@ -16,13 +17,12 @@ import javax.xml.bind.Unmarshaller;
|
|||
|
||||
import org.bench4q.master.api.TestPlanController;
|
||||
import org.bench4q.master.api.model.AgentBriefModel;
|
||||
import org.bench4q.master.api.model.ScriptIdRequireLoadModel;
|
||||
import org.bench4q.master.api.model.RunningScriptModel;
|
||||
import org.bench4q.master.api.model.TestPlanModel;
|
||||
import org.bench4q.master.api.model.RunTestPlanResultModel;
|
||||
import org.bench4q.master.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.master.communication.agent.ParameterModel;
|
||||
import org.bench4q.master.communication.agent.RunScenarioModel;
|
||||
import org.bench4q.master.communication.agent.RunScenarioResultModel;
|
||||
import org.bench4q.master.communication.agent.UsePluginModel;
|
||||
import org.bench4q.master.communication.agent.UserBehaviorModel;
|
||||
import org.bench4q.master.service.AgentService;
|
||||
|
@ -62,8 +62,8 @@ public class TestPlanTester extends TestBase {
|
|||
}
|
||||
|
||||
private void _createATestPlan() {
|
||||
List<ScriptIdRequireLoadModel> list = new ArrayList<ScriptIdRequireLoadModel>();
|
||||
ScriptIdRequireLoadModel model = new ScriptIdRequireLoadModel();
|
||||
List<RunningScriptModel> list = new ArrayList<RunningScriptModel>();
|
||||
RunningScriptModel model = new RunningScriptModel();
|
||||
model.setScriptId(8);
|
||||
model.setRequireLoad(200);
|
||||
list.add(model);
|
||||
|
@ -150,16 +150,16 @@ public class TestPlanTester extends TestBase {
|
|||
marshaller.marshal(runScenarioModel, stringWriter);
|
||||
// String content = stringWriter.toString();
|
||||
|
||||
List<RunScenarioResultModel> map = testPlanController
|
||||
.getTestPlanRunner().runTestWithRunScenarioModel(
|
||||
runScenarioModel, runScenarioModel.getTotalCount());
|
||||
Iterator<RunScenarioResultModel> iterator = map.iterator();
|
||||
RunScenarioResultModel runResultModel;
|
||||
RunningScriptModel map = testPlanController.getTestPlanRunner()
|
||||
.runTestWithRunScenarioModel(runScenarioModel,
|
||||
runScenarioModel.getTotalCount(), 1);
|
||||
Iterator<UUID> iterator = map.getAgentRunIds().iterator();
|
||||
UUID agentRunId;
|
||||
while (iterator.hasNext()) {
|
||||
runResultModel = iterator.next();
|
||||
agentRunId = iterator.next();
|
||||
AgentBriefModel agentBriefModel = testPlanController
|
||||
.getTestPlanRunner().getBriefStatusFromAgent(
|
||||
runResultModel.getRunId());
|
||||
.getTestPlanRunner().getBriefStatusFromAgent(agentRunId);
|
||||
|
||||
System.out.println(agentBriefModel.getTestStatusModel()
|
||||
.getAverageResponseTime());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue