parent
e50013404d
commit
ee7c390bc6
|
@ -0,0 +1,39 @@
|
|||
package org.bench4q.agent.plugin.basic.context;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bench4q.agent.plugin.Constructor;
|
||||
import org.bench4q.agent.plugin.Parameter;
|
||||
import org.bench4q.agent.plugin.ParameterBarn;
|
||||
import org.bench4q.agent.plugin.Plugin;
|
||||
import org.bench4q.agent.plugin.behavior.Behavior;
|
||||
import org.bench4q.agent.plugin.behavior.BehaviorType;
|
||||
import org.bench4q.agent.utils.Type.SupportTypes;
|
||||
|
||||
@Plugin("Context")
|
||||
public class Context extends ParameterBarn {
|
||||
private List<String> values;
|
||||
|
||||
@Constructor
|
||||
public Context(
|
||||
@Parameter(type = SupportTypes.Field, value = "testId") String testId) {
|
||||
super(testId);
|
||||
this.values = new ArrayList<String>();
|
||||
}
|
||||
|
||||
@Behavior(value = "set", type = BehaviorType.CONTROL_BEHAVIOR)
|
||||
public void set(
|
||||
@Parameter(value = "toSave", type = SupportTypes.Field) String toSave) {
|
||||
this.values.add(toSave);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(String var) {
|
||||
Random random = new Random();
|
||||
int index = random.nextInt(this.values.size());
|
||||
return this.values.get(index);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE ui SYSTEM "../../dtd/ui.dtd">
|
||||
<ui>
|
||||
<plugin name="CsvProvider">
|
||||
<params />
|
||||
</plugin>
|
||||
<control name="set">
|
||||
<params />
|
||||
</control>
|
||||
</ui>
|
|
@ -71,7 +71,6 @@ public class VUser implements Runnable {
|
|||
doRunBatch(plugins, batch, context.getDataStatistics());
|
||||
}
|
||||
long endTime = System.currentTimeMillis();
|
||||
|
||||
context.getDataStatistics().add(
|
||||
PageResult.buildPageResult(i, startTime, endTime));
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package org.bench4q.agent.scenario.behavior;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.bench4q.agent.datacollector.DataCollector;
|
||||
import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResult;
|
||||
|
||||
public class TransactionBehavior extends Behavior {
|
||||
|
||||
@Override
|
||||
public boolean shouldBeCount() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, BehaviorStatusCodeResult> getBehaviorBriefResult(
|
||||
DataCollector dataStatistics) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package org.bench4q.agent.test.plugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
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.test.TestBase;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.agent.ParameterModel;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
import org.bench4q.share.models.agent.scriptrecord.BatchModel;
|
||||
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
|
||||
import org.bench4q.share.models.agent.scriptrecord.PageModel;
|
||||
import org.bench4q.share.models.agent.scriptrecord.UsePluginModel;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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_ContextPlugin extends TestBase {
|
||||
@Test
|
||||
public void test_SetAndGet() {
|
||||
Context context = new Context(UUID.randomUUID().toString());
|
||||
context.set("abcd");
|
||||
System.out.println(context.getValue(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithScenario() {
|
||||
RunScenarioModel scenarioModel = new RunScenarioModel();
|
||||
String pluginId = "context1";
|
||||
UsePluginModel context = UsePluginModel.createUsePlugin(pluginId,
|
||||
"Context", new ArrayList<ParameterModel>());
|
||||
UsePluginModel log = UsePluginModel.createUsePlugin("log1", "Log",
|
||||
new ArrayList<ParameterModel>());
|
||||
scenarioModel.getUsePlugins().add(context);
|
||||
scenarioModel.getUsePlugins().add(log);
|
||||
BehaviorModel set = BehaviorModel.ControlBehaviorBuilder(0, "set",
|
||||
pluginId, Arrays.asList(ParameterModel.createParameter(
|
||||
"toSave", "chentienan")));
|
||||
BehaviorModel logIt = BehaviorModel.UserBehaviorBuilder(1, "Log",
|
||||
"log1", Arrays.asList(ParameterModel.createParameter("message",
|
||||
"${context1:test}")));
|
||||
PageModel pageModel = new PageModel();
|
||||
scenarioModel.getPages().add(pageModel);
|
||||
BatchModel batchModel = new BatchModel();
|
||||
pageModel.getBatches().add(batchModel);
|
||||
batchModel.getBehaviors().add(set);
|
||||
batchModel.getBehaviors().add(logIt);
|
||||
// System.out.println(MarshalHelper.tryMarshal(scenarioModel));
|
||||
VUser vuser = createVUser(
|
||||
Scenario.scenarioBuilderWithCompile(scenarioModel),
|
||||
UUID.randomUUID());
|
||||
vuser.run();
|
||||
}
|
||||
}
|
|
@ -14,7 +14,6 @@ import org.bench4q.share.models.agent.scriptrecord.UsePluginModel;
|
|||
public class RunScenarioModel {
|
||||
private int poolSize;
|
||||
private List<UsePluginModel> usePlugins;
|
||||
private List<DefinedParameterModel> definedParameters;
|
||||
private List<PageModel> pages;
|
||||
|
||||
@XmlElement
|
||||
|
@ -36,17 +35,6 @@ public class RunScenarioModel {
|
|||
this.usePlugins = usePlugins;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "definedParams")
|
||||
@XmlElement(name = "definedParam")
|
||||
public List<DefinedParameterModel> getDefinedParameters() {
|
||||
return definedParameters;
|
||||
}
|
||||
|
||||
public void setDefinedParameters(
|
||||
List<DefinedParameterModel> definedParameters) {
|
||||
this.definedParameters = definedParameters;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "pages")
|
||||
@XmlElement(name = "page")
|
||||
public List<PageModel> getPages() {
|
||||
|
@ -60,6 +48,5 @@ public class RunScenarioModel {
|
|||
public RunScenarioModel() {
|
||||
this.setUsePlugins(new LinkedList<UsePluginModel>());
|
||||
this.setPages(new LinkedList<PageModel>());
|
||||
this.setDefinedParameters(new LinkedList<DefinedParameterModel>());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,4 +90,12 @@ public class BehaviorModel {
|
|||
behaviorBaseModel.setType("USERBEHAVIOR");
|
||||
return behaviorBaseModel;
|
||||
}
|
||||
|
||||
public static BehaviorModel ControlBehaviorBuilder(int id, String name,
|
||||
String use, List<ParameterModel> parameters) {
|
||||
BehaviorModel result = buildBehaviorModelWithoutType(id, name, use,
|
||||
parameters);
|
||||
result.setType("CONTROLBEHAVIOR");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package org.bench4q.share.models.agent.scriptrecord;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement
|
||||
public class RunScenarioModelNew {
|
||||
private int poolSize;
|
||||
private List<UsePluginModel> usePlugins;
|
||||
private List<BehaviorModel> behaviors;
|
||||
|
||||
@XmlElement
|
||||
public int getPoolSize() {
|
||||
return poolSize;
|
||||
}
|
||||
|
||||
public void setPoolSize(int poolSize) {
|
||||
this.poolSize = poolSize;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "plugins")
|
||||
@XmlElement(name = "plugin")
|
||||
public List<UsePluginModel> getUsePlugins() {
|
||||
return usePlugins;
|
||||
}
|
||||
|
||||
public void setUsePlugins(List<UsePluginModel> usePlugins) {
|
||||
this.usePlugins = usePlugins;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "behaviors")
|
||||
@XmlElement(name = "behavior")
|
||||
public List<BehaviorModel> getBehaviors() {
|
||||
return behaviors;
|
||||
}
|
||||
|
||||
public void setBehaviors(List<BehaviorModel> behaviors) {
|
||||
this.behaviors = behaviors;
|
||||
}
|
||||
|
||||
}
|
|
@ -42,4 +42,15 @@ public class UsePluginModel {
|
|||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public UsePluginModel() {
|
||||
}
|
||||
|
||||
public static UsePluginModel createUsePlugin(String id, String name,
|
||||
List<ParameterModel> initParameters) {
|
||||
UsePluginModel result = new UsePluginModel();
|
||||
result.setId(id);
|
||||
result.setName(name);
|
||||
result.setParameters(initParameters);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
package org.bench4q.share.models.agent.scriptrecord.refactor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.bench4q.share.models.agent.ParameterModel;
|
||||
|
||||
@XmlRootElement(name = "behaviorModel")
|
||||
public class BehaviorModel {
|
||||
private int id;
|
||||
private String use;
|
||||
private String name;
|
||||
private String type;
|
||||
private List<ParameterModel> parameters;
|
||||
|
||||
@XmlElement
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getUse() {
|
||||
return use;
|
||||
}
|
||||
|
||||
public void setUse(String use) {
|
||||
this.use = use;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "parameters")
|
||||
@XmlElement(name = "parameter")
|
||||
public List<ParameterModel> getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public void setParameters(List<ParameterModel> parameters) {
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public BehaviorModel() {
|
||||
}
|
||||
|
||||
public static BehaviorModel TimerBehaviorBuilder(int id, String name,
|
||||
String use, List<ParameterModel> parameters) {
|
||||
BehaviorModel behaviorBaseModel = buildBehaviorModelWithoutType(id,
|
||||
name, use, parameters);
|
||||
behaviorBaseModel.setType("TIMERBEHAVIOR");
|
||||
return behaviorBaseModel;
|
||||
}
|
||||
|
||||
private static BehaviorModel buildBehaviorModelWithoutType(int id,
|
||||
String name, String use, List<ParameterModel> parameters) {
|
||||
BehaviorModel behaviorBaseModel = new BehaviorModel();
|
||||
behaviorBaseModel.setId(id);
|
||||
behaviorBaseModel.setName(name);
|
||||
behaviorBaseModel.setUse(use);
|
||||
behaviorBaseModel.setParameters(parameters);
|
||||
return behaviorBaseModel;
|
||||
}
|
||||
|
||||
public static BehaviorModel UserBehaviorBuilder(int id, String name,
|
||||
String use, List<ParameterModel> parameters) {
|
||||
BehaviorModel behaviorBaseModel = buildBehaviorModelWithoutType(id,
|
||||
name, use, parameters);
|
||||
behaviorBaseModel.setType("USERBEHAVIOR");
|
||||
return behaviorBaseModel;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue