From 0f56154c393cd6de93f05dc9663ced16c44b187e Mon Sep 17 00:00:00 2001 From: coderfengyun Date: Fri, 30 Aug 2013 09:22:01 +0800 Subject: [PATCH] get agent's already runed time by brief --- .../org/bench4q/agent/api/TestController.java | 29 ++++++++++++++++++- .../agent/scenario/ScenarioContext.java | 18 ++++++++++++ .../agent/scenario/ScenarioEngine.java | 19 ++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/bench4q/agent/api/TestController.java b/src/main/java/org/bench4q/agent/api/TestController.java index c8ecfa39..21f81bfe 100644 --- a/src/main/java/org/bench4q/agent/api/TestController.java +++ b/src/main/java/org/bench4q/agent/api/TestController.java @@ -205,6 +205,11 @@ public class TestController { long maxDate = 0, minDate = Long.MAX_VALUE; int validCount = 0; for (BehaviorResult behaviorResult : behaviorResults) { + // TODO: remove this + if (behaviorResult.getStartDate().getTime() < scenarioContext + .getStartDate().getTime()) { + continue; + } if (behaviorResult.getEndDate().getTime() > maxDate) { maxDate = behaviorResult.getEndDate().getTime(); } @@ -225,13 +230,15 @@ public class TestController { / validCount); testBriefStatusModel.setElapsedTime(maxDate - testBriefStatusModel.getStartDate().getTime()); - testBriefStatusModel.setRunningTime(maxDate - minDate); + testBriefStatusModel.setRunningTime(maxDate + - scenarioContext.getStartDate().getTime()); testBriefStatusModel.setFailCount(failCount); testBriefStatusModel.setSuccessCount(successCount); testBriefStatusModel.setFinishedCount(behaviorResults.size()); testBriefStatusModel.setTotalCount(scenarioContext.getTotalCount()); testBriefStatusModel.setScenarioBehaviorCount(scenarioContext .getScenario().getUserBehaviors().length); + testBriefStatusModel.setRunningTime(maxDate - minDate); return testBriefStatusModel; } @@ -277,4 +284,24 @@ public class TestController { saveTestResultModel.setSuccess(true); return saveTestResultModel; } + + @RequestMapping(value = "/startSave/{runId}", method = { RequestMethod.GET, + RequestMethod.POST }) + @ResponseBody + public SaveTestResultModel startSave(@PathVariable UUID runId) { + this.getScenarioEngine().startSaveResultsWithEdit(runId); + SaveTestResultModel saveTestResultModel = new SaveTestResultModel(); + saveTestResultModel.setSuccess(true); + return saveTestResultModel; + } + + @RequestMapping(value = "/stopSave/{runId}", method = { RequestMethod.GET, + RequestMethod.POST }) + @ResponseBody + public SaveTestResultModel stopSave(@PathVariable UUID runId) { + this.getScenarioEngine().stopSaveResultWithEdit(runId); + SaveTestResultModel saveTestResultModel = new SaveTestResultModel(); + saveTestResultModel.setSuccess(true); + return saveTestResultModel; + } } diff --git a/src/main/java/org/bench4q/agent/scenario/ScenarioContext.java b/src/main/java/org/bench4q/agent/scenario/ScenarioContext.java index 3695ce91..d1f0d0e1 100644 --- a/src/main/java/org/bench4q/agent/scenario/ScenarioContext.java +++ b/src/main/java/org/bench4q/agent/scenario/ScenarioContext.java @@ -9,10 +9,12 @@ public class ScenarioContext { private int totalCount; private int finishedCount; private Date startDate; + private Date stopDate; private ExecutorService executorService; private Scenario scenario; private List results; private boolean finished; + private boolean toSave; public int getPoolSize() { return poolSize; @@ -46,6 +48,14 @@ public class ScenarioContext { this.startDate = startDate; } + public Date getStopDate() { + return stopDate; + } + + public void setStopDate(Date stopDate) { + this.stopDate = stopDate; + } + public ExecutorService getExecutorService() { return executorService; } @@ -78,4 +88,12 @@ public class ScenarioContext { this.finished = finished; } + public boolean isToSave() { + return toSave; + } + + public void setToSave(boolean startToSave) { + this.toSave = startToSave; + } + } diff --git a/src/main/java/org/bench4q/agent/scenario/ScenarioEngine.java b/src/main/java/org/bench4q/agent/scenario/ScenarioEngine.java index 033ae4f3..69685b69 100644 --- a/src/main/java/org/bench4q/agent/scenario/ScenarioEngine.java +++ b/src/main/java/org/bench4q/agent/scenario/ScenarioEngine.java @@ -85,6 +85,7 @@ public class ScenarioEngine { scenarioContext.setTotalCount(totalCount * scenario.getUserBehaviors().length); scenarioContext.setPoolSize(poolSize); + // TODO: set it to null scenarioContext.setStartDate(new Date(System.currentTimeMillis())); scenarioContext.setExecutorService(executorService); scenarioContext.setResults(ret); @@ -174,6 +175,24 @@ public class ScenarioEngine { return directory; } + public void startSaveResultsWithEdit(UUID runId) { + ScenarioContext scenarioContext = this.getRunningTests().get(runId); + if (scenarioContext == null) { + return; + } + scenarioContext.setStartDate(new Date(System.currentTimeMillis())); + scenarioContext.setToSave(true); + } + + public void stopSaveResultWithEdit(UUID runId) { + ScenarioContext scenarioContext = this.getRunningTests().get(runId); + if (scenarioContext == null) { + return; + } + scenarioContext.setStopDate(new Date(System.currentTimeMillis())); + scenarioContext.setToSave(false); + } + public void saveTestResults(UUID runId) { ScenarioContext scenarioContext = this.getRunningTests().get(runId); if (scenarioContext == null) {