From fd82b54d4e8bf83a3e9a4d77407bc80ceccac030 Mon Sep 17 00:00:00 2001 From: coderfengyun Date: Tue, 2 Sep 2014 10:12:28 +0800 Subject: [PATCH] refs the api of bookTest refs the api of bookTest --- .../org/bench4q/agent/api/TestController.java | 2 +- .../scenario/engine/ScenarioContext.java | 5 ++-- .../agent/scenario/engine/ScenarioEngine.java | 24 +++++++++++++------ .../agent/scenario/engine/Schedule.java | 13 ++++++++++ 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/api/TestController.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/api/TestController.java index 6f91d1ea..fb274090 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/api/TestController.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/api/TestController.java @@ -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, diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/engine/ScenarioContext.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/engine/ScenarioContext.java index 9d32ae01..d0530543 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/engine/ScenarioContext.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/engine/ScenarioContext.java @@ -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(); } } diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/engine/ScenarioEngine.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/engine/ScenarioEngine.java index 6fc9d661..5721b713 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/engine/ScenarioEngine.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/engine/ScenarioEngine.java @@ -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 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); } - - + } diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/engine/Schedule.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/engine/Schedule.java index 04a45c10..d1837a2f 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/engine/Schedule.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/engine/Schedule.java @@ -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;