refs the api of bookTest

refs the api of bookTest
This commit is contained in:
coderfengyun 2014-09-02 10:12:28 +08:00
parent b288d92336
commit fd82b54d4e
4 changed files with 34 additions and 10 deletions

View File

@ -61,7 +61,7 @@ public class TestController {
@RequestMapping(value = "/bookTest/{poolSize}", method = { @RequestMapping(value = "/bookTest/{poolSize}", method = {
RequestMethod.GET, RequestMethod.POST }) RequestMethod.GET, RequestMethod.POST })
@ResponseBody @ResponseBody
public RunScenarioResultModel bookTest(@PathVariable int poolSize) { public RunScenarioResultModel bookTest(@PathVariable int poolSize, @RequestParam long startTime) {
try { try {
UUID runId = UUID.randomUUID(); UUID runId = UUID.randomUUID();
this.getScenarioEngine().addRunningTestWithoutScenario(runId, this.getScenarioEngine().addRunningTestWithoutScenario(runId,

View File

@ -130,8 +130,9 @@ public class ScenarioContext implements Observer {
this.getExecutor().getActiveCount()); this.getExecutor().getActiveCount());
} }
public void initTasks() { public void initTasks(int currentLoad) {
for (int i = 0; i < this.getExecutor().getCorePoolSize(); i++) { this.updatePopulation(currentLoad);
for (int i = 0; i < currentLoad; i++) {
addTask(); addTask();
} }
} }

View File

@ -13,9 +13,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
public class ScenarioEngine implements Observer{ public class ScenarioEngine implements Observer {
private Map<UUID, ScenarioContext> runningTests; private Map<UUID, ScenarioContext> runningTests;
private Logger logger = Logger.getLogger(ScenarioEngine.class); private final Logger logger = Logger.getLogger(ScenarioEngine.class);
private PluginManager pluginManager; private PluginManager pluginManager;
public ScenarioEngine() { public ScenarioEngine() {
@ -72,9 +72,20 @@ public class ScenarioEngine implements Observer{
logger.error("The context required is null"); logger.error("The context required is null");
return false; return false;
} }
scenarioContext.initTasks(); try {
new Supervisor(scenarioContext).start();; int currentLoad = scenarioContext
return true; .getScenario()
.getSchedule()
.loadFor(
System.currentTimeMillis()
- scenarioContext.getStartDate().getTime());
scenarioContext.initTasks(currentLoad);
new Supervisor(scenarioContext).start();
return true;
} catch (Exception e) {
this.logger.info(e, e);
return false;
}
} }
@Override @Override
@ -85,6 +96,5 @@ public class ScenarioEngine implements Observer{
UUID testId = (UUID) arg; UUID testId = (UUID) arg;
this.getRunningTests().remove(testId); this.getRunningTests().remove(testId);
} }
} }

View File

@ -101,6 +101,19 @@ public class Schedule extends Observable {
throw new Bench4QRunTimeException("Should not come to this place"); throw new Bench4QRunTimeException("Should not come to this place");
} }
/**
*
* @param relativeTime, relativeTime from beginDate
* @return
*/
public int loadFor(long relativeTime){
Segment segment = getSegment(relativeTime);
if (segment == null) {
throw new IllegalArgumentException();
}
return segment.loadFor(relativeTime);
}
public static class Segment { public static class Segment {
private final Point start; private final Point start;
private final Point end; private final Point end;