add things about controlling the test by timer

This commit is contained in:
coderfengyun 2013-08-21 17:40:33 +08:00
parent c505bc4edf
commit f073d37fe7
6 changed files with 68 additions and 21 deletions

View File

@ -38,7 +38,7 @@ public class HomeController {
getScenarioEngine().getRunningTests());
for (UUID key : contexts.keySet()) {
ScenarioContext value = contexts.get(key);
if (value.getResults().size() == value.getTotalCount()) {
if (value.isFinished()) {
serverStatusModel.getFinishedTests().add(key);
} else {
serverStatusModel.getRunningTests().add(key);

View File

@ -231,15 +231,19 @@ public class TestController {
return testBriefStatusModel;
}
@RequestMapping(value = "/stop/{runId}", method = RequestMethod.GET)
@RequestMapping(value = "/stop/{runId}", method = { RequestMethod.GET,
RequestMethod.POST })
@ResponseBody
public StopTestModel stop(@PathVariable UUID runId) {
System.out.println("stop method");
ScenarioContext scenarioContext = this.getScenarioEngine()
.getRunningTests().get(runId);
if (scenarioContext == null) {
return null;
}
scenarioContext.getExecutorService().shutdownNow();
scenarioContext.setFinished(true);
StopTestModel stopTestModel = new StopTestModel();
stopTestModel.setSuccess(true);
return stopTestModel;

View File

@ -13,7 +13,6 @@ public class TestBriefStatusModel {
private int failCount;
private int finishedCount;
private int totalCount;
private int finishedScenarioCount;
private int scenarioBehaviorCount;
private double averageResponseTime;
@ -71,15 +70,6 @@ public class TestBriefStatusModel {
this.totalCount = totalCount;
}
@XmlElement
public int getFinishedScenarioCount() {
return finishedScenarioCount;
}
public void setFinishedScenarioCount(int finishedScenarioCount) {
this.finishedScenarioCount = finishedScenarioCount;
}
@XmlElement
public double getAverageResponseTime() {
return averageResponseTime;

View File

@ -0,0 +1,49 @@
package org.bench4q.agent.scenario;
import java.util.List;
import java.util.UUID;
public class RunnableExecutor implements Runnable {
private ScenarioEngine scenarioEngine;
private UUID runId;
private List<BehaviorResult> behaviorResults;
private Scenario scenario;
private void setScenarioEngine(ScenarioEngine scenarioEngine) {
this.scenarioEngine = scenarioEngine;
}
private void setBehaviorResults(List<BehaviorResult> behaviorResults) {
this.behaviorResults = behaviorResults;
}
private void setRunId(UUID runId) {
this.runId = runId;
}
private void setScenario(Scenario scenario) {
this.scenario = scenario;
}
public RunnableExecutor(ScenarioEngine scenarioEngine, UUID runId,
Scenario scenario, List<BehaviorResult> behaviorResults) {
this.setScenarioEngine(scenarioEngine);
this.setRunId(runId);
this.setScenario(scenario);
this.setBehaviorResults(behaviorResults);
}
public void run() {
this.behaviorResults.addAll(this.scenarioEngine
.doRunScenario(this.scenario));
ScenarioContext scenarioContext = this.scenarioEngine.getRunningTests()
.get(this.runId);
if (scenarioContext.getExecutorService().isShutdown()) {
return;
}
scenarioContext.getExecutorService().execute(
new RunnableExecutor(this.scenarioEngine, this.runId,
this.scenario, this.behaviorResults));
}
}

View File

@ -12,6 +12,7 @@ public class ScenarioContext {
private ExecutorService executorService;
private Scenario scenario;
private List<BehaviorResult> results;
private boolean finished;
public int getPoolSize() {
return poolSize;
@ -68,4 +69,13 @@ public class ScenarioContext {
public void setResults(List<BehaviorResult> results) {
this.results = results;
}
public boolean isFinished() {
return finished;
}
public void setFinished(boolean finished) {
this.finished = finished;
}
}

View File

@ -68,16 +68,10 @@ public class ScenarioEngine {
poolSize, totalCount, executorService, ret);
int i;
this.getRunningTests().put(runId, scenarioContext);
Runnable runnable = new Runnable() {
public void run() {
ret.addAll(doRunScenario(scenario));
}
};
for (i = 0; i < totalCount; i++) {
scenarioContext.setFinishedCount(i - 1);
Runnable runnable = new RunnableExecutor(this, runId, scenario, ret);
for (i = 0; i < poolSize; i++) {
executorService.execute(runnable);
}
executorService.shutdown();
} catch (Exception e) {
e.printStackTrace();
}
@ -97,7 +91,7 @@ public class ScenarioEngine {
return scenarioContext;
}
private List<BehaviorResult> doRunScenario(Scenario scenario) {
public List<BehaviorResult> doRunScenario(Scenario scenario) {
Map<String, Object> plugins = new HashMap<String, Object>();
preparePlugins(scenario, plugins);