From f4f22a47d4952b1b4da74308f0c37f8941d2a3f5 Mon Sep 17 00:00:00 2001 From: Zhen Tang Date: Sun, 30 Jun 2013 11:48:52 +0800 Subject: [PATCH] add pool size setting now. --- .../java/org/bench4q/agent/api/TestController.java | 3 ++- .../org/bench4q/agent/api/model/RunScenarioModel.java | 10 ++++++++++ .../org/bench4q/agent/scenario/ScenarioContext.java | 9 +++++++++ .../org/bench4q/agent/scenario/ScenarioEngine.java | 6 ++++-- .../java/org/bench4q/agent/test/RunScenarioTest.java | 6 ++++-- 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/bench4q/agent/api/TestController.java b/src/main/java/org/bench4q/agent/api/TestController.java index 78243e58..c215b0be 100644 --- a/src/main/java/org/bench4q/agent/api/TestController.java +++ b/src/main/java/org/bench4q/agent/api/TestController.java @@ -94,7 +94,8 @@ public class TestController { RunScenarioResultModel runScenarioResultModel = new RunScenarioResultModel(); runScenarioResultModel.setRunId(UUID.randomUUID()); this.getScenarioEngine().runScenario(runScenarioResultModel.getRunId(), - scenario, runScenarioModel.getTotalCount()); + scenario, runScenarioModel.getPoolSize(), + runScenarioModel.getTotalCount()); return runScenarioResultModel; } diff --git a/src/main/java/org/bench4q/agent/api/model/RunScenarioModel.java b/src/main/java/org/bench4q/agent/api/model/RunScenarioModel.java index 2bcc4aca..7d8cf9bd 100644 --- a/src/main/java/org/bench4q/agent/api/model/RunScenarioModel.java +++ b/src/main/java/org/bench4q/agent/api/model/RunScenarioModel.java @@ -8,10 +8,20 @@ import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement(name = "runScenario") public class RunScenarioModel { + private int poolSize; private int totalCount; private List usePlugins; private List userBehaviors; + @XmlElement + public int getPoolSize() { + return poolSize; + } + + public void setPoolSize(int poolSize) { + this.poolSize = poolSize; + } + @XmlElement public int getTotalCount() { return totalCount; diff --git a/src/main/java/org/bench4q/agent/scenario/ScenarioContext.java b/src/main/java/org/bench4q/agent/scenario/ScenarioContext.java index 08ec51c9..35ffde4e 100644 --- a/src/main/java/org/bench4q/agent/scenario/ScenarioContext.java +++ b/src/main/java/org/bench4q/agent/scenario/ScenarioContext.java @@ -7,12 +7,21 @@ import java.util.concurrent.ExecutorService; import org.bench4q.agent.plugin.BehaviorResult; public class ScenarioContext { + private int poolSize; private int totalCount; private Date startDate; private ExecutorService executorService; private Scenario scenario; private List results; + public int getPoolSize() { + return poolSize; + } + + public void setPoolSize(int poolSize) { + this.poolSize = poolSize; + } + public int getTotalCount() { return totalCount; } diff --git a/src/main/java/org/bench4q/agent/scenario/ScenarioEngine.java b/src/main/java/org/bench4q/agent/scenario/ScenarioEngine.java index fe7e682e..645e0434 100644 --- a/src/main/java/org/bench4q/agent/scenario/ScenarioEngine.java +++ b/src/main/java/org/bench4q/agent/scenario/ScenarioEngine.java @@ -46,15 +46,17 @@ public class ScenarioEngine { return this.getRunningTests().get(uuid); } - public void runScenario(UUID runId, final Scenario scenario, int totalCount) { + public void runScenario(UUID runId, final Scenario scenario, int poolSize, + int totalCount) { try { ScenarioContext scenarioContext = new ScenarioContext(); scenarioContext.setScenario(scenario); scenarioContext.setTotalCount(totalCount * scenario.getUserBehaviors().length); + scenarioContext.setPoolSize(poolSize); scenarioContext.setStartDate(new Date(System.currentTimeMillis())); ExecutorService executorService = Executors - .newFixedThreadPool(totalCount); + .newFixedThreadPool(poolSize); scenarioContext.setExecutorService(executorService); int i; final List ret = Collections diff --git a/src/test/java/org/bench4q/agent/test/RunScenarioTest.java b/src/test/java/org/bench4q/agent/test/RunScenarioTest.java index 5336aa36..2e1d5052 100644 --- a/src/test/java/org/bench4q/agent/test/RunScenarioTest.java +++ b/src/test/java/org/bench4q/agent/test/RunScenarioTest.java @@ -23,7 +23,8 @@ public class RunScenarioTest { public void testRunScenario() { try { RunScenarioModel runScenarioModel = new RunScenarioModel(); - runScenarioModel.setTotalCount(300); + runScenarioModel.setTotalCount(30000); + runScenarioModel.setPoolSize(300); runScenarioModel.setUsePlugins(new ArrayList()); runScenarioModel .setUserBehaviors(new ArrayList()); @@ -85,7 +86,8 @@ public class RunScenarioTest { httpURLConnection.setDoInput(true); httpURLConnection.setUseCaches(false); httpURLConnection.setRequestMethod("POST"); - httpURLConnection.setRequestProperty("Content-Type", "application/xml"); + httpURLConnection.setRequestProperty("Content-Type", + "application/xml"); OutputStreamWriter outputStreamWriter = new OutputStreamWriter( httpURLConnection.getOutputStream()); outputStreamWriter.write(content);