remove all bugs about testplan's current status

This commit is contained in:
Tienan Chen 2013-10-28 11:28:00 +08:00
parent a346117b8b
commit 1425c9c5db
4 changed files with 57 additions and 30 deletions

View File

@ -126,23 +126,24 @@ public class TestPlanController extends BaseController {
return result;
}
@RequestMapping(value = "/getRunningInfo", method = RequestMethod.GET)
@RequestMapping(value = "/getRunningInfo", method = { RequestMethod.GET,
RequestMethod.POST })
@ResponseBody
public TestPlanResultModel getTestPlanRunningInfo(
@RequestParam UUID testPlanID) {
@RequestParam UUID testPlanId) {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
return null;
}
TestPlanContext testPlanContext = this.getTestPlanContainer()
.getRunningTestPlans().get(testPlanID);
.getRunningTestPlans().get(testPlanId);
if (testPlanContext == null) {
this.getLogger().error("testPlanContext is null!!");
return buildResponseModel(this.getTestPlanService()
.queryTestPlanStatus(testPlanID), testPlanID, null, null);
.queryTestPlanStatus(testPlanId), testPlanId, null, null);
}
this.getLogger().info("testPlanContext exists!");
return buildResponseModel(this.getTestPlanService()
.queryTestPlanStatus(testPlanID), testPlanID,
.queryTestPlanStatus(testPlanId), testPlanId,
new ArrayList<RunningScriptModel>(testPlanContext
.getRunningScriptMap().values()), testPlanContext
.getTestPlanModel().getMonitorModles());

View File

@ -332,8 +332,8 @@ public class TestPlanService {
try {
TestPlan testPlan = (TestPlan) session
.createCriteria(TestPlan.class)
.add(Restrictions.eq("testPlanRunId", testPlanRunID))
.uniqueResult();
.add(Restrictions.eq("testPlanRunId",
testPlanRunID.toString())).uniqueResult();
return testPlan == null ? -1 : testPlan.getCurrentStatus();
} catch (Exception e) {
logger.error("there is an exception in queryTestPlanStatus!");

View File

@ -1,5 +1,27 @@
log4j.rootLogger = INFO,WARN,ERROR,FALTAL,D
log4j.appender.WARN = org.apache.log4j.DailyRollingFileAppender
log4j.appender.WARN.File = logs/log.log
log4j.appender.WARN.Append = true
log4j.appender.WARN.Threshold = WARN
log4j.appender.WARN.layout = org.apache.log4j.PatternLayout
log4j.appender.WARN.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
log4j.appender.ERROR = org.apache.log4j.DailyRollingFileAppender
log4j.appender.ERROR.File = logs/log.log
log4j.appender.ERROR.Append = true
log4j.appender.ERROR.Threshold = ERROR
log4j.appender.ERROR.layout = org.apache.log4j.PatternLayout
log4j.appender.ERROR.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
log4j.appender.FALTAL = org.apache.log4j.DailyRollingFileAppender
log4j.appender.FALTAL.File = logs/log.log
log4j.appender.FALTAL.Append = true
log4j.appender.FALTAL.Threshold = ERROR
log4j.appender.FALTAL.layout = org.apache.log4j.PatternLayout
log4j.appender.FALTAL.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = logs/log.log
log4j.appender.D.Append = true

View File

@ -16,10 +16,12 @@ import javax.xml.bind.Unmarshaller;
import org.bench4q.master.api.model.MonitorModel;
import org.bench4q.master.api.model.RunningScriptModel;
import org.bench4q.master.api.model.ScriptBriefResultModel;
import org.bench4q.master.api.model.TestScriptConfig;
import org.bench4q.master.api.model.TestPlanModel;
import org.bench4q.master.api.model.TestPlanResultModel;
import org.bench4q.master.communication.HttpRequester.HttpResponse;
import org.bench4q.master.service.TestPlanService;
public class TestPlanTester extends TestBase {
private TestPlanModel testPlan = new TestPlanModel();
@ -102,23 +104,30 @@ public class TestPlanTester extends TestBase {
private TestPlanResultModel _extractRunTestPlanResultModel(String content)
throws JAXBException {
TestPlanResultModel resultModel = new TestPlanResultModel();
Unmarshaller unmarshaller = JAXBContext.newInstance(
resultModel.getClass()).createUnmarshaller();
resultModel = (TestPlanResultModel) unmarshaller
TestPlanResultModel.class).createUnmarshaller();
return (TestPlanResultModel) unmarshaller
.unmarshal(new ByteArrayInputStream(content.getBytes()));
return resultModel;
}
public void getScriptBrief(UUID testPlanId, int scriptId)
throws IOException {
public ScriptBriefResultModel getScriptBrief(UUID testPlanId, int scriptId)
throws IOException, JAXBException {
Map<String, String> params = new HashMap<String, String>();
params.put("testPlanId", testPlanId.toString());
params.put("scriptId", String.valueOf(scriptId));
Map<String, String> properties = createAccessTokenMap();
HttpResponse httpResponse = this.httpRequester.sendGet(this._url
+ "/getScriptBrief", params, properties);
+ "/getScriptBrief", params, createAccessTokenMap());
System.out.println(httpResponse.getContent());
return extractScriptBriefModel(httpResponse.getContent());
}
private ScriptBriefResultModel extractScriptBriefModel(String content)
throws JAXBException {
Unmarshaller unmarshaller = JAXBContext.newInstance(
ScriptBriefResultModel.class).createUnmarshaller();
return (ScriptBriefResultModel) unmarshaller
.unmarshal(new ByteArrayInputStream(content.getBytes()));
}
private Map<String, String> createAccessTokenMap() {
@ -131,7 +140,6 @@ public class TestPlanTester extends TestBase {
public void getMonitorBrief(UUID testPlanID, String hostName, String port)
throws IOException, InterruptedException {
for (int i = 0; i < 2; i++) {
Thread.sleep(6000);
getMonitorMemoryResult(testPlanID, hostName, port);
getProcessorResult(testPlanID, hostName, port);
getLogicalDiskResult(testPlanID, hostName, port);
@ -201,25 +209,21 @@ public class TestPlanTester extends TestBase {
public void runAndGetBrief() throws IOException, JAXBException,
InterruptedException {
UUID testPlanID = this.testWithTestPlanModel();
Thread.sleep(6000);
this.getRunningInfo(testPlanID);
Thread.sleep(14000);
this.getScriptBrief(testPlanID, SCRIPTID);
Thread.sleep(10000);
this.getScriptBrief(testPlanID, SCRIPTID);
TestPlanResultModel testPlanResultModel = this
.getRunningInfo(testPlanID);
if (testPlanResultModel.getCurrentStatus() != TestPlanService.TEST_PLAN_STATUS_IN_RUNNING) {
return;
}
Thread.sleep(10000);
for (int i = 0; i < 3; i++) {
Thread.sleep(15000);
this.getScriptBrief(testPlanID, SCRIPTID);
}
this.getScriptBrief(testPlanID, SCRIPTID);
Thread.sleep(6000);
this.getMonitorBrief(testPlanID, Monitor_Host_Name, monitor_port);
this.getTestPlanReport(testPlanID);
}