This commit is contained in:
hmm 2014-08-29 17:37:14 +08:00
commit 38b11ff38f
35 changed files with 159 additions and 101 deletions

View File

@ -5,8 +5,8 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.bench4q.agent.scenario.ScenarioContext; import org.bench4q.agent.scenario.engine.ScenarioContext;
import org.bench4q.agent.scenario.ScenarioEngine; import org.bench4q.agent.scenario.engine.ScenarioEngine;
import org.bench4q.share.models.agent.ServerStatusModel; import org.bench4q.share.models.agent.ServerStatusModel;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; 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.datacollector.impl.BehaviorStatusCodeResult;
import org.bench4q.agent.plugin.ParameterFileCollector; import org.bench4q.agent.plugin.ParameterFileCollector;
import org.bench4q.agent.scenario.Scenario; 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.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.helper.MarshalHelper;
import org.bench4q.share.models.agent.BehaviorBriefModel; import org.bench4q.share.models.agent.BehaviorBriefModel;
import org.bench4q.share.models.agent.BehaviorStatusCodeResultModel; import org.bench4q.share.models.agent.BehaviorStatusCodeResultModel;
@ -97,7 +97,7 @@ public class TestController {
return null; return null;
} }
} }
private RunScenarioResultModel buildWith(UUID runId) { private RunScenarioResultModel buildWith(UUID runId) {
RunScenarioResultModel result = new RunScenarioResultModel(); RunScenarioResultModel result = new RunScenarioResultModel();
result.setRunId(runId); result.setRunId(runId);
@ -267,7 +267,8 @@ public class TestController {
return new CleanTestResultModel(true); return new CleanTestResultModel(true);
} }
@RequestMapping(value = "/updatePopulation/{runId}/{requiredLoad}", method = RequestMethod.POST) @RequestMapping(value = "/updatePopulation/{runId}/{requiredLoad}", method = {
RequestMethod.POST, RequestMethod.GET })
@ResponseBody @ResponseBody
public UpdatePopulationModel updatePopulation(@PathVariable UUID runId, public UpdatePopulationModel updatePopulation(@PathVariable UUID runId,
@PathVariable int requiredLoad) { @PathVariable int requiredLoad) {

View File

@ -3,8 +3,8 @@ package org.bench4q.agent.datacollector;
import java.util.Map; import java.util.Map;
import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResult; import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResult;
import org.bench4q.agent.scenario.BehaviorResult; import org.bench4q.agent.scenario.engine.BehaviorResult;
import org.bench4q.agent.scenario.PageResult; import org.bench4q.agent.scenario.engine.PageResult;
public interface DataCollector { public interface DataCollector {
public void add(BehaviorResult behaviorResult); 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.Main;
import org.bench4q.agent.datacollector.DataCollector; import org.bench4q.agent.datacollector.DataCollector;
import org.bench4q.agent.helper.ApplicationContextHelper; 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.agent.storage.StorageHelper;
import org.bench4q.share.models.agent.BehaviorResultModel; import org.bench4q.share.models.agent.BehaviorResultModel;

View File

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

View File

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

View File

@ -3,30 +3,30 @@
<ui> <ui>
<plugin name="MongoDBPlugin"> <plugin name="MongoDBPlugin">
<params> <params>
<param name="hostName" label="hostName"> <param name="hostName" label="hostName" required="true">
<field size="7" /> <field size="7" />
</param> </param>
<param name="port" label="port"> <param name="port" label="port" required="true">
<field size="7" /> <field size="7" />
</param> </param>
<param name="dbname" label="dbname"> <param name="dbname" label="dbname" required="true">
<field size="7" /> <field size="7" />
</param> </param>
</params> </params>
</plugin> </plugin>
<behavior name="Insert"> <behavior name="Insert">
<params> <params>
<param name="key" label="key"> <param name="key" label="key" required="true">
<field size="7" /> <field size="7" />
</param> </param>
<param name="value" label="value"> <param name="value" label="value" required="true">
<field size="7" /> <field size="7" />
</param> </param>
</params> </params>
</behavior> </behavior>
<behavior name="Query"> <behavior name="Query">
<params> <params>
<param name="properties" label="properties"> <param name="properties" label="properties" required="true">
<table cols="propertyName;propertyValue" /> <table cols="propertyName;propertyValue" />
</param> </param>
</params> </params>

View File

@ -6,7 +6,7 @@
</plugin> </plugin>
<behavior name="Command"> <behavior name="Command">
<params> <params>
<param name="command"> <param name="command" required="true">
<field size="6"></field> <field size="6"></field>
</param> </param>
</params> </params>

View File

@ -6,7 +6,7 @@
</plugin> </plugin>
<control name="Set"> <control name="Set">
<params> <params>
<param name="toSave"> <param name="toSave" required="true">
<field size="7"></field> <field size="7"></field>
</param> </param>
</params> </params>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ui SYSTEM "../../dtd/ui.dtd"> <!-- <!DOCTYPE ui SYSTEM "../../dtd/ui.dtd"> -->
<ui> <ui>
<plugin name="Http"> <plugin name="Http">
<params> <params>
@ -7,7 +7,7 @@
</plugin> </plugin>
<behavior name="Get"> <behavior name="Get">
<params> <params>
<param name="url" label="The Url to request!!!!!!" required="true"> <param name="url" label="The Url to request" required="true">
<field size="7" /> <field size="7" />
</param> </param>
<param name="queryParams" label="The query params of this request" required="false"> <param name="queryParams" label="The query params of this request" required="false">

View File

@ -3,10 +3,11 @@
<ui> <ui>
<plugin name="IteratorNumber"> <plugin name="IteratorNumber">
<params> <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> <field size="5"></field>
</param> </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> <field size="5"></field>
</param> </param>
</params> </params>

View File

@ -6,7 +6,7 @@
</plugin> </plugin>
<behavior name="Log"> <behavior name="Log">
<params> <params>
<param name="message"> <param name="message" required="true">
<field size="4" /> <field size="4" />
</param> </param>
</params> </params>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ui SYSTEM "../../dtd/ui.dtd"> <!-- <!DOCTYPE ui SYSTEM "../../dtd/ui.dtd"> -->
<ui> <ui>
<plugin name="Random"> <plugin name="Random">
<params> <params>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ui SYSTEM "../../dtd/ui.dtd"> <!-- <!DOCTYPE ui SYSTEM "../../dtd/ui.dtd"> -->
<ui> <ui>
<plugin name="ConstantTimer"> <plugin name="ConstantTimer">
<params /> <params />

View File

@ -3,10 +3,11 @@
<ui> <ui>
<plugin name="UniqueNumber"> <plugin name="UniqueNumber">
<params> <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> <field size="5"></field>
</param> </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> <field size="5"></field>
</param> </param>
</params> </params>

View File

@ -20,7 +20,7 @@
<!ATTLIST param <!ATTLIST param
name CDATA #REQUIRED name CDATA #REQUIRED
label CDATA #IMPLIED label CDATA #IMPLIED
required CDATA #REQUIRED required CDATA #REQUIRED
> >
<!ELEMENT group (param|group)*> <!ELEMENT group (param|group)*>
<!ATTLIST group <!ATTLIST group

View File

@ -1,4 +1,4 @@
package org.bench4q.agent.scenario; package org.bench4q.agent.scenario.engine;
import java.util.Date; import java.util.Date;

View File

@ -1,4 +1,4 @@
package org.bench4q.agent.scenario; package org.bench4q.agent.scenario.engine;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@ -1,14 +1,17 @@
package org.bench4q.agent.scenario; package org.bench4q.agent.scenario.engine;
import java.util.Date; import java.util.Date;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.ThreadPoolExecutor.DiscardPolicy; import java.util.concurrent.ThreadPoolExecutor.DiscardPolicy;
import org.apache.log4j.Logger;
import org.bench4q.agent.datacollector.DataCollector; import org.bench4q.agent.datacollector.DataCollector;
import org.bench4q.agent.datacollector.impl.ScenarioResultCollector; import org.bench4q.agent.datacollector.impl.ScenarioResultCollector;
import org.bench4q.agent.plugin.PluginManager;
import org.bench4q.agent.scenario.Scenario;
public class ScenarioContext { public class ScenarioContext {
private static final long keepAliveTime = 10; private static final long keepAliveTime = 10;
@ -19,6 +22,7 @@ public class ScenarioContext {
private Scenario scenario; private Scenario scenario;
private boolean finished; private boolean finished;
private DataCollector dataStatistics; private DataCollector dataStatistics;
private PluginManager pluginManager;
public UUID getTestId() { public UUID getTestId() {
return testId; return testId;
@ -76,29 +80,32 @@ public class ScenarioContext {
this.dataStatistics = dataStatistics; this.dataStatistics = dataStatistics;
} }
private PluginManager getPluginManager() {
return pluginManager;
}
private void setPluginManager(PluginManager pluginManager) {
this.pluginManager = pluginManager;
}
private ScenarioContext() { private ScenarioContext() {
} }
public static ScenarioContext buildScenarioContext(UUID testId, public static ScenarioContext buildScenarioContext(UUID testId,
final Scenario scenario, int poolSize) { final Scenario scenario, int poolSize, PluginManager pluginManager) {
ScenarioContext scenarioContext = new ScenarioContext(); ScenarioContext scenarioContext = buildScenarioContextWithoutScenario(
scenarioContext.setTestId(testId); testId, poolSize, pluginManager);
final SynchronousQueue<Runnable> workQueue = new SynchronousQueue<Runnable>();
ThreadPoolExecutor executor = new ThreadPoolExecutor(poolSize,
poolSize, keepAliveTime, TimeUnit.MINUTES, workQueue,
new DiscardPolicy());
scenarioContext.setScenario(scenario); scenarioContext.setScenario(scenario);
scenarioContext.setStartDate(new Date(System.currentTimeMillis()));
scenarioContext.setExecutorService(executor);
scenarioContext.setDataStatistics(new ScenarioResultCollector(testId));
return scenarioContext; return scenarioContext;
} }
public static ScenarioContext buildScenarioContextWithoutScenario( public static ScenarioContext buildScenarioContextWithoutScenario(
UUID testId, int poolSize) { UUID testId, int poolSize, PluginManager pluginManager) {
ScenarioContext scenarioContext = new ScenarioContext(); ScenarioContext scenarioContext = new ScenarioContext();
scenarioContext.setTestId(testId); 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, ThreadPoolExecutor executor = new ThreadPoolExecutor(poolSize,
poolSize, keepAliveTime, TimeUnit.MINUTES, workQueue, poolSize, keepAliveTime, TimeUnit.MINUTES, workQueue,
new DiscardPolicy()); new DiscardPolicy());
@ -125,4 +132,18 @@ public class ScenarioContext {
this.getExecutor().setMaximumPoolSize(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

@ -1,13 +1,11 @@
package org.bench4q.agent.scenario; package org.bench4q.agent.scenario.engine;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.bench4q.agent.plugin.PluginManager; import org.bench4q.agent.plugin.PluginManager;
import org.bench4q.agent.scenario.Scenario;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -41,7 +39,8 @@ public class ScenarioEngine {
public void addRunningTestWithoutScenario(UUID runId, int poolSize) { public void addRunningTestWithoutScenario(UUID runId, int poolSize) {
try { try {
final ScenarioContext scenarioContext = ScenarioContext final ScenarioContext scenarioContext = ScenarioContext
.buildScenarioContextWithoutScenario(runId, poolSize); .buildScenarioContextWithoutScenario(runId, poolSize,
getPluginManager());
this.getRunningTests().put(runId, scenarioContext); this.getRunningTests().put(runId, scenarioContext);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -61,28 +60,15 @@ public class ScenarioEngine {
return false; return false;
} }
final ScenarioContext context = this.getRunningTests().get(runId); final ScenarioContext context = this.getRunningTests().get(runId);
return runWith(context, runId); return runWith(context);
} }
private boolean runWith(final ScenarioContext scenarioContext, private boolean runWith(final ScenarioContext scenarioContext) {
final UUID runId) {
if (scenarioContext == null) { if (scenarioContext == null) {
logger.error("The context required is null"); logger.error("The context required is null");
return false; return false;
} }
ExecutorService taskMaker = Executors.newSingleThreadExecutor(); scenarioContext.initTasks();
taskMaker.execute(new Runnable() {
public void run() {
int currentIterationId = 0;
while (!scenarioContext.isFinished()) {
scenarioContext.getExecutor().execute(
new VUser(scenarioContext, currentIterationId,
getPluginManager()));
currentIterationId++;
}
}
});
return true; return true;
} }

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

@ -1,4 +1,4 @@
package org.bench4q.agent.scenario; package org.bench4q.agent.scenario.engine;
import java.util.Date; import java.util.Date;
import java.util.HashMap; 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.PluginManager;
import org.bench4q.agent.plugin.basic.PluginReturn; import org.bench4q.agent.plugin.basic.PluginReturn;
import org.bench4q.agent.plugin.basic.http.HttpReturn; 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.behavior.Behavior;
import org.bench4q.agent.scenario.dfa.ParamPart; import org.bench4q.agent.scenario.dfa.ParamPart;
@ -58,6 +63,7 @@ public class VUser implements Runnable {
} }
private void doCleanUp() { private void doCleanUp() {
this.getScenarioContext().addTask();
this.setScenarioContext(null); this.setScenarioContext(null);
} }

View File

@ -10,8 +10,8 @@ import org.apache.commons.io.FileUtils;
import org.bench4q.agent.plugin.ParameterBarn; import org.bench4q.agent.plugin.ParameterBarn;
import org.bench4q.agent.plugin.PluginManager; import org.bench4q.agent.plugin.PluginManager;
import org.bench4q.agent.scenario.Scenario; import org.bench4q.agent.scenario.Scenario;
import org.bench4q.agent.scenario.ScenarioContext; import org.bench4q.agent.scenario.engine.ScenarioContext;
import org.bench4q.agent.scenario.VUser; import org.bench4q.agent.scenario.engine.VUser;
import org.bench4q.share.helper.TestHelper; import org.bench4q.share.helper.TestHelper;
import org.bench4q.share.models.agent.ParameterModel; import org.bench4q.share.models.agent.ParameterModel;
import org.bench4q.share.models.agent.RunScenarioModel; import org.bench4q.share.models.agent.RunScenarioModel;
@ -111,6 +111,6 @@ public abstract class TestBase {
public VUser createVUser(Scenario scenario, UUID testId) { public VUser createVUser(Scenario scenario, UUID testId) {
return new VUser(ScenarioContext.buildScenarioContext(testId, scenario, return new VUser(ScenarioContext.buildScenarioContext(testId, scenario,
10), 1, this.getPluginManager()); 10, pluginManager), 1, this.getPluginManager());
} }
} }

View File

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

View File

@ -9,7 +9,7 @@ import java.util.UUID;
import org.bench4q.agent.datacollector.DataCollector; import org.bench4q.agent.datacollector.DataCollector;
import org.bench4q.agent.datacollector.impl.ScenarioResultCollector; import org.bench4q.agent.datacollector.impl.ScenarioResultCollector;
import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResult; 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.bench4q.agent.storage.StorageHelper;
import org.junit.Test; import org.junit.Test;
import org.springframework.context.ApplicationContext; 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.DataCollector;
import org.bench4q.agent.datacollector.impl.PageResultCollector; 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.bench4q.share.models.agent.statistics.AgentPageBriefModel;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; 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.DataCollector;
import org.bench4q.agent.datacollector.impl.ScenarioResultCollector; import org.bench4q.agent.datacollector.impl.ScenarioResultCollector;
import org.bench4q.agent.scenario.BehaviorResult; import org.bench4q.agent.scenario.engine.BehaviorResult;
import org.bench4q.agent.scenario.PageResult; import org.bench4q.agent.scenario.engine.PageResult;
import org.bench4q.agent.storage.StorageHelper; import org.bench4q.agent.storage.StorageHelper;
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel; import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
import org.junit.Test; 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.plugin.basic.context.Context;
import org.bench4q.agent.scenario.Scenario; 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.agent.test.TestBase;
import org.bench4q.share.models.agent.ParameterModel; import org.bench4q.share.models.agent.ParameterModel;
import org.bench4q.share.models.agent.RunScenarioModel; 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.PluginManager;
import org.bench4q.agent.plugin.basic.csvprovider.CsvProvider; import org.bench4q.agent.plugin.basic.csvprovider.CsvProvider;
import org.bench4q.agent.scenario.Scenario; 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.agent.test.TestBase;
import org.bench4q.share.helper.TestHelper; import org.bench4q.share.helper.TestHelper;
import org.bench4q.share.models.agent.ParameterModel; 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.HttpPlugin;
import org.bench4q.agent.plugin.basic.http.HttpReturn; import org.bench4q.agent.plugin.basic.http.HttpReturn;
import org.bench4q.agent.scenario.Scenario; 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.agent.test.TestBase;
import org.bench4q.share.helper.MarshalHelper; import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.helper.TestHelper; 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.MongoDBPlugin;
import org.bench4q.agent.plugin.basic.MongoDB.MongoDBReturn; import org.bench4q.agent.plugin.basic.MongoDB.MongoDBReturn;
import org.bench4q.agent.scenario.Scenario; 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.agent.test.TestBase;
import org.bench4q.share.helper.MarshalHelper; import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.helper.TestHelper; import org.bench4q.share.helper.TestHelper;

View File

@ -5,21 +5,25 @@ import static org.junit.Assert.*;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.bench4q.agent.plugin.PluginManager;
import org.bench4q.agent.scenario.Scenario; 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.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:application-context.xml" }) @ContextConfiguration(locations = { "classpath:application-context.xml" })
public class Test_ScenarioContext { public class Test_ScenarioContext {
@Autowired
private PluginManager pluginManager;
@Test @Test
public void testBuildScenarioContext() { public void testBuildScenarioContext() {
ScenarioContext context = ScenarioContext.buildScenarioContext( ScenarioContext context = ScenarioContext.buildScenarioContext(
UUID.randomUUID(), new Scenario(), 20); UUID.randomUUID(), new Scenario(), 20, this.pluginManager);
assertEquals(10, assertEquals(10,
context.getExecutor().getKeepAliveTime(TimeUnit.MINUTES)); context.getExecutor().getKeepAliveTime(TimeUnit.MINUTES));
assertEquals(20, context.getExecutor().getMaximumPoolSize()); assertEquals(20, context.getExecutor().getMaximumPoolSize());

View File

@ -2,12 +2,16 @@ package org.bench4q.agent.test.scenario;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.UUID; 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.Scenario;
import org.bench4q.agent.scenario.ScenarioContext; import org.bench4q.agent.scenario.engine.ScenarioContext;
import org.bench4q.agent.scenario.ScenarioEngine; import org.bench4q.agent.scenario.engine.ScenarioEngine;
import org.bench4q.agent.test.TestBase; import org.bench4q.agent.test.TestBase;
import org.bench4q.share.models.agent.ParameterModel; import org.bench4q.share.models.agent.ParameterModel;
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel; 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" }) @ContextConfiguration(locations = { "classpath:application-context.xml" })
public class Test_ScenarioEngine extends TestBase { public class Test_ScenarioEngine extends TestBase {
private ScenarioEngine scenarioEngine; private ScenarioEngine scenarioEngine;
private UUID testId = UUID.randomUUID();
@Autowired
private PluginManager pluginManager;
private ScenarioEngine getScenarioEngine() { private ScenarioEngine getScenarioEngine() {
return scenarioEngine; return scenarioEngine;
@ -34,19 +41,27 @@ public class Test_ScenarioEngine extends TestBase {
@Test @Test
public void test_UpdatePopulation() { public void test_UpdatePopulation() {
UUID testId = UUID.randomUUID(); ScenarioContext scenarioContext = ScenarioContext.buildScenarioContext(
ScenarioContext scenarioContext = ScenarioContext testId,
.buildScenarioContext( Scenario.scenarioBuilderWithCompile(buildRunScenarioModelWith(
testId, new ArrayList<UsePluginModel>(), BehaviorModel
Scenario.scenarioBuilderWithCompile(buildRunScenarioModelWith( .UserBehaviorBuilder(1, "ok", "http",
new ArrayList<UsePluginModel>(), new ArrayList<ParameterModel>()))),
BehaviorModel 100, this.pluginManager);
.UserBehaviorBuilder(1, "ok", "http",
new ArrayList<ParameterModel>()))),
100);
this.getScenarioEngine().getRunningTests().put(testId, scenarioContext); this.getScenarioEngine().getRunningTests().put(testId, scenarioContext);
this.getScenarioEngine().updatePopulation(testId, 20); this.getScenarioEngine().updatePopulation(testId, 20);
assertEquals(20, scenarioContext.getExecutor().getMaximumPoolSize()); assertEquals(20, scenarioContext.getExecutor().getMaximumPoolSize());
System.out.println(scenarioContext.getExecutor().getActiveCount()); 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);
}
} }

View File

@ -9,8 +9,8 @@ import static org.junit.Assert.*;
import org.bench4q.agent.plugin.basic.csvprovider.CsvProvider; import org.bench4q.agent.plugin.basic.csvprovider.CsvProvider;
import org.bench4q.agent.scenario.Scenario; import org.bench4q.agent.scenario.Scenario;
import org.bench4q.agent.scenario.VUser;
import org.bench4q.agent.scenario.behavior.Behavior; import org.bench4q.agent.scenario.behavior.Behavior;
import org.bench4q.agent.scenario.engine.VUser;
import org.bench4q.agent.test.TestBase; import org.bench4q.agent.test.TestBase;
import org.bench4q.share.helper.TestHelper; import org.bench4q.share.helper.TestHelper;
import org.bench4q.share.models.agent.ParameterModel; 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 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/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"> http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="org.bench4q" />
<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" />
<mvc:annotation-driven /> <mvc:annotation-driven />
</beans> </beans>