diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/context/Context.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/context/Context.java new file mode 100644 index 00000000..1874bc79 --- /dev/null +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/context/Context.java @@ -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 values; + + @Constructor + public Context( + @Parameter(type = SupportTypes.Field, value = "testId") String testId) { + super(testId); + this.values = new ArrayList(); + } + + @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); + } + +} diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/context/ui.xml b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/context/ui.xml new file mode 100644 index 00000000..81192890 --- /dev/null +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/context/ui.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/VUser.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/VUser.java index 0e1961a3..daca84df 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/VUser.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/VUser.java @@ -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)); } diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/behavior/TransactionBehavior.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/behavior/TransactionBehavior.java new file mode 100644 index 00000000..ba109b3b --- /dev/null +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/behavior/TransactionBehavior.java @@ -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 getBehaviorBriefResult( + DataCollector dataStatistics) { + return null; + } + +} diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_ContextPlugin.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_ContextPlugin.java new file mode 100644 index 00000000..058e8051 --- /dev/null +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_ContextPlugin.java @@ -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()); + UsePluginModel log = UsePluginModel.createUsePlugin("log1", "Log", + new ArrayList()); + 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(); + } +} diff --git a/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/RunScenarioModel.java b/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/RunScenarioModel.java index 65204887..227fca67 100644 --- a/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/RunScenarioModel.java +++ b/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/RunScenarioModel.java @@ -14,7 +14,6 @@ import org.bench4q.share.models.agent.scriptrecord.UsePluginModel; public class RunScenarioModel { private int poolSize; private List usePlugins; - private List definedParameters; private List pages; @XmlElement @@ -36,17 +35,6 @@ public class RunScenarioModel { this.usePlugins = usePlugins; } - @XmlElementWrapper(name = "definedParams") - @XmlElement(name = "definedParam") - public List getDefinedParameters() { - return definedParameters; - } - - public void setDefinedParameters( - List definedParameters) { - this.definedParameters = definedParameters; - } - @XmlElementWrapper(name = "pages") @XmlElement(name = "page") public List getPages() { @@ -60,6 +48,5 @@ public class RunScenarioModel { public RunScenarioModel() { this.setUsePlugins(new LinkedList()); this.setPages(new LinkedList()); - this.setDefinedParameters(new LinkedList()); } } diff --git a/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/BehaviorModel.java b/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/BehaviorModel.java index 490f7a99..0b9eaa86 100644 --- a/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/BehaviorModel.java +++ b/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/BehaviorModel.java @@ -90,4 +90,12 @@ public class BehaviorModel { behaviorBaseModel.setType("USERBEHAVIOR"); return behaviorBaseModel; } + + public static BehaviorModel ControlBehaviorBuilder(int id, String name, + String use, List parameters) { + BehaviorModel result = buildBehaviorModelWithoutType(id, name, use, + parameters); + result.setType("CONTROLBEHAVIOR"); + return result; + } } diff --git a/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/RunScenarioModelNew.java b/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/RunScenarioModelNew.java new file mode 100644 index 00000000..81127dd3 --- /dev/null +++ b/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/RunScenarioModelNew.java @@ -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 usePlugins; + private List behaviors; + + @XmlElement + public int getPoolSize() { + return poolSize; + } + + public void setPoolSize(int poolSize) { + this.poolSize = poolSize; + } + + @XmlElementWrapper(name = "plugins") + @XmlElement(name = "plugin") + public List getUsePlugins() { + return usePlugins; + } + + public void setUsePlugins(List usePlugins) { + this.usePlugins = usePlugins; + } + + @XmlElementWrapper(name = "behaviors") + @XmlElement(name = "behavior") + public List getBehaviors() { + return behaviors; + } + + public void setBehaviors(List behaviors) { + this.behaviors = behaviors; + } + +} diff --git a/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/UsePluginModel.java b/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/UsePluginModel.java index daa2913a..8a70c081 100644 --- a/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/UsePluginModel.java +++ b/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/UsePluginModel.java @@ -42,4 +42,15 @@ public class UsePluginModel { this.parameters = parameters; } + public UsePluginModel() { + } + + public static UsePluginModel createUsePlugin(String id, String name, + List initParameters) { + UsePluginModel result = new UsePluginModel(); + result.setId(id); + result.setName(name); + result.setParameters(initParameters); + return result; + } } diff --git a/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/refactor/BehaviorModel.java b/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/refactor/BehaviorModel.java new file mode 100644 index 00000000..26c4cb52 --- /dev/null +++ b/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/refactor/BehaviorModel.java @@ -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 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 getParameters() { + return parameters; + } + + public void setParameters(List parameters) { + this.parameters = parameters; + } + + public BehaviorModel() { + } + + public static BehaviorModel TimerBehaviorBuilder(int id, String name, + String use, List parameters) { + BehaviorModel behaviorBaseModel = buildBehaviorModelWithoutType(id, + name, use, parameters); + behaviorBaseModel.setType("TIMERBEHAVIOR"); + return behaviorBaseModel; + } + + private static BehaviorModel buildBehaviorModelWithoutType(int id, + String name, String use, List 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 parameters) { + BehaviorModel behaviorBaseModel = buildBehaviorModelWithoutType(id, + name, use, parameters); + behaviorBaseModel.setType("USERBEHAVIOR"); + return behaviorBaseModel; + } +}