Merge branch 'master' of https://github.com/lostcharlie/Bench4Q.git
This commit is contained in:
commit
38b11ff38f
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,30 +3,30 @@
|
|||
<ui>
|
||||
<plugin name="MongoDBPlugin">
|
||||
<params>
|
||||
<param name="hostName" label="hostName">
|
||||
<param name="hostName" label="hostName" required="true">
|
||||
<field size="7" />
|
||||
</param>
|
||||
<param name="port" label="port">
|
||||
<param name="port" label="port" required="true">
|
||||
<field size="7" />
|
||||
</param>
|
||||
<param name="dbname" label="dbname">
|
||||
<param name="dbname" label="dbname" required="true">
|
||||
<field size="7" />
|
||||
</param>
|
||||
</params>
|
||||
</plugin>
|
||||
<behavior name="Insert">
|
||||
<params>
|
||||
<param name="key" label="key">
|
||||
<param name="key" label="key" required="true">
|
||||
<field size="7" />
|
||||
</param>
|
||||
<param name="value" label="value">
|
||||
<param name="value" label="value" required="true">
|
||||
<field size="7" />
|
||||
</param>
|
||||
</params>
|
||||
</behavior>
|
||||
<behavior name="Query">
|
||||
<params>
|
||||
<param name="properties" label="properties">
|
||||
<param name="properties" label="properties" required="true">
|
||||
<table cols="propertyName;propertyValue" />
|
||||
</param>
|
||||
</params>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
</plugin>
|
||||
<behavior name="Command">
|
||||
<params>
|
||||
<param name="command">
|
||||
<param name="command" required="true">
|
||||
<field size="6"></field>
|
||||
</param>
|
||||
</params>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
</plugin>
|
||||
<control name="Set">
|
||||
<params>
|
||||
<param name="toSave">
|
||||
<param name="toSave" required="true">
|
||||
<field size="7"></field>
|
||||
</param>
|
||||
</params>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE ui SYSTEM "../../dtd/ui.dtd">
|
||||
<!-- <!DOCTYPE ui SYSTEM "../../dtd/ui.dtd"> -->
|
||||
<ui>
|
||||
<plugin name="Http">
|
||||
<params>
|
||||
|
@ -7,7 +7,7 @@
|
|||
</plugin>
|
||||
<behavior name="Get">
|
||||
<params>
|
||||
<param name="url" label="The Url to request!!!!!!" required="true">
|
||||
<param name="url" label="The Url to request" required="true">
|
||||
<field size="7" />
|
||||
</param>
|
||||
<param name="queryParams" label="The query params of this request" required="false">
|
||||
|
|
|
@ -3,10 +3,11 @@
|
|||
<ui>
|
||||
<plugin name="IteratorNumber">
|
||||
<params>
|
||||
<param name="begin" label="The Beginning of the Iteration">
|
||||
<param name="begin" label="The Beginning of the Iteration"
|
||||
required="true">
|
||||
<field size="5"></field>
|
||||
</param>
|
||||
<param name="format" label="The format of the value">
|
||||
<param name="format" label="The format of the value" required="false">
|
||||
<field size="5"></field>
|
||||
</param>
|
||||
</params>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
</plugin>
|
||||
<behavior name="Log">
|
||||
<params>
|
||||
<param name="message">
|
||||
<param name="message" required="true">
|
||||
<field size="4" />
|
||||
</param>
|
||||
</params>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE ui SYSTEM "../../dtd/ui.dtd">
|
||||
<!-- <!DOCTYPE ui SYSTEM "../../dtd/ui.dtd"> -->
|
||||
<ui>
|
||||
<plugin name="Random">
|
||||
<params>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE ui SYSTEM "../../dtd/ui.dtd">
|
||||
<!-- <!DOCTYPE ui SYSTEM "../../dtd/ui.dtd"> -->
|
||||
<ui>
|
||||
<plugin name="ConstantTimer">
|
||||
<params />
|
||||
|
|
|
@ -3,10 +3,11 @@
|
|||
<ui>
|
||||
<plugin name="UniqueNumber">
|
||||
<params>
|
||||
<param name="begin" label="The Beginning of the Iteration">
|
||||
<param name="begin" label="The Beginning of the Iteration"
|
||||
required="true">
|
||||
<field size="5"></field>
|
||||
</param>
|
||||
<param name="format" label="The format of the value">
|
||||
<param name="format" label="The format of the value" required="true">
|
||||
<field size="5"></field>
|
||||
</param>
|
||||
</params>
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
<!ATTLIST param
|
||||
name CDATA #REQUIRED
|
||||
label CDATA #IMPLIED
|
||||
required CDATA #REQUIRED
|
||||
required CDATA #REQUIRED
|
||||
>
|
||||
<!ELEMENT group (param|group)*>
|
||||
<!ATTLIST group
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.agent.scenario;
|
||||
package org.bench4q.agent.scenario.engine;
|
||||
|
||||
import java.util.Date;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.agent.scenario;
|
||||
package org.bench4q.agent.scenario.engine;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
|
@ -1,14 +1,17 @@
|
|||
package org.bench4q.agent.scenario;
|
||||
package org.bench4q.agent.scenario.engine;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
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;
|
||||
|
@ -19,6 +22,7 @@ public class ScenarioContext {
|
|||
private Scenario scenario;
|
||||
private boolean finished;
|
||||
private DataCollector dataStatistics;
|
||||
private PluginManager pluginManager;
|
||||
|
||||
public UUID getTestId() {
|
||||
return testId;
|
||||
|
@ -76,29 +80,32 @@ public class ScenarioContext {
|
|||
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) {
|
||||
ScenarioContext scenarioContext = new ScenarioContext();
|
||||
scenarioContext.setTestId(testId);
|
||||
final SynchronousQueue<Runnable> workQueue = new SynchronousQueue<Runnable>();
|
||||
ThreadPoolExecutor executor = new ThreadPoolExecutor(poolSize,
|
||||
poolSize, keepAliveTime, TimeUnit.MINUTES, workQueue,
|
||||
new DiscardPolicy());
|
||||
final Scenario scenario, int poolSize, PluginManager pluginManager) {
|
||||
ScenarioContext scenarioContext = buildScenarioContextWithoutScenario(
|
||||
testId, poolSize, pluginManager);
|
||||
scenarioContext.setScenario(scenario);
|
||||
scenarioContext.setStartDate(new Date(System.currentTimeMillis()));
|
||||
scenarioContext.setExecutorService(executor);
|
||||
scenarioContext.setDataStatistics(new ScenarioResultCollector(testId));
|
||||
return scenarioContext;
|
||||
}
|
||||
|
||||
public static ScenarioContext buildScenarioContextWithoutScenario(
|
||||
UUID testId, int poolSize) {
|
||||
UUID testId, int poolSize, PluginManager pluginManager) {
|
||||
ScenarioContext scenarioContext = new ScenarioContext();
|
||||
scenarioContext.setTestId(testId);
|
||||
final SynchronousQueue<Runnable> workQueue = new SynchronousQueue<Runnable>();
|
||||
scenarioContext.setPluginManager(pluginManager);
|
||||
final ArrayBlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<Runnable>(
|
||||
poolSize);
|
||||
ThreadPoolExecutor executor = new ThreadPoolExecutor(poolSize,
|
||||
poolSize, keepAliveTime, TimeUnit.MINUTES, workQueue,
|
||||
new DiscardPolicy());
|
||||
|
@ -125,4 +132,18 @@ public class ScenarioContext {
|
|||
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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,13 +1,11 @@
|
|||
package org.bench4q.agent.scenario;
|
||||
package org.bench4q.agent.scenario.engine;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
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;
|
||||
|
||||
|
@ -41,7 +39,8 @@ public class ScenarioEngine {
|
|||
public void addRunningTestWithoutScenario(UUID runId, int poolSize) {
|
||||
try {
|
||||
final ScenarioContext scenarioContext = ScenarioContext
|
||||
.buildScenarioContextWithoutScenario(runId, poolSize);
|
||||
.buildScenarioContextWithoutScenario(runId, poolSize,
|
||||
getPluginManager());
|
||||
this.getRunningTests().put(runId, scenarioContext);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -61,28 +60,15 @@ public class ScenarioEngine {
|
|||
return false;
|
||||
}
|
||||
final ScenarioContext context = this.getRunningTests().get(runId);
|
||||
return runWith(context, runId);
|
||||
return runWith(context);
|
||||
}
|
||||
|
||||
private boolean runWith(final ScenarioContext scenarioContext,
|
||||
final UUID runId) {
|
||||
private boolean runWith(final ScenarioContext scenarioContext) {
|
||||
if (scenarioContext == null) {
|
||||
logger.error("The context required is null");
|
||||
return false;
|
||||
}
|
||||
ExecutorService taskMaker = Executors.newSingleThreadExecutor();
|
||||
|
||||
taskMaker.execute(new Runnable() {
|
||||
public void run() {
|
||||
int currentIterationId = 0;
|
||||
while (!scenarioContext.isFinished()) {
|
||||
scenarioContext.getExecutor().execute(
|
||||
new VUser(scenarioContext, currentIterationId,
|
||||
getPluginManager()));
|
||||
currentIterationId++;
|
||||
}
|
||||
}
|
||||
});
|
||||
scenarioContext.initTasks();
|
||||
return true;
|
||||
}
|
||||
|
|
@ -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 {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.agent.scenario;
|
||||
package org.bench4q.agent.scenario.engine;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
@ -12,6 +12,11 @@ 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;
|
||||
|
||||
|
@ -58,6 +63,7 @@ public class VUser implements Runnable {
|
|||
}
|
||||
|
||||
private void doCleanUp() {
|
||||
this.getScenarioContext().addTask();
|
||||
this.setScenarioContext(null);
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
@ -111,6 +111,6 @@ public abstract class TestBase {
|
|||
|
||||
public VUser createVUser(Scenario scenario, UUID testId) {
|
||||
return new VUser(ScenarioContext.buildScenarioContext(testId, scenario,
|
||||
10), 1, this.getPluginManager());
|
||||
10, pluginManager), 1, this.getPluginManager());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -5,21 +5,25 @@ import static org.junit.Assert.*;
|
|||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bench4q.agent.plugin.PluginManager;
|
||||
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.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "classpath:application-context.xml" })
|
||||
public class Test_ScenarioContext {
|
||||
@Autowired
|
||||
private PluginManager pluginManager;
|
||||
|
||||
@Test
|
||||
public void testBuildScenarioContext() {
|
||||
ScenarioContext context = ScenarioContext.buildScenarioContext(
|
||||
UUID.randomUUID(), new Scenario(), 20);
|
||||
UUID.randomUUID(), new Scenario(), 20, this.pluginManager);
|
||||
assertEquals(10,
|
||||
context.getExecutor().getKeepAliveTime(TimeUnit.MINUTES));
|
||||
assertEquals(20, context.getExecutor().getMaximumPoolSize());
|
||||
|
|
|
@ -2,12 +2,16 @@ 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.plugin.PluginManager;
|
||||
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 +26,9 @@ 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();
|
||||
@Autowired
|
||||
private PluginManager pluginManager;
|
||||
|
||||
private ScenarioEngine getScenarioEngine() {
|
||||
return scenarioEngine;
|
||||
|
@ -34,19 +41,27 @@ public class Test_ScenarioEngine extends TestBase {
|
|||
|
||||
@Test
|
||||
public void test_UpdatePopulation() {
|
||||
UUID testId = UUID.randomUUID();
|
||||
ScenarioContext scenarioContext = ScenarioContext
|
||||
.buildScenarioContext(
|
||||
testId,
|
||||
Scenario.scenarioBuilderWithCompile(buildRunScenarioModelWith(
|
||||
new ArrayList<UsePluginModel>(),
|
||||
BehaviorModel
|
||||
.UserBehaviorBuilder(1, "ok", "http",
|
||||
new ArrayList<ParameterModel>()))),
|
||||
100);
|
||||
ScenarioContext scenarioContext = ScenarioContext.buildScenarioContext(
|
||||
testId,
|
||||
Scenario.scenarioBuilderWithCompile(buildRunScenarioModelWith(
|
||||
new ArrayList<UsePluginModel>(), BehaviorModel
|
||||
.UserBehaviorBuilder(1, "ok", "http",
|
||||
new ArrayList<ParameterModel>()))),
|
||||
100, this.pluginManager);
|
||||
this.getScenarioEngine().getRunningTests().put(testId, scenarioContext);
|
||||
this.getScenarioEngine().updatePopulation(testId, 20);
|
||||
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.pluginManager);
|
||||
this.getScenarioEngine().getRunningTests().put(testId, scenarioContext);
|
||||
this.getScenarioEngine().runWith(testId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue