diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/api/TestController.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/api/TestController.java index aaf90162..02841011 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/api/TestController.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/api/TestController.java @@ -11,6 +11,7 @@ import org.bench4q.agent.scenario.engine.ScenarioContext; import org.bench4q.agent.scenario.engine.ScenarioEngine; import org.bench4q.agent.scenario.engine.Schedule; import org.bench4q.agent.scenario.node.Behavior; +import org.bench4q.agent.scenario.node.PluginImplementBehavior; import org.bench4q.agent.scenario.node.UserBehavior; import org.bench4q.share.helper.MarshalHelper; import org.bench4q.share.models.agent.CleanTestResultModel; @@ -90,8 +91,8 @@ public class TestController { RunScenarioModel.class, scenarioModel); System.out.println(scheduleContent); this.logger.info(scheduleContent); - ScheduleModel scheduleModel = MarshalHelper - .unmarshal(ScheduleModel.class, scheduleContent); + ScheduleModel scheduleModel = MarshalHelper.unmarshal( + ScheduleModel.class, scheduleContent); this.getScenarioEngine().submitScenario(runId, Scenario.scenarioCompiler(runScenarioModel), Schedule.build(scheduleModel), realStartTime); @@ -159,16 +160,19 @@ public class TestController { if (!(behavior instanceof UserBehavior)) { continue; } + PluginImplementBehavior pluginImplementBehavior = (PluginImplementBehavior) behavior; try { - BehaviorBriefModel briefModel = behavior + BehaviorBriefModel briefModel = pluginImplementBehavior .getBehaviorBriefResult(scenarioContext .getDataCollector()); - logger.info(behavior.getId()); - briefModel - .setBehaviorUrl(behavior.getSpecificParamValue("url")); + logger.info(pluginImplementBehavior.getId()); + briefModel.setBehaviorUrl(pluginImplementBehavior + .getSpecificParamValue("url")); behaviorBriefModels.add(briefModel); } catch (Exception e) { - logger.info("where behaviorId is " + behavior.getId(), e); + logger.info( + "where behaviorId is " + + pluginImplementBehavior.getId(), e); } } diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/behavior/Behavior.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/Behavior.java similarity index 87% rename from Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/behavior/Behavior.java rename to Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/Behavior.java index d1a32f4d..ad060e73 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/behavior/Behavior.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/Behavior.java @@ -1,4 +1,4 @@ -package org.bench4q.agent.plugin.behavior; +package org.bench4q.agent.plugin; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/behavior/BehaviorType.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/BehaviorType.java similarity index 68% rename from Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/behavior/BehaviorType.java rename to Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/BehaviorType.java index 4fd79aef..4c2271a9 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/behavior/BehaviorType.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/BehaviorType.java @@ -1,4 +1,4 @@ -package org.bench4q.agent.plugin.behavior; +package org.bench4q.agent.plugin; public enum BehaviorType { USER_BEHAVIOR, TIMER_BEHAVIOR, CONTROL_BEHAVIOR, TEST_BEHAVIOR diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/PluginManager.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/PluginManager.java index fb92526f..121d7241 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/PluginManager.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/PluginManager.java @@ -10,7 +10,7 @@ import java.util.Map; import org.apache.log4j.Logger; import org.bench4q.agent.helper.ClassHelper; import org.bench4q.agent.helper.ClassLoadRestriction; -import org.bench4q.agent.plugin.behavior.Behavior; +import org.bench4q.agent.plugin.Behavior; import org.bench4q.share.helper.ExceptionLog; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/HBasePlugin/HBasePlugin.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/HBasePlugin/HBasePlugin.java index a50f3539..304b5f86 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/HBasePlugin/HBasePlugin.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/HBasePlugin/HBasePlugin.java @@ -21,8 +21,8 @@ import org.apache.log4j.Logger; import org.bench4q.agent.plugin.Constructor; import org.bench4q.agent.plugin.Parameter; import org.bench4q.agent.plugin.Plugin; -import org.bench4q.agent.plugin.behavior.Behavior; -import org.bench4q.agent.plugin.behavior.BehaviorType; +import org.bench4q.agent.plugin.Behavior; +import org.bench4q.agent.plugin.BehaviorType; import org.bench4q.agent.utils.Type.SupportTypes; import org.bench4q.share.exception.Bench4QRunTimeException; diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/MongoDB/MongoDBPlugin.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/MongoDB/MongoDBPlugin.java index f051bd86..374f6c53 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/MongoDB/MongoDBPlugin.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/MongoDB/MongoDBPlugin.java @@ -8,8 +8,8 @@ import org.apache.log4j.Logger; import org.bench4q.agent.plugin.Constructor; import org.bench4q.agent.plugin.Parameter; import org.bench4q.agent.plugin.Plugin; -import org.bench4q.agent.plugin.behavior.Behavior; -import org.bench4q.agent.plugin.behavior.BehaviorType; +import org.bench4q.agent.plugin.Behavior; +import org.bench4q.agent.plugin.BehaviorType; import org.bench4q.agent.utils.Type.SupportTypes; import org.bench4q.agent.utils.types.Table; import org.bench4q.agent.utils.types.Table.Row; @@ -48,18 +48,18 @@ public class MongoDBPlugin { try { List hostsList = new ArrayList(); String[] hosts = hostName.split(","); - for(String host : hosts) - { - hostsList.add(new ServerAddress(host)); + for (String host : hosts) { + hostsList.add(new ServerAddress(host)); } - - mongo = new Mongo(hostsList , - new MongoOptions(new MongoClientOptions.Builder() - .maxWaitTime(1000 * 40).build())); - /*mongo = new Mongo(new ServerAddress(hostName, port), - new MongoOptions(new MongoClientOptions.Builder() - .maxWaitTime(1000 * 40).build())); - */ + + mongo = new Mongo(hostsList, new MongoOptions( + new MongoClientOptions.Builder().maxWaitTime(1000 * 40) + .build())); + /* + * mongo = new Mongo(new ServerAddress(hostName, port), new + * MongoOptions(new MongoClientOptions.Builder() .maxWaitTime(1000 * + * 40).build())); + */ DB db = mongo.getDB(dbName); DBCollection table = db.getCollection(this.tableUnderTest); DBObject valueToInsert = new BasicDBObject(); @@ -85,14 +85,13 @@ public class MongoDBPlugin { try { List hostsList = new ArrayList(); String[] hosts = hostName.split(","); - for(String host : hosts) - { - hostsList.add(new ServerAddress(host)); + for (String host : hosts) { + hostsList.add(new ServerAddress(host)); } - - mongo = new Mongo(hostsList , - new MongoOptions(new MongoClientOptions.Builder() - .maxWaitTime(1000 * 40).build())); + + mongo = new Mongo(hostsList, new MongoOptions( + new MongoClientOptions.Builder().maxWaitTime(1000 * 40) + .build())); DB db = mongo.getDB(dbName); DBCollection table = db.getCollection(this.tableUnderTest); Table propertiesTable = Table.buildTable(properties, diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/UUID/UUID.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/UUID/UUID.java index ce34fa2b..03d33920 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/UUID/UUID.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/UUID/UUID.java @@ -4,8 +4,8 @@ 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.plugin.Behavior; +import org.bench4q.agent.plugin.BehaviorType; import org.bench4q.agent.utils.Type.SupportTypes; @Plugin("UUID") diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/comandline/CommandLinePlugin.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/comandline/CommandLinePlugin.java index 188e3b47..a393014b 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/comandline/CommandLinePlugin.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/comandline/CommandLinePlugin.java @@ -6,8 +6,8 @@ import java.io.InputStreamReader; import org.bench4q.agent.plugin.Constructor; import org.bench4q.agent.plugin.Parameter; import org.bench4q.agent.plugin.Plugin; -import org.bench4q.agent.plugin.behavior.Behavior; -import org.bench4q.agent.plugin.behavior.BehaviorType; +import org.bench4q.agent.plugin.Behavior; +import org.bench4q.agent.plugin.BehaviorType; import org.bench4q.agent.utils.Type.SupportTypes; @Plugin("CommandLine") 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 index 36a90bd7..a19e0de7 100644 --- 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 @@ -8,8 +8,8 @@ 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.plugin.Behavior; +import org.bench4q.agent.plugin.BehaviorType; import org.bench4q.agent.utils.Type.SupportTypes; @Plugin("Context") diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/csvprovider/CsvProvider.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/csvprovider/CsvProvider.java index c27e03ab..f607327b 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/csvprovider/CsvProvider.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/csvprovider/CsvProvider.java @@ -15,8 +15,8 @@ import org.bench4q.agent.plugin.ParameterBarn; import org.bench4q.agent.plugin.Constructor; import org.bench4q.agent.plugin.Parameter; import org.bench4q.agent.plugin.Plugin; -import org.bench4q.agent.plugin.behavior.Behavior; -import org.bench4q.agent.plugin.behavior.BehaviorType; +import org.bench4q.agent.plugin.Behavior; +import org.bench4q.agent.plugin.BehaviorType; import org.bench4q.agent.utils.ParameterParser; import org.bench4q.agent.utils.Type.SupportTypes; diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpPlugin.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpPlugin.java index 33f27ab9..12d8f317 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpPlugin.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpPlugin.java @@ -41,8 +41,8 @@ import org.bench4q.agent.plugin.Constructor; import org.bench4q.agent.plugin.Parameter; import org.bench4q.agent.plugin.Plugin; import org.bench4q.agent.plugin.basic.http.BatchRequest.BatchItem; -import org.bench4q.agent.plugin.behavior.Behavior; -import org.bench4q.agent.plugin.behavior.BehaviorType; +import org.bench4q.agent.plugin.Behavior; +import org.bench4q.agent.plugin.BehaviorType; import org.bench4q.agent.utils.ParameterParser; import org.bench4q.agent.utils.Type.SupportTypes; import org.bench4q.agent.utils.types.Table; diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/iterator/IteratorNumber.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/iterator/IteratorNumber.java index b2c386de..774312cc 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/iterator/IteratorNumber.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/iterator/IteratorNumber.java @@ -4,8 +4,8 @@ import org.bench4q.agent.plugin.ParameterBarn; import org.bench4q.agent.plugin.Constructor; import org.bench4q.agent.plugin.Parameter; import org.bench4q.agent.plugin.Plugin; -import org.bench4q.agent.plugin.behavior.Behavior; -import org.bench4q.agent.plugin.behavior.BehaviorType; +import org.bench4q.agent.plugin.Behavior; +import org.bench4q.agent.plugin.BehaviorType; import org.bench4q.agent.utils.Type.SupportTypes; @Plugin(value = "IteratorNumber") diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/log/LogPlugin.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/log/LogPlugin.java index c21713a2..ce8ff92e 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/log/LogPlugin.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/log/LogPlugin.java @@ -3,8 +3,8 @@ package org.bench4q.agent.plugin.basic.log; import org.bench4q.agent.plugin.Constructor; import org.bench4q.agent.plugin.Parameter; import org.bench4q.agent.plugin.Plugin; -import org.bench4q.agent.plugin.behavior.Behavior; -import org.bench4q.agent.plugin.behavior.BehaviorType; +import org.bench4q.agent.plugin.Behavior; +import org.bench4q.agent.plugin.BehaviorType; import org.bench4q.agent.utils.Type.SupportTypes; @Plugin("Log") diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/random/Random.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/random/Random.java index c7b4856d..7bb4c3a4 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/random/Random.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/random/Random.java @@ -7,8 +7,8 @@ import org.bench4q.agent.plugin.ParameterBarn; import org.bench4q.agent.plugin.Constructor; import org.bench4q.agent.plugin.Parameter; import org.bench4q.agent.plugin.Plugin; -import org.bench4q.agent.plugin.behavior.Behavior; -import org.bench4q.agent.plugin.behavior.BehaviorType; +import org.bench4q.agent.plugin.Behavior; +import org.bench4q.agent.plugin.BehaviorType; import org.bench4q.agent.utils.ParameterParser; import org.bench4q.agent.utils.Type.SupportTypes; diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/timer/ConstantTimerPlugin.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/timer/ConstantTimerPlugin.java index 4e01dd1a..0940a386 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/timer/ConstantTimerPlugin.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/timer/ConstantTimerPlugin.java @@ -4,8 +4,8 @@ import org.apache.log4j.Logger; import org.bench4q.agent.plugin.Constructor; import org.bench4q.agent.plugin.Parameter; import org.bench4q.agent.plugin.Plugin; -import org.bench4q.agent.plugin.behavior.Behavior; -import org.bench4q.agent.plugin.behavior.BehaviorType; +import org.bench4q.agent.plugin.Behavior; +import org.bench4q.agent.plugin.BehaviorType; import org.bench4q.agent.utils.Type.SupportTypes; @Plugin("ConstantTimer") diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/unique/UniqueNumber.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/unique/UniqueNumber.java index bb70bc6a..4bc29f8b 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/unique/UniqueNumber.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/unique/UniqueNumber.java @@ -4,8 +4,8 @@ import org.bench4q.agent.plugin.ParameterBarn; import org.bench4q.agent.plugin.Constructor; import org.bench4q.agent.plugin.Parameter; import org.bench4q.agent.plugin.Plugin; -import org.bench4q.agent.plugin.behavior.Behavior; -import org.bench4q.agent.plugin.behavior.BehaviorType; +import org.bench4q.agent.plugin.Behavior; +import org.bench4q.agent.plugin.BehaviorType; import org.bench4q.agent.utils.Type.SupportTypes; @Plugin(value = "UniqueNumber") diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/Scenario.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/Scenario.java index 250bc569..835df217 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/Scenario.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/Scenario.java @@ -63,11 +63,12 @@ public class Scenario { return Collections.unmodifiableList(behaviors); } - public void compile() { + public List compile() { + ArrayList result = new ArrayList(); for (Behavior behavior : this.getAllBehaviors()) { - behavior.compile(new ArrayList(), - new Stack()); + behavior.compile(result, new Stack()); } + return result; } public static Scenario scenarioBuilderWithCompile(String scenarioContent) { diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/engine/VUser.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/engine/VUser.java index 2761e042..1cb9b00c 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/engine/VUser.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/engine/VUser.java @@ -19,6 +19,7 @@ import org.bench4q.agent.scenario.Scenario; import org.bench4q.agent.scenario.UsePlugin; import org.bench4q.agent.scenario.dfa.ParamPart; import org.bench4q.agent.scenario.node.Behavior; +import org.bench4q.agent.scenario.node.PluginImplementBehavior; public class VUser implements Runnable { private ScenarioContext scenarioContext; @@ -85,13 +86,14 @@ public class VUser implements Runnable { private void doRunBatch(Map plugins, Batch batch, DataCollector dataCollector) { for (Behavior behavior : batch.getBehaviors()) { - Object plugin = plugins.get(behavior.getUse()); + PluginImplementBehavior pluginBehavior = (PluginImplementBehavior) behavior; + Object plugin = plugins.get(pluginBehavior.getUse()); Date startDate = new Date(System.currentTimeMillis()); PluginReturn pluginReturn = (PluginReturn) this.getPluginManager() - .doBehavior(plugin, behavior.getName(), - reassamblyParameters(behavior, plugins)); + .doBehavior(plugin, pluginBehavior.getName(), + reassamblyParameters(pluginBehavior, plugins)); Date endDate = new Date(System.currentTimeMillis()); - if (!behavior.shouldBeCount()) { + if (!pluginBehavior.shouldBeCount()) { continue; } dataCollector.add(buildBehaviorResult(behavior, plugin, startDate, @@ -99,8 +101,8 @@ public class VUser implements Runnable { } } - private Map reassamblyParameters(Behavior behavior, - Map plugins) { + private Map reassamblyParameters( + PluginImplementBehavior behavior, Map plugins) { Map behaviorParameters = new HashMap(); for (Parameter parameter : behavior.getParameters()) { behaviorParameters.put(parameter.getKey(), @@ -157,21 +159,24 @@ public class VUser implements Runnable { Object plugin, Date startDate, PluginReturn pluginReturn, Date endDate) { BehaviorResult result = new BehaviorResult(); - result.setBehaviorId(behavior.getId()); + PluginImplementBehavior pluginImplementBehavior = (PluginImplementBehavior) behavior; + result.setBehaviorId(pluginImplementBehavior.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.setBehaviorName(pluginImplementBehavior.getName()); + result.setPluginId(pluginImplementBehavior.getUse()); result.setPluginName(plugin.getClass().getAnnotation(Plugin.class) .value()); - result.setShouldBeCountResponseTime(behavior.shouldBeCount()); + result.setShouldBeCountResponseTime(pluginImplementBehavior + .shouldBeCount()); if (pluginReturn instanceof HttpReturn) { HttpReturn httpReturn = (HttpReturn) pluginReturn; // TODO: this param in result is not Appropriate - result.setBehaviorUrl(behavior.getSpecificParamValue("url")); + result.setBehaviorUrl(pluginImplementBehavior + .getSpecificParamValue("url")); result.setContentLength(httpReturn.getContentLength()); result.setContentType(httpReturn.getContentType()); result.setStatusCode(httpReturn.getStatusCode()); diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/Behavior.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/Behavior.java index 2b445146..87ee3a84 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/Behavior.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/Behavior.java @@ -3,15 +3,11 @@ package org.bench4q.agent.scenario.node; import java.util.ArrayList; import java.util.Stack; -import org.bench4q.agent.datacollector.DataCollector; -import org.bench4q.agent.scenario.Parameter; import org.bench4q.agent.scenario.instruction.Instruction; import org.bench4q.agent.scenario.instruction.TestInstruction; -import org.bench4q.share.models.agent.ParameterModel; import org.bench4q.share.models.agent.scriptrecord.BehaviorModel; import org.bench4q.share.models.agent.scriptrecord.ConditionBehaviorModel; import org.bench4q.share.models.agent.scriptrecord.IfBehaviorModel; -import org.bench4q.share.models.agent.statistics.BehaviorBriefModel; /** * @@ -24,60 +20,6 @@ public abstract class Behavior { public static final String TIMER_BEHAVIOR = "TIMERBEHAVIOR"; public static final String TEST_BEHAVIOR = "TESTBEHAVIOR"; - private int id; - private String use; - private String name; - private Parameter[] parameters; - - protected Behavior() { - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getUse() { - return use; - } - - public void setUse(String use) { - this.use = use; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Parameter[] getParameters() { - return parameters; - } - - public void setParameters(Parameter[] parameters) { - this.parameters = parameters; - } - - public abstract boolean shouldBeCount(); - - public abstract BehaviorBriefModel getBehaviorBriefResult( - DataCollector dataStatistics); - - public String getSpecificParamValue(String paramName) { - for (Parameter parameter : this.getParameters()) { - if (parameter.getKey().equalsIgnoreCase(paramName)) { - return parameter.getValue(); - } - } - return ""; - } - /** * No matter which one to inherit from this class, it should call * baseCompile in its own compile function. @@ -88,6 +30,16 @@ public abstract class Behavior { public abstract void compile(ArrayList code, Stack conditions); + private int id; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + public static Behavior buildWith(BehaviorModel behaviorModel) { Behavior behavior = null; if (behaviorModel.getType().equalsIgnoreCase(TIMER_BEHAVIOR)) { @@ -107,7 +59,6 @@ public abstract class Behavior { throw new RuntimeException("Error type: TestInstruction" + behaviorModel.getClass().getName()); } - } else { throw new IllegalArgumentException( "The input BehaviorModel's type is not proper"); @@ -115,17 +66,4 @@ public abstract class Behavior { return behavior; } - protected void buildAndGenerateParameterPart(BehaviorModel behaviorModel) { - this.setName(behaviorModel.getName()); - this.setUse(behaviorModel.getUse()); - this.setId(behaviorModel.getId()); - this.setParameters(new Parameter[behaviorModel.getParameters().size()]); - - for (int k = 0; k < behaviorModel.getParameters().size(); k++) { - ParameterModel parameterModel = behaviorModel.getParameters() - .get(k); - this.getParameters()[k] = Parameter.generateParamParts( - parameterModel.getKey(), parameterModel.getValue()); - } - } } diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/ConditionedBehavior.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/ConditionedBehavior.java index 47ee4d7c..97ec7989 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/ConditionedBehavior.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/ConditionedBehavior.java @@ -1,20 +1,6 @@ package org.bench4q.agent.scenario.node; -import org.bench4q.agent.datacollector.DataCollector; -import org.bench4q.share.models.agent.statistics.BehaviorBriefModel; - public abstract class ConditionedBehavior extends Behavior { protected ConditionBehavior condition; - @Override - public boolean shouldBeCount() { - return false; - } - - @Override - public BehaviorBriefModel getBehaviorBriefResult( - DataCollector dataStatistics) { - return null; - } - } diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/PluginImplementBehavior.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/PluginImplementBehavior.java index e4f7b313..61b7369c 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/PluginImplementBehavior.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/PluginImplementBehavior.java @@ -3,8 +3,13 @@ package org.bench4q.agent.scenario.node; import java.util.ArrayList; import java.util.Stack; +import org.bench4q.agent.datacollector.DataCollector; +import org.bench4q.agent.scenario.Parameter; import org.bench4q.agent.scenario.instruction.Instruction; import org.bench4q.agent.scenario.instruction.TestInstruction; +import org.bench4q.share.models.agent.ParameterModel; +import org.bench4q.share.models.agent.scriptrecord.BehaviorModel; +import org.bench4q.share.models.agent.statistics.BehaviorBriefModel; /** * This class is the base class of those nodes that will be implemented in @@ -17,9 +22,64 @@ import org.bench4q.agent.scenario.instruction.TestInstruction; * */ public abstract class PluginImplementBehavior extends Behavior { + private String use; + private String name; + private Parameter[] parameters; + + public String getUse() { + return use; + } + + public void setUse(String use) { + this.use = use; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Parameter[] getParameters() { + return parameters; + } + + public void setParameters(Parameter[] parameters) { + this.parameters = parameters; + } + + public abstract boolean shouldBeCount(); + + public abstract BehaviorBriefModel getBehaviorBriefResult( + DataCollector dataStatistics); + + public String getSpecificParamValue(String paramName) { + for (Parameter parameter : this.getParameters()) { + if (parameter.getKey().equalsIgnoreCase(paramName)) { + return parameter.getValue(); + } + } + return ""; + } protected void checkCondition(ArrayList code, Stack conditions) { code.addAll(conditions); } + + protected void buildAndGenerateParameterPart(BehaviorModel behaviorModel) { + this.setName(behaviorModel.getName()); + this.setUse(behaviorModel.getUse()); + this.setId(behaviorModel.getId()); + this.setParameters(new Parameter[behaviorModel.getParameters().size()]); + + for (int k = 0; k < behaviorModel.getParameters().size(); k++) { + ParameterModel parameterModel = behaviorModel.getParameters() + .get(k); + this.getParameters()[k] = Parameter.generateParamParts( + parameterModel.getKey(), parameterModel.getValue()); + } + } } diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/TimerBehavior.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/TimerBehavior.java index 31e1f46e..25f97302 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/TimerBehavior.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/TimerBehavior.java @@ -11,7 +11,7 @@ import org.bench4q.share.exception.Bench4QRunTimeException; import org.bench4q.share.models.agent.scriptrecord.BehaviorModel; import org.bench4q.share.models.agent.statistics.BehaviorBriefModel; -public class TimerBehavior extends Behavior { +public class TimerBehavior extends PluginImplementBehavior { public TimerBehavior(BehaviorModel timerBehaviorModel) { if (timerBehaviorModel.getType() != Behavior.TIMER_BEHAVIOR) { diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/TransactionBehavior.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/TransactionBehavior.java index 5d60cd3d..857265ec 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/TransactionBehavior.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/TransactionBehavior.java @@ -3,10 +3,8 @@ package org.bench4q.agent.scenario.node; import java.util.ArrayList; import java.util.Stack; -import org.bench4q.agent.datacollector.DataCollector; import org.bench4q.agent.scenario.instruction.Instruction; import org.bench4q.agent.scenario.instruction.TestInstruction; -import org.bench4q.share.models.agent.statistics.BehaviorBriefModel; public class TransactionBehavior extends Behavior { @Override @@ -15,15 +13,4 @@ public class TransactionBehavior extends Behavior { // TODO: } - @Override - public boolean shouldBeCount() { - return true; - } - - @Override - public BehaviorBriefModel getBehaviorBriefResult( - DataCollector dataStatistics) { - return null; - } - } diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/UserBehavior.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/UserBehavior.java index 43fc23d8..572ff5af 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/UserBehavior.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/node/UserBehavior.java @@ -37,8 +37,9 @@ public class UserBehavior extends PluginImplementBehavior { @Override public BehaviorBriefModel getBehaviorBriefResult( DataCollector dataStatistics) { - return (BehaviorBriefModel) dataStatistics + BehaviorBriefModel result = (BehaviorBriefModel) dataStatistics .getBehaviorBriefStatistics(this.getId()); + return result; } } diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/Test_Behavior.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/Test_Behavior.java new file mode 100644 index 00000000..b1646415 --- /dev/null +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/Test_Behavior.java @@ -0,0 +1,87 @@ +package org.bench4q.agent.test.scenario; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Stack; + +import org.bench4q.agent.scenario.instruction.ControlInstruction; +import org.bench4q.agent.scenario.instruction.Instruction; +import org.bench4q.agent.scenario.instruction.SampleInstruction; +import org.bench4q.agent.scenario.instruction.TestInstruction; +import org.bench4q.agent.scenario.instruction.TimerInstruction; +import org.bench4q.agent.scenario.node.Behavior; +import org.bench4q.agent.scenario.node.PluginImplementBehavior; +import org.bench4q.share.models.agent.ParameterModel; +import org.bench4q.share.models.agent.scriptrecord.BehaviorModel; +import org.junit.Test; + +public class Test_Behavior { + @Test + public void tsetComileUserBehaviorToInstructions() { + PluginImplementBehavior behavior = (PluginImplementBehavior) Behavior + .buildWith(BehaviorModel.UserBehaviorBuilder(1, "GET", "Http", + Arrays.asList(ParameterModel.createParameter("url", + "http://www.baidu.com")))); + ArrayList code = new ArrayList(); + Stack conditions = new Stack(); + behavior.compile(code, conditions); + assertEquals(1, code.size()); + assertEquals(0, conditions.size()); + assertEquals(behavior.getName(), + ((SampleInstruction) code.get(0)).getBehaviorName()); + assertEquals(behavior.getUse(), + ((SampleInstruction) code.get(0)).getPluginName()); + assertEquals(1, + ((SampleInstruction) code.get(0)).getParameters().length); + assertArrayEquals(behavior.getParameters(), + ((SampleInstruction) code.get(0)).getParameters()); + } + + @Test + public void testCompileTimerBehaviorToInstruction() { + PluginImplementBehavior behavior = (PluginImplementBehavior) Behavior + .buildWith(BehaviorModel.TimerBehaviorBuilder(1, "sleep", + "ConstantTimer", Arrays.asList(ParameterModel + .createParameter("time", "20")))); + ArrayList code = new ArrayList(); + Stack conditions = new Stack(); + behavior.compile(code, conditions); + assertEquals(1, code.size()); + assertEquals(0, conditions.size()); + assertEquals(behavior.getName(), + ((TimerInstruction) code.get(0)).getBehaviorName()); + assertEquals(behavior.getUse(), + ((TimerInstruction) code.get(0)).getPluginName()); + assertEquals(1, ((TimerInstruction) code.get(0)).getParameters().length); + assertArrayEquals(behavior.getParameters(), + ((TimerInstruction) code.get(0)).getParameters()); + } + + @Test + public void testCompileControlBehavior2Instruction() { + PluginImplementBehavior behavior = (PluginImplementBehavior) Behavior + .buildWith(BehaviorModel.ControlBehaviorBuilder(1, "next", + "CsvProvider", Collections. emptyList())); + ArrayList code = new ArrayList(); + Stack conditions = new Stack(); + behavior.compile(code, conditions); + assertEquals(1, code.size()); + assertEquals(0, conditions.size()); + assertEquals(behavior.getName(), + ((ControlInstruction) code.get(0)).getBehaviorName()); + assertEquals(behavior.getUse(), + ((ControlInstruction) code.get(0)).getPluginName()); + assertEquals(0, + ((ControlInstruction) code.get(0)).getParameters().length); + assertArrayEquals(behavior.getParameters(), + ((ControlInstruction) code.get(0)).getParameters()); + } + + @Test + public void testCompileIfBehavior2Instruction() { + // Behavior behavior = Behavior.buildWith(BehaviorModel.) + } +} diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/Test_Scenario.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/Test_Scenario.java index e20a28e3..507fdf69 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/Test_Scenario.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/Test_Scenario.java @@ -16,6 +16,7 @@ import org.bench4q.agent.scenario.Scenario; import org.bench4q.agent.scenario.dfa.ParamPart; import org.bench4q.agent.scenario.dfa.ParamPart.ParamPartType; import org.bench4q.agent.scenario.node.Behavior; +import org.bench4q.agent.scenario.node.PluginImplementBehavior; import org.bench4q.agent.test.TestBase; import org.bench4q.share.helper.MarshalHelper; import org.bench4q.share.helper.TestHelper; @@ -119,10 +120,11 @@ public class Test_Scenario extends TestBase { })); Scenario scenario = Scenario.scenarioCompiler(inputModel); for (Behavior behavior : scenario.getAllBehaviors()) { - assertEquals("first", behavior.getName()); - assertEquals(0, behavior.getId()); - assertEquals("http", behavior.getUse()); - for (Parameter parameter : behavior.getParameters()) { + PluginImplementBehavior pluginBehavior = (PluginImplementBehavior) behavior; + assertEquals("first", pluginBehavior.getName()); + assertEquals(0, pluginBehavior.getId()); + assertEquals("http", pluginBehavior.getUse()); + for (Parameter parameter : pluginBehavior.getParameters()) { assertNotNull(parameter.getParamParts()); List result = Arrays.asList(parameter .getParamParts()); diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/Test_ScenarioContext.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/Test_ScenarioContext.java index 4d7eb5c6..23de8a5c 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/Test_ScenarioContext.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/Test_ScenarioContext.java @@ -66,7 +66,7 @@ public class Test_ScenarioContext extends TestBase { assertEquals(1, context.getExecutor().getMaximumPoolSize()); } - @Test(expected = IllegalArgumentException.class) + @Test public void test_updatePopulationWithZero() { ScenarioContext context = getScenarioWithScenarioAndSchedule(); context.initTasks(10);