refactor and remove redundant code
This commit is contained in:
parent
caeccbb6ff
commit
9adaf27722
|
@ -103,9 +103,6 @@ public class TestPlanScriptService {
|
|||
agentBriefList.add(briefStatusModel);
|
||||
}
|
||||
result = calculateScriptAverage(agentBriefList);
|
||||
if (result.isFinished()) {
|
||||
runningScriptModel.setFinish(true);
|
||||
}
|
||||
saveResult(testPlanId, runningScriptModel.getScriptId(), result);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -133,44 +133,6 @@ public class TestPlanService {
|
|||
return true;
|
||||
}
|
||||
|
||||
public long queryExecuteTime(UUID testPlanRunId, int scriptId) {
|
||||
Session session = this.sessionHelper.openSession();
|
||||
try {
|
||||
TestPlan testPlan = (TestPlan) session
|
||||
.createCriteria(TestPlan.class)
|
||||
.add(Restrictions.eq("testPlanRunId",
|
||||
testPlanRunId.toString())).uniqueResult();
|
||||
if (testPlan == null) {
|
||||
return -1;
|
||||
}
|
||||
TestPlanScript testPlanScript = (TestPlanScript) session
|
||||
.createCriteria(TestPlanScript.class)
|
||||
.add(Restrictions.eq("testPlan", testPlan))
|
||||
.add(Restrictions.eq("script",
|
||||
ScriptService.doGetScript(scriptId, session)))
|
||||
.uniqueResult();
|
||||
if (testPlanScript == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
PlanedConfig planedConfig = (PlanedConfig) session
|
||||
.createCriteria(PlanedConfig.class)
|
||||
.add(Restrictions.eq("testPlanScript", testPlanScript))
|
||||
.uniqueResult();
|
||||
if (planedConfig == null) {
|
||||
return -1;
|
||||
}
|
||||
return planedConfig.getExecuteRange() * TIME_UNIT;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return -1;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TestPlan getTestPlan(UUID testPlanRunId) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
try {
|
||||
|
|
|
@ -38,7 +38,7 @@ public class TestPlanContainer {
|
|||
return testPlanContext.queryRunningScriptModel(scriptId);
|
||||
}
|
||||
|
||||
public boolean verifyTestPlanFinish(UUID testPlanId) {
|
||||
public boolean isTestPlanFinished(UUID testPlanId) {
|
||||
TestPlanContext testPlanContext = this.queryTestPlanContext(testPlanId);
|
||||
boolean finish = true;
|
||||
for (RunningScriptModel model : testPlanContext.getRunningScriptMap()
|
||||
|
|
|
@ -167,42 +167,52 @@ public class TestPlanRunner implements TaskCompleteCallback {
|
|||
}
|
||||
|
||||
public void doTaskComplete(UUID testPlanID) {
|
||||
// TODO: when taskComplete do something, reallocate the load.
|
||||
if (this.getTestPlanContainer().verifyTestPlanFinish(testPlanID)) {
|
||||
TestPlanContext context = this.getTestPlanContainer()
|
||||
.getRunningTestPlans().get(testPlanID);
|
||||
for (RunningScriptModel runningScriptModel : context
|
||||
.getRunningScriptMap().values()) {
|
||||
for (RunningAgentModel runningAgentModel : runningScriptModel
|
||||
.getRunningAgents()) {
|
||||
this.getHaPool().getAgentRunBlotters()
|
||||
.remove(runningAgentModel.getAgentRunId());
|
||||
logger.info("see the agentBlotter after run : "
|
||||
+ this.getHaPool().getAgentRunBlotters()
|
||||
.get(runningAgentModel.getAgentRunId()));
|
||||
}
|
||||
}
|
||||
this.getTestPlanContainer().getRunningTestPlans()
|
||||
.remove(testPlanID);
|
||||
this.getTestPlanService().handleTestPlanComplete(testPlanID);
|
||||
logger.info("Test plan with id " + testPlanID.toString()
|
||||
+ " finishes!");
|
||||
// TODO: verify if the matters about this test plan has been
|
||||
// cleaned.
|
||||
if (!this.getTestPlanContainer().isTestPlanFinished(testPlanID)) {
|
||||
return;
|
||||
}
|
||||
TestPlanContext context = this.getTestPlanContainer()
|
||||
.getRunningTestPlans().get(testPlanID);
|
||||
for (RunningScriptModel runningScriptModel : context
|
||||
.getRunningScriptMap().values()) {
|
||||
for (RunningAgentModel runningAgentModel : runningScriptModel
|
||||
.getRunningAgents()) {
|
||||
this.getHaPool().getAgentRunBlotters()
|
||||
.remove(runningAgentModel.getAgentRunId());
|
||||
logger.info("see the agentBlotter after run : "
|
||||
+ this.getHaPool().getAgentRunBlotters()
|
||||
.get(runningAgentModel.getAgentRunId()));
|
||||
}
|
||||
}
|
||||
this.getTestPlanContainer().getRunningTestPlans().remove(testPlanID);
|
||||
this.getTestPlanService().handleTestPlanComplete(testPlanID);
|
||||
logger.info("Test plan with id " + testPlanID.toString() + " finishes!");
|
||||
// TODO: when taskComplete do something, pick a test plan which is not
|
||||
// Pending or Error to execute.
|
||||
pickAnotherToRun();
|
||||
}
|
||||
|
||||
private void pickAnotherToRun() {
|
||||
|
||||
}
|
||||
|
||||
public ScriptBriefResultModel getScriptBrief(UUID testPlanId, int scriptId) {
|
||||
RunningScriptModel runningScriptModel = this.testPlanContainer
|
||||
RunningScriptModel runningScriptModel = this.getTestPlanContainer()
|
||||
.queryRunningScriptModel(testPlanId, scriptId);
|
||||
if (runningScriptModel == null) {
|
||||
return null;
|
||||
}
|
||||
if (runningScriptModel.isFinish()) {
|
||||
ScriptBriefResultModel result = new ScriptBriefResultModel();
|
||||
result.setFinished(true);
|
||||
return result;
|
||||
}
|
||||
ScriptBriefResultModel result = this.getTestPlanScriptService()
|
||||
.getRunningScriptBrief(testPlanId, runningScriptModel);
|
||||
if (result == null) {
|
||||
return null;
|
||||
}
|
||||
long planedExecuteTime = this.testPlanService.queryExecuteTime(
|
||||
testPlanId, scriptId);
|
||||
result.setPlanedRunningTime(planedExecuteTime);
|
||||
result.setPlanedRunningTime(runningScriptModel.getConfig()
|
||||
.getExecuteRange());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue