diff --git a/Bench4Q-Master/RecordScriptTestCase/baidu.html b/Bench4Q-Master/RecordScriptTestCase/baidu.html new file mode 100644 index 00000000..52ca5b51 --- /dev/null +++ b/Bench4Q-Master/RecordScriptTestCase/baidu.html @@ -0,0 +1,63 @@ + + + +???--??????????? + + + + + + + + +
???????? + + + + + + +
 ???????????
+
+
+

????????????????????!


+
+
+
    +
  1. 1. ?????????????????????

  2. +
  3. 2. ?????????????????????????????????????????

  4. +
  5. 3. ??????????????????
  6. + +
  7. + 4.?????????????????????????? +


    + ???????????????????????????????????????????????????????hao123 +
  8. ??
+ + +
+ + scriptIds, List monitorModels) { + List scripts, List monitorModels) { TestPlanResultModel result = new TestPlanResultModel(); result.setCurrentStatus(currentStatus); result.setTestPlanId(testPlanId); - result.setScriptIds(scriptIds); + result.setScripts(scripts); result.setMonitorModels(monitorModels); return result; } @@ -165,6 +166,7 @@ public class TestPlanController extends BaseController { return ret; } + @RequestMapping(value = "/getBehaviorsBrief/{testPlanRunID}/{scriptId}") @ResponseBody public ScriptBehaviorsBriefModel getBehaviorsBrief( @@ -180,7 +182,6 @@ public class TestPlanController extends BaseController { return result; } - @RequestMapping(value = "/pagesBrief/{testPlanRunId}/{scriptId}") @ResponseBody public ScriptPagesBriefModel getPagesBrief( @@ -283,5 +284,19 @@ public class TestPlanController extends BaseController { e.printStackTrace(); } } + @RequestMapping(value = "/scriptBrief/{testPlanId}/{scriptId}/latestResult") + @ResponseStatus(value = HttpStatus.OK) + @ResponseBody + public ScriptBriefResultModel getLatestScriptResult( + @PathVariable UUID testPlanId, @PathVariable int scriptId) + throws Bench4QException { + if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) { + throw new Bench4QException(HAVE_NO_POWER, + "You have not power to get test plan script brief", + "/getLatestScriptResult"); + } + return this.getTestPlanScriptResultService() + .getLatestScriptBriefResultModel(testPlanId, scriptId); + } } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/TestPlanScriptResultService.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/TestPlanScriptResultService.java index a50da4ac..8e615518 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/TestPlanScriptResultService.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/TestPlanScriptResultService.java @@ -108,6 +108,7 @@ public class TestPlanScriptResultService { return new ScriptBehaviorsBriefModel(); } + private TestPlanScriptResult doGetLastSampleResult(UUID testPlanId, int scriptId, Class resultType, Session session) { TestPlanScript testPlanScript = this.getTestPlanRepository() @@ -147,4 +148,16 @@ public class TestPlanScriptResultService { } return result; } + public ScriptBriefResultModel getLatestScriptBriefResultModel( + UUID testPlanId, int scriptId) { + Session session = this.getSessionHelper().openSession(); + TestPlanScriptResult testPlanScriptResult = this.doGetLastSampleResult( + testPlanId, scriptId, ScriptBriefResultModel.class, session); + if (testPlanScriptResult == null) { + return null; + } + return (ScriptBriefResultModel) MarshalHelper.tryUnmarshal( + ScriptBriefResultModel.class, + testPlanScriptResult.getResultContent()); + } } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/TestPlanService.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/TestPlanService.java index e9a6fa19..52f8641f 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/TestPlanService.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/TestPlanService.java @@ -12,6 +12,7 @@ import org.bench4q.master.domain.factory.BusinessModelMapFactory; import org.bench4q.master.domain.repository.TestPlanRepository; import org.bench4q.share.enums.master.TestPlanStatus; import org.bench4q.share.models.master.MonitorModel; +import org.bench4q.share.models.master.ScriptHandleModel; import org.bench4q.share.models.master.TestPlanDBModel; import org.bench4q.share.models.master.TestPlanResultModel; import org.springframework.beans.factory.annotation.Autowired; @@ -66,11 +67,14 @@ public class TestPlanService { resultModel.setCurrentStatus(TestPlanStatus.valueOf(testPlan .getCurrentStatus())); resultModel.setTestPlanId(runId); - List scriptIds = new LinkedList(); + List scripts = new LinkedList(); for (TestPlanScript testPlanScript : testPlan.getTestPlanScripts()) { - scriptIds.add(testPlanScript.getScript().getId()); + ScriptHandleModel scriptHandleModel = new ScriptHandleModel( + testPlanScript.getScript().getId(), testPlanScript + .getScript().getName()); + scripts.add(scriptHandleModel); } - resultModel.setScriptIds(scriptIds); + resultModel.setScripts(scripts); List monitorModels = new LinkedList(); for (Monitor monitor : testPlan.getMonitors()) { monitorModels.add(BusinessModelMapFactory.toModel(monitor)); diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_TestPlanService.java b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_TestPlanService.java index c6a6f062..d9b63e1d 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_TestPlanService.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_TestPlanService.java @@ -91,7 +91,7 @@ public class Test_TestPlanService extends TestBase_MakeUpTestPlan { public void testBuildResponseModel() { TestPlanResultModel responseModel = this.getTestPlanService() .buildResultModel(getTestPlanRunIdUuid()); - assertEquals(1, responseModel.getScriptIds().size()); + assertEquals(1, responseModel.getScripts().size()); assertEquals(1, responseModel.getMonitorModels().size()); assertEquals(getTestPlanRunIdUuid(), responseModel.getTestPlanId()); } diff --git a/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/ScriptHandleModel.java b/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/ScriptHandleModel.java new file mode 100644 index 00000000..e3ef6f2f --- /dev/null +++ b/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/ScriptHandleModel.java @@ -0,0 +1,38 @@ +package org.bench4q.share.models.master; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +public class ScriptHandleModel { + private Integer scriptId; + private String scriptName; + + public ScriptHandleModel() { + + } + + public ScriptHandleModel(Integer scriptId, String scriptName) { + this.scriptId = scriptId; + this.scriptName = scriptName; + } + + @XmlElement + public Integer getScriptId() { + return scriptId; + } + + public void setScriptId(Integer scriptId) { + this.scriptId = scriptId; + } + + @XmlElement + public String getScriptName() { + return scriptName; + } + + public void setScriptName(String scriptName) { + this.scriptName = scriptName; + } + +} diff --git a/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/TestPlanResultModel.java b/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/TestPlanResultModel.java index ad9001cb..ea3e3e17 100644 --- a/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/TestPlanResultModel.java +++ b/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/TestPlanResultModel.java @@ -13,7 +13,7 @@ import org.bench4q.share.enums.master.TestPlanStatus; public class TestPlanResultModel { private UUID testPlanId; private TestPlanStatus currentStatus; - private List scriptIds; + private List scripts; private List monitorModels; @XmlElement(name = "testPlanId") @@ -34,16 +34,6 @@ public class TestPlanResultModel { this.currentStatus = currentStatus; } - @XmlElementWrapper(name = "scriptIdList") - @XmlElement(name = "scriptId") - public List getScriptIds() { - return scriptIds; - } - - public void setScriptIds(List scriptIds) { - this.scriptIds = scriptIds; - } - @XmlElementWrapper(name = "MonitorModelList") @XmlElement(name = "MonitorModel") public List getMonitorModels() { @@ -54,4 +44,14 @@ public class TestPlanResultModel { this.monitorModels = monitorModels; } + @XmlElementWrapper(name = "scripts") + @XmlElement(name = "script") + public List getScripts() { + return scripts; + } + + public void setScripts(List scripts) { + this.scripts = scripts; + } + } diff --git a/Bench4Q-Web/TestResult.xml b/Bench4Q-Web/TestResult.xml new file mode 100644 index 00000000..51e76106 --- /dev/null +++ b/Bench4Q-Web/TestResult.xml @@ -0,0 +1,105 @@ + + + + + + processorTimePercent + 使用率 + + + privilegedTimePercent + 系统使用率 + + + userTimePercent + 用户使用率 + + cpu + cpu + + + + pagesPerSecond + 页速率 + + + pagesInputPerSecond + 读页速率 + + + pagesOutputPerSecond + 写页速率 + + + availableKiloBytes + 可用内存(kb) + + + totalKiloBytes + 总容量(kb) + + + memoryUsedPercent + 使用率 + + + swapKiloBytes + 交换内存(kb) + + + swapFreeKiloBytes + + + 内存 + mem + + + + 累计成功数目 + totalSuccessCountFromBegin + + + 累计失败数目 + totalFailCountFromBegin + + + 平均响应时间 + averageResponseTime + + + 最大响应时间 + maxResponseTime + + + 最小响应时间 + minResponseTime + + + 最大吞吐率 + successThroughputThisTime + + + 失败吞吐率 + failThroughputThisTime + + + 响应时间 + responseTimeDeviationThisTime + + + 平均延迟时间 + averageElapsedTime + + + 计划运行时间 + planedRunningTime + + + 虚拟用户 + vUserCount + + 脚本运行结果 + scriptBriefResult + + + diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/api/Main.java b/Bench4Q-Web/src/main/java/org/bench4q/web/api/Main.java new file mode 100644 index 00000000..2065b23a --- /dev/null +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/api/Main.java @@ -0,0 +1,110 @@ +package org.bench4q.web.api; + +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.util.LinkedList; +import java.util.List; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; + +import org.bench4q.web.model.ResultInfoModel; +import org.bench4q.web.model.TestResult; + +public class Main { + + public static void main(String[] args) throws JAXBException { + Main main=new Main(); + try { + TestResult testResult = new TestResult(); + List results = new LinkedList(); + results.add(main.createCpuResult()); + results.add(main.createMemoryResult()); + testResult.setResultInfoModels(results); + OutputStream os = new FileOutputStream("sut.xml"); + Marshaller marshaller = JAXBContext.newInstance(TestResult.class) + .createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + marshaller.marshal(testResult, os); + + + results.clear(); + results.add(main.createScriptResult()); + testResult.setResultInfoModels(results); + OutputStream os1 = new FileOutputStream("script.xml"); + + marshaller.marshal(testResult, os1); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + private ResultInfoModel createScriptResult() { + try { + ResultInfoModel resultInfoModel = new ResultInfoModel(); + resultInfoModel.setName("脚本运行结果"); + resultInfoModel.setValue("scriptBriefResult"); + + List resultIntems = new LinkedList(); + resultIntems.add(new ResultInfoModel("累计成功数目", + "totalSuccessCountFromBegin")); + resultIntems.add(new ResultInfoModel("累计失败数目", + "totalFailCountFromBegin")); + resultIntems.add(new ResultInfoModel("平均响应时间", + "averageResponseTime")); + resultIntems.add(new ResultInfoModel("最大响应时间", "maxResponseTime")); + resultIntems.add(new ResultInfoModel("最小响应时间", "minResponseTime")); + resultIntems.add(new ResultInfoModel("最大吞吐率", + "successThroughputThisTime")); + resultIntems.add(new ResultInfoModel("失败吞吐率", + "failThroughputThisTime")); + resultIntems.add(new ResultInfoModel("响应时间", + "responseTimeDeviationThisTime")); + resultIntems + .add(new ResultInfoModel("平均延迟时间", "averageElapsedTime")); + resultIntems + .add(new ResultInfoModel("计划运行时间", "planedRunningTime")); + resultIntems.add(new ResultInfoModel("虚拟用户", "vUserCount")); + resultInfoModel.setChildren(resultIntems); + return resultInfoModel; + + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + + private ResultInfoModel createCpuResult() { + ResultInfoModel resultInfoModel = new ResultInfoModel(); + resultInfoModel.setName("cpu"); + resultInfoModel.setValue("cpu"); + List cpuItems = new LinkedList(); + cpuItems.add(new ResultInfoModel("processorTimePercent", "使用率")); + cpuItems.add(new ResultInfoModel("privilegedTimePercent", "系统使用率")); + cpuItems.add(new ResultInfoModel("userTimePercent", "用户使用率")); + resultInfoModel.setChildren(cpuItems); + return resultInfoModel; + + } + + private ResultInfoModel createMemoryResult() { + ResultInfoModel resultInfoModel = new ResultInfoModel(); + resultInfoModel.setName("内存"); + resultInfoModel.setValue("mem"); + List memItems = new LinkedList(); + memItems.add(new ResultInfoModel("pagesPerSecond", "页速率")); + memItems.add(new ResultInfoModel("pagesInputPerSecond", "读页速率")); + memItems.add(new ResultInfoModel("pagesOutputPerSecond", "写页速率")); + memItems.add(new ResultInfoModel("availableKiloBytes", "可用内存(kb)")); + memItems.add(new ResultInfoModel("totalKiloBytes", "总容量(kb)")); + memItems.add(new ResultInfoModel("memoryUsedPercent", "使用率")); + memItems.add(new ResultInfoModel("swapKiloBytes", "交换内存(kb)")); + memItems.add(new ResultInfoModel("swapFreeKiloBytes", "")); + resultInfoModel.setChildren(memItems); + return resultInfoModel; + } + +} diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/api/TestPlanController.java b/Bench4Q-Web/src/main/java/org/bench4q/web/api/TestPlanController.java new file mode 100644 index 00000000..775ddd01 --- /dev/null +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/api/TestPlanController.java @@ -0,0 +1,395 @@ +package org.bench4q.web.api; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.xml.bind.JAXBException; +import org.apache.log4j.Logger; +import org.bench4q.share.helper.ExceptionLog; +import org.bench4q.share.helper.MarshalHelper; +import org.bench4q.share.models.agent.BehaviorStatusCodeResultModel; +import org.bench4q.share.models.master.MonitorModel; +import org.bench4q.share.models.master.ScriptHandleModel; +import org.bench4q.share.models.master.TestPlanDBModel; +import org.bench4q.share.models.master.TestPlanModel; +import org.bench4q.share.models.master.TestPlanResultModel; +import org.bench4q.share.models.master.TestPlanScriptBriefResultModel; +import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel; +import org.bench4q.share.models.master.statistics.ScriptBriefResultModel; +import org.bench4q.share.models.master.statistics.ScriptPageBriefModel; +import org.bench4q.web.init.TestResultHandle; +import org.bench4q.web.masterMessager.TestPlanMessager; +import org.bench4q.web.model.ResultInfoModel; +import org.bench4q.web.model.TestBriefStatusModel; +import org.bench4q.web.model.TestPlanRequestModel; +import org.bench4q.web.model.UrlContentTypeDistributionModel; +import org.bench4q.web.service.TestPlanService; +import org.bench4q.web.validation.TestPlanValidate; +import org.bench4q.web.validation.ValidateResponseModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.SessionAttributes; + +@Controller +@SessionAttributes({ "accessToken" }) +public class TestPlanController extends BaseController { + private TestPlanMessager testPlanMessager; + + private TestPlanValidate testPlanValidate; + + private TestPlanService testPlanService; + + private final int monitorPort = 5556; + + private TestPlanMessager getTestPlanMessager() { + return testPlanMessager; + } + + + @Autowired + private void setTestPlanMessager(TestPlanMessager testPlanMessager) { + this.testPlanMessager = testPlanMessager; + } + + private TestPlanValidate getTestPlanValidate() { + return testPlanValidate; + } + + @Autowired + private void setTestPlanValidate(TestPlanValidate testPlanValidate) { + this.testPlanValidate = testPlanValidate; + } + + private TestPlanService getTestPlanService() { + return testPlanService; + } + + @Autowired + private void setTestPlanService(TestPlanService testPlanService) { + this.testPlanService = testPlanService; + } + + + @RequestMapping(value = "runTestPlan", method = RequestMethod.POST) + @ResponseBody + public Map runTestPlan( + @ModelAttribute("accessToken") String accessToken, + @RequestBody TestPlanRequestModel testPlanRequestModel) { + Map map = new HashMap(); + ValidateResponseModel validateResponseModel = this + .getTestPlanValidate().validateTestPlanSubmited( + testPlanRequestModel); + if (!validateResponseModel.isSuccess()) { + return fail(map, validateResponseModel.getMessage()); + } else { + TestPlanModel testPlanModel = this.getTestPlanService() + .createTestPlan(testPlanRequestModel, monitorPort); + String testPlanContent; + try { + testPlanContent = MarshalHelper.marshal(TestPlanModel.class, + testPlanModel); + + } catch (JAXBException e) { + Logger.getLogger(TestPlanController.class).info( + ExceptionLog.getStackTrace(e)); + return fail(map, "error testPlan"); + } + TestPlanResultModel testPlanResultModel = this + .getTestPlanMessager().runTestPlan(accessToken, + testPlanContent); + if (testPlanResultModel != null + && testPlanResultModel.getTestPlanId() != null) { + map = success(map); + map.put("testPlanResult", testPlanResultModel); + return map; + } else { + return fail(map, "empty test plan id"); + } + } + } + + @RequestMapping("/{testPlanId}/runningInfo") + @ResponseBody + public Map getRunningInfo( + @ModelAttribute("accessToken") String accessToken, + @PathVariable String testPlanId) { + Map map = new HashMap(); + TestPlanResultModel testPlanResultModel = this.getTestPlanMessager() + .getRunningTestInfo(accessToken, testPlanId); + if (testPlanResultModel == null) { + return fail(map, ""); + } else { + success(map); + map.put("testPlan", testPlanResultModel); + return map; + } + } + + @RequestMapping(value = "/{testPlanId}/queryTestPlan") + @ResponseBody + public Map queryTestPlan( + @ModelAttribute("accessToken") String accessToken, + @PathVariable String testPlanId) { + Map map = new HashMap(); + TestPlanDBModel testPlanResultModel = this.getTestPlanMessager() + .queryTestPlanById(accessToken, testPlanId); + if (testPlanResultModel != null) { + success(map); + map.put("testPlan", testPlanResultModel); + return map; + } else { + return fail(map, ""); + } + } + @RequestMapping("/{testPlanId}/testResultHanadle") + @ResponseBody + public Map getTestResultHandle( + @ModelAttribute("accessToken") String accessToken, + @PathVariable String testPlanId) { + Map map = new HashMap(); + TestPlanResultModel testPlanResultModel = this.getTestPlanMessager() + .getRunningTestInfo(accessToken, testPlanId); + if (testPlanResultModel == null) { + return fail(map, ""); + } + try { + List results = new LinkedList(); + List scriptResultInfoModels = TestResultHandle.scriptResultInfoModel; + List sutResultInfoModels = TestResultHandle.sutInfoModel; + + for (ScriptHandleModel scriptHandleModel : testPlanResultModel + .getScripts()) { + if (scriptHandleModel == null) { + continue; + } + results.add(getScriptResultInfoModels(scriptHandleModel, + scriptResultInfoModels)); + } + if (testPlanResultModel.getMonitorModels() != null) { + for (MonitorModel monitorModel : testPlanResultModel + .getMonitorModels()) { + results.add(getSUTResultInfoModel(monitorModel, + sutResultInfoModels)); + } + } + + map.put("resultHandle", results); + success(map); + return map; + } catch (Exception e) { + Logger.getLogger(this.getClass()).info( + ExceptionLog.getStackTrace(e)); + return fail(map, ""); + } + } + + private ResultInfoModel getScriptResultInfoModels( + ScriptHandleModel scriptHandleModel, + List scriptResultModels) { + ResultInfoModel resultInfoModel = new ResultInfoModel(); + resultInfoModel.setName(scriptHandleModel.getScriptName()); + resultInfoModel.setValue(scriptHandleModel.getScriptId().toString()); + resultInfoModel.setChildren(scriptResultModels); + return resultInfoModel; + } + + private ResultInfoModel getSUTResultInfoModel( + MonitorModel monitorModel, List resultInfoModels) { + ResultInfoModel resultInfoModel = new ResultInfoModel(); + resultInfoModel.setName(monitorModel.getHostName()); + resultInfoModel.setValue(monitorModel.getHostName()); + resultInfoModel.setChildren(resultInfoModels); + return resultInfoModel; + } + + + @RequestMapping("/{testPlanId}/{scriptId}/scriptBriefResult/{fieldName}/{startTime}") + @ResponseBody + public Map getScriptBriefStatus( + @ModelAttribute("accessToken") String accessToken, + @PathVariable String testPlanId, @PathVariable String scriptId, + @PathVariable String fieldName, @PathVariable String startTime) { + Map map = new HashMap(); + TestPlanScriptBriefResultModel testPlanScriptBriefResultModel = this + .getTestPlanMessager().getScriptBriefResult(accessToken, + testPlanId, scriptId, startTime); + if (testPlanScriptBriefResultModel != null) { + success(map); + map.put("result", + this.getTestPlanService().extractResultModelList( + testPlanScriptBriefResultModel, fieldName)); + return map; + + } else { + return fail(map, ""); + } + } + + @RequestMapping("/{testPlanId}/testBriefStatus") + @ResponseBody + public Map getTestBriefStatus( + @ModelAttribute("accessToken") String accessToken, + @PathVariable String testPlanId) { + Map map = new HashMap(); + TestBriefStatusModel testBriefStatusModel = new TestBriefStatusModel(); + long vus = 0; + long requests = 0; + TestPlanResultModel testPlanResultModel = this.getTestPlanMessager() + .getRunningTestInfo(accessToken, testPlanId); + + if (testPlanResultModel == null) { + return fail(map, ""); + } + for (ScriptHandleModel scriptHandleModel : testPlanResultModel + .getScripts()) { + ScriptBriefResultModel lastScriptBriefResultModel = this + .getTestPlanMessager().getLatestScriptBriefResult( + accessToken, testPlanId, + scriptHandleModel.getScriptId().toString()); + if (lastScriptBriefResultModel == null) { + continue; + } + requests += lastScriptBriefResultModel.getTotalFailCountFromBegin() + + lastScriptBriefResultModel + .getTotalSuccessCountFromBegin(); + vus += lastScriptBriefResultModel.getvUserCount(); + } + testBriefStatusModel.setRequests(requests); + testBriefStatusModel.setVus(vus); + map.put("briefInfo", testBriefStatusModel); + return success(map); + } + + + @RequestMapping("/{testPlanId}/script/{scriptId}/behaviors") + @ResponseBody + public Map getScriptBehaviorBriefModel( + @ModelAttribute("accessToken") String accessToken, + @PathVariable String testPlanId, @PathVariable String scriptId) { + Map map = new HashMap(); + ScriptBehaviorsBriefModel scriptBehaviorsBriefModel = this + .getTestPlanMessager().getScriptBehaviorsBriefResult( + accessToken, testPlanId, scriptId); + if (scriptBehaviorsBriefModel == null) { + return fail(map, ""); + } + map = success(map); + map.put("result", scriptBehaviorsBriefModel); + return map; + } + + @RequestMapping("/{testPlanId}/script/{scriptId}/page") + @ResponseBody + public Map getScriptPageBriefModel( + @ModelAttribute("accessToken") String accessToken, + @PathVariable String testPlanId, @PathVariable String scriptId) { + Map map = new HashMap(); + ScriptPageBriefModel scriptPageBriefModel = this.getTestPlanMessager() + .getScriptPageBriefModel(accessToken, testPlanId, scriptId); + + if (scriptPageBriefModel == null) { + return fail(map, ""); + } + map = success(map); + map.put("result", scriptPageBriefModel); + return map; + } + + @SuppressWarnings("unchecked") + @RequestMapping("/{testPlanId}/urlContentTypeDistribution") + @ResponseBody + public Map getUrlContentTypeDistribution( + @ModelAttribute("accessToken") String accessToken, + @PathVariable String testPlanId) { + List urlContentTypeDistributionModels = new ArrayList(); + Map map = new HashMap(); + Map urlContentTypeCountMap = (Map) getUrlContentTypeCount( + accessToken, testPlanId).get("result"); + if (urlContentTypeCountMap == null) { + return fail(map, ""); + } + Map urlContentTypePercentMap = this + .getTestPlanService().getUrlContentTypePercent( + urlContentTypeCountMap); + Set keys = urlContentTypeCountMap.keySet(); + Iterator iterator = keys.iterator(); + while (iterator.hasNext()) { + String key = iterator.next(); + urlContentTypeDistributionModels + .add(new UrlContentTypeDistributionModel(key, + urlContentTypeCountMap.get(key), + urlContentTypePercentMap.get(key))); + } + map = success(map); + map.put("result", urlContentTypePercentMap); + return map; + + } + + @SuppressWarnings("unchecked") + @RequestMapping("/{testPlanId}/urlContentTypePercent") + @ResponseBody + public Map getUrlContentTypePercent( + @ModelAttribute("accessToken") String accessToken, + @PathVariable String testPlanId) { + Map map = new HashMap(); + Map urlContentTypeCountMap = (Map) getUrlContentTypeCount( + accessToken, testPlanId).get("result"); + if (urlContentTypeCountMap == null) { + return fail(map, ""); + } + map = success(map); + map.put("result", + this.getTestPlanService().getUrlContentTypePercent( + urlContentTypeCountMap)); + return map; + + } + + @RequestMapping("/{testPlanId}/urlContentTypeCount") + @ResponseBody + public Map getUrlContentTypeCount( + @ModelAttribute("accessToken") String accessToken, + @PathVariable String testPlanId) { + + Map map = new HashMap(); + List behaviorStatusCodeResultModels = this + .getTestPlanService().getAllBehaviorStatusCodeResultModels( + accessToken, testPlanId); + if (behaviorStatusCodeResultModels == null) { + map.put("result", null); + return fail(map, ""); + } + Map urlContentCountMap = new HashMap(); + for (BehaviorStatusCodeResultModel behaviorStatusCodeResultModel : behaviorStatusCodeResultModels) { + if (urlContentCountMap.get(behaviorStatusCodeResultModel + .getContentType()) == null) + urlContentCountMap.put( + behaviorStatusCodeResultModel.getContentType(), + behaviorStatusCodeResultModel.getCount()); + else { + long originalValue = urlContentCountMap + .get(behaviorStatusCodeResultModel.getContentType()); + urlContentCountMap.put( + behaviorStatusCodeResultModel.getContentType(), + originalValue + + behaviorStatusCodeResultModel.getCount()); + } + + } + map = success(map); + map.put("result", urlContentCountMap); + return map; + + } +} diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/api/TestPlanHistoryController.java b/Bench4Q-Web/src/main/java/org/bench4q/web/api/TestPlanHistoryController.java new file mode 100644 index 00000000..c01a7d4a --- /dev/null +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/api/TestPlanHistoryController.java @@ -0,0 +1,103 @@ +package org.bench4q.web.api; + +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.bench4q.share.communication.HttpRequester.HttpResponse; +import org.bench4q.share.helper.ExceptionLog; +import org.bench4q.share.helper.MarshalHelper; +import org.bench4q.share.models.master.TestPlanResponseModel; +import org.bench4q.web.masterMessager.TestPlanMessager; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.SessionAttributes; + +@Controller +@SessionAttributes({ "accessToken" }) +public class TestPlanHistoryController extends BaseController { + + private TestPlanMessager testPlanMessager; + + public TestPlanMessager getTestPlanMessager() { + return testPlanMessager; + } + + @Autowired + public void setTestPlanMessager(TestPlanMessager testPlanMessager) { + this.testPlanMessager = testPlanMessager; + } + + @RequestMapping(value = "loadTestPlans", method = { RequestMethod.GET, + RequestMethod.POST }) + @ResponseBody + public Map loadTestPlans( + @ModelAttribute("accessToken") String accessToken) { + Map map = new HashMap(); + TestPlanResponseModel testPlanResponseModel = this + .getTestPlanMessager().loadTestPlans(accessToken); + System.out.println(MarshalHelper.tryMarshal(testPlanResponseModel)); + if (testPlanResponseModel == null || !testPlanResponseModel.isSuccess()) { + return fail(map, ""); + + } else { + success(map); + map.put("testPlans", testPlanResponseModel.getTestPlanDBModels()); + return map; + } + } + + @RequestMapping(value = "downloadReport", method = { RequestMethod.GET, + RequestMethod.POST }) + public void downloadReport(HttpServletResponse response, + @ModelAttribute("accessToken") String accessToken, + @RequestParam String testPlanId) { + HttpResponse httpResponse = this.getTestPlanMessager().loadReport( + accessToken, testPlanId); + if (httpResponse == null || httpResponse.getContent() == "") { + return; + } + try { + byte[] pdfBuffer = httpResponse.getContent().getBytes(); + ServletOutputStream outputStream = response.getOutputStream(); + response.reset(); + response.setHeader("Content-disposition", "attachment; filename=\"" + + testPlanId.toString() + ".pdf\""); + response.addHeader("Content-Length", "" + pdfBuffer.length); + response.setContentType("application/pdf"); + outputStream.write(pdfBuffer); + outputStream.flush(); + outputStream.close(); + } catch (Exception e) { + Logger.getLogger(this.getClass()).info( + ExceptionLog.getStackTrace(e)); + return; + } + + } + + @RequestMapping(value = "deleteTest", method = { RequestMethod.GET, + RequestMethod.POST }) + @ResponseBody + public Map deleteTest(HttpServletResponse response, + @ModelAttribute("accessToken") String accessToken, + @RequestParam String testPlanId) { + Map map = new HashMap(); + TestPlanResponseModel testPlanResponseModel = this + .getTestPlanMessager().deleteTestPlan(accessToken, testPlanId); + if (testPlanResponseModel == null || !testPlanResponseModel.isSuccess()) { + return fail(map, ""); + } else { + return success(map); + } + + } +} diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/init/TestResultHandle.java b/Bench4Q-Web/src/main/java/org/bench4q/web/init/TestResultHandle.java new file mode 100644 index 00000000..963c3d24 --- /dev/null +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/init/TestResultHandle.java @@ -0,0 +1,54 @@ +package org.bench4q.web.init; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URISyntaxException; +import java.util.List; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import org.bench4q.web.model.ResultInfoModel; +import org.bench4q.web.model.TestResult; + +public class TestResultHandle { + private static final String SCRIPT_RESULT_FILE_NAME = "script_result.xml"; + private static final String SUT_RESULT_FILE_NAME = "SUT_result.xml"; + public static List scriptResultInfoModel; + public static List sutInfoModel; + static { + String filePath; + try { + filePath = TestResultHandle.class.getClassLoader().getResource("") + .toURI().getPath(); + + scriptResultInfoModel = readTestResultFromFile(filePath + + SCRIPT_RESULT_FILE_NAME); + sutInfoModel = readTestResultFromFile(filePath + + SUT_RESULT_FILE_NAME); + } catch (URISyntaxException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (JAXBException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private static List readTestResultFromFile(String filePath) + throws JAXBException, IOException { + InputStreamReader is = new InputStreamReader(new FileInputStream( + new File(filePath)), "UTF-8"); + BufferedReader reader = new BufferedReader(is); + JAXBContext context = JAXBContext.newInstance(TestResult.class); + Unmarshaller unmarshaller = context.createUnmarshaller(); + TestResult testResult = (TestResult) unmarshaller.unmarshal(reader); + return testResult.getResultInfoModels(); + } + +} diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/ScriptMessager.java b/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/ScriptMessager.java index 2e96c1b3..1065859d 100644 --- a/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/ScriptMessager.java +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/ScriptMessager.java @@ -160,6 +160,10 @@ public class ScriptMessager extends MasterMessager { try { httpResponse = this.getHttpRequester().sendPost(url, params, makeAccessTockenMap(accessToken)); + if (!validateHttpResponse(httpResponse)) { + handleInvalidatedResponse(url); + return createFailOperateScriptServerResponseModel(); + } return extractOperateScriptServerResponseModel(httpResponse); } catch (JAXBException | IOException e) { this.handleException(httpResponse, e); diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/model/ResultInfoModel.java b/Bench4Q-Web/src/main/java/org/bench4q/web/model/ResultInfoModel.java index 7efd3cc3..08d9c1b2 100644 --- a/Bench4Q-Web/src/main/java/org/bench4q/web/model/ResultInfoModel.java +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/model/ResultInfoModel.java @@ -5,30 +5,38 @@ import java.util.List; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class ResultInfoModel { - - private String result; - private List childResults; + private String name; + private String value; + private List children; public ResultInfoModel(){ } - public ResultInfoModel(String result) { - this.result=result; + public ResultInfoModel(String name,String value,List resultInfoModels){ + this.name=name; + this.value=value; + this.children=resultInfoModels; } - public ResultInfoModel(String result,List resultInfoModels){ - this.result=result; - this.childResults=resultInfoModels; + public ResultInfoModel(String name,String value){ + this.name=name; + this.value=value; } - public String getResult() { - return result; + public String getName() { + return name; } - public void setResult(String result) { - this.result = result; + public void setName(String name) { + this.name = name; } - public List getChildResults() { - return childResults; + public String getValue() { + return value; } - public void setChildResults(List childResults) { - this.childResults = childResults; + public void setValue(String value) { + this.value = value; + } + public List getChildren() { + return children; + } + public void setChildren(List children) { + this.children = children; } } diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/model/TestResult.java b/Bench4Q-Web/src/main/java/org/bench4q/web/model/TestResult.java new file mode 100644 index 00000000..3542a5de --- /dev/null +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/model/TestResult.java @@ -0,0 +1,22 @@ +package org.bench4q.web.model; + +import java.util.List; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +public class TestResult { + List resultInfoModels; + @XmlElementWrapper(name="results") + @XmlElement(name="result") + public List getResultInfoModels() { + return resultInfoModels; + } + public void setResultInfoModels(List resultInfoModels) { + this.resultInfoModels = resultInfoModels; + } + + +} diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/model/WebTestPlanResultModel.java b/Bench4Q-Web/src/main/java/org/bench4q/web/model/WebTestPlanResultModel.java deleted file mode 100644 index b0d2d6fb..00000000 --- a/Bench4Q-Web/src/main/java/org/bench4q/web/model/WebTestPlanResultModel.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.bench4q.web.model; - -import java.util.List; -import java.util.UUID; - -import org.bench4q.share.enums.master.TestPlanStatus; -import org.bench4q.share.models.master.MonitorModel; -import org.bench4q.share.models.master.TestPlanResultModel; - -public class WebTestPlanResultModel { - private UUID testPlanId; - private TestPlanStatus currentStatus; - private List scriptIdNameMap; - private List monitorModels; - private List scriptIds; - - public WebTestPlanResultModel(TestPlanResultModel testPlanResultModel) { - this.testPlanId = testPlanResultModel.getTestPlanId(); - this.currentStatus = testPlanResultModel.getCurrentStatus(); - this.monitorModels = testPlanResultModel.getMonitorModels(); - this.scriptIds = testPlanResultModel.getScriptIds(); - } - - public UUID getTestPlanId() { - return testPlanId; - } - - public void setTestPlanId(UUID testPlanId) { - this.testPlanId = testPlanId; - } - - public TestPlanStatus getCurrentStatus() { - return currentStatus; - } - - public void setCurrentStatus(TestPlanStatus currentStatus) { - this.currentStatus = currentStatus; - } - - public List getScriptIdNameMap() { - return scriptIdNameMap; - } - - public void setScriptIdNameMap(List scriptIdNameMap) { - this.scriptIdNameMap = scriptIdNameMap; - } - - public List getMonitorModels() { - return monitorModels; - } - - public void setMonitorModels(List monitorModels) { - this.monitorModels = monitorModels; - } - - public List getScriptIds() { - return scriptIds; - } - - public void setScriptIds(List scriptIds) { - this.scriptIds = scriptIds; - } - -} diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/service/MonitorService.java b/Bench4Q-Web/src/main/java/org/bench4q/web/service/MonitorService.java new file mode 100644 index 00000000..5d03cc0d --- /dev/null +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/service/MonitorService.java @@ -0,0 +1,149 @@ +package org.bench4q.web.service; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +import org.apache.log4j.Logger; +import org.bench4q.share.helper.ExceptionLog; +import org.bench4q.share.models.master.MonitorProcessorResponseModel; +import org.bench4q.share.models.monitor.MemoryModel; +import org.bench4q.share.models.monitor.ProcessorModel; +import org.bench4q.share.models.monitor.ProcessorModelChild; +import org.bench4q.web.masterMessager.MonitorMessager; +import org.bench4q.web.model.ResultModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestParam; + +@Component +public class MonitorService { + private MonitorMessager monitorMessager; + + private MonitorMessager getMonitorMessager() { + return monitorMessager; + } + + @Autowired + private void setMonitorMessager(MonitorMessager monitorMessager) { + this.monitorMessager = monitorMessager; + } + + private Logger logger = Logger.getLogger(MonitorService.class); + + public List extractCpuResultModelList( + List processorModels, String instance, + String fieldName) { + if (processorModels == null) { + return null; + } + List resultModels = new ArrayList(); + for (ProcessorModel processorModel : processorModels) { + if (processorModel != null) { + ResultModel resultModel; + try { + resultModel = extractResultModel(processorModel, instance, + fieldName); + if (resultModel != null) + resultModels.add(resultModel); + } catch (NoSuchFieldException | IllegalArgumentException e) { + // TODO Auto-generated catch block + logger.info(ExceptionLog.getStackTrace(e)); + } + + } + + } + return resultModels; + } + + public List extractResultModelList( + List memoryModels, String fieldName) { + if (memoryModels == null) + return null; + List resultModels = new ArrayList(); + List fieldNames = new ArrayList(); + fieldNames.add(fieldName); + for (MemoryModel memoryModel : memoryModels) { + if (memoryModel != null) { + ResultModel resultModel; + try { + resultModel = ChangeToResultModel.getResultModel( + memoryModel, fieldNames); + resultModel.setTime(memoryModel.getSamplingTime()); + resultModels.add(resultModel); + } catch (NoSuchFieldException e) { + // TODO Auto-generated catch block + logger.info(ExceptionLog.getStackTrace(e)); + } + + } + } + return resultModels; + } + + private ResultModel extractResultModel(ProcessorModel processorModel, + String instance, String fieldName) throws NoSuchFieldException, + IllegalArgumentException { + List fieldNames = new ArrayList(); + fieldNames.add(fieldName); + if (processorModel.getProcessorModelList() == null) { + return null; + } + for (ProcessorModelChild processorModelChild : processorModel + .getProcessorModelList()) { + if (processorModelChild.getInstance().equalsIgnoreCase(instance)) { + ResultModel resultModel = ChangeToResultModel.getResultModel( + processorModelChild, fieldNames); + resultModel.setFinished(false); + resultModel.setTime(processorModel.getSamplingTime()); + return resultModel; + } + } + logger.info("no such cpu instance"); + return null; + } + + public List getCpuList( + @ModelAttribute("accessToken") String accessToken, + @RequestParam("testPlanId") String testPlanId, + @RequestParam String ip, String port) { + try { + MonitorProcessorResponseModel monitorProcessorResponseModel = getCpus( + accessToken, testPlanId, ip, port, "0"); + + ProcessorModel processorModel = null; + List processorModels = monitorProcessorResponseModel + .getProcessorModels(); + if (processorModels.size() > 0){ + processorModel = processorModels.get(0); + } + + else{ + return new ArrayList(); + } + + List cpuList = new ArrayList(); + for (ProcessorModelChild processorModelChild : processorModel + .getProcessorModelList()) { + cpuList.add(processorModelChild.getInstance()); + } + return cpuList; + } catch (NullPointerException e) { + logger.info(ExceptionLog.getStackTrace(e)); + return new LinkedList(); + } + } + + public MonitorProcessorResponseModel getCpus( + @ModelAttribute("accessToken") String accessToken, + String testPlanId, String ip, String port, String startTime) + { + MonitorProcessorResponseModel model = this.getMonitorMessager() + .porcessor(accessToken, testPlanId, ip, port, startTime); + return model; + + } + +} diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/service/PluginService.java b/Bench4Q-Web/src/main/java/org/bench4q/web/service/PluginService.java new file mode 100644 index 00000000..a67860a4 --- /dev/null +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/service/PluginService.java @@ -0,0 +1,30 @@ +package org.bench4q.web.service; + +import java.util.LinkedList; +import java.util.List; + +import org.bench4q.share.models.master.plugin.PluginInfoModel; +import org.bench4q.share.models.master.plugin.PluginResponseModel; +import org.bench4q.share.models.master.plugin.PluginUIModel; +import org.springframework.stereotype.Component; + +@Component +public class PluginService { + + public List extractPluginInfoModels( + PluginResponseModel pluginResponseModel) { + + List pluginInfoModels = new LinkedList(); + if (pluginResponseModel == null + || pluginResponseModel.getPluginUIModels() == null) { + return pluginInfoModels; + } else { + for (PluginUIModel pluginUIModel : pluginResponseModel + .getPluginUIModels()) { + pluginInfoModels.add(pluginUIModel.getPluginInfoModel()); + } + return pluginInfoModels; + } + + } +} diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/service/TestPlanService.java b/Bench4Q-Web/src/main/java/org/bench4q/web/service/TestPlanService.java index 0f8fddb5..1fb8fdcd 100644 --- a/Bench4Q-Web/src/main/java/org/bench4q/web/service/TestPlanService.java +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/service/TestPlanService.java @@ -1,6 +1,5 @@ package org.bench4q.web.service; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -13,14 +12,13 @@ import org.bench4q.share.models.agent.BehaviorBriefModel; import org.bench4q.share.models.agent.BehaviorStatusCodeResultModel; import org.bench4q.share.models.master.MonitorModel; import org.bench4q.share.models.master.RunningScriptModel; -import org.bench4q.share.models.master.ScriptModel; +import org.bench4q.share.models.master.ScriptHandleModel; import org.bench4q.share.models.master.TestPlanModel; import org.bench4q.share.models.master.TestPlanScriptBriefResultModel; import org.bench4q.share.models.master.TestScriptConfig; import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel; import org.bench4q.share.models.master.statistics.ScriptBriefResultModel; import org.bench4q.web.masterMessager.TestPlanMessager; -import org.bench4q.web.model.ResultInfoModel; import org.bench4q.web.model.ResultModel; import org.bench4q.web.model.TestPlanRequestModel; import org.bench4q.web.model.WebScriptModel; @@ -88,43 +86,6 @@ public class TestPlanService { return ipList; } - public ResultInfoModel getScriptBriefStatusResultInfo() { - String result = "briefStatus"; - LinkedList results = new LinkedList(); - for (Field field : ScriptBriefResultModel.class.getDeclaredFields()) { - System.out.println(field.getGenericType()); - if (field.getGenericType().toString().equals("long")) { - results.add(field.getName()); - } - } - return getResultInfoModel(result, results); - } - - public ResultInfoModel getResultInfoModel(String result, List fields) { - ResultInfoModel resultInfoModel = new ResultInfoModel(); - resultInfoModel.setResult(result); - if (fields.size() <= 0) - return resultInfoModel; - - resultInfoModel.setChildResults(new ArrayList()); - for (String field : fields) { - ResultInfoModel scriptResultInfoModelChild = new ResultInfoModel(); - - scriptResultInfoModelChild.setResult(field); - resultInfoModel.getChildResults().add(scriptResultInfoModelChild); - } - return resultInfoModel; - } - - public Map getScriptNameIdMap( - List scriptModels) { - Map map = new HashMap(); - for (ScriptModel scriptModel : scriptModels) { - map.put(scriptModel.getName(), scriptModel.getId()); - } - return map; - } - public List extractResultModelList( TestPlanScriptBriefResultModel testPlanScriptBriefResultModel, String fieldName) { @@ -156,16 +117,17 @@ public class TestPlanService { public List getAllBehaviorStatusCodeResultModels( String accessToken, String testPlanId) { - List scriptIdList = this.getTestPlanMessager() - .getRunningTestInfo(accessToken, testPlanId).getScriptIds(); - if (scriptIdList == null) { + List scriptList = this.getTestPlanMessager() + .getRunningTestInfo(accessToken, testPlanId).getScripts(); + if (scriptList == null) { return null; } List behaviorStatusCodeResultModels = new LinkedList(); - for (Integer scriptId : scriptIdList) { + for (ScriptHandleModel scriptHandleModel : scriptList) { ScriptBehaviorsBriefModel scriptBehaviorBriefModel = this .getTestPlanMessager().getScriptBehaviorsBriefResult( - accessToken, testPlanId, scriptId.toString()); + accessToken, testPlanId, + scriptHandleModel.getScriptId().toString()); behaviorStatusCodeResultModels .addAll(extractBehaviorStatusCodeResultModels(scriptBehaviorBriefModel)); } @@ -189,6 +151,7 @@ public class TestPlanService { } return behaviorStatusCodeResultModels; } + public long getTotalCount(Map urlContentTypeCountMap) { Set keys = urlContentTypeCountMap.keySet(); @@ -199,9 +162,10 @@ public class TestPlanService { } return totalCount; } + public Map getUrlContentTypePercent( Map urlContentTypeCountMap) { - long totalCount=this.getTotalCount(urlContentTypeCountMap); + long totalCount = this.getTotalCount(urlContentTypeCountMap); if (urlContentTypeCountMap == null) return null; diff --git a/Bench4Q-Web/src/main/resources/SUT_result.xml b/Bench4Q-Web/src/main/resources/SUT_result.xml new file mode 100644 index 00000000..bf47802b --- /dev/null +++ b/Bench4Q-Web/src/main/resources/SUT_result.xml @@ -0,0 +1,57 @@ + + + + + + processorTimePercent + 使用率 + + + privilegedTimePercent + 系统使用率 + + + userTimePercent + 用户使用率 + + cpu + cpu + + + + pagesPerSecond + 页速率 + + + pagesInputPerSecond + 读页速率 + + + pagesOutputPerSecond + 写页速率 + + + availableKiloBytes + 可用内存(kb) + + + totalKiloBytes + 总容量(kb) + + + memoryUsedPercent + 使用率 + + + swapKiloBytes + 交换内存(kb) + + + swapFreeKiloBytes + + + 内存 + mem + + + diff --git a/Bench4Q-Web/src/main/resources/ipConfig.properties b/Bench4Q-Web/src/main/resources/ipConfig.properties index 63e5d3c0..8eb97e32 100644 --- a/Bench4Q-Web/src/main/resources/ipConfig.properties +++ b/Bench4Q-Web/src/main/resources/ipConfig.properties @@ -1 +1 @@ -masterAddress=127.0.0.1:7979/ \ No newline at end of file +masterAddress=127.0.0.1:7979 \ No newline at end of file diff --git a/Bench4Q-Web/src/main/resources/script_result.xml b/Bench4Q-Web/src/main/resources/script_result.xml new file mode 100644 index 00000000..e2968058 --- /dev/null +++ b/Bench4Q-Web/src/main/resources/script_result.xml @@ -0,0 +1,53 @@ + + + + + + 累计成功数目 + totalSuccessCountFromBegin + + + 累计失败数目 + totalFailCountFromBegin + + + 平均响应时间 + averageResponseTime + + + 最大响应时间 + maxResponseTime + + + 最小响应时间 + minResponseTime + + + 最大吞吐率 + successThroughputThisTime + + + 失败吞吐率 + failThroughputThisTime + + + 响应时间 + responseTimeDeviationThisTime + + + 平均延迟时间 + averageElapsedTime + + + 计划运行时间 + planedRunningTime + + + 虚拟用户 + vUserCount + + 脚本运行结果 + scriptBriefResult + + + diff --git a/Bench4Q-Web/src/main/webapp/WEB-INF/homepage.jsp b/Bench4Q-Web/src/main/webapp/WEB-INF/homepage.jsp new file mode 100644 index 00000000..cccd6623 --- /dev/null +++ b/Bench4Q-Web/src/main/webapp/WEB-INF/homepage.jsp @@ -0,0 +1,134 @@ + +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + +<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> + +Electricity + + + + + + + + + + + + + + +
+ +
+
+ + + + +
+
+ +
+
+
+
+

+ +

+
+ +
+
+ +
+ + + + + + + + + + + + +
ID
+
+
+ +
+ +
+ +
+
+ +
+ + + + + + + + + + + + + + +
+ + diff --git a/Bench4Q-Web/src/main/webapp/portManage.jsp b/Bench4Q-Web/src/main/webapp/portManage.jsp index c51e2393..854e4ff5 100644 --- a/Bench4Q-Web/src/main/webapp/portManage.jsp +++ b/Bench4Q-Web/src/main/webapp/portManage.jsp @@ -20,7 +20,7 @@
diff --git a/Bench4Q-Web/src/main/webapp/result.jsp b/Bench4Q-Web/src/main/webapp/result.jsp index fdfad1ba..80161b3b 100644 --- a/Bench4Q-Web/src/main/webapp/result.jsp +++ b/Bench4Q-Web/src/main/webapp/result.jsp @@ -1,193 +1,3 @@ -<<<<<<< HEAD - -<%@ page language="java" contentType="text/html; charset=UTF-8" - pageEncoding="UTF-8"%> - - - - - -Bench4q 2013 - - - - - - -<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> - - - -
-
- - -
- -
- -
-
-
- Test Status

-
-
- VUs active

-
-
- Requests

-
-
-
-

Charts

-
- - -
-
- - -
-
- -
-
-

Pages

-
-
- - - - - - - - - - - - - - -
PageScriptCountTest MinTest MaxAverageLast
-
-
-

Urls

-
-
- - - - - - - - - - - - -
URLScriptSuccessfulTotal
- -
-
-
-
- -
- - - -
- - - - - - - - - - - - - - - - - - - - - - - - - -
- -======= <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> @@ -363,17 +173,17 @@ body { + - - - + + + - + ->>>>>>> parent of b008839... upadte result jsp \ No newline at end of file diff --git a/Bench4Q-Web/src/main/webapp/script/script.js b/Bench4Q-Web/src/main/webapp/script/script.js index 55c28027..5eb9bfcb 100644 --- a/Bench4Q-Web/src/main/webapp/script/script.js +++ b/Bench4Q-Web/src/main/webapp/script/script.js @@ -24,13 +24,12 @@ function startServer() { + " and the port: " + server.port + " to record the script."); + $('#startServer').attr('disabled', true); + $('#stopServer').attr('disabled', false); } else{ $('#scriptInfo').html("Fail to start record server:"+data.failedMessage); } - $('#startServer').attr('disabled', true); - $('#stopServer').attr('disabled', false); - $('#uploadScript').attr('disabled',false); }, "json"); @@ -63,10 +62,15 @@ function stopServer() { if(server!=null){ $.post("stopRecordServer", { port : server.port, - fileNameUUID : server.fileName + scriptRecordUUID : server.fileName }, function(data) { - if (!data.success) + if (!data.success){ $('#scriptInfo').text("stop record server error:"+data.failedMessage); + $('#stopServer').attr('disabled', true); + $('#startServer').attr('disabled', false); + } + + else { $('#fileName').show(); $('#scriptInfo').text( @@ -78,8 +82,7 @@ function stopServer() { else{ $('#scriptInfo').text("record script server has not started"); } - $('#stopServer').attr('disabled', true); - $('#startServer').attr('disabled', false); + } function saveScript() { diff --git a/Bench4Q-Web/src/main/webapp/script/testResult/behaviorAndPage.js b/Bench4Q-Web/src/main/webapp/script/testResult/behaviorAndPage.js index 52a17607..5043543b 100644 --- a/Bench4Q-Web/src/main/webapp/script/testResult/behaviorAndPage.js +++ b/Bench4Q-Web/src/main/webapp/script/testResult/behaviorAndPage.js @@ -13,7 +13,7 @@ function getScriptList(testPlanId) { var scriptList = new Array(); $.ajax({ type : "POST", - url : testPlanId + "/queryTestPlan", + url : testPlanId + "/runningInfo", dataType : "json", async : false, success : function(data) { @@ -21,12 +21,12 @@ function getScriptList(testPlanId) { alert(data.failedMessage); return; } - else data=data.data; + else data=data.testPlan; if (data.scriptIds.length <= 0) return null; - for ( var i = 0; i < data.scriptIdNameMap.length; i++) { - scriptList.push(data.scriptIdNameMap[i]); - } +// for ( var i = 0; i < data.scriptIdNameMap.length; i++) { +// scriptList.push(data.scriptIdNameMap[i]); +// } } }); @@ -102,9 +102,7 @@ PageResult.prototype.getSinglePageResult = function(pageResult, intervalId, clearInterval(intervalId); return; } - - else data=data.data; - data = data.scriptPageBriefModels; + data = data.result; var scriptPagesFinished = true; for ( var i = 0; i < data.length; i++) { pageResult.result = $.merge(pageResult.result, @@ -177,7 +175,7 @@ BehaviorResult.prototype.getSingleBehaviorResult = function(behaviorResult, clearInterval(intervalId); return; } - data=data.data; + data=data.result; if (data.finished || data.testBehaviorsBriefModel == null) { finishedCount++; } @@ -346,5 +344,3 @@ BehaviorModel.prototype.getTotalCount = function(behaviorStatusResultList) { return count; }; -// need to abstract the tow -// part---------------------------------------------------- diff --git a/Bench4Q-Web/src/main/webapp/script/testResult/charts.js b/Bench4Q-Web/src/main/webapp/script/testResult/charts.js index e7bffbd1..33f6f62c 100644 --- a/Bench4Q-Web/src/main/webapp/script/testResult/charts.js +++ b/Bench4Q-Web/src/main/webapp/script/testResult/charts.js @@ -1,134 +1,130 @@ -var intervalTime = 5000; -var Chart = function() { -}; -Chart.prototype.createChart = function(container) { - container.highcharts({ - chart : { - type : 'spline' - }, - tooltip : { - formatter : function() { - return Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) - + '
' + '' + this.series.name + ':' - + '
' + Highcharts.numberFormat(this.y, 2); - } - }, - }); - var chart = container.highcharts(); - chart.setTitle({ - text : "" - }); - chart.xAxis[0].update({ - type : 'datetime', - tickInterval : 1000 * 60, - tickWidth : 0, - gridLineWidth : 1, - tickPixelInterval : 50 - }); - this.highChart = chart; - this.modelArray = new Array(); -}; - -Chart.prototype.addAxis = function(axis, seriesId, data) { - this.highChart.addAxis({ // Secondary yAxis - id : axis, - title : { - text : seriesId, - }, - lineWidth : 2, - opposite : true - }); - this.addSeries(axis, seriesId, data); -}; - -Chart.prototype.addSeries = function(axis, seriesId, data) { - this.highChart.addSeries({ - id : seriesId, - name : seriesId, - yAxis : axis, - data : data, - marker : { - enabled : true, - radius : 3 - }, - showInLegend : true - }, true); -}; -Chart.prototype.removeAxis = function(axisId) { - this.highChart.get(axisId).remove(); -}; - -Chart.prototype.addPoint = function(seriesId, point) { - if (point.y == "NaN") - point.y = 0; - this.highChart.get(seriesId).addPoint([ point.x, point.y ]); -}; -Chart.prototype.addPoints = function(seriesId, data) { - var chart = this; - for ( var i = 0; i < data.length; i++) { - chart.addPoint(seriesId, data[i]); - } - -}; - -var Point = function(x, y) { - this.x = x; - this.y = y; -}; -Chart.prototype.addGraph = function(model) { - - var chart = this; - chart.addAxis(model.axis, model.series, []); - - var intervalId = setInterval(function() { - - $.post(model.url + "/" + model.time, {}, function(data) { - loadItems.scriptBriefStatusAve = true; - if (!data.success) { - alert(data.failedMessage); - clearInterval(intervalId); - return; - } - data = data.data; - if (data instanceof Array) { - - var points = new Array(); - for ( var i = 0; i < data.length; i++) { - chart.addDataToGraph(chart, model, intervalId, data[i]); - } - } else - chart.addDataToGraph(chart, model, intervalId, data); - loadItems.scriptBriefStatusAve = true; - - }, "json"); - - }, intervalTime); - model.setIntervalId(intervalId); - this.modelArray.push(model); - -}; -Chart.prototype.addDataToGraph = function(chart, model, intervalId, data) { - - if (data.finished) { - clearInterval(intervalId); - return; - } - var point = new Point(data.time, data.data); - if (data.time > model.time) - model.time = data.time; - model.time++; - chart.addPoint(model.series, point); - -}; -Chart.prototype.deleteGraph = function(model) { - for ( var i = 0; i < this.modelArray.length; i++) { - if (model.series == this.modelArray[i].series) { - clearInterval(this.modelArray[i].intervalId); - break; - } - } - this.removeAxis(model.axis); -}; -Chart.prototype.addModel = function(model) { - this.modelArray.push(model); +var intervalTime = 5000; +var Chart = function() { +}; +Chart.prototype.createChart = function(container) { + container.highcharts({ + chart : { + type : 'spline' + }, + tooltip : { + formatter : function() { + return Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + + '
' + '' + this.series.name + ':' + + '
' + Highcharts.numberFormat(this.y, 2); + } + }, + }); + var chart = container.highcharts(); + chart.setTitle({ + text : "" + }); + chart.xAxis[0].update({ + type : 'datetime', + tickInterval : 1000 * 60, + tickWidth : 0, + gridLineWidth : 1, + tickPixelInterval : 50 + }); + this.highChart = chart; + this.modelArray = new Array(); +}; + +Chart.prototype.addAxis = function(axis, seriesId, data) { + this.highChart.addAxis({ // Secondary yAxis + id : axis, + title : { + text : seriesId, + }, + lineWidth : 2, + opposite : true + }); + this.addSeries(axis, seriesId, data); +}; + +Chart.prototype.addSeries = function(axis, seriesId, data) { + this.highChart.addSeries({ + id : seriesId, + name : seriesId, + yAxis : axis, + data : data, + marker : { + enabled : true, + radius : 3 + }, + showInLegend : true + }, true); +}; +Chart.prototype.removeAxis = function(axisId) { + this.highChart.get(axisId).remove(); +}; + +Chart.prototype.addPoint = function(seriesId, point) { + if (point.y == "NaN") + point.y = 0; + this.highChart.get(seriesId).addPoint([ point.x, point.y ]); +}; +Chart.prototype.addPoints = function(seriesId, data) { + var chart = this; + for ( var i = 0; i < data.length; i++) { + chart.addPoint(seriesId, data[i]); + } + +}; + +var Point = function(x, y) { + this.x = x; + this.y = y; +}; +Chart.prototype.addGraph = function(model) { + var chart = this; + chart.addAxis(model.axis, model.series, []); + var intervalId = setInterval(function() { + $.post(model.url + "/" + model.time, {}, function(data) { + loadItems.scriptBriefStatusAve = true;// this need to change + if (data==null||!data.success) { + clearInterval(intervalId); + return; + } + data = data.result; + if (data instanceof Array) { + + var points = new Array(); + for ( var i = 0; i < data.length; i++) { + chart.addDataToGraph(chart, model, intervalId, data[i]); + } + } else{ + chart.addDataToGraph(chart, model, intervalId, data); + } + + }, "json"); + + }, intervalTime); + model.setIntervalId(intervalId); + this.modelArray.push(model); + +}; +Chart.prototype.addDataToGraph = function(chart, model, intervalId, data) { + + if (data.finished) { + clearInterval(intervalId); + return; + } + var point = new Point(data.time, data.data); + if (data.time > model.time){ + model.time = data.time; + } + model.time++; + chart.addPoint(model.series, point); +}; +Chart.prototype.deleteGraph = function(model) { + for ( var i = 0; i < this.modelArray.length; i++) { + if (model.series == this.modelArray[i].series) { + clearInterval(this.modelArray[i].intervalId); + break; + } + } + this.removeAxis(model.axis); +}; +Chart.prototype.addModel = function(model) { + this.modelArray.push(model); }; \ No newline at end of file diff --git a/Bench4Q-Web/src/main/webapp/script/testResult/graphSelector.js b/Bench4Q-Web/src/main/webapp/script/testResult/graphSelector.js new file mode 100644 index 00000000..8f8a7064 --- /dev/null +++ b/Bench4Q-Web/src/main/webapp/script/testResult/graphSelector.js @@ -0,0 +1,253 @@ +var ChartSelector = function(allTree, showTree, chart, addSelectorId, + deleteSelectorId, addButton, deleteButton, showTreePathValues) { + + this.allTree = allTree; + this.showTree = showTree; + this.addSelectorId = addSelectorId; + this.deleteSelectorId = deleteSelectorId; + this.excessTree = this.getExcessTree(allTree, showTreePathValues); + this.addButton = addButton; + this.deleteButton = deleteButton; + this.createSelector($("#" + addSelectorId), this.excessTree.root); + this.chart = chart; + this.addEventListener(this); +}; +ChartSelector.prototype.getExcessTree = function(allTree, pathValues) { + var excessTree = allTree.getClonedTree(allTree); + + excessTree.deleteFromTree(pathValues); + return excessTree; +}; +ChartSelector.prototype.addEventListener = function(chartSelector) { + this.addButton.click(function(e) { + e.preventDefault(); + chartSelector.addGraph(); + }); + this.deleteButton.click(function(e) { + e.preventDefault(); + chartSelector.deleteGraph(); + }); + +}; +ChartSelector.prototype.updateSelector = function(selectorId, updatedData, tree) { + var parentDomNode = $("#" + selectorId); + this.deleteChildSelector(parentDomNode, updatedData); + var newShowTree = tree.getClondSubTreeByValue(updatedData); + if (newShowTree == null) + return; + this.createSelector(parentDomNode, newShowTree.root); + this.addSelectlistEvent(); +}; +ChartSelector.prototype.deleteChildSelector = function(parentDomNode, + updatedData) { + var selectArray = $("#" + parentDomNode.attr("id") + " select"); + var divArray = $("#" + parentDomNode.attr("id") + " div"); + parentDomNode.html(""); + for ( var i = 0; i < selectArray.length; i++) { + parentDomNode.append(divArray[i]); + if ($(selectArray[i]).find("option:selected").val() == updatedData) { + break; + } + + } + +}; +; +ChartSelector.prototype.createSelectorByValues = function(parentDomNode, + treeNode, pathValues) { + var currentNode = treeNode; + if (currentNode == null) + return; + var selectedNode; + if (currentNode.children != null && currentNode.children.length > 0) { + selectedNode = this.getSelectNodeByValue(currentNode, pathValues); + if (selectedNode == null) + selectedNode = currentNode.children[0]; + var selectOptions = new Array(); + for ( var i = 0; i < currentNode.children.length; i++) { + selectOptions.push(currentNode.children[i]); + } + var childName = "result"; + parentDomNode + .append(this.createSingleListDom(childName, selectOptions)); + this.createSelectorByValues(parentDomNode, selectedNode, pathValues); + } + +}; +ChartSelector.prototype.addSelectlistEvent = function() { + var chartSelector = this; + $("#" + this.deleteSelectorId + " select").change( + function(event) { + var updatedData = $(this).find("option:selected").val(); + chartSelector.updateSelector(chartSelector.deleteSelectorId, + updatedData, chartSelector.showTree); + event.stopImmediatePropagation(); + }); + $("#" + this.addSelectorId + " select").change( + function(event) { + var updatedData = $(this).find("option:selected").val(); + chartSelector.updateSelector(chartSelector.addSelectorId, + updatedData, chartSelector.excessTree); + event.stopImmediatePropagation(); + }); +}; +ChartSelector.prototype.createSelector = function(parentDomNode, treeNode) { + var currentNode = treeNode; + if (currentNode == null) + return; + + var selectedNode; + if (currentNode.children != null && currentNode.children.length > 0) { + selectedNode = currentNode.children[0]; + var selectOptions = new Array(); + for ( var i = 0; i < currentNode.children.length; i++) { + selectOptions.push(currentNode.children[i]); + } + parentDomNode.append(this.createSingleListDom("result", selectOptions)); + this.createSelector(parentDomNode, selectedNode); + } + +}; +ChartSelector.prototype.getSelectNodeByValue = function(parentNode, values) { + for ( var i = 0; i < values.length; i++) { + for ( var j = 0; j < parentNode.children.length; j++) { + if (parentNode.children[j].value == values[i]) + return parentNode.children[j]; + } + } + return null; + +}; +ChartSelector.prototype.createSingleListDom = function(lableText, options) { + var div = $("
"); + div.addClass("control-group"); + var lable = $(""); + lable.addClass("control-label"); + lable.text(lableText); + div.append(lable); + div.append("
"); + var select = $(""); + select.addClass("form-control"); + for ( var i = 0; i < options.length; i++) { + + var option = $(""); + option.text(options[i].name); + option.val(options[i].value); + if (i == 0) { + option.attr("selected", true); + } + + select.append(option); + } + + div.append(select); + return div; +}; + +ChartSelector.prototype.getSlectedVluesArray = function(selectorId) { + var dataArray = new Array(); + var selectArray = $("#" + selectorId + " select"); + for ( var i = 0; i < selectArray.length; i++) { + dataArray.push($(selectArray[i]).find("option:selected").val()); + } + return dataArray; +}; +ChartSelector.prototype.getSelectedNames = function(selectorId) { + var dataArray = new Array(); + var selectArray = $("#" + selectorId + " select"); + for ( var i = 0; i < selectArray.length; i++) { + dataArray.push($(selectArray[i]).find("option:selected").text()); + } + return dataArray; +}; + +ChartSelector.prototype.addGraphToTree = function(tree, selectorId) { + var pathValues = this.getSlectedVluesArray(selectorId); + var singlePathTree = this.allTree.getCloneTreeFromVlaue(pathValues); + if (tree == null) + tree = singlePathTree; + else + tree.insertToTree(tree.root, singlePathTree.root); + return tree; +}; +ChartSelector.prototype.deleteGraphFromTree = function(tree, selectorId) { + if (tree == null) + return null; + var pathValues = this.getSlectedVluesArray(selectorId); + tree.deleteFromTree(pathValues); + return tree; +}; + +ChartSelector.prototype.addGraph = function() { + this.showTree = this.addGraphToTree(this.showTree, this.addSelectorId); + this.excessTree = this.deleteGraphFromTree(this.excessTree, + this.addSelectorId); + var model = new Model(); + model.setSeries(this.getSelectedNames(this.addSelectorId)); + model.setUrl(this.getSlectedVluesArray(this.addSelectorId), this); + model.axis = (model.series + "_Axis"); + this.chart.addGraph(model); +}; +ChartSelector.prototype.initChart = function() { + var model = new Model(); + model.setSeries(this.getSelectedNames(this.addSelectorId)); + model.setUrl(this.getSlectedVluesArray(this.addSelectorId), this); + model.axis = (model.series + "_Axis"); + this.chart.addGraph(model); +}; +ChartSelector.prototype.deleteGraph = function() { + this.showTree = this.deleteGraphFromTree(this.showTree, + this.deleteSelectorId); + this.excessTree = this.addGraphToTree(this.excessTree, + this.deleteSelectorId); + var model = new Model(); + model.setSeries(this.getSlectedVluesArray(this.deleteSelectorId)); + model.axis = (model.series + "_Axis"); + this.chart.deleteGraph(model); +}; +var Model = function() { + this.url = ""; + this.series = ""; + this.data = null; + this.intervalId = null; + this.axis = ""; + this.time = 0; +}; +Model.prototype.setUrl = function(pathValue, chartSelector) { + /* this.url = "/"+chartSelector.allTree.root.value; */ + this.url = chartSelector.allTree.root.value; + if (pathValue == null) + return null; + if (pathValue.length <= 0) + return null; + + for ( var i = 0; i < pathValue.length; i++) { + this.url += "/" + pathValue[i]; + } + +}; + +Model.prototype.setSeries = function(pathValue) { + this.series = ""; + if (pathValue == null) + return null; + if (pathValue.length <= 0) + return null; + this.series += pathValue[0]; + for ( var i = 1; i < pathValue.length; i++) { + this.series += "_" + pathValue[i]; + } +}; +Model.prototype.setIntervalId = function(intervalId) { + this.intervalId = intervalId; +}; +function getSubDataArray(indexData, dataArray) { + var subDataArray = new Array(); + for ( var i = 0; i < dataArray.length; i++) { + subDataArray.push(dataArray[i]); + if (dataArray[i] == indexData) { + break; + } + } + return subDataArray; +} \ No newline at end of file diff --git a/Bench4Q-Web/src/main/webapp/script/testResult/graphSelectorTree.js b/Bench4Q-Web/src/main/webapp/script/testResult/graphSelectorTree.js new file mode 100644 index 00000000..d02ebacc --- /dev/null +++ b/Bench4Q-Web/src/main/webapp/script/testResult/graphSelectorTree.js @@ -0,0 +1,131 @@ +function getResultInfoTree(testPlanId) { + + var tree = new Tree(); + tree.createRoot("Test Result","testPlan" ,testPlanId); + createScriptResultInfoTree(testPlanId, tree); + var sutResultInfo = new SutResult(testPlanId); + if (sutResultInfo.root != null) + tree.root.insertSingleNode(sutResultInfo.root); + return tree; +} + +function getResultTree(testPlanId) { + var tree = new Tree(); + tree.createRoot("Test Result", "testPlan",testPlanId); + $.ajax({ + type : "POST", + url : testPlanId + "/testResultHanadle", + dataType : "json", + async : false, + success : function(data) { + if (!data.success) { + return; + } else { + data = data.resultHandle; + for ( var i = 0; i < data.length; i++) { + tree.root.insertSingleNode(data[i]); + } + + } + + } + }); + return tree; +} + +function createScriptResultInfoTree(testPlanId, tree) { + var scriptResultTree = new Tree(); + scriptResultTree.createRoot("Script", "script"); + + $.ajax({ + type : "POST", + url : testPlanId + "/runningScriptInfo", + dataType : "json", + async : false, + success : function(data) { + if (!data.success) { + return; + } else + data = data.scriptInfo; + createScriptTree(data, scriptResultTree); + tree.root.insertSingleNode(scriptResultTree.root); + } + }); +} + +function createScriptTree(scriptResultInfoList, tree) { + + if (scriptResultInfoList == null) + return; + for ( var i = 0; i < scriptResultInfoList.length; i++) { + + var node = new TreeNode("Script Result", + scriptResultInfoList[i].scriptName, null); + tree.root.insertSingleNode(node); + var nodeArray = insertResultList(scriptResultInfoList[i].childResults); + for ( var j = 0; j < nodeArray.length; j++) { + node.insertSingleNode(nodeArray[j]); + } + + } + +}; + +var SutResult = function(testPlanId) { + var sutResultInfo = this; + var scriptResultTree = new Tree(); + + $.ajax({ + type : "POST", + url : testPlanId + "/sutInfo", + dataType : "json", + async : false, + success : function(data) { + if (!data.success) { + sutResultInfo.root = null; + return; + } else + data = data.sutInfo; + scriptResultTree.createRoot("SUT", "SUT"); + sutResultInfo.root = scriptResultTree.root; + sutResultInfo.data = data; + sutResultInfo.createTree(data); + } + }); + +}; +SutResult.prototype.createTree = function(sutResultInfoList) { + for ( var i = 0; i < sutResultInfoList.length; i++) { + var ipNode = new TreeNode("port", sutResultInfoList[i].ip, null); + this.root.insertSingleNode(ipNode); + var portNode = new TreeNode("sut result", sutResultInfoList[i].port, + null); + ipNode.insertSingleNode(portNode); + var nodeArray = insertResultList(sutResultInfoList[i].childResults); + for ( var j = 0; j < nodeArray.length; j++) { + portNode.insertSingleNode(nodeArray[j]); + } + } +} + +function insertResultList(childResults) { + + if (childResults == null) + return null; + else { + var nodeArray = new Array(); + for ( var i = 0; i < childResults.length; i++) { + var node = new TreeNode(childResults[i].result, + childResults[i].result, null); + var childNode = insertResultList(childResults[i].childResults); + if (childNode !== null) { + for ( var j = 0; j < childNode.length; j++) { + node.insertSingleNode(childNode[j]); + } + + } + nodeArray.push(node); + } + } + return nodeArray; +}; \ No newline at end of file diff --git a/Bench4Q-Web/src/main/webapp/script/testResult/result.js b/Bench4Q-Web/src/main/webapp/script/testResult/result.js index bdc60939..0b25caac 100644 --- a/Bench4Q-Web/src/main/webapp/script/testResult/result.js +++ b/Bench4Q-Web/src/main/webapp/script/testResult/result.js @@ -99,32 +99,32 @@ var ReplaceNode = function(oldWord, newWord) { this.oldWord = oldWord; this.newWord = newWord; }; -function createUrlReplaceArray(testPlanId) { - var replaceArray = new Array(); - $.ajax({ - type : "POST", - /* url : "/" + testPlanId + "/mapInfo", */ - url : testPlanId + "/mapInfo", - dataType : "json", - async : false, - success : function(data) { - if (!data.success) { - alert(data.failedMessage); - return; - } - - else - data = data.data; - for ( var key in data) { - var replaceNode = new ReplaceNode(key, data[key]); - replaceArray.push(replaceNode); - } - - } - }); - return replaceArray; - -} +//function createUrlReplaceArray(testPlanId) { +// var replaceArray = new Array(); +// $.ajax({ +// type : "POST", +// /* url : "/" + testPlanId + "/mapInfo", */ +// url : testPlanId + "/mapInfo", +// dataType : "json", +// async : false, +// success : function(data) { +// if (!data.success) { +// alert(data.failedMessage); +// return; +// } +// +// else +// data = data.data; +// for ( var key in data) { +// var replaceNode = new ReplaceNode(key, data[key]); +// replaceArray.push(replaceNode); +// } +// +// } +// }); +// return replaceArray; +// +//} function getvars() { var vars = [], hash; diff --git a/Bench4Q-Web/src/main/webapp/script/testResult/resultNew.js b/Bench4Q-Web/src/main/webapp/script/testResult/resultNew.js new file mode 100644 index 00000000..ffb3751d --- /dev/null +++ b/Bench4Q-Web/src/main/webapp/script/testResult/resultNew.js @@ -0,0 +1,178 @@ +var loadItems = new loadItems(); +var testStatus; + +$(function() { + var testPlanId=getvars()['testPlanId']; + var testPlan=getTestInfo(testPlanId); +// getTestBrief(); + var tree=getResultTree(testPlanId); + var chart = new Chart(); + chart.createChart($("#chart")); + var chartSelector = createChartSelector(tree, chart, + getShowTreePathValues(tree)); +chartSelector.initChart(); + graphButtonListener(chartSelector); + var behaviorResult = new BehaviorResult(); + behaviorResult.getResult(testPlanId, getScriptList(testPlanId)); + var pageResult = new PageResult(); + pageResult.getResult(testPlanId, getScriptList(testPlanId)); + var urlContentTypeDistribution = new UrlContentTypeDistribution( + "url-distribution", testPlanId); +}); +function getTestInfo( testPlanId){ + var testPlan; + $.ajax({ + type : "POST", + url : testPlanId + "/runningInfo", + dataType : "json", + async : false, + success : function(data) { + if (!data.success) { + alert("no such testPlan!") + return; + } else{ + testPlan = data.testPlan; + } + } + }); + return testPlan; + } + + + +//$(document).ready( +// function() { +// testPlanId = getvars()['testPlanId']; +// if (!getTestPlanStatus(testPlanId)) +// return; +// getTestBrief(testPlanId); +// var tree = getResultInfoTree(testPlanId); +// var replaceArray = createUrlReplaceArray(testPlanId); +// doProgress(); +// var chart = new Chart(); +// chart.createChart($("#chart")); +// var chartSelector = createChartSelector(tree, chart, +// getShowTreePathValues(tree)); +// chartSelector.initChart(getShowTreePathValues(tree), this); +// graphButtonListener(chartSelector); +// var behaviorResult = new BehaviorResult(); +// behaviorResult.getResult(testPlanId, getScriptList(testPlanId)); +// var pageResult = new PageResult(); +// pageResult.getResult(testPlanId, getScriptList(testPlanId)); +// var urlContentTypeDistribution = new UrlContentTypeDistribution( +// "url-distribution", testPlanId); +// }); + +function replace(keyArray, replaceArray) { + for ( var i = 0; i < keyArray.length; i++) { + for ( var j = 0; j < replaceArray.length; j++) { + if (keyArray[i] == replaceArray[j].oldWord) + keyArray[i] = replaceArray[j].newWord; + } + } +} + +function graphButtonListener(chartSelector) { + $("#del-graph").click( + function(event) { + + $("#" + chartSelector.deleteSelectorId).html(""); + if (chartSelector.showTree != null) { + if (chartSelector.showTree.root != null) + chartSelector.createSelector($("#" + + chartSelector.deleteSelectorId), + chartSelector.showTree.root); + } + + chartSelector.addSelectlistEvent(); + $("#del-graph-modal").modal('show'); + }); + $("#add-graph").click( + function(event) { + $("#" + chartSelector.addSelectorId).html(""); + if (chartSelector.excessTree != null) { + if (chartSelector.excessTree.root != null) + chartSelector.createSelector($("#" + + chartSelector.addSelectorId), + chartSelector.excessTree.root); + } + chartSelector.addSelectlistEvent(); + + $("#add-graph-modal").modal('show'); + }); +} + +function createChartSelector(tree, chart, replaceArray, showTreePathValues) { + + var addSelectorId = "add-graph-list"; + var deleteSelectorId = "del-graph-list"; + var addButton = $("#add-graph-add"); + var deleteButton = $("#del-graph-del"); + var showTree = initShowTree(tree); + var chartSelector = new ChartSelector(tree, showTree, chart, addSelectorId, + deleteSelectorId, addButton, deleteButton, replaceArray, + showTreePathValues); + + return chartSelector; +} +function getShowTreePathValues(tree) { + var currentNode = tree.root.children[0]; + var pathValues = new Array(); + while (currentNode != null) { + pathValues.push(currentNode.value); + if (currentNode.children !== null) + currentNode = currentNode.children[0]; + else + currentNode = null; + + } + return pathValues; +} +function initShowTree(tree) { + + var pathValues = getShowTreePathValues(tree); + + return tree.getCloneTreeFromVlaue(pathValues); +} +var ReplaceNode = function(oldWord, newWord) { + this.oldWord = oldWord; + this.newWord = newWord; +}; +// function createUrlReplaceArray(testPlanId) { +// var replaceArray = new Array(); +// $.ajax({ +// type : "POST", +// /* url : "/" + testPlanId + "/mapInfo", */ +// url : testPlanId + "/mapInfo", +// dataType : "json", +// async : false, +// success : function(data) { +// if (!data.success) { +// alert(data.failedMessage); +// return; +// } +// +// else +// data = data.data; +// for ( var key in data) { +// var replaceNode = new ReplaceNode(key, data[key]); +// replaceArray.push(replaceNode); +// } +// +// } +// }); +// return replaceArray; +// +// } + +function getvars() { + var vars = [], hash; + var hashes = window.location.href.slice( + window.location.href.indexOf('?') + 1).split('&'); + for ( var i = 0; i < hashes.length; i++) { + hash = hashes[i].split('='); + vars.push(hash[0]); + vars[hash[0]] = hash[1]; + } + return vars; +} \ No newline at end of file diff --git a/Bench4Q-Web/src/main/webapp/script/testResult/testBriefResult.js b/Bench4Q-Web/src/main/webapp/script/testResult/testBriefResult.js index 5b39d535..45033e07 100644 --- a/Bench4Q-Web/src/main/webapp/script/testResult/testBriefResult.js +++ b/Bench4Q-Web/src/main/webapp/script/testResult/testBriefResult.js @@ -1,63 +1,64 @@ -function getTestBrief(testPlanId) { - var intervalId=setInterval(function(){ - showTestPlanStatusAsync(testPlanId); - var startTime=0; - showTestBriefStatus(startTime); - loadItems.testBrief=true; - if(testStatus=="Complete") - clearInterval(intervalId); - },5000); -} -function showTestPlanStatusAsync(testPlanId){ -/* var urlAddress= "/" + testPlanId + "/queryTestPlan";*/ - var urlAddress= testPlanId + "/queryTestPlan"; - $.post(urlAddress,{},function(data){ - if(!data.success){ - alert(data.failedMessage); - return; - } - - else data=data.data; - testStatus=data.currentStatus; - $('#status').html('Test Status

'+testStatus+'

'); - },"json"); -} -function showTestBriefStatus(startTime){ - var urlAddress= testPlanId + "/testBriefStatus"+"/"+startTime; - $.post(urlAddress,{},function(data){ - if(!data.success){ - alert(data.failedMessage); - return; - } - - else data=data.data; - startTime=data.time; - $("#vu").html('VUs active

'+data.vus+'

'); - $("#request").html('Requests

'+data.requests+'

'); - - },"json"); -} -function getTestPlanStatus(testPlanId) { - var flag = null; - $.ajax({ - type : "POST", - url : testPlanId + "/queryTestPlan", - dataType : "json", - async : false, - success : function(data) { - if(!data.success){ - flag=false; - return; - } - - else data=data.data; - testStatus = data.currentStatus; - if (data.currentStatus == "Complete" - || data.currentStatus == "InRunning") { - flag = true; - } else - flag = false; - } - }); - return flag; -} +function getTestBrief(testPlanId) { + var intervalId = setInterval(function() { + showTestPlanStatusAsync(testPlanId); + showTestBriefStatus(); + loadItems.testBrief = true; + if (testStatus == "Complete") + clearInterval(intervalId); + }, 5000); +} +function showTestPlanStatusAsync(testPlanId) { + var urlAddress = testPlanId + "/runningInfo"; + $.post(urlAddress, {}, function(data) { + if (!data.success) { + alert("runningInfo"); + return; + } + + else + data = data.testPlan; + testStatus =testStatusMap(data.currentStatus); + $('#status').html($('#status').html()+"

"+testStatus+'

'); + }, "json"); +} +function showTestBriefStatus() { + var urlAddress = testPlanId + "/testBriefStatus" ; + $.post(urlAddress, {}, function(data) { + if (!data.success) { + alert("testBrief"); + return; + } + + else + data = data.briefInfo; + startTime = data.time; + $("#vu").html($("#vu").html()+"

"+data.vus+"

"); + $("#request").html( $("#request").html()+"

"+data.requests+"

") + + }, "json"); +} +function getTestPlanStatus(testPlanId) { + var flag = null; + $.ajax({ + type : "POST", + url : testPlanId + "/runningInfo", + dataType : "json", + async : false, + success : function(data) { + if (!data.success) { + flag = false; + return; + } + + else + data = data.testPlan; + testStatus = data.currentStatus; + if (data.currentStatus == "Complete" + || data.currentStatus == "InRunning") { + flag = true; + } else + flag = false; + } + }); + return flag; +} diff --git a/Bench4Q-Web/src/main/webapp/script/testResult/tree.js b/Bench4Q-Web/src/main/webapp/script/testResult/tree.js new file mode 100644 index 00000000..5b47e1d9 --- /dev/null +++ b/Bench4Q-Web/src/main/webapp/script/testResult/tree.js @@ -0,0 +1,226 @@ +//Tree + +var TreeNode = function(childClassName, name, value, childArray) { + this.childClassName = childClassName; + this.name = name; + this.value = value; + this.children = childArray; +}; +TreeNode.prototype.insertSingleNode = function(childNode) { + if (childNode == null) + return; + if (this.children == null) + this.children = new Array(); + this.children.push(childNode); + +}; +TreeNode.prototype.insertNodes = function(childNodes) { + if (this.children == null) + this.children = new Array(); + if (childNodes == null) + return; + for ( var i = 0; i < childNodes.length; i++) { + this.children.push(childNodes[i]); + } + +}; +var Tree = function() { + this.root = null; +}; + +Tree.prototype.createRoot = function(rootChildrenClassName,name, value) { + this.root = new TreeNode(rootChildrenClassName,name, value, null); +}; + +Tree.prototype.getClondSubTreeByValue = function(value) { + if (value == null) + return null; + if (this.root == null) + return null; + var clonedTree = new Tree(); + clonedTree.createRoot(this.root.childClassName, this.root.name,this.root.value); + var parentNode = this.searchTreeNodeByValue(this.root, value); + clonedTree.root.childClassName = parentNode.childClassName; + this.getClonedSubTree(parentNode, clonedTree.root);// 这个就把引用传递过去了,应该没什么影响,我再看看吧 + return clonedTree; +}; + +Tree.prototype.searchTreeNodeByValue = function(parentNode, value) { + + if (parentNode.children == null) + return null; + + for ( var i = 0; i < parentNode.children.length; i++) { + if (value == parentNode.children[i].value) { + return parentNode.children[i]; + } + var node = this.searchTreeNodeByValue(parentNode.children[i], value); + if (node != null) + return node; + } + +}; +Tree.prototype.getCloneTreeFromVlaue = function(pathValues) { + + if (pathValues == null) + return null; + if (pathValues.length <= 0) + return null; + if (this.root == null) + return null; + var clonedTree = new Tree(); + clonedTree.createRoot(this.root.childClassName,this.root.name, this.root.value); + var currentNode = this.root; + var clonedTreeCurrentNode = clonedTree.root; + for ( var i = 0; i < pathValues.length; i++) { + var flag = false; + for ( var j = 0; j < currentNode.children.length; j++) { + if (currentNode.children[j].value == pathValues[i]) { + var clonedNode = new TreeNode( + currentNode.children[j].childClassName,currentNode.children[j].name, + currentNode.children[j].value, null); + clonedTreeCurrentNode.insertSingleNode(clonedNode); + clonedTreeCurrentNode = clonedNode; + currentNode = currentNode.children[j]; + flag = true; + break; + } + } + if (flag == false) { + return null; + } + + } + if (currentNode != null) + this.getClonedSubTree(currentNode, clonedTreeCurrentNode);// 这个就把引用传递过去了,应该没什么影响,我再看看吧 + return clonedTree; +}; + +// no problem to copy the tree +Tree.prototype.getClonedSubTree = function(startNode, parentNode) { + if (startNode == null) + return null; + if (startNode.children == null) + return null; + if (startNode.children.length <= 0) + return null; + for ( var i = 0; i < startNode.children.length; i++) { + var node = new TreeNode(startNode.children[i].childClassName,startNode.children[i].name, + startNode.children[i].value, null); + parentNode.insertSingleNode(node); + this.getClonedSubTree(startNode.children[i], node); + } +}; + +Tree.prototype.insertToTree = function(insertedTree, singlePathTree) { + if (singlePathTree == null) + return; + + if (singlePathTree.children == null) + return; + if (singlePathTree.children.length < 1) + return; + if (insertedTree.children == null) { + insertedTree.insertSingleNode(singlePathTree.children[0]); + } + var children = insertedTree.children; + var flag = false; + for ( var i = 0; i < children.length; i++) { + if (children[i].value == singlePathTree.children[0].value) { + + this.insertToTree(children[i], singlePathTree.children[0]); + flag = true; + break; + } + } + if (!flag) + insertedTree.insertSingleNode(singlePathTree.children[0]); +}; + +Tree.prototype.deleteFromTree = function(pathValues) { + if (pathValues == null) + return; + if (this.root == null) + return; + var nodeArray = this.getTreePathNodes(pathValues); + var currentNode = nodeArray.pop(); + var length = nodeArray.length; + for ( var i = 0; i < length; i++) { + var parent = nodeArray.pop(); + if (parent.treeNode.children.length == 1 + && currentNode.treeNode.children == null) + parent.treeNode.children = null; + else if (parent.treeNode.children.length > 1 + && currentNode.treeNode.children == null) { + parent.treeNode.children.splice(currentNode.index, 1); + } else + return; + currentNode = parent; + } + ; +}; + +Tree.prototype.getTreePathNodes = function(pathValues) { + + var DeleteNode = function(treeNode, index) { + this.treeNode = treeNode; + this.index = index; + }; + if (pathValues == null) + return; + if (this.root == null) { + alert("error"); + return; + } + var currentNode = this.root; + + var nodeArray = new Array(); + nodeArray.push(new DeleteNode(this.root, 0)); + for ( var i = 0; i < pathValues.length; i++) { + if (currentNode.children == null) { + alert("error"); + return null; + } + for ( var j = 0; j < currentNode.children.length; j++) + if (currentNode.children[j].value == pathValues[i]) { + nodeArray.push(new DeleteNode(currentNode.children[j], j)); + currentNode = currentNode.children[j]; + break; + } + + } + return nodeArray; +}; +Tree.prototype.getClonedTree = function(tree) { + var clonedTree = new Tree(); + clonedTree.root = this.getClonedNode(tree.root); + return clonedTree; + +}; +Tree.prototype.getClonedNode = function(node) { + if (node == null) + return null; + var clonedNode = new TreeNode(node.childClassName, node.name,node.value, null); + if (node.children != null && node.children.length > 0) { + for ( var i = 0; i < node.children.length; i++) { + var childClonedNode = this.getClonedNode(node.children[i]); + if (childClonedNode != null) + clonedNode.insertSingleNode(childClonedNode); + } + } + return clonedNode; +}; +function getClonedSubTree(startNode, parentNode) { + if (startNode == null) + return null; + if (startNode.children == null) + return null; + if (startNode.children.length <= 0) + return null; + for ( var i = 0; i < startNode.children.length; i++) { + var node = new TreeNode(startNode.children[i].childClassName,startNode.children[i].name, + startNode.children[i].value, null); + parentNode.insertSingleNode(node); + this.getClonedSubTree(startNode.children[i], node); + } +};