add pool size setting now.

This commit is contained in:
Zhen Tang 2013-06-30 11:48:52 +08:00
parent f5f0455f3c
commit f4f22a47d4
5 changed files with 29 additions and 5 deletions

View File

@ -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;
}

View File

@ -8,10 +8,20 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "runScenario")
public class RunScenarioModel {
private int poolSize;
private int totalCount;
private List<UsePluginModel> usePlugins;
private List<UserBehaviorModel> userBehaviors;
@XmlElement
public int getPoolSize() {
return poolSize;
}
public void setPoolSize(int poolSize) {
this.poolSize = poolSize;
}
@XmlElement
public int getTotalCount() {
return totalCount;

View File

@ -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<BehaviorResult> results;
public int getPoolSize() {
return poolSize;
}
public void setPoolSize(int poolSize) {
this.poolSize = poolSize;
}
public int getTotalCount() {
return totalCount;
}

View File

@ -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<BehaviorResult> ret = Collections

View File

@ -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<UsePluginModel>());
runScenarioModel
.setUserBehaviors(new ArrayList<UserBehaviorModel>());
@ -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);