refactor the runningScript, add the runScenarioModel to it
This commit is contained in:
parent
2488a32971
commit
95d89204cd
|
@ -15,6 +15,7 @@ import org.bench4q.master.api.modelfactory.BusinessModelMapFactory;
|
|||
import org.bench4q.master.domain.MonitorInBusiness;
|
||||
import org.bench4q.master.domain.RunningScript;
|
||||
import org.bench4q.master.domain.TestPlanContext;
|
||||
import org.bench4q.master.domain.TestPlanInBusiness;
|
||||
import org.bench4q.master.entity.TestPlanDB;
|
||||
import org.bench4q.master.exception.Bench4QException;
|
||||
import org.bench4q.master.report.ReportService;
|
||||
|
@ -128,10 +129,10 @@ public class TestPlanController extends BaseController {
|
|||
"You don't have enough power to run a test plan!",
|
||||
"/runTestPlanWithTestPlanModel");
|
||||
}
|
||||
|
||||
TestPlanInBusiness testPlanInBusiness = BusinessModelMapFactory
|
||||
.toBusiness(testPlanBusinessModel);
|
||||
UUID testPlanRunID = this.getTestPlanRunner().runTestPlanWithModel(
|
||||
BusinessModelMapFactory.toBusiness(testPlanBusinessModel),
|
||||
this.getPrincipal());
|
||||
testPlanInBusiness, this.getPrincipal());
|
||||
if (testPlanRunID == null) {
|
||||
throw new Bench4QException("TestPlan_Commit_Error",
|
||||
"There is an exception when commit the test plan",
|
||||
|
|
|
@ -9,9 +9,9 @@ import java.util.UUID;
|
|||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.helper.ApplicationContextHelper;
|
||||
import org.bench4q.master.service.communication.RunningScriptService;
|
||||
import org.bench4q.master.service.infrastructure.AgentService;
|
||||
import org.bench4q.master.service.infrastructure.RunningAgentService;
|
||||
import org.bench4q.master.service.infrastructure.ScriptService;
|
||||
import org.bench4q.master.service.infrastructure.TestPlanService;
|
||||
import org.bench4q.master.testplan.TestPlanEngine;
|
||||
import org.bench4q.master.testplan.datastatistics.BehaviorsBriefStatistics;
|
||||
|
@ -22,6 +22,7 @@ import org.bench4q.master.testplan.highavailable.AgentRunBlotter;
|
|||
import org.bench4q.master.testplan.highavailable.faultolerence.StopAgentFault;
|
||||
import org.bench4q.master.testplan.schedulscript.ExecutionOverTask;
|
||||
import org.bench4q.master.testplan.schedulscript.WarmUpOverTask;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
import org.bench4q.share.models.agent.StopTestModel;
|
||||
import org.bench4q.share.models.agent.statistics.AgentBehaviorsBriefModel;
|
||||
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
|
||||
|
@ -36,12 +37,16 @@ public class RunningScript {
|
|||
private int requireLoad;
|
||||
private boolean finished;
|
||||
private TestScriptConfig config;
|
||||
private RunScenarioModel scenario;
|
||||
private List<RunningAgent> runningAgents = new ArrayList<RunningAgent>();
|
||||
|
||||
private Timer timer;
|
||||
private List<DataStatistics> dataStatisticsList;
|
||||
private RunningAgentService runningAgentService;
|
||||
private AgentService agentService;
|
||||
private ScriptService scriptService;
|
||||
private static Logger logger = Logger.getLogger(RunningScript.class);
|
||||
private ScriptBriefResultModel latestScriptBriefModel;
|
||||
|
||||
public int getScriptId() {
|
||||
return scriptId;
|
||||
|
@ -75,6 +80,14 @@ public class RunningScript {
|
|||
this.finished = finish;
|
||||
}
|
||||
|
||||
public RunScenarioModel getScenario() {
|
||||
return scenario;
|
||||
}
|
||||
|
||||
private void setScenario(RunScenarioModel scenario) {
|
||||
this.scenario = scenario;
|
||||
}
|
||||
|
||||
private List<RunningAgent> getRunningAgents() {
|
||||
return this.runningAgents;
|
||||
}
|
||||
|
@ -115,16 +128,48 @@ public class RunningScript {
|
|||
this.agentService = agentService;
|
||||
}
|
||||
|
||||
private ScriptService getScriptService() {
|
||||
return scriptService;
|
||||
}
|
||||
|
||||
private void setScriptService(ScriptService scriptService) {
|
||||
this.scriptService = scriptService;
|
||||
}
|
||||
|
||||
private Timer getTimer() {
|
||||
return timer;
|
||||
}
|
||||
|
||||
private void setTimer(Timer timer) {
|
||||
this.timer = timer;
|
||||
}
|
||||
|
||||
public ScriptBriefResultModel getLatestScriptBriefModel() {
|
||||
return latestScriptBriefModel;
|
||||
}
|
||||
|
||||
private void setLatestScriptBriefModel(
|
||||
ScriptBriefResultModel latestScriptBriefModel) {
|
||||
this.latestScriptBriefModel = latestScriptBriefModel;
|
||||
}
|
||||
|
||||
private RunningScript() {
|
||||
ScriptBriefResultModel scriptBriefResultModel = new ScriptBriefResultModel();
|
||||
scriptBriefResultModel.setAverageResponseTime(-1);
|
||||
this.setLatestScriptBriefModel(scriptBriefResultModel);
|
||||
|
||||
this.setRunningAgents(new ArrayList<RunningAgent>());
|
||||
this.setDataStatisticsList(new ArrayList<DataStatistics>());
|
||||
this.getDataStatisticsList().add(new ScriptBriefStatistics());
|
||||
this.getDataStatisticsList().add(new PageBriefStatistics());
|
||||
this.getDataStatisticsList().add(new BehaviorsBriefStatistics());
|
||||
this.setTimer(new Timer());
|
||||
this.setRunningAgentService(ApplicationContextHelper.getContext()
|
||||
.getBean(RunningAgentService.class));
|
||||
this.setAgentService(ApplicationContextHelper.getContext().getBean(
|
||||
AgentService.class));
|
||||
this.setScriptService(ApplicationContextHelper.getContext().getBean(
|
||||
ScriptService.class));
|
||||
}
|
||||
|
||||
public RunningScript(TestScriptConfig config, int requireLoad,
|
||||
|
@ -135,7 +180,9 @@ public class RunningScript {
|
|||
this.setRequireLoad(requireLoad);
|
||||
this.setTestPlanID(testPlanId);
|
||||
this.setScriptId(scriptId);
|
||||
this.runningAgents.addAll(runningAgents);
|
||||
this.getRunningAgents().addAll(runningAgents);
|
||||
this.setScenario(this.getScriptService().getRunSceniroModelByScriptId(
|
||||
this.getScriptId()));
|
||||
}
|
||||
|
||||
public static boolean notValidScript(RunningScript input) {
|
||||
|
@ -147,38 +194,18 @@ public class RunningScript {
|
|||
}
|
||||
|
||||
private DataStatistics getScriptBriefStatistics() {
|
||||
return getSpecificStaitstics(ScriptBriefStatistics.class);
|
||||
return new ScriptBriefStatistics();
|
||||
}
|
||||
|
||||
private DataStatistics getPageBriefStatistics() {
|
||||
return getSpecificStaitstics(PageBriefStatistics.class);
|
||||
return new PageBriefStatistics();
|
||||
}
|
||||
|
||||
private DataStatistics getBehaviorsBriefStatistics() {
|
||||
return getSpecificStaitstics(BehaviorsBriefStatistics.class);
|
||||
return new BehaviorsBriefStatistics();
|
||||
}
|
||||
|
||||
private DataStatistics getSpecificStaitstics(
|
||||
Class<?> specificStatisticsClass) {
|
||||
for (DataStatistics dataStatistics : this.getDataStatisticsList()) {
|
||||
if (specificStatisticsClass.equals(ScriptBriefStatistics.class)
|
||||
&& (dataStatistics instanceof ScriptBriefStatistics)) {
|
||||
return dataStatistics;
|
||||
}
|
||||
if (specificStatisticsClass.equals(BehaviorsBriefStatistics.class)
|
||||
&& (dataStatistics instanceof BehaviorsBriefStatistics)) {
|
||||
return dataStatistics;
|
||||
}
|
||||
if (specificStatisticsClass.equals(PageBriefStatistics.class)
|
||||
&& (dataStatistics instanceof PageBriefStatistics)) {
|
||||
return dataStatistics;
|
||||
}
|
||||
}
|
||||
return new DataStatistics.DefaultStatistics();
|
||||
}
|
||||
|
||||
public ScriptBriefResultModel getScriptBrief(
|
||||
RunningScriptService runningScriptService) {
|
||||
public ScriptBriefResultModel getScriptBrief() {
|
||||
for (RunningAgent runningAgent : getRunningAgents()) {
|
||||
if (runningAgent.isBreakDown()) {
|
||||
continue;
|
||||
|
@ -194,11 +221,11 @@ public class RunningScript {
|
|||
ScriptBriefResultModel result = (ScriptBriefResultModel) getScriptBriefStatistics()
|
||||
.getStatistics();
|
||||
result.setFinished(isFinished());
|
||||
this.setLatestScriptBriefModel(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public ScriptBehaviorsBriefModel getBehaviorsBrief(
|
||||
RunningScriptService runningScriptService) {
|
||||
public ScriptBehaviorsBriefModel getBehaviorsBrief() {
|
||||
for (RunningAgent runningAgent : getRunningAgents()) {
|
||||
getBehaviorsBriefStatistics().add(
|
||||
this.getRunningAgentService().behaviorsBrief(
|
||||
|
@ -258,8 +285,19 @@ public class RunningScript {
|
|||
|
||||
public void doAfterDistributeLoad(List<RunningAgent> agentsAfterDistribute) {
|
||||
this.getRunningAgents().addAll(agentsAfterDistribute);
|
||||
// TODO: start to cyclic brief
|
||||
|
||||
}
|
||||
|
||||
public void doPeriodicBrief() {
|
||||
this.getTimer().scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
getScriptBrief();
|
||||
for (int i = 0; i < getScenario().getPages().size(); i++) {
|
||||
getPageBriefModel(i);
|
||||
}
|
||||
getBehaviorsBrief();
|
||||
}
|
||||
}, 0, 10000);
|
||||
}
|
||||
|
||||
public void doForComplete() {
|
||||
|
@ -275,6 +313,7 @@ public class RunningScript {
|
|||
}
|
||||
backLoadAndCleanUp(runningAgent);
|
||||
}
|
||||
this.getTimer().cancel();
|
||||
this.runningAgents.clear();
|
||||
this.setFinished(true);
|
||||
}
|
||||
|
@ -292,8 +331,4 @@ public class RunningScript {
|
|||
this.getAgentService().backLoadToAgent(hostName,
|
||||
runningAgent.getLoadInUse());
|
||||
}
|
||||
|
||||
public void addAgentToScriptForTest(RunningAgent runningAgent) {
|
||||
this.getRunningAgents().add(runningAgent);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,8 +39,8 @@ public class TestPlanContext {
|
|||
|
||||
public TestPlanContext(TestPlanInBusiness testPlan, UUID testPlanID) {
|
||||
this.setRunningScriptMap(new HashMap<Integer, RunningScript>());
|
||||
this.fillScriptMapAndAssignTestPlanId(testPlan.getRunningScripts(),
|
||||
testPlanID);
|
||||
this.fillScriptMapAndAssignTestPlanIdAndScenario(
|
||||
testPlan.getRunningScripts(), testPlanID);
|
||||
this.setTestPlan(testPlan);
|
||||
}
|
||||
|
||||
|
@ -51,15 +51,15 @@ public class TestPlanContext {
|
|||
System.gc();
|
||||
}
|
||||
|
||||
private void fillScriptMapAndAssignTestPlanId(List<RunningScript> list,
|
||||
UUID testPlanID) {
|
||||
if (runningScriptMap == null) {
|
||||
private void fillScriptMapAndAssignTestPlanIdAndScenario(
|
||||
List<RunningScript> list, UUID testPlanID) {
|
||||
if (this.getRunningScriptMap() == null) {
|
||||
this.setRunningScriptMap(new HashMap<Integer, RunningScript>());
|
||||
}
|
||||
for (RunningScript runningScript : list) {
|
||||
runningScript.setTestPlanID(testPlanID);
|
||||
this.runningScriptMap.put(new Integer(runningScript.getScriptId()),
|
||||
runningScript);
|
||||
this.getRunningScriptMap().put(
|
||||
new Integer(runningScript.getScriptId()), runningScript);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ public class RunningScriptService {
|
|||
public ScriptBriefResultModel getScriptBrief(RunningScript runningScript)
|
||||
throws NullPointerException {
|
||||
guardRunningScriptExist(runningScript);
|
||||
ScriptBriefResultModel result = runningScript.getScriptBrief(this);
|
||||
ScriptBriefResultModel result = runningScript.getScriptBrief();
|
||||
this.getTestPlanScriptService().saveScriptBriefResult(
|
||||
runningScript.getTestPlanID(), runningScript.getScriptId(),
|
||||
result);
|
||||
|
@ -42,8 +42,7 @@ public class RunningScriptService {
|
|||
public ScriptBehaviorsBriefModel getBehaviorsBrief(
|
||||
RunningScript runningScript) throws NullPointerException {
|
||||
guardRunningScriptExist(runningScript);
|
||||
ScriptBehaviorsBriefModel result = runningScript
|
||||
.getBehaviorsBrief(this);
|
||||
ScriptBehaviorsBriefModel result = runningScript.getBehaviorsBrief();
|
||||
this.getTestPlanScriptService().saveBehaviorsBriefResult(
|
||||
runningScript.getTestPlanID(), runningScript.getScriptId(),
|
||||
result);
|
||||
|
|
|
@ -63,6 +63,7 @@ public class LoadDistribute {
|
|||
private void doAfterDistributeLoadSuccess(RunningScript scriptInput,
|
||||
List<RunningAgent> runningAgents) {
|
||||
scriptInput.doAfterDistributeLoad(runningAgents);
|
||||
scriptInput.doPeriodicBrief();
|
||||
}
|
||||
|
||||
private boolean hasEnoughCurrentLoad(TestPlanContext testPlanContext) {
|
||||
|
|
|
@ -69,12 +69,12 @@ public class TestPlanEngine implements TaskCompleteCallback,
|
|||
|
||||
final TestPlanContext testPlanContext = new TestPlanContext(testPlan,
|
||||
testPlanId);
|
||||
if (!this.testPlanService.saveTestPlanToDB(testPlan, user, testPlanId,
|
||||
testPlanContext.getAllScript())) {
|
||||
if (!this.getTestPlanService().saveTestPlanToDB(testPlan, user,
|
||||
testPlanId, testPlanContext.getAllScript())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
this.testPlanContainer.addATask(testPlanId, testPlanContext);
|
||||
this.getContainer().addATask(testPlanId, testPlanContext);
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
doRunTestPlan(testPlanContext, testPlanId);
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package org.bench4q.master.testplan.datastatistics;
|
||||
|
||||
import org.bench4q.master.helper.ApplicationContextHelper;
|
||||
import org.bench4q.master.service.infrastructure.TestPlanScriptResultService;
|
||||
import org.bench4q.share.models.agent.statistics.DataStatisticsModel;
|
||||
|
||||
public abstract class AbstractDataStatistics implements DataStatistics {
|
||||
private TestPlanScriptResultService testPlanScriptResultService;
|
||||
|
||||
private TestPlanScriptResultService getTestPlanScriptResultService() {
|
||||
return testPlanScriptResultService;
|
||||
}
|
||||
|
||||
private void setTestPlanScriptResultService(
|
||||
TestPlanScriptResultService testPlanScriptResultService) {
|
||||
this.testPlanScriptResultService = testPlanScriptResultService;
|
||||
}
|
||||
|
||||
public AbstractDataStatistics() {
|
||||
this.setTestPlanScriptResultService(ApplicationContextHelper
|
||||
.getContext().getBean(TestPlanScriptResultService.class));
|
||||
}
|
||||
|
||||
public abstract void add(DataStatisticsModel dataUnit);
|
||||
|
||||
public Object getStatistics() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -13,7 +13,6 @@ import org.bench4q.master.entity.Agent;
|
|||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.master.helper.ApplicationContextHelper;
|
||||
import org.bench4q.master.service.infrastructure.RunningAgentService;
|
||||
import org.bench4q.master.service.infrastructure.ScriptService;
|
||||
import org.bench4q.master.testplan.highavailable.AgentRunBlotter;
|
||||
import org.bench4q.master.testplan.highavailable.HighAvailablePool;
|
||||
import org.bench4q.master.testplan.transaction.Transaction;
|
||||
|
@ -28,7 +27,6 @@ public abstract class ScriptLoadBase implements Transaction {
|
|||
private UUID testPlanRunID;
|
||||
private List<RunningAgent> agentListThisTime = new ArrayList<RunningAgent>();
|
||||
private RunningAgentService runningAgentService;
|
||||
private ScriptService scriptService;
|
||||
private HighAvailablePool highAvailableAgentPool;
|
||||
private static Logger logger = Logger.getLogger(ScriptLoadCommand.class);
|
||||
|
||||
|
@ -56,22 +54,14 @@ public abstract class ScriptLoadBase implements Transaction {
|
|||
this.agentListThisTime = agentListThisTime;
|
||||
}
|
||||
|
||||
public RunningAgentService getRunningAgentService() {
|
||||
private RunningAgentService getRunningAgentService() {
|
||||
return runningAgentService;
|
||||
}
|
||||
|
||||
public void setRunningAgentService(RunningAgentService runningAgentService) {
|
||||
private void setRunningAgentService(RunningAgentService runningAgentService) {
|
||||
this.runningAgentService = runningAgentService;
|
||||
}
|
||||
|
||||
private ScriptService getScriptService() {
|
||||
return scriptService;
|
||||
}
|
||||
|
||||
private void setScriptService(ScriptService scriptService) {
|
||||
this.scriptService = scriptService;
|
||||
}
|
||||
|
||||
private HighAvailablePool getHighAvailableAgentPool() {
|
||||
return highAvailableAgentPool;
|
||||
}
|
||||
|
@ -98,8 +88,6 @@ public abstract class ScriptLoadBase implements Transaction {
|
|||
this.setTestPlanRunID(testPlanID);
|
||||
this.setRunningAgentService(ApplicationContextHelper.getContext()
|
||||
.getBean(RunningAgentService.class));
|
||||
this.setScriptService(ApplicationContextHelper.getContext().getBean(
|
||||
ScriptService.class));
|
||||
this.setHighAvailableAgentPool(ApplicationContextHelper.getContext()
|
||||
.getBean(HighAvailablePool.class));
|
||||
this.setAgentListThisTime(new ArrayList<RunningAgent>());
|
||||
|
@ -107,9 +95,11 @@ public abstract class ScriptLoadBase implements Transaction {
|
|||
|
||||
public List<RunningAgent> execute() {
|
||||
logger.info(this.getRunningScript().getScriptId());
|
||||
RunScenarioModel runScenarioModel = this.getScriptService()
|
||||
.getRunSceniroModelByScriptId(
|
||||
this.getRunningScript().getScriptId());
|
||||
// RunScenarioModel runScenarioModel = this.getScriptService()
|
||||
// .getRunSceniroModelByScriptId(
|
||||
// this.getRunningScript().getScriptId());
|
||||
RunScenarioModel runScenarioModel = this.getRunningScript()
|
||||
.getScenario();
|
||||
if (runScenarioModel == null) {
|
||||
logger.error("runScenarioModel is null!");
|
||||
return null;
|
||||
|
|
|
@ -2,6 +2,9 @@ package org.bench4q.master.test.domain;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bench4q.master.api.modelfactory.BusinessModelMapFactory;
|
||||
import org.bench4q.master.domain.RunningAgent;
|
||||
import org.bench4q.master.domain.RunningScript;
|
||||
|
@ -32,11 +35,13 @@ public class Test_RunningScript extends TestBase_MakeUpTestPlan {
|
|||
public Test_RunningScript() {
|
||||
this.setRunningScript(BusinessModelMapFactory
|
||||
.toBusiness(buildScriptModel(USE_SCRIPT)));
|
||||
List<RunningAgent> runningAgents = new ArrayList<RunningAgent>();
|
||||
RunningAgent runningAgent = new RunningAgent();
|
||||
runningAgent.setLoadInUse(40);
|
||||
runningAgent.setScriptId(this.getScriptId());
|
||||
runningAgent.setAgent(new Agent());
|
||||
this.getRunningScript().addAgentToScriptForTest(runningAgent);
|
||||
runningAgents.add(runningAgent);
|
||||
this.getRunningScript().doAfterDistributeLoad(runningAgents);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -51,7 +56,10 @@ public class Test_RunningScript extends TestBase_MakeUpTestPlan {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testForBriefByCycle() {
|
||||
|
||||
public void testForBriefByCycle() throws InterruptedException {
|
||||
this.getRunningScript().doPeriodicBrief();
|
||||
Thread.sleep(20000);
|
||||
assertEquals(0, this.getRunningScript().getLatestScriptBriefModel()
|
||||
.getAverageResponseTime());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue