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 = {
RequestMethod.GET, RequestMethod.POST })
@ResponseBody
public RunScenarioResultModel bookTest(@PathVariable int poolSize) {
public RunScenarioResultModel bookTest(@PathVariable int poolSize, @RequestParam long startTime) {
try {
UUID runId = UUID.randomUUID();
this.getScenarioEngine().addRunningTestWithoutScenario(runId,

View File

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

View File

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

View File

@ -101,6 +101,19 @@ public class Schedule extends Observable {
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 {
private final Point start;
private final Point end;