This commit is contained in:
coderfengyun 2013-12-30 09:18:03 +08:00
parent 0c48de4325
commit 4e9ad53156
4 changed files with 19 additions and 21 deletions

View File

@ -166,7 +166,7 @@ public class TestPlanController extends BaseController {
"/getRunningInfo");
}
TestPlanContext testPlanContext = this.getTestPlanContainer()
.getRunningTestPlans().get(testPlanId);
.queryTestPlanContext(testPlanId);
if (testPlanContext == null) {
this.getLogger().error("testPlanContext is null!!");
throw new Bench4QException(CONTEXT_NOT_EXIST,
@ -204,13 +204,12 @@ public class TestPlanController extends BaseController {
"/getRunningInfo");
}
ScriptBriefResultModel ret = new ScriptBriefResultModel();
if (!this.getTestPlanContainer().getRunningTestPlans()
.containsKey(testPlanId)) {
if (!this.getTestPlanContainer().isContextExist(testPlanId)) {
throw new Bench4QException(CONTEXT_NOT_EXIST,
THE_CONTEXT_IS_NULL_WHOSE_ID_IS, "/getScriptBrief");
}
TestPlanContext context = this.getTestPlanContainer()
.getRunningTestPlans().get(testPlanId);
.queryTestPlanContext(testPlanId);
if (context.isFinish()) {
ret.setFinished(true);
return ret;
@ -322,7 +321,7 @@ public class TestPlanController extends BaseController {
guardForTestPlan(testPlanRunID);
ScriptBehaviorsBriefModel ret = new ScriptBehaviorsBriefModel();
TestPlanContext context = this.getTestPlanContainer()
.getRunningTestPlans().get(testPlanRunID);
.queryTestPlanContext(testPlanRunID);
if (context.isFinish() || !context.isContains(scriptId)) {
ret.setFinished(true);
return ret;
@ -340,8 +339,7 @@ public class TestPlanController extends BaseController {
throw new Bench4QException(HAVE_NO_POWER, EXCEPTION_HAPPEND
+ "when get behaviors's brief", "/getBehaviorsBrief");
}
if (!this.getTestPlanContainer().getRunningTestPlans()
.containsKey(testPlanRunID)) {
if (!this.getTestPlanContainer().isContextExist(testPlanRunID)) {
throw new Bench4QException(CONTEXT_NOT_EXIST,
THE_CONTEXT_IS_NULL_WHOSE_ID_IS, "/getBehaviorsBrief");
}
@ -354,7 +352,7 @@ public class TestPlanController extends BaseController {
throws Bench4QException, NullPointerException {
guardForTestPlan(testPlanRunId);
TestPlanContext context = this.getTestPlanContainer()
.getRunningTestPlans().get(testPlanRunId);
.queryTestPlanContext(testPlanRunId);
RunningScript runningScript = context.queryRunningScript(scriptId);
if (RunningScript.notValidScript(runningScript)) {
throw new Bench4QException(EXCEPTION_HAPPEND + " RunningScript",

View File

@ -59,4 +59,5 @@ public class RunningScriptService {
result);
return result;
}
}

View File

@ -11,36 +11,35 @@ import org.springframework.stereotype.Component;
@Component
public class TestPlanContainer {
private Map<UUID, TestPlanContext> runningTestPlans = new HashMap<UUID, TestPlanContext>();
private Map<UUID, TestPlanContext> runningTestPlans;
private Logger logger = Logger.getLogger(TestPlanContainer.class);
public Map<UUID, TestPlanContext> getRunningTestPlans() {
private Map<UUID, TestPlanContext> getRunningTestPlans() {
return runningTestPlans;
}
public void setRunningTestPlans(Map<UUID, TestPlanContext> runningTestPlans) {
private void setRunningTestPlans(Map<UUID, TestPlanContext> runningTestPlans) {
this.runningTestPlans = runningTestPlans;
}
private TestPlanContainer() {
this.setRunningTestPlans(new HashMap<UUID, TestPlanContext>());
}
public TestPlanContext queryTestPlanContext(UUID testPlanId) {
return this.runningTestPlans.get(testPlanId);
}
public boolean isContextExist(UUID testPlanId) {
return this.getRunningTestPlans().containsKey(testPlanId);
}
public TestPlanContext addATask(UUID testPlanId,
TestPlanContext testPlanContext) {
return this.runningTestPlans.put(testPlanId, testPlanContext);
}
public RunningScript queryRunningScriptModel(UUID testPlanId, int scriptId) {
TestPlanContext testPlanContext = this.getRunningTestPlans().get(
testPlanId);
if (testPlanContext == null) {
return null;
}
return testPlanContext.queryRunningScript(scriptId);
}
public boolean isTestPlanFinished(UUID testPlanId) {
TestPlanContext testPlanContext = this.queryTestPlanContext(testPlanId);
boolean finish = true;

View File

@ -165,7 +165,7 @@ public class HighAvailablePool extends CurrentLoadSubject {
UUID deadRunId) {
logger.info("enter substituteOnBoard");
TestPlanContext context = this.getTestPlanContainer()
.getRunningTestPlans().get(deadAgentBlotter.getTestPlanId());
.queryTestPlanContext(deadAgentBlotter.getTestPlanId());
if (context == null) {
logger.info("The testPlan has finished or not started, so no need to substitute!");
return;