remove the bug of taskMaker

remove the bug of taskMaker that just make so many junk jobs
This commit is contained in:
coderfengyun 2014-08-29 15:34:14 +08:00
parent 77168b6ac7
commit 5ff8fb00ac
25 changed files with 721 additions and 34 deletions

View File

@ -5,8 +5,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bench4q.agent.scenario.ScenarioContext;
import org.bench4q.agent.scenario.ScenarioEngine;
import org.bench4q.agent.scenario.engine.ScenarioContext;
import org.bench4q.agent.scenario.engine.ScenarioEngine;
import org.bench4q.share.models.agent.ServerStatusModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

View File

@ -10,9 +10,9 @@ import org.apache.log4j.Logger;
import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResult;
import org.bench4q.agent.plugin.ParameterFileCollector;
import org.bench4q.agent.scenario.Scenario;
import org.bench4q.agent.scenario.ScenarioContext;
import org.bench4q.agent.scenario.ScenarioEngine;
import org.bench4q.agent.scenario.behavior.Behavior;
import org.bench4q.agent.scenario.engine.ScenarioContext;
import org.bench4q.agent.scenario.engine.ScenarioEngine;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.agent.BehaviorBriefModel;
import org.bench4q.share.models.agent.BehaviorStatusCodeResultModel;
@ -97,7 +97,7 @@ public class TestController {
return null;
}
}
private RunScenarioResultModel buildWith(UUID runId) {
RunScenarioResultModel result = new RunScenarioResultModel();
result.setRunId(runId);
@ -267,7 +267,8 @@ public class TestController {
return new CleanTestResultModel(true);
}
@RequestMapping(value = "/updatePopulation/{runId}/{requiredLoad}", method = RequestMethod.POST)
@RequestMapping(value = "/updatePopulation/{runId}/{requiredLoad}", method = {
RequestMethod.POST, RequestMethod.GET })
@ResponseBody
public UpdatePopulationModel updatePopulation(@PathVariable UUID runId,
@PathVariable int requiredLoad) {

View File

@ -3,8 +3,8 @@ package org.bench4q.agent.datacollector;
import java.util.Map;
import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResult;
import org.bench4q.agent.scenario.BehaviorResult;
import org.bench4q.agent.scenario.PageResult;
import org.bench4q.agent.scenario.engine.BehaviorResult;
import org.bench4q.agent.scenario.engine.PageResult;
public interface DataCollector {
public void add(BehaviorResult behaviorResult);

View File

@ -7,7 +7,7 @@ import java.util.concurrent.Executors;
import org.bench4q.agent.Main;
import org.bench4q.agent.datacollector.DataCollector;
import org.bench4q.agent.helper.ApplicationContextHelper;
import org.bench4q.agent.scenario.BehaviorResult;
import org.bench4q.agent.scenario.engine.BehaviorResult;
import org.bench4q.agent.storage.StorageHelper;
import org.bench4q.share.models.agent.BehaviorResultModel;

View File

@ -4,8 +4,8 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.bench4q.agent.scenario.BehaviorResult;
import org.bench4q.agent.scenario.PageResult;
import org.bench4q.agent.scenario.engine.BehaviorResult;
import org.bench4q.agent.scenario.engine.PageResult;
import org.bench4q.share.models.agent.statistics.AgentPageBriefModel;
public class PageResultCollector extends AbstractDataCollector {

View File

@ -7,8 +7,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bench4q.agent.scenario.BehaviorResult;
import org.bench4q.agent.scenario.PageResult;
import org.bench4q.agent.scenario.engine.BehaviorResult;
import org.bench4q.agent.scenario.engine.PageResult;
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
/**

View File

@ -0,0 +1,134 @@
package org.bench4q.agent.scenario.engine;
import java.util.Date;
public class BehaviorResult {
private String pluginId;
private String pluginName;
private int behaviorId;
private String behaviorName;
private Date startDate;
private Date endDate;
private long responseTime;
private int successCount;
private int failCount;
private boolean shouldBeCountResponseTime;
private String behaviorUrl;
private long contentLength;
private int statusCode;
private String contentType;
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;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
public long getResponseTime() {
return responseTime;
}
public void setResponseTime(long responseTime) {
this.responseTime = responseTime;
}
public int getSuccessCount() {
return successCount;
}
public void setSuccessCount(int successCount) {
this.successCount = successCount;
}
public int getFailCount() {
return failCount;
}
public void setFailCount(int failCount) {
this.failCount = failCount;
}
public int getBehaviorId() {
return behaviorId;
}
public void setBehaviorId(int behaviorId) {
this.behaviorId = behaviorId;
}
public String getBehaviorUrl() {
return behaviorUrl;
}
public void setBehaviorUrl(String behaviorUrl) {
this.behaviorUrl = behaviorUrl;
}
public long getContentLength() {
return contentLength;
}
public void setContentLength(long contentLength) {
this.contentLength = contentLength;
}
public int getStatusCode() {
return statusCode;
}
public void setStatusCode(int statusCode) {
this.statusCode = statusCode;
}
public String getContentType() {
return contentType;
}
public void setContentType(String contentType) {
this.contentType = contentType;
}
public boolean isShouldBeCountResponseTime() {
return shouldBeCountResponseTime;
}
public void setShouldBeCountResponseTime(boolean shouldBeCountResponseTime) {
this.shouldBeCountResponseTime = shouldBeCountResponseTime;
}
}

View File

@ -0,0 +1,87 @@
package org.bench4q.agent.scenario.engine;
import java.util.ArrayList;
import java.util.List;
public class PageResult {
private int pageId;
private long pageStartTime;
private long pageEndTime;
private long executeRange;
public int getPageId() {
return pageId;
}
private void setPageId(int pageId) {
this.pageId = pageId;
}
private long getPageStartTime() {
return pageStartTime;
}
private void setPageStartTime(long pageStartTime) {
this.pageStartTime = pageStartTime;
}
public long getPageEndTime() {
return pageEndTime;
}
private void setPageEndTime(long pageEndTime) {
this.pageEndTime = pageEndTime;
}
public long getExecuteRange() {
return executeRange;
}
private void setExecuteRange(long executeRange) {
this.executeRange = executeRange;
}
private PageResult() {
init();
}
private void init() {
this.setPageStartTime(Long.MAX_VALUE);
this.setPageEndTime(Long.MIN_VALUE);
this.setExecuteRange(0);
}
public static PageResult buildPageResult(int pageId,
List<BehaviorResult> behaviorResults) {
PageResult result = new PageResult();
result.setPageId(pageId);
if (behaviorResults == null) {
behaviorResults = new ArrayList<BehaviorResult>();
}
for (BehaviorResult behaviorResult : behaviorResults) {
if (behaviorResult.getStartDate().getTime() < result
.getPageStartTime()) {
result.setPageStartTime(behaviorResult.getStartDate().getTime());
}
if (behaviorResult.getEndDate().getTime() > result.getPageEndTime()) {
result.setPageEndTime(behaviorResult.getEndDate().getTime());
}
// Page excuteRange rely on the behaviors' execute way, if it's
// executed in batch, i should take the longest behavior in batch
// to calculate this One.
}
result.setExecuteRange(result.getPageEndTime()
- result.getPageStartTime());
return result;
}
public static PageResult buildPageResult(int pageId, long startTime,
long endTime) {
PageResult result = new PageResult();
result.setPageId(pageId);
result.setPageStartTime(startTime);
result.setPageEndTime(endTime);
result.setExecuteRange(endTime - startTime);
return result;
}
}

View File

@ -0,0 +1,149 @@
package org.bench4q.agent.scenario.engine;
import java.util.Date;
import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.ThreadPoolExecutor.DiscardPolicy;
import org.apache.log4j.Logger;
import org.bench4q.agent.datacollector.DataCollector;
import org.bench4q.agent.datacollector.impl.ScenarioResultCollector;
import org.bench4q.agent.plugin.PluginManager;
import org.bench4q.agent.scenario.Scenario;
public class ScenarioContext {
private static final long keepAliveTime = 10;
private UUID testId;
private Date startDate;
private Date endDate;
private ThreadPoolExecutor executor;
private Scenario scenario;
private boolean finished;
private DataCollector dataStatistics;
private PluginManager pluginManager;
public UUID getTestId() {
return testId;
}
private void setTestId(UUID testId) {
this.testId = testId;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date saveStartDate) {
this.startDate = saveStartDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
public ThreadPoolExecutor getExecutor() {
return executor;
}
public void setExecutorService(ThreadPoolExecutor executor) {
this.executor = executor;
}
public Scenario getScenario() {
return scenario;
}
public void setScenario(Scenario scenario) {
this.scenario = scenario;
}
public boolean isFinished() {
return finished;
}
public void setFinished(boolean finished) {
this.finished = finished;
}
public DataCollector getDataStatistics() {
return dataStatistics;
}
private void setDataStatistics(DataCollector dataStatistics) {
this.dataStatistics = dataStatistics;
}
private PluginManager getPluginManager() {
return pluginManager;
}
private void setPluginManager(PluginManager pluginManager) {
this.pluginManager = pluginManager;
}
private ScenarioContext() {
}
public static ScenarioContext buildScenarioContext(UUID testId,
final Scenario scenario, int poolSize, PluginManager pluginManager) {
ScenarioContext scenarioContext = buildScenarioContextWithoutScenario(
testId, poolSize, pluginManager);
scenarioContext.setScenario(scenario);
return scenarioContext;
}
public static ScenarioContext buildScenarioContextWithoutScenario(
UUID testId, int poolSize, PluginManager pluginManager) {
ScenarioContext scenarioContext = new ScenarioContext();
scenarioContext.setTestId(testId);
scenarioContext.setPluginManager(pluginManager);
final ArrayBlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<Runnable>(
poolSize);
ThreadPoolExecutor executor = new ThreadPoolExecutor(poolSize,
poolSize, keepAliveTime, TimeUnit.MINUTES, workQueue,
new DiscardPolicy());
scenarioContext.setStartDate(new Date(System.currentTimeMillis()));
scenarioContext.setExecutorService(executor);
scenarioContext.setDataStatistics(new ScenarioResultCollector(testId));
return scenarioContext;
}
public ScenarioContext addScenrio(Scenario scenario) {
this.setScenario(scenario);
return this;
}
/**
* Now, I tolerate that if the requiredLoad <
* this.getExecutor.getCorePoolSize(), then the excess threads will be
* killed when its current task complete
*
* @param requiredLoad
*/
void updatePopulation(int requiredLoad) {
this.getExecutor().setCorePoolSize(requiredLoad);
this.getExecutor().setMaximumPoolSize(requiredLoad);
}
public void addTask() {
if (this.isFinished()) {
return;
}
this.getExecutor().execute(new VUser(this, 1, getPluginManager()));
Logger.getLogger(this.getClass()).info(
this.getExecutor().getActiveCount());
}
public void initTasks() {
for (int i = 0; i < this.getExecutor().getCorePoolSize(); i++) {
addTask();
}
}
}

View File

@ -0,0 +1,79 @@
package org.bench4q.agent.scenario.engine;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.apache.log4j.Logger;
import org.bench4q.agent.plugin.PluginManager;
import org.bench4q.agent.scenario.Scenario;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class ScenarioEngine {
private Map<UUID, ScenarioContext> runningTests;
private Logger logger = Logger.getLogger(ScenarioEngine.class);
private PluginManager pluginManager;
public ScenarioEngine() {
this.setRunningTests(new HashMap<UUID, ScenarioContext>());
}
public Map<UUID, ScenarioContext> getRunningTests() {
return runningTests;
}
private void setRunningTests(Map<UUID, ScenarioContext> runningTests) {
this.runningTests = runningTests;
}
private PluginManager getPluginManager() {
return pluginManager;
}
@Autowired
private void setPluginManager(PluginManager pluginManager) {
this.pluginManager = pluginManager;
}
public void addRunningTestWithoutScenario(UUID runId, int poolSize) {
try {
final ScenarioContext scenarioContext = ScenarioContext
.buildScenarioContextWithoutScenario(runId, poolSize,
getPluginManager());
this.getRunningTests().put(runId, scenarioContext);
} catch (Exception e) {
e.printStackTrace();
}
}
public void submitScenario(UUID runId, final Scenario scenario) {
try {
this.getRunningTests().get(runId).addScenrio(scenario);
} catch (Exception e) {
e.printStackTrace();
}
}
public boolean runWith(UUID runId) {
if (!this.getRunningTests().containsKey(runId)) {
return false;
}
final ScenarioContext context = this.getRunningTests().get(runId);
return runWith(context);
}
private boolean runWith(final ScenarioContext scenarioContext) {
if (scenarioContext == null) {
logger.error("The context required is null");
return false;
}
scenarioContext.initTasks();
return true;
}
public void updatePopulation(UUID testId, int requiredLoad) {
ScenarioContext context = this.getRunningTests().get(testId);
context.updatePopulation(requiredLoad);
}
}

View File

@ -0,0 +1,26 @@
package org.bench4q.agent.scenario.engine;
public class TaskMonitor {
public static class TaskProducer implements Runnable {
private ScenarioContext context;
public TaskProducer(ScenarioContext context) {
this.context = context;
}
@Override
public void run() {
int poolSize = context.getExecutor().getCorePoolSize();
try {
if (context.getExecutor().getTaskCount() > poolSize * 2) {
this.wait();
}
} catch (Exception e) {
} finally {
}
}
}
}

View File

@ -0,0 +1,200 @@
package org.bench4q.agent.scenario.engine;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import org.bench4q.agent.datacollector.DataCollector;
import org.bench4q.agent.plugin.ParameterBarn;
import org.bench4q.agent.plugin.Plugin;
import org.bench4q.agent.plugin.PluginManager;
import org.bench4q.agent.plugin.basic.PluginReturn;
import org.bench4q.agent.plugin.basic.http.HttpReturn;
import org.bench4q.agent.scenario.Batch;
import org.bench4q.agent.scenario.Page;
import org.bench4q.agent.scenario.Parameter;
import org.bench4q.agent.scenario.Scenario;
import org.bench4q.agent.scenario.UsePlugin;
import org.bench4q.agent.scenario.behavior.Behavior;
import org.bench4q.agent.scenario.dfa.ParamPart;
public class VUser implements Runnable {
private ScenarioContext scenarioContext;
private int currentIterationId;
private PluginManager pluginManager;
private int getCurrentIterationId() {
return currentIterationId;
}
private void setCurrentIterationId(int currentIterationId) {
this.currentIterationId = currentIterationId;
}
private ScenarioContext getScenarioContext() {
return scenarioContext;
}
private void setScenarioContext(ScenarioContext scenarioContext) {
this.scenarioContext = scenarioContext;
}
private PluginManager getPluginManager() {
return pluginManager;
}
private void setPluginManager(PluginManager pluginManager) {
this.pluginManager = pluginManager;
}
public VUser(ScenarioContext scenarioContext, int currentIterationId,
PluginManager pluginManager) {
this.setScenarioContext(scenarioContext);
this.setPluginManager(pluginManager);
this.setCurrentIterationId(currentIterationId);
}
public void run() {
doRunScenario(getScenarioContext());
doCleanUp();
}
private void doCleanUp() {
this.getScenarioContext().addTask();
this.setScenarioContext(null);
}
private void doRunScenario(ScenarioContext context) {
Map<String, Object> plugins = new LinkedHashMap<String, Object>();
preparePlugins(context.getScenario(), plugins);
for (int i = 0; i < context.getScenario().getPages().length; i++) {
Page page = context.getScenario().getPages()[i];
long startTime = System.currentTimeMillis();
for (Batch batch : page.getBatches()) {
doRunBatch(plugins, batch, context.getDataStatistics());
}
long endTime = System.currentTimeMillis();
context.getDataStatistics().add(
PageResult.buildPageResult(i, startTime, endTime));
}
}
private void doRunBatch(Map<String, Object> plugins, Batch batch,
DataCollector dataCollector) {
for (Behavior behavior : batch.getBehaviors()) {
Object plugin = plugins.get(behavior.getUse());
Date startDate = new Date(System.currentTimeMillis());
PluginReturn pluginReturn = (PluginReturn) this.getPluginManager()
.doBehavior(plugin, behavior.getName(),
reassamblyParameters(behavior, plugins));
Date endDate = new Date(System.currentTimeMillis());
if (!behavior.shouldBeCount()) {
continue;
}
dataCollector.add(buildBehaviorResult(behavior, plugin, startDate,
pluginReturn, endDate));
}
}
private Map<String, String> reassamblyParameters(Behavior behavior,
Map<String, Object> plugins) {
Map<String, String> behaviorParameters = new HashMap<String, String>();
for (Parameter parameter : behavior.getParameters()) {
behaviorParameters.put(parameter.getKey(),
reassamblyParameter(parameter.getParamParts(), plugins));
}
return behaviorParameters;
}
private String reassamblyParameter(ParamPart[] parts,
Map<String, Object> plugins) {
StringBuilder buf = new StringBuilder();
for (int i = 0, len = parts.length; i < len; i++) {
switch (parts[i].getType()) {
case STRING:
buf.append(parts[i].getContentForStringType());
break;
case SESSION_ID:
buf.append(this.getCurrentIterationId());
break;
case CONTEXT_CALL:
try {
Object dpObj = plugins.get(parts[i]
.getPluginIdForContextCallType());
if (dpObj == null) {
throw new RuntimeException("No such plug-in id: "
+ parts[i].getPluginIdForContextCallType());
} else if (dpObj instanceof ParameterBarn) {
buf.append(((ParameterBarn) dpObj).getValue(parts[i]
.getVariableForContextCallAndProperty()));
} else {
throw new RuntimeException("Plug-in "
+ parts[i].getPluginIdForContextCallType()
+ " is not a data provider.");
}
} catch (Exception e) {
Logger.getLogger(VUser.class)
.error(parts[i].getPluginIdForContextCallType()
+ "variable "
+ parts[i]
.getVariableForContextCallAndProperty(),
e);
}
break;
case PROPERTY:
buf.append(System.getProperty(
parts[i].getVariableForContextCallAndProperty(), ""));
break;
}
}
return buf.toString();
}
private BehaviorResult buildBehaviorResult(Behavior behavior,
Object plugin, Date startDate, PluginReturn pluginReturn,
Date endDate) {
BehaviorResult result = new BehaviorResult();
result.setBehaviorId(behavior.getId());
result.setStartDate(startDate);
result.setEndDate(endDate);
result.setSuccessCount(pluginReturn.getSuccessCount());
result.setFailCount(pluginReturn.getFailCount());
result.setResponseTime(endDate.getTime() - startDate.getTime());
result.setBehaviorName(behavior.getName());
result.setPluginId(behavior.getUse());
result.setPluginName(plugin.getClass().getAnnotation(Plugin.class)
.value());
result.setShouldBeCountResponseTime(behavior.shouldBeCount());
if (pluginReturn instanceof HttpReturn) {
HttpReturn httpReturn = (HttpReturn) pluginReturn;
// TODO: this param in result is not Appropriate
result.setBehaviorUrl(behavior.getSpecificParamValue("url"));
result.setContentLength(httpReturn.getContentLength());
result.setContentType(httpReturn.getContentType());
result.setStatusCode(httpReturn.getStatusCode());
}
return result;
}
private void preparePlugins(Scenario scenario, Map<String, Object> plugins) {
for (UsePlugin usePlugin : scenario.getUsePlugins()) {
String pluginId = usePlugin.getId();
Class<?> pluginClass = this.getPluginManager().getPlugins()
.get(usePlugin.getName());
Map<String, String> initParameters = new HashMap<String, String>();
for (Parameter parameter : usePlugin.getParameters()) {
initParameters.put(parameter.getKey(), parameter.getValue());
}
Map<String, String> extraParameters = new HashMap<String, String>();
extraParameters.put("testId", this.getScenarioContext().getTestId()
.toString());
Object plugin = this.getPluginManager().initializePlugin(
pluginClass, initParameters, extraParameters);
plugins.put(pluginId, plugin);
}
}
}

View File

@ -10,8 +10,8 @@ import org.apache.commons.io.FileUtils;
import org.bench4q.agent.plugin.ParameterBarn;
import org.bench4q.agent.plugin.PluginManager;
import org.bench4q.agent.scenario.Scenario;
import org.bench4q.agent.scenario.ScenarioContext;
import org.bench4q.agent.scenario.VUser;
import org.bench4q.agent.scenario.engine.ScenarioContext;
import org.bench4q.agent.scenario.engine.VUser;
import org.bench4q.share.helper.TestHelper;
import org.bench4q.share.models.agent.ParameterModel;
import org.bench4q.share.models.agent.RunScenarioModel;

View File

@ -62,7 +62,7 @@ public class TestWithScriptFile {
public TestWithScriptFile() {
this.setFilePath("Scripts" + System.getProperty("file.separator")
+ "httpWithoutTimer.xml");
+ "homepage.xml");
this.setHttpRequester(new HttpRequester());
}
@ -193,7 +193,7 @@ public class TestWithScriptFile {
files.add(new File("Scripts" + System.getProperty("file.separator")
+ "testJD.xml"));
HttpResponse httpResponse1 = this.getHttpRequester().sendPost(
url + "/bookTest/10", null, null);
url + "/bookTest/100", null, null);
RunScenarioResultModel bookResponse = (RunScenarioResultModel) MarshalHelper
.tryUnmarshal(RunScenarioResultModel.class,
httpResponse1.getContent());

View File

@ -9,7 +9,7 @@ import java.util.UUID;
import org.bench4q.agent.datacollector.DataCollector;
import org.bench4q.agent.datacollector.impl.ScenarioResultCollector;
import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResult;
import org.bench4q.agent.scenario.BehaviorResult;
import org.bench4q.agent.scenario.engine.BehaviorResult;
import org.bench4q.agent.storage.StorageHelper;
import org.junit.Test;
import org.springframework.context.ApplicationContext;

View File

@ -2,7 +2,7 @@ package org.bench4q.agent.test.datastatistics;
import org.bench4q.agent.datacollector.DataCollector;
import org.bench4q.agent.datacollector.impl.PageResultCollector;
import org.bench4q.agent.scenario.PageResult;
import org.bench4q.agent.scenario.engine.PageResult;
import org.bench4q.share.models.agent.statistics.AgentPageBriefModel;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@ -9,8 +9,8 @@ import java.util.UUID;
import org.bench4q.agent.datacollector.DataCollector;
import org.bench4q.agent.datacollector.impl.ScenarioResultCollector;
import org.bench4q.agent.scenario.BehaviorResult;
import org.bench4q.agent.scenario.PageResult;
import org.bench4q.agent.scenario.engine.BehaviorResult;
import org.bench4q.agent.scenario.engine.PageResult;
import org.bench4q.agent.storage.StorageHelper;
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
import org.junit.Test;

View File

@ -6,7 +6,7 @@ import java.util.UUID;
import org.bench4q.agent.plugin.basic.context.Context;
import org.bench4q.agent.scenario.Scenario;
import org.bench4q.agent.scenario.VUser;
import org.bench4q.agent.scenario.engine.VUser;
import org.bench4q.agent.test.TestBase;
import org.bench4q.share.models.agent.ParameterModel;
import org.bench4q.share.models.agent.RunScenarioModel;

View File

@ -13,7 +13,7 @@ import java.util.UUID;
import org.bench4q.agent.plugin.PluginManager;
import org.bench4q.agent.plugin.basic.csvprovider.CsvProvider;
import org.bench4q.agent.scenario.Scenario;
import org.bench4q.agent.scenario.VUser;
import org.bench4q.agent.scenario.engine.VUser;
import org.bench4q.agent.test.TestBase;
import org.bench4q.share.helper.TestHelper;
import org.bench4q.share.models.agent.ParameterModel;

View File

@ -16,7 +16,7 @@ import org.bench4q.agent.plugin.basic.http.BatchRequest;
import org.bench4q.agent.plugin.basic.http.HttpPlugin;
import org.bench4q.agent.plugin.basic.http.HttpReturn;
import org.bench4q.agent.scenario.Scenario;
import org.bench4q.agent.scenario.VUser;
import org.bench4q.agent.scenario.engine.VUser;
import org.bench4q.agent.test.TestBase;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.helper.TestHelper;

View File

@ -12,7 +12,7 @@ import org.apache.commons.io.FileUtils;
import org.bench4q.agent.plugin.basic.MongoDB.MongoDBPlugin;
import org.bench4q.agent.plugin.basic.MongoDB.MongoDBReturn;
import org.bench4q.agent.scenario.Scenario;
import org.bench4q.agent.scenario.VUser;
import org.bench4q.agent.scenario.engine.VUser;
import org.bench4q.agent.test.TestBase;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.helper.TestHelper;

View File

@ -6,7 +6,7 @@ import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.bench4q.agent.scenario.Scenario;
import org.bench4q.agent.scenario.ScenarioContext;
import org.bench4q.agent.scenario.engine.ScenarioContext;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;

View File

@ -2,12 +2,15 @@ package org.bench4q.agent.test.scenario;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.UUID;
import org.apache.commons.io.FileUtils;
import org.bench4q.agent.scenario.Scenario;
import org.bench4q.agent.scenario.ScenarioContext;
import org.bench4q.agent.scenario.ScenarioEngine;
import org.bench4q.agent.scenario.engine.ScenarioContext;
import org.bench4q.agent.scenario.engine.ScenarioEngine;
import org.bench4q.agent.test.TestBase;
import org.bench4q.share.models.agent.ParameterModel;
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
@ -22,6 +25,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ContextConfiguration(locations = { "classpath:application-context.xml" })
public class Test_ScenarioEngine extends TestBase {
private ScenarioEngine scenarioEngine;
private UUID testId = UUID.randomUUID();
private ScenarioEngine getScenarioEngine() {
return scenarioEngine;
@ -34,7 +38,6 @@ public class Test_ScenarioEngine extends TestBase {
@Test
public void test_UpdatePopulation() {
UUID testId = UUID.randomUUID();
ScenarioContext scenarioContext = ScenarioContext
.buildScenarioContext(
testId,
@ -49,4 +52,15 @@ public class Test_ScenarioEngine extends TestBase {
assertEquals(20, scenarioContext.getExecutor().getMaximumPoolSize());
System.out.println(scenarioContext.getExecutor().getActiveCount());
}
@Test
public void test_RunWithContext() throws IOException {
ScenarioContext scenarioContext = ScenarioContext.buildScenarioContext(
testId, Scenario.scenarioBuilderWithCompile(FileUtils
.readFileToString(new File("Scripts"
+ System.getProperty("file.separator")
+ "homepage.xml"))), 100);
this.getScenarioEngine().getRunningTests().put(testId, scenarioContext);
this.getScenarioEngine().runWith(testId);
}
}

View File

@ -9,8 +9,8 @@ import static org.junit.Assert.*;
import org.bench4q.agent.plugin.basic.csvprovider.CsvProvider;
import org.bench4q.agent.scenario.Scenario;
import org.bench4q.agent.scenario.VUser;
import org.bench4q.agent.scenario.behavior.Behavior;
import org.bench4q.agent.scenario.engine.VUser;
import org.bench4q.agent.test.TestBase;
import org.bench4q.share.helper.TestHelper;
import org.bench4q.share.models.agent.ParameterModel;

View File

@ -5,9 +5,6 @@
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan
base-package="org.bench4q.agent.helper, org.bench4q.agent.plugin, org.bench4q.agent.storage, org.bench4q.agent.parameterization,org.bench4q.agent.scenario" />
<context:component-scan base-package="org.bench4q" />
<mvc:annotation-driven />
</beans>