Test status service added.
This commit is contained in:
parent
d0a14e6ea4
commit
92fb5fb76f
|
@ -1,8 +1,13 @@
|
|||
package org.bench4q.agent.api;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.agent.api.model.TestBriefStatusModel;
|
||||
import org.bench4q.agent.api.model.TestDetailModel;
|
||||
import org.bench4q.agent.api.model.TestDetailStatusModel;
|
||||
import org.bench4q.agent.plugin.BehaviorResult;
|
||||
import org.bench4q.agent.scenario.Parameter;
|
||||
import org.bench4q.agent.scenario.Scenario;
|
||||
import org.bench4q.agent.scenario.ScenarioContext;
|
||||
|
@ -11,6 +16,7 @@ import org.bench4q.agent.scenario.UsePlugin;
|
|||
import org.bench4q.agent.scenario.UserBehavior;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
@ -31,7 +37,7 @@ public class TestController {
|
|||
|
||||
@RequestMapping(value = "/run", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public String run() {
|
||||
public UUID run() {
|
||||
Scenario scenario = new Scenario();
|
||||
|
||||
scenario.setUsePlugins(new UsePlugin[2]);
|
||||
|
@ -53,7 +59,15 @@ public class TestController {
|
|||
scenario.getUserBehaviors()[0].getParameters()[0] = new Parameter();
|
||||
scenario.getUserBehaviors()[0].getParameters()[0].setKey("url");
|
||||
scenario.getUserBehaviors()[0].getParameters()[0]
|
||||
.setValue("http://www.baidu.com");
|
||||
.setValue("http://localhost:6565");
|
||||
|
||||
scenario.getUserBehaviors()[2] = new UserBehavior();
|
||||
scenario.getUserBehaviors()[2].setUse("timer");
|
||||
scenario.getUserBehaviors()[2].setName("Sleep");
|
||||
scenario.getUserBehaviors()[2].setParameters(new Parameter[1]);
|
||||
scenario.getUserBehaviors()[2].getParameters()[0] = new Parameter();
|
||||
scenario.getUserBehaviors()[2].getParameters()[0].setKey("time");
|
||||
scenario.getUserBehaviors()[2].getParameters()[0].setValue("1000");
|
||||
|
||||
scenario.getUserBehaviors()[1] = new UserBehavior();
|
||||
scenario.getUserBehaviors()[1].setUse("http");
|
||||
|
@ -68,24 +82,91 @@ public class TestController {
|
|||
scenario.getUserBehaviors()[1].getParameters()[1]
|
||||
.setValue("Hello,world!");
|
||||
|
||||
scenario.getUserBehaviors()[2] = new UserBehavior();
|
||||
scenario.getUserBehaviors()[2].setUse("timer");
|
||||
scenario.getUserBehaviors()[2].setName("Sleep");
|
||||
scenario.getUserBehaviors()[2].setParameters(new Parameter[1]);
|
||||
scenario.getUserBehaviors()[2].getParameters()[0] = new Parameter();
|
||||
scenario.getUserBehaviors()[2].getParameters()[0].setKey("time");
|
||||
scenario.getUserBehaviors()[2].getParameters()[0].setValue("1000");
|
||||
|
||||
this.getScenarioEngine().runScenario(UUID.randomUUID(), scenario, 100);
|
||||
return "It works!";
|
||||
UUID uuid = UUID.randomUUID();
|
||||
this.getScenarioEngine().runScenario(uuid, scenario, 200);
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/status", method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/detail/{uuid}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public String status() {
|
||||
Map<UUID, ScenarioContext> map = this.getScenarioEngine()
|
||||
.getRunningTests();
|
||||
System.out.println(map.toString());
|
||||
return "It works!";
|
||||
public TestDetailStatusModel detail(@PathVariable UUID uuid) {
|
||||
ScenarioContext scenarioContext = this.getScenarioEngine()
|
||||
.getRunningTests().get(uuid);
|
||||
TestDetailStatusModel testStatusModel = new TestDetailStatusModel();
|
||||
testStatusModel.setStartDate(scenarioContext.getStartDate());
|
||||
testStatusModel.setTestDetailModels(new ArrayList<TestDetailModel>());
|
||||
int failCount = 0;
|
||||
int successCount = 0;
|
||||
List<BehaviorResult> behaviorResults = scenarioContext.getResults();
|
||||
long maxDate = 0;
|
||||
long totalResponseTime = 0;
|
||||
for (BehaviorResult behaviorResult : behaviorResults) {
|
||||
TestDetailModel testDetailModel = new TestDetailModel();
|
||||
testDetailModel.setBehaviorName(behaviorResult.getBehaviorName());
|
||||
testDetailModel.setEndDate(behaviorResult.getEndDate());
|
||||
testDetailModel.setPluginId(behaviorResult.getPluginId());
|
||||
testDetailModel.setPluginName(behaviorResult.getPluginName());
|
||||
testDetailModel.setResponseTime(behaviorResult.getResponseTime());
|
||||
testDetailModel.setStartDate(behaviorResult.getStartDate());
|
||||
testDetailModel.setSuccess(behaviorResult.isSuccess());
|
||||
testStatusModel.getTestDetailModels().add(testDetailModel);
|
||||
if (testDetailModel.getEndDate().getTime() > maxDate) {
|
||||
maxDate = testDetailModel.getEndDate().getTime();
|
||||
}
|
||||
if (testDetailModel.isSuccess()) {
|
||||
successCount++;
|
||||
} else {
|
||||
failCount++;
|
||||
}
|
||||
if (!behaviorResult.getPluginName().contains("Timer")) {
|
||||
totalResponseTime += behaviorResult.getResponseTime();
|
||||
}
|
||||
}
|
||||
testStatusModel.setAverageResponseTime((totalResponseTime + 0.0)
|
||||
/ behaviorResults.size());
|
||||
testStatusModel.setElapsedTime(maxDate
|
||||
- testStatusModel.getStartDate().getTime());
|
||||
testStatusModel.setFailCount(failCount);
|
||||
testStatusModel.setSuccessCount(successCount);
|
||||
testStatusModel.setFinishedCount(testStatusModel.getTestDetailModels()
|
||||
.size());
|
||||
testStatusModel.setTotalCount(scenarioContext.getTotalCount());
|
||||
return testStatusModel;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/brief/{uuid}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public TestBriefStatusModel brief(@PathVariable UUID uuid) {
|
||||
ScenarioContext scenarioContext = this.getScenarioEngine()
|
||||
.getRunningTests().get(uuid);
|
||||
TestBriefStatusModel testBriefStatusModel = new TestBriefStatusModel();
|
||||
testBriefStatusModel.setStartDate(scenarioContext.getStartDate());
|
||||
int failCount = 0;
|
||||
int successCount = 0;
|
||||
long totalResponseTime = 0;
|
||||
List<BehaviorResult> behaviorResults = scenarioContext.getResults();
|
||||
long maxDate = 0;
|
||||
for (BehaviorResult behaviorResult : behaviorResults) {
|
||||
if (behaviorResult.getEndDate().getTime() > maxDate) {
|
||||
maxDate = behaviorResult.getEndDate().getTime();
|
||||
}
|
||||
if (behaviorResult.isSuccess()) {
|
||||
successCount++;
|
||||
} else {
|
||||
failCount++;
|
||||
}
|
||||
if (!behaviorResult.getPluginName().contains("Timer")) {
|
||||
totalResponseTime += behaviorResult.getResponseTime();
|
||||
}
|
||||
}
|
||||
testBriefStatusModel.setAverageResponseTime((totalResponseTime + 0.0)
|
||||
/ behaviorResults.size());
|
||||
testBriefStatusModel.setElapsedTime(maxDate
|
||||
- testBriefStatusModel.getStartDate().getTime());
|
||||
testBriefStatusModel.setFailCount(failCount);
|
||||
testBriefStatusModel.setSuccessCount(successCount);
|
||||
testBriefStatusModel.setFinishedCount(behaviorResults.size());
|
||||
testBriefStatusModel.setTotalCount(scenarioContext.getTotalCount());
|
||||
return testBriefStatusModel;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
package org.bench4q.agent.api.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "testBriefStatus")
|
||||
public class TestBriefStatusModel {
|
||||
private Date startDate;
|
||||
private long elapsedTime;
|
||||
private int successCount;
|
||||
private int failCount;
|
||||
private int finishedCount;
|
||||
private int totalCount;
|
||||
private double averageResponseTime;
|
||||
|
||||
@XmlElement
|
||||
public Date getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(Date startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public long getElapsedTime() {
|
||||
return elapsedTime;
|
||||
}
|
||||
|
||||
public void setElapsedTime(long elapsedTime) {
|
||||
this.elapsedTime = elapsedTime;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public int getSuccessCount() {
|
||||
return successCount;
|
||||
}
|
||||
|
||||
public void setSuccessCount(int successCount) {
|
||||
this.successCount = successCount;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public int getFailCount() {
|
||||
return failCount;
|
||||
}
|
||||
|
||||
public void setFailCount(int failCount) {
|
||||
this.failCount = failCount;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public int getFinishedCount() {
|
||||
return finishedCount;
|
||||
}
|
||||
|
||||
public void setFinishedCount(int finishedCount) {
|
||||
this.finishedCount = finishedCount;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public int getTotalCount() {
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
public void setTotalCount(int totalCount) {
|
||||
this.totalCount = totalCount;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public double getAverageResponseTime() {
|
||||
return averageResponseTime;
|
||||
}
|
||||
|
||||
public void setAverageResponseTime(double averageResponseTime) {
|
||||
this.averageResponseTime = averageResponseTime;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package org.bench4q.agent.api.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "testDetail")
|
||||
public class TestDetailModel {
|
||||
private String pluginId;
|
||||
private String pluginName;
|
||||
private String behaviorName;
|
||||
private Date startDate;
|
||||
private Date endDate;
|
||||
private long responseTime;
|
||||
private boolean success;
|
||||
|
||||
@XmlElement
|
||||
public String getPluginId() {
|
||||
return pluginId;
|
||||
}
|
||||
|
||||
public void setPluginId(String pluginId) {
|
||||
this.pluginId = pluginId;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getPluginName() {
|
||||
return pluginName;
|
||||
}
|
||||
|
||||
public void setPluginName(String pluginName) {
|
||||
this.pluginName = pluginName;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getBehaviorName() {
|
||||
return behaviorName;
|
||||
}
|
||||
|
||||
public void setBehaviorName(String behaviorName) {
|
||||
this.behaviorName = behaviorName;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public Date getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(Date startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public Date getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
public void setEndDate(Date endDate) {
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public long getResponseTime() {
|
||||
return responseTime;
|
||||
}
|
||||
|
||||
public void setResponseTime(long responseTime) {
|
||||
this.responseTime = responseTime;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
package org.bench4q.agent.api.model;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "testDetailStatus")
|
||||
public class TestDetailStatusModel {
|
||||
private Date startDate;
|
||||
private long elapsedTime;
|
||||
private int successCount;
|
||||
private int failCount;
|
||||
private int finishedCount;
|
||||
private int totalCount;
|
||||
private double averageResponseTime;
|
||||
private List<TestDetailModel> testDetailModels;
|
||||
|
||||
@XmlElement
|
||||
public Date getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(Date startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public long getElapsedTime() {
|
||||
return elapsedTime;
|
||||
}
|
||||
|
||||
public void setElapsedTime(long elapsedTime) {
|
||||
this.elapsedTime = elapsedTime;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public int getSuccessCount() {
|
||||
return successCount;
|
||||
}
|
||||
|
||||
public void setSuccessCount(int successCount) {
|
||||
this.successCount = successCount;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public int getFailCount() {
|
||||
return failCount;
|
||||
}
|
||||
|
||||
public void setFailCount(int failCount) {
|
||||
this.failCount = failCount;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public int getFinishedCount() {
|
||||
return finishedCount;
|
||||
}
|
||||
|
||||
public void setFinishedCount(int finishedCount) {
|
||||
this.finishedCount = finishedCount;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public int getTotalCount() {
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
public void setTotalCount(int totalCount) {
|
||||
this.totalCount = totalCount;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public double getAverageResponseTime() {
|
||||
return averageResponseTime;
|
||||
}
|
||||
|
||||
public void setAverageResponseTime(double averageResponseTime) {
|
||||
this.averageResponseTime = averageResponseTime;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "testDetails")
|
||||
@XmlElement(name = "testDetail")
|
||||
public List<TestDetailModel> getTestDetailModels() {
|
||||
return testDetailModels;
|
||||
}
|
||||
|
||||
public void setTestDetailModels(List<TestDetailModel> testDetailModels) {
|
||||
this.testDetailModels = testDetailModels;
|
||||
}
|
||||
|
||||
}
|
|
@ -3,10 +3,38 @@ package org.bench4q.agent.plugin;
|
|||
import java.util.Date;
|
||||
|
||||
public class BehaviorResult {
|
||||
private String pluginId;
|
||||
private String pluginName;
|
||||
private String behaviorName;
|
||||
private Date startDate;
|
||||
private Date endDate;
|
||||
private long responseTime;
|
||||
private boolean success;
|
||||
|
||||
public String getPluginId() {
|
||||
return pluginId;
|
||||
}
|
||||
|
||||
public void setPluginId(String pluginId) {
|
||||
this.pluginId = pluginId;
|
||||
}
|
||||
|
||||
public String getPluginName() {
|
||||
return pluginName;
|
||||
}
|
||||
|
||||
public void setPluginName(String pluginName) {
|
||||
this.pluginName = pluginName;
|
||||
}
|
||||
|
||||
public String getBehaviorName() {
|
||||
return behaviorName;
|
||||
}
|
||||
|
||||
public void setBehaviorName(String behaviorName) {
|
||||
this.behaviorName = behaviorName;
|
||||
}
|
||||
|
||||
public Date getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
@ -23,6 +51,14 @@ public class BehaviorResult {
|
|||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
public long getResponseTime() {
|
||||
return responseTime;
|
||||
}
|
||||
|
||||
public void setResponseTime(long responseTime) {
|
||||
this.responseTime = responseTime;
|
||||
}
|
||||
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
|
|
@ -5,22 +5,18 @@ import java.io.InputStreamReader;
|
|||
import java.io.OutputStreamWriter;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Date;
|
||||
|
||||
import org.bench4q.agent.plugin.Behavior;
|
||||
import org.bench4q.agent.plugin.BehaviorResult;
|
||||
import org.bench4q.agent.plugin.Plugin;
|
||||
|
||||
@Plugin("Http")
|
||||
public class HttpPlugin {
|
||||
|
||||
public HttpPlugin() {
|
||||
|
||||
}
|
||||
|
||||
@Behavior("Get")
|
||||
public BehaviorResult get(String url) {
|
||||
BehaviorResult behaviorResult = new BehaviorResult();
|
||||
behaviorResult.setStartDate(new Date(System.currentTimeMillis()));
|
||||
public boolean get(String url) {
|
||||
try {
|
||||
URL target = new URL(url);
|
||||
HttpURLConnection httpURLConnection = (HttpURLConnection) target
|
||||
|
@ -37,20 +33,15 @@ public class HttpPlugin {
|
|||
stringBuffer.append((char) temp);
|
||||
}
|
||||
bufferedReader.close();
|
||||
behaviorResult.setSuccess(true);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
behaviorResult.setSuccess(false);
|
||||
} finally {
|
||||
behaviorResult.setEndDate(new Date(System.currentTimeMillis()));
|
||||
return false;
|
||||
}
|
||||
return behaviorResult;
|
||||
}
|
||||
|
||||
@Behavior("Post")
|
||||
public BehaviorResult post(String url, String content) {
|
||||
BehaviorResult behaviorResult = new BehaviorResult();
|
||||
behaviorResult.setStartDate(new Date(System.currentTimeMillis()));
|
||||
public boolean post(String url, String content) {
|
||||
try {
|
||||
URL target = new URL(url);
|
||||
HttpURLConnection httpURLConnection = (HttpURLConnection) target
|
||||
|
@ -72,13 +63,10 @@ public class HttpPlugin {
|
|||
stringBuffer.append((char) temp);
|
||||
}
|
||||
bufferedReader.close();
|
||||
behaviorResult.setSuccess(true);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
behaviorResult.setSuccess(false);
|
||||
} finally {
|
||||
behaviorResult.setEndDate(new Date(System.currentTimeMillis()));
|
||||
return false;
|
||||
}
|
||||
return behaviorResult;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
package org.bench4q.agent.plugin.timer;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.bench4q.agent.plugin.Behavior;
|
||||
import org.bench4q.agent.plugin.BehaviorResult;
|
||||
import org.bench4q.agent.plugin.Plugin;
|
||||
|
||||
@Plugin("ConstantTimer")
|
||||
|
@ -13,18 +10,13 @@ public class ConstantTimerPlugin {
|
|||
}
|
||||
|
||||
@Behavior("Sleep")
|
||||
public BehaviorResult sleep(int time) {
|
||||
BehaviorResult behaviorResult = new BehaviorResult();
|
||||
behaviorResult.setStartDate(new Date(System.currentTimeMillis()));
|
||||
public boolean sleep(int time) {
|
||||
try {
|
||||
Thread.sleep(time);
|
||||
behaviorResult.setSuccess(true);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
behaviorResult.setSuccess(false);
|
||||
} finally {
|
||||
behaviorResult.setEndDate(new Date(System.currentTimeMillis()));
|
||||
return false;
|
||||
}
|
||||
return behaviorResult;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,34 @@
|
|||
package org.bench4q.agent.scenario;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import org.bench4q.agent.plugin.BehaviorResult;
|
||||
|
||||
public class ScenarioContext {
|
||||
private int totalCount;
|
||||
private Date startDate;
|
||||
private ExecutorService executorService;
|
||||
private Scenario scenario;
|
||||
private List<BehaviorResult> results;
|
||||
|
||||
public int getTotalCount() {
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
public void setTotalCount(int totalCount) {
|
||||
this.totalCount = totalCount;
|
||||
}
|
||||
|
||||
public Date getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(Date startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
public ExecutorService getExecutorService() {
|
||||
return executorService;
|
||||
}
|
||||
|
@ -33,6 +52,5 @@ public class ScenarioContext {
|
|||
public void setResults(List<BehaviorResult> results) {
|
||||
this.results = results;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.bench4q.agent.scenario;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -10,6 +11,7 @@ import java.util.concurrent.ExecutorService;
|
|||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.bench4q.agent.plugin.BehaviorResult;
|
||||
import org.bench4q.agent.plugin.Plugin;
|
||||
import org.bench4q.agent.plugin.PluginManager;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -44,12 +46,15 @@ public class ScenarioEngine {
|
|||
return this.getRunningTests().get(uuid);
|
||||
}
|
||||
|
||||
public void runScenario(UUID uuid, final Scenario scenario, int threadCount) {
|
||||
public void runScenario(UUID uuid, final Scenario scenario, int totalCount) {
|
||||
try {
|
||||
ScenarioContext scenarioContext = new ScenarioContext();
|
||||
scenarioContext.setScenario(scenario);
|
||||
scenarioContext.setTotalCount(totalCount
|
||||
* scenario.getUserBehaviors().length);
|
||||
scenarioContext.setStartDate(new Date(System.currentTimeMillis()));
|
||||
ExecutorService executorService = Executors
|
||||
.newFixedThreadPool(threadCount);
|
||||
.newFixedThreadPool(totalCount);
|
||||
scenarioContext.setExecutorService(executorService);
|
||||
int i;
|
||||
final List<BehaviorResult> ret = Collections
|
||||
|
@ -61,7 +66,7 @@ public class ScenarioEngine {
|
|||
ret.addAll(doRunScenario(scenario));
|
||||
}
|
||||
};
|
||||
for (i = 0; i < threadCount; i++) {
|
||||
for (i = 0; i < totalCount; i++) {
|
||||
executorService.execute(runnable);
|
||||
}
|
||||
executorService.shutdown();
|
||||
|
@ -94,8 +99,19 @@ public class ScenarioEngine {
|
|||
behaviorParameters
|
||||
.put(parameter.getKey(), parameter.getValue());
|
||||
}
|
||||
ret.add((BehaviorResult) this.getPluginManager().doBehavior(plugin,
|
||||
behaviorName, behaviorParameters));
|
||||
BehaviorResult result = new BehaviorResult();
|
||||
result.setStartDate(new Date(System.currentTimeMillis()));
|
||||
boolean success = (Boolean) this.getPluginManager().doBehavior(
|
||||
plugin, behaviorName, behaviorParameters);
|
||||
result.setEndDate(new Date(System.currentTimeMillis()));
|
||||
result.setSuccess(success);
|
||||
result.setResponseTime(result.getEndDate().getTime()
|
||||
- result.getStartDate().getTime());
|
||||
result.setBehaviorName(behaviorName);
|
||||
result.setPluginId(userBehavior.getUse());
|
||||
result.setPluginName(plugin.getClass().getAnnotation(Plugin.class)
|
||||
.value());
|
||||
ret.add(result);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue