add two fields for testplan

This commit is contained in:
coderfengyun 2014-02-28 10:48:27 +08:00
parent c80a2bcbf3
commit 87e778dcde
4 changed files with 45 additions and 11 deletions

View File

@ -24,7 +24,9 @@ import org.bench4q.master.domain.testplan.LoadDistribute;
public class TestPlan implements IAggregate {
private int id;
private String name;
private int sampleCycleInSeconds;
private Date createDateTime;
private Date latestRunningTime;
private User user;
private String testPlanRunId;
private String currentStatus;
@ -53,6 +55,15 @@ public class TestPlan implements IAggregate {
this.name = name;
}
@Column(name = "sampleCycleInSeconds", nullable = false)
public int getSampleCycleInSeconds() {
return sampleCycleInSeconds;
}
public void setSampleCycleInSeconds(int sampleCycleInSeconds) {
this.sampleCycleInSeconds = sampleCycleInSeconds;
}
@Column(name = "testPlanRunId", columnDefinition = "TEXT", nullable = false)
public String getTestPlanRunId() {
return testPlanRunId;
@ -71,6 +82,15 @@ public class TestPlan implements IAggregate {
this.createDateTime = createDateTime;
}
@Column(name = "latesetRunningTime", nullable = false)
public Date getLatestRunningTime() {
return latestRunningTime;
}
public void setLatestRunningTime(Date latestRunningTime) {
this.latestRunningTime = latestRunningTime;
}
@ManyToOne
@JoinColumn(name = "userId", nullable = false)
public User getUser() {

View File

@ -31,6 +31,7 @@ import org.springframework.stereotype.Component;
@Component
public class TestPlanFactory {
private static final int Min_Sample_Cycle_InSecond = 10;
private ScriptService scriptService;
private AgentRepository agentRepository;
@ -52,17 +53,19 @@ public class TestPlanFactory {
this.agentRepository = agentRepository;
}
public TestPlan createATestPlanWithoutIdentity(
TestPlanModel testPlanBusinessModel, User user, UUID runId) {
public TestPlan createATestPlanWithoutIdentity(TestPlanModel testPlanModel,
User user, UUID runId) {
TestPlan result = new TestPlan();
result.setCreateDateTime(new Date());
result.setCurrentStatus(TestPlanStatus.NotStart.name());
result.setFailTimes(0);
result.setName(testPlanBusinessModel.getName());
result.setName(testPlanModel.getName());
result.setSampleCycleInSeconds(getLargerOneBetweenUserOptionAndMinInSystem(testPlanModel));
result.setLatestRunningTime(new Date(0));
result.setTestPlanRunId(runId.toString());
result.setUser(user);
Set<TestPlanScript> testPlanScripts = new HashSet<TestPlanScript>();
for (RunningScriptModel runningScriptModel : testPlanBusinessModel
for (RunningScriptModel runningScriptModel : testPlanModel
.getRunningScriptModels()) {
testPlanScripts.add(createATestPlanScriptWithoutId(
runningScriptModel.getRequireLoad(),
@ -72,8 +75,7 @@ public class TestPlanFactory {
result.setTestPlanScripts(testPlanScripts);
Set<Monitor> monitors = new HashSet<Monitor>();
for (MonitorModel monitorModel : testPlanBusinessModel
.getMonitorModels()) {
for (MonitorModel monitorModel : testPlanModel.getMonitorModels()) {
Monitor monitorInBusiness = BusinessModelMapFactory
.toBusiness(monitorModel);
monitorInBusiness.setTestPlan(result);
@ -83,6 +85,12 @@ public class TestPlanFactory {
return result;
}
private int getLargerOneBetweenUserOptionAndMinInSystem(
TestPlanModel testPlanModel) {
return testPlanModel.getSampleCycleInSeconds() <= Min_Sample_Cycle_InSecond ? Min_Sample_Cycle_InSecond
: testPlanModel.getSampleCycleInSeconds();
}
public TestPlanScript createATestPlanScriptWithoutId(int requireLoad,
int scriptId, TestScriptConfig config, TestPlan testPlanDB) {
TestPlanScript testPlanScript = new TestPlanScript();

View File

@ -1,5 +1,6 @@
package org.bench4q.master.domain.service;
import java.util.Date;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@ -105,6 +106,7 @@ public class TestPlanEngine implements TaskCompleteCallback,
private void commitInRunning(TestPlan testPlan) {
testPlan.setCurrentStatus(TestPlanStatus.InRunning.name());
testPlan.setLatestRunningTime(new Date());
getTestPlanRepository().updateEntity(testPlan);
}

View File

@ -1,5 +1,7 @@
package org.bench4q.master.test.service;
import java.util.Date;
import org.bench4q.master.domain.entity.TestPlan;
import org.bench4q.master.domain.entity.User;
import org.bench4q.master.domain.service.TestPlanEngine;
@ -53,14 +55,16 @@ public class Test_TestPlanEngine extends TestBase_MakeUpTestPlan {
User user = this.getUserRepository().getUser("admin");
int scriptId = getUserFirstScript(user);
this.getHaPool().timerTask();
Date dateBeforeRun = new Date();
this.setTestPlanRunIdUuid(this.getTestPlanEngine().runWith(
createATestPlanWithOneScript(scriptId), user));
assertNotNull(getTestPlanRunIdUuid());
Thread.sleep(10000);
assertEquals(
TestPlanStatus.InRunning,
TestPlanStatus.valueOf(this.getTestPlanRepository()
.getTestPlanBy(getTestPlanRunIdUuid())
.getCurrentStatus()));
TestPlan testPlan = this.getTestPlanRepository().getTestPlanBy(
getTestPlanRunIdUuid());
assertEquals(TestPlanStatus.InRunning,
TestPlanStatus.valueOf(testPlan.getCurrentStatus()));
assertTrue(testPlan.getLatestRunningTime().after(dateBeforeRun));
assertEquals(
TestPlanStatus.InRunning,
TestPlanStatus.valueOf(this.getTestPlanRepository()