refactor a little

This commit is contained in:
coderfengyun 2014-02-28 15:36:37 +08:00
parent ea976a2ee4
commit 36eab5585b
7 changed files with 20 additions and 18 deletions

View File

@ -27,7 +27,7 @@ public class TestPlan implements IAggregate {
private String name;
private int sampleCycleInSeconds;
private Date createDateTime;
private Date latestRunningTime;
private Date lastRunningTime;
private User user;
private String testPlanRunId;
private String currentStatus;
@ -84,13 +84,13 @@ public class TestPlan implements IAggregate {
this.createDateTime = createDateTime;
}
@Column(name = "latestRunningTime", nullable = false)
public Date getLatestRunningTime() {
return latestRunningTime;
@Column(name = "lastRunningTime", nullable = false)
public Date getLastRunningTime() {
return lastRunningTime;
}
public void setLatestRunningTime(Date latestRunningTime) {
this.latestRunningTime = latestRunningTime;
public void setLastRunningTime(Date lastRunningTime) {
this.lastRunningTime = lastRunningTime;
}
@ManyToOne

View File

@ -62,7 +62,7 @@ public class TestPlanFactory {
result.setFailTimes(0);
result.setName(testPlanModel.getName());
result.setSampleCycleInSeconds(getLargerOneBetweenUserOptionAndMinInSystem(testPlanModel));
result.setLatestRunningTime(new Date(0));
result.setLastRunningTime(new Date(0));
result.setTestPlanRunId(runId.toString());
result.setUser(user);
Set<TestPlanScript> testPlanScripts = new HashSet<TestPlanScript>();

View File

@ -100,7 +100,7 @@ public class TestPlanEngine implements TaskCompleteCallback,
private void commitInRunning(TestPlan testPlan) {
testPlan.setCurrentStatus(TestPlanStatus.InRunning.name());
testPlan.setLatestRunningTime(new Date());
testPlan.setLastRunningTime(new Date());
getTestPlanRepository().attachRunningTestPlan(testPlan);
getTestPlanRepository().updateEntity(testPlan);
}

View File

@ -125,7 +125,7 @@ public class HighAvailablePool extends CurrentLoadSubject {
this.setCurrentAvailableLoad((long) 0);
this.setMaxAvailableLoad((long) 0);
for (Agent agent : this.agentService.loadAgentPoolFromDB()) {
checkHeartBeat(agent);
checkHeartBeatAndUpdateMaxLoadAndAvailableLoad(agent);
}
logger.info("Current Available load in pool is "
+ this.getCurrentAvailableLoad());
@ -133,7 +133,7 @@ public class HighAvailablePool extends CurrentLoadSubject {
+ this.getMaxAvailableLoad());
}
public void checkHeartBeat(Agent agent) {
public void checkHeartBeatAndUpdateMaxLoadAndAvailableLoad(Agent agent) {
this.getPool().put(agent.getHostName(), agent);
ServerStatusModel model = queryAgentStatus(agent);
if (model == null) {

View File

@ -48,7 +48,7 @@ public class BriefAgentFault implements FaultTolerance {
}
synchronized (this.getHaPool().getPool()) {
this.getHaPool().checkHeartBeat(this.getAgent());
this.getHaPool().checkHeartBeatAndUpdateMaxLoadAndAvailableLoad(this.getAgent());
}
}

View File

@ -1 +1,3 @@
portToServe=7979
maxFailTime=10
minExcuteIntervalInSeconds=600

View File

@ -59,7 +59,7 @@ public class Test_TestPlanEngine extends TestBase_MakeUpTestPlan {
getTestPlanRunIdUuid());
assertEquals(TestPlanStatus.InRunning,
TestPlanStatus.valueOf(testPlan.getCurrentStatus()));
assertTrue(testPlan.getLatestRunningTime().after(dateBeforeRun));
assertTrue(testPlan.getLastRunningTime().after(dateBeforeRun));
assertEquals(TestPlanStatus.InRunning,
TestPlanStatus.valueOf(getTestPlanRepository()
.getRunningTestPlanBy(getTestPlanRunIdUuid())
@ -73,14 +73,14 @@ public class Test_TestPlanEngine extends TestBase_MakeUpTestPlan {
System.out.println("This need each agent not in running");
User user = this.getUserRepository().getUser("admin");
int scriptId = getUserFirstScript(user);
this.getHaPool().getPool().clear();
this.setTestPlanRunIdUuid(this.getTestPlanEngine().runWith(
createATestPlanWithOneScript(scriptId), user));
Thread.sleep(10000);
assertNotEquals(
TestPlanStatus.InRunning,
TestPlanStatus.valueOf(this.getTestPlanRepository()
.getTestPlanBy(getTestPlanRunIdUuid())
.getCurrentStatus()));
TestPlan testPlan = this.getTestPlanRepository().getTestPlanBy(
getTestPlanRunIdUuid());
assertNotEquals(TestPlanStatus.InRunning,
TestPlanStatus.valueOf(testPlan.getCurrentStatus()));
assertNull(this.getTestPlanRepository().getRunningTestPlanBy(
getTestPlanRunIdUuid()));
deleteTestPlan();