Merge branch 'master' of https://github.com/lostcharlie/Bench4Q.git
This commit is contained in:
commit
846c226496
|
@ -7,11 +7,11 @@ import java.util.UUID;
|
|||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.agent.plugin.ParameterFileCollector;
|
||||
import org.bench4q.agent.scenario.Scenario;
|
||||
import org.bench4q.agent.scenario.behavior.Behavior;
|
||||
import org.bench4q.agent.scenario.behavior.UserBehavior;
|
||||
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.UserBehavior;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.agent.CleanTestResultModel;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bench4q.agent.scenario;
|
||||
|
||||
import org.bench4q.agent.scenario.behavior.Behavior;
|
||||
import org.bench4q.agent.scenario.node.Behavior;
|
||||
|
||||
public class Batch {
|
||||
private int id;
|
||||
|
|
|
@ -37,13 +37,19 @@ public class Parameter {
|
|||
public Parameter() {
|
||||
}
|
||||
|
||||
public Parameter(String key, String value) {
|
||||
private Parameter(String key, String value) {
|
||||
this();
|
||||
this.setKey(key);
|
||||
this.setValue(value);
|
||||
}
|
||||
|
||||
public void compileToGenerateParts() {
|
||||
public static Parameter generateParamParts(String key, String value) {
|
||||
Parameter parameter = new Parameter(key, value);
|
||||
parameter.compileToGenerateParts();
|
||||
return parameter;
|
||||
}
|
||||
|
||||
private void compileToGenerateParts() {
|
||||
List<ParamPart> paramParts = DFA.resolveMaltipleParamPart(this
|
||||
.getValue());
|
||||
this.setParamParts(paramParts.toArray(new ParamPart[paramParts.size()]));
|
||||
|
|
|
@ -3,8 +3,11 @@ package org.bench4q.agent.scenario;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import org.bench4q.agent.scenario.behavior.Behavior;
|
||||
import org.bench4q.agent.scenario.instruction.Instruction;
|
||||
import org.bench4q.agent.scenario.instruction.TestInstruction;
|
||||
import org.bench4q.agent.scenario.node.Behavior;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.agent.ParameterModel;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
|
@ -62,7 +65,8 @@ public class Scenario {
|
|||
|
||||
public void compile() {
|
||||
for (Behavior behavior : this.getAllBehaviors()) {
|
||||
behavior.compile();
|
||||
behavior.compile(new ArrayList<Instruction>(),
|
||||
new Stack<TestInstruction>());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,7 +80,6 @@ public class Scenario {
|
|||
throw new NullPointerException();
|
||||
}
|
||||
Scenario scenario = extractScenario(scenarioModel);
|
||||
scenario.compile();
|
||||
return scenario;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
package org.bench4q.agent.scenario.behavior;
|
||||
|
||||
import org.bench4q.agent.datacollector.DataCollector;
|
||||
import org.bench4q.share.models.agent.statistics.BehaviorBriefModel;
|
||||
|
||||
public class TestBehavior extends Behavior {
|
||||
|
||||
@Override
|
||||
public boolean shouldBeCount() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BehaviorBriefModel getBehaviorBriefResult(
|
||||
DataCollector dataStatistics) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package org.bench4q.agent.scenario.behavior;
|
||||
|
||||
import org.bench4q.agent.datacollector.DataCollector;
|
||||
import org.bench4q.share.models.agent.statistics.BehaviorBriefModel;
|
||||
|
||||
public class TimerBehavior extends Behavior {
|
||||
|
||||
@Override
|
||||
public boolean shouldBeCount() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BehaviorBriefModel getBehaviorBriefResult(
|
||||
DataCollector dataStatistics) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package org.bench4q.agent.scenario.behavior;
|
||||
|
||||
import org.bench4q.agent.datacollector.DataCollector;
|
||||
import org.bench4q.share.models.agent.statistics.BehaviorBriefModel;
|
||||
|
||||
public class UserBehavior extends Behavior {
|
||||
@Override
|
||||
public boolean shouldBeCount() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BehaviorBriefModel getBehaviorBriefResult(
|
||||
DataCollector dataStatistics) {
|
||||
return (BehaviorBriefModel) dataStatistics.getBehaviorBriefStatistics(this.getId());
|
||||
}
|
||||
|
||||
}
|
|
@ -17,8 +17,8 @@ import org.bench4q.agent.scenario.Page;
|
|||
import org.bench4q.agent.scenario.Parameter;
|
||||
import org.bench4q.agent.scenario.Scenario;
|
||||
import org.bench4q.agent.scenario.UsePlugin;
|
||||
import org.bench4q.agent.scenario.behavior.Behavior;
|
||||
import org.bench4q.agent.scenario.dfa.ParamPart;
|
||||
import org.bench4q.agent.scenario.node.Behavior;
|
||||
|
||||
public class VUser implements Runnable {
|
||||
private ScenarioContext scenarioContext;
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package org.bench4q.agent.scenario.instruction;
|
||||
|
||||
import org.bench4q.agent.scenario.Parameter;
|
||||
|
||||
public class ControlInstruction extends PluginImplementInstruction {
|
||||
|
||||
public ControlInstruction(String pluginName, String behaviorName,
|
||||
Parameter[] parameters) {
|
||||
super(pluginName, behaviorName, parameters);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package org.bench4q.agent.scenario.instruction;
|
||||
|
||||
public class GotoInstruction implements Instruction {
|
||||
public int label;
|
||||
|
||||
public GotoInstruction(int label) {
|
||||
this.label = label;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package org.bench4q.agent.scenario.instruction;
|
||||
|
||||
public interface Instruction {
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package org.bench4q.agent.scenario.instruction;
|
||||
|
||||
import org.bench4q.agent.scenario.Parameter;
|
||||
|
||||
public abstract class PluginImplementInstruction implements Instruction {
|
||||
private final String pluginName;
|
||||
private final String behaviorName;
|
||||
private final Parameter[] parameters;
|
||||
|
||||
public PluginImplementInstruction(String pluginName, String behaviorName,
|
||||
Parameter[] parameters) {
|
||||
this.pluginName = pluginName;
|
||||
this.behaviorName = behaviorName;
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public String getPluginName() {
|
||||
return pluginName;
|
||||
}
|
||||
|
||||
public String getBehaviorName() {
|
||||
return behaviorName;
|
||||
}
|
||||
|
||||
public Parameter[] getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package org.bench4q.agent.scenario.instruction;
|
||||
|
||||
import org.bench4q.agent.scenario.Parameter;
|
||||
|
||||
public class SampleInstruction extends PluginImplementInstruction {
|
||||
|
||||
public SampleInstruction(String pluginName, String behaviorName,
|
||||
Parameter[] parameters) {
|
||||
super(pluginName, behaviorName, parameters);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package org.bench4q.agent.scenario.instruction;
|
||||
|
||||
import org.bench4q.agent.scenario.Parameter;
|
||||
|
||||
public class TestInstruction extends PluginImplementInstruction {
|
||||
private int falseLabel;
|
||||
|
||||
public TestInstruction(String pluginName, String behaviorName,
|
||||
Parameter[] parameters) {
|
||||
super(pluginName, behaviorName, parameters);
|
||||
}
|
||||
|
||||
public int getFalseLabel() {
|
||||
return falseLabel;
|
||||
}
|
||||
|
||||
public void setFalseLabel(int elseLabel) {
|
||||
this.falseLabel = elseLabel;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package org.bench4q.agent.scenario.instruction;
|
||||
|
||||
import org.bench4q.agent.scenario.Parameter;
|
||||
|
||||
public class TimerInstruction extends PluginImplementInstruction {
|
||||
|
||||
public TimerInstruction(String pluginName, String behaviorName,
|
||||
Parameter[] parameters) {
|
||||
super(pluginName, behaviorName, parameters);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,22 +1,37 @@
|
|||
package org.bench4q.agent.scenario.behavior;
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author coderfengyun
|
||||
*
|
||||
*/
|
||||
public abstract class Behavior {
|
||||
private static final String CONTROL_BEHAVIOR = "CONTROLBEHAVIOR";
|
||||
private static final String USER_BEHAVIOR = "USERBEHAVIOR";
|
||||
private static final String TIMER_BEHAVIOR = "TIMERBEHAVIOR";
|
||||
private static final String TEST_BEHAVIOR = "TESTBEHAVIOR";
|
||||
public static final String CONTROL_BEHAVIOR = "CONTROLBEHAVIOR";
|
||||
public static final String USER_BEHAVIOR = "USERBEHAVIOR";
|
||||
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;
|
||||
}
|
||||
|
@ -63,38 +78,54 @@ public abstract class Behavior {
|
|||
return "";
|
||||
}
|
||||
|
||||
public void compile() {
|
||||
for (Parameter parameter : this.getParameters()) {
|
||||
parameter.compileToGenerateParts();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* No matter which one to inherit from this class, it should call
|
||||
* baseCompile in its own compile function.
|
||||
*
|
||||
* This function has side effect, the result is both code and conditions
|
||||
*/
|
||||
|
||||
public abstract void compile(ArrayList<Instruction> code,
|
||||
Stack<TestInstruction> conditions);
|
||||
|
||||
public static Behavior buildWith(BehaviorModel behaviorModel) {
|
||||
Behavior behavior = null;
|
||||
if (behaviorModel.getType().equalsIgnoreCase(TIMER_BEHAVIOR)) {
|
||||
behavior = new TimerBehavior();
|
||||
behavior = new TimerBehavior(behaviorModel);
|
||||
} else if (behaviorModel.getType().equalsIgnoreCase(USER_BEHAVIOR)) {
|
||||
behavior = new UserBehavior();
|
||||
behavior = new UserBehavior(behaviorModel);
|
||||
} else if (behaviorModel.getType().equalsIgnoreCase(CONTROL_BEHAVIOR)) {
|
||||
behavior = new ControlBehavior();
|
||||
behavior = new ControlBehavior(behaviorModel);
|
||||
} else if (behaviorModel.getType().equalsIgnoreCase(TEST_BEHAVIOR)) {
|
||||
behavior = new TestBehavior();
|
||||
// TODO: refactor this
|
||||
if (behaviorModel instanceof IfBehaviorModel) {
|
||||
behavior = new IfBehavior((IfBehaviorModel) behaviorModel);
|
||||
} else if (behaviorModel instanceof ConditionBehaviorModel) {
|
||||
behavior = new ConditionBehavior(
|
||||
(ConditionBehaviorModel) behaviorModel);
|
||||
} else {
|
||||
throw new RuntimeException("Error type: TestInstruction"
|
||||
+ behaviorModel.getClass().getName());
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
"The input BehaviorModel's type is not proper");
|
||||
}
|
||||
behavior.setName(behaviorModel.getName());
|
||||
behavior.setUse(behaviorModel.getUse());
|
||||
behavior.setId(behaviorModel.getId());
|
||||
behavior.setParameters(new Parameter[behaviorModel.getParameters()
|
||||
.size()]);
|
||||
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);
|
||||
behavior.getParameters()[k] = new Parameter(
|
||||
this.getParameters()[k] = Parameter.generateParamParts(
|
||||
parameterModel.getKey(), parameterModel.getValue());
|
||||
}
|
||||
return behavior;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
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.scriptrecord.ConditionBehaviorModel;
|
||||
import org.bench4q.share.models.agent.statistics.BehaviorBriefModel;
|
||||
|
||||
public class ConditionBehavior extends PluginImplementBehavior {
|
||||
|
||||
public ConditionBehavior(ConditionBehaviorModel condition) {
|
||||
buildAndGenerateParameterPart(condition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldBeCount() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BehaviorBriefModel getBehaviorBriefResult(
|
||||
DataCollector dataStatistics) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compile(ArrayList<Instruction> code,
|
||||
Stack<TestInstruction> conditions) {
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +1,10 @@
|
|||
package org.bench4q.agent.scenario.behavior;
|
||||
package org.bench4q.agent.scenario.node;
|
||||
|
||||
import org.bench4q.agent.datacollector.DataCollector;
|
||||
import org.bench4q.share.models.agent.statistics.BehaviorBriefModel;
|
||||
|
||||
public class ControlBehavior extends Behavior {
|
||||
public abstract class ConditionedBehavior extends Behavior {
|
||||
protected ConditionBehavior condition;
|
||||
|
||||
@Override
|
||||
public boolean shouldBeCount() {
|
|
@ -0,0 +1,42 @@
|
|||
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.ControlInstruction;
|
||||
import org.bench4q.agent.scenario.instruction.Instruction;
|
||||
import org.bench4q.agent.scenario.instruction.TestInstruction;
|
||||
import org.bench4q.share.exception.Bench4QRunTimeException;
|
||||
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
|
||||
import org.bench4q.share.models.agent.statistics.BehaviorBriefModel;
|
||||
|
||||
public class ControlBehavior extends PluginImplementBehavior {
|
||||
|
||||
public ControlBehavior(BehaviorModel behaviorModel) {
|
||||
if (behaviorModel.getType() != Behavior.CONTROL_BEHAVIOR) {
|
||||
throw new Bench4QRunTimeException(
|
||||
"Not the right type, here we need CONTROL_BEHAVIOR, but it is"
|
||||
+ behaviorModel.getType());
|
||||
}
|
||||
buildAndGenerateParameterPart(behaviorModel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldBeCount() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BehaviorBriefModel getBehaviorBriefResult(
|
||||
DataCollector dataStatistics) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compile(ArrayList<Instruction> code,
|
||||
Stack<TestInstruction> conditions) {
|
||||
code.add(new ControlInstruction(this.getUse(), this.getName(), this
|
||||
.getParameters()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package org.bench4q.agent.scenario.node;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import org.bench4q.agent.scenario.instruction.GotoInstruction;
|
||||
import org.bench4q.agent.scenario.instruction.Instruction;
|
||||
import org.bench4q.agent.scenario.instruction.TestInstruction;
|
||||
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
|
||||
import org.bench4q.share.models.agent.scriptrecord.IfBehaviorModel;
|
||||
|
||||
public class IfBehavior extends ConditionedBehavior {
|
||||
private List<Behavior> thenBehaviors;
|
||||
private List<Behavior> elseBehaviors;
|
||||
|
||||
public IfBehavior(IfBehaviorModel model) {
|
||||
this.thenBehaviors = new ArrayList<Behavior>();
|
||||
this.elseBehaviors = new ArrayList<Behavior>();
|
||||
this.condition = new ConditionBehavior(model.getCondition());
|
||||
for (BehaviorModel then : model.getThenBehaviors()) {
|
||||
this.thenBehaviors.add(Behavior.buildWith(then));
|
||||
}
|
||||
|
||||
for (BehaviorModel elseModel : model.getElseBehaviors()) {
|
||||
this.elseBehaviors.add(Behavior.buildWith(elseModel));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* both code and conditions are result
|
||||
*/
|
||||
@Override
|
||||
public void compile(ArrayList<Instruction> code,
|
||||
Stack<TestInstruction> conditions) {
|
||||
TestInstruction testInstruction;
|
||||
GotoInstruction gotoInstruction;
|
||||
condition.checkCondition(code, conditions);
|
||||
|
||||
code.add(testInstruction = new TestInstruction(condition.getUse(),
|
||||
condition.getName(), condition.getParameters()));
|
||||
|
||||
for (Behavior behavior : thenBehaviors) {
|
||||
behavior.compile(code, conditions);
|
||||
}
|
||||
if (this.thenBehaviors.size() != 0) {
|
||||
code.add(gotoInstruction = new GotoInstruction(0));
|
||||
testInstruction.setFalseLabel(code.size());
|
||||
for (Behavior behavior : this.elseBehaviors) {
|
||||
behavior.compile(code, conditions);
|
||||
}
|
||||
gotoInstruction.label = code.size();
|
||||
} else {
|
||||
testInstruction.setFalseLabel(code.size());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package org.bench4q.agent.scenario.node;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Stack;
|
||||
|
||||
import org.bench4q.agent.scenario.instruction.Instruction;
|
||||
import org.bench4q.agent.scenario.instruction.TestInstruction;
|
||||
|
||||
/**
|
||||
* This class is the base class of those nodes that will be implemented in
|
||||
* plugin
|
||||
*
|
||||
* This kind of design has some problems that PluginImplementBehavior need not
|
||||
* extends Behavior
|
||||
*
|
||||
* @author chentienan
|
||||
*
|
||||
*/
|
||||
public abstract class PluginImplementBehavior extends Behavior {
|
||||
|
||||
protected void checkCondition(ArrayList<Instruction> code,
|
||||
Stack<TestInstruction> conditions) {
|
||||
code.addAll(conditions);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
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.agent.scenario.instruction.TimerInstruction;
|
||||
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 TimerBehavior(BehaviorModel timerBehaviorModel) {
|
||||
if (timerBehaviorModel.getType() != Behavior.TIMER_BEHAVIOR) {
|
||||
throw new Bench4QRunTimeException(
|
||||
"The type is not expected. Expected is TIMER_BEHAVIOR, but it is "
|
||||
+ timerBehaviorModel.getType());
|
||||
}
|
||||
this.buildAndGenerateParameterPart(timerBehaviorModel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compile(ArrayList<Instruction> code,
|
||||
Stack<TestInstruction> conditions) {
|
||||
code.add(new TimerInstruction(this.getUse(), this.getName(), this
|
||||
.getParameters()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldBeCount() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BehaviorBriefModel getBehaviorBriefResult(
|
||||
DataCollector dataStatistics) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,9 +1,19 @@
|
|||
package org.bench4q.agent.scenario.behavior;
|
||||
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
|
||||
public void compile(ArrayList<Instruction> code,
|
||||
Stack<TestInstruction> conditions) {
|
||||
// TODO:
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldBeCount() {
|
|
@ -0,0 +1,44 @@
|
|||
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.SampleInstruction;
|
||||
import org.bench4q.agent.scenario.instruction.TestInstruction;
|
||||
import org.bench4q.share.exception.Bench4QRunTimeException;
|
||||
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
|
||||
import org.bench4q.share.models.agent.statistics.BehaviorBriefModel;
|
||||
|
||||
public class UserBehavior extends PluginImplementBehavior {
|
||||
|
||||
public UserBehavior(BehaviorModel behaviorModel) {
|
||||
if (behaviorModel.getType() != Behavior.USER_BEHAVIOR) {
|
||||
throw new Bench4QRunTimeException(
|
||||
"Not the expected type, expected is USER_BEHAVIOR, but is "
|
||||
+ behaviorModel.getType());
|
||||
}
|
||||
buildAndGenerateParameterPart(behaviorModel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compile(ArrayList<Instruction> code,
|
||||
Stack<TestInstruction> conditions) {
|
||||
code.add(new SampleInstruction(this.getUse(), this.getName(), this
|
||||
.getParameters()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldBeCount() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BehaviorBriefModel getBehaviorBriefResult(
|
||||
DataCollector dataStatistics) {
|
||||
return (BehaviorBriefModel) dataStatistics
|
||||
.getBehaviorBriefStatistics(this.getId());
|
||||
}
|
||||
|
||||
}
|
|
@ -13,9 +13,9 @@ import java.util.UUID;
|
|||
import org.apache.commons.io.FileUtils;
|
||||
import org.bench4q.agent.scenario.Parameter;
|
||||
import org.bench4q.agent.scenario.Scenario;
|
||||
import org.bench4q.agent.scenario.behavior.Behavior;
|
||||
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.test.TestBase;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.helper.TestHelper;
|
||||
|
|
|
@ -9,8 +9,8 @@ import static org.junit.Assert.*;
|
|||
|
||||
import org.bench4q.agent.plugin.basic.csvprovider.CsvProvider;
|
||||
import org.bench4q.agent.scenario.Scenario;
|
||||
import org.bench4q.agent.scenario.behavior.Behavior;
|
||||
import org.bench4q.agent.scenario.engine.VUser;
|
||||
import org.bench4q.agent.scenario.node.Behavior;
|
||||
import org.bench4q.agent.test.TestBase;
|
||||
import org.bench4q.share.helper.TestHelper;
|
||||
import org.bench4q.share.models.agent.ParameterModel;
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package org.bench4q.share.models.agent.scriptrecord;
|
||||
|
||||
public class ConditionBehaviorModel extends BehaviorModel {
|
||||
|
||||
}
|
|
@ -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 IfBehaviorModel extends BehaviorModel {
|
||||
private ConditionBehaviorModel condition;
|
||||
private List<BehaviorModel> thenBehaviors;
|
||||
private List<BehaviorModel> elseBehaviors;
|
||||
|
||||
@XmlElement
|
||||
public ConditionBehaviorModel getCondition() {
|
||||
return condition;
|
||||
}
|
||||
|
||||
public void setCondition(ConditionBehaviorModel condition) {
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "thenBehaviors")
|
||||
@XmlElement
|
||||
public List<BehaviorModel> getThenBehaviors() {
|
||||
return thenBehaviors;
|
||||
}
|
||||
|
||||
public void setThenBehaviors(List<BehaviorModel> thenBehaviors) {
|
||||
this.thenBehaviors = thenBehaviors;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "elseBehaviors")
|
||||
@XmlElement
|
||||
public List<BehaviorModel> getElseBehaviors() {
|
||||
return elseBehaviors;
|
||||
}
|
||||
|
||||
public void setElseBehaviors(List<BehaviorModel> elseBehaviors) {
|
||||
this.elseBehaviors = elseBehaviors;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
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