adding the ifNode to Scenario
adding the ifNode to Scenario
This commit is contained in:
parent
755ac2db3c
commit
29e2bd8eda
|
@ -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;
|
||||
|
|
|
@ -4,7 +4,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.bench4q.agent.scenario.behavior.Behavior;
|
||||
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;
|
||||
|
|
|
@ -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,5 @@
|
|||
package org.bench4q.agent.scenario.instruction;
|
||||
|
||||
public class GotoInstruction {
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package org.bench4q.agent.scenario.instruction;
|
||||
|
||||
public interface Instruction {
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package org.bench4q.agent.scenario.instruction;
|
||||
|
||||
public class TestInstruction implements Instruction {
|
||||
|
||||
public TestInstruction(String pluginName, String behaviorName) {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
package org.bench4q.agent.scenario.node;
|
||||
|
||||
import org.bench4q.agent.datacollector.DataCollector;
|
||||
import org.bench4q.agent.scenario.Parameter;
|
||||
import org.bench4q.share.models.agent.ParameterModel;
|
||||
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
|
||||
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";
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
public abstract void compile();
|
||||
|
||||
protected void baseCompile() {
|
||||
for (Parameter parameter : this.getParameters()) {
|
||||
parameter.compileToGenerateParts();
|
||||
}
|
||||
}
|
||||
|
||||
public static Behavior buildWith(BehaviorModel behaviorModel) {
|
||||
Behavior behavior = null;
|
||||
if (behaviorModel.getType().equalsIgnoreCase(TIMER_BEHAVIOR)) {
|
||||
behavior = new TimerBehavior();
|
||||
} else if (behaviorModel.getType().equalsIgnoreCase(USER_BEHAVIOR)) {
|
||||
behavior = new UserBehavior();
|
||||
} else if (behaviorModel.getType().equalsIgnoreCase(CONTROL_BEHAVIOR)) {
|
||||
behavior = new ControlBehavior();
|
||||
} else if (behaviorModel.getType().equalsIgnoreCase(TEST_BEHAVIOR)) {
|
||||
// TODO: refactor this
|
||||
behavior = new IfBehavior();
|
||||
} 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()]);
|
||||
|
||||
for (int k = 0; k < behaviorModel.getParameters().size(); k++) {
|
||||
ParameterModel parameterModel = behaviorModel.getParameters()
|
||||
.get(k);
|
||||
behavior.getParameters()[k] = new Parameter(
|
||||
parameterModel.getKey(), parameterModel.getValue());
|
||||
}
|
||||
return behavior;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package org.bench4q.agent.scenario.node;
|
||||
|
||||
public class ConditionNode {
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
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 ConditionNode condition;
|
||||
|
||||
@Override
|
||||
public boolean shouldBeCount() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BehaviorBriefModel getBehaviorBriefResult(
|
||||
DataCollector dataStatistics) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
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 {
|
||||
|
||||
@Override
|
||||
public boolean shouldBeCount() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BehaviorBriefModel getBehaviorBriefResult(
|
||||
DataCollector dataStatistics) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compile() {
|
||||
this.baseCompile();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package org.bench4q.agent.scenario.node;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class IfBehavior extends ConditionedBehavior {
|
||||
private List<Behavior> thenBehaviors;
|
||||
private List<Behavior> elseBehaviors;
|
||||
|
||||
@Override
|
||||
public void compile() {
|
||||
this.baseCompile();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package org.bench4q.agent.scenario.node;
|
||||
|
||||
import org.bench4q.agent.datacollector.DataCollector;
|
||||
import org.bench4q.share.models.agent.statistics.BehaviorBriefModel;
|
||||
|
||||
public class TimerBehavior extends Behavior {
|
||||
@Override
|
||||
public void compile() {
|
||||
this.baseCompile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldBeCount() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BehaviorBriefModel getBehaviorBriefResult(
|
||||
DataCollector dataStatistics) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package org.bench4q.agent.scenario.node;
|
||||
|
||||
import org.bench4q.agent.datacollector.DataCollector;
|
||||
import org.bench4q.share.models.agent.statistics.BehaviorBriefModel;
|
||||
|
||||
public class TransactionBehavior extends Behavior {
|
||||
@Override
|
||||
public void compile() {
|
||||
this.baseCompile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldBeCount() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BehaviorBriefModel getBehaviorBriefResult(
|
||||
DataCollector dataStatistics) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package org.bench4q.agent.scenario.node;
|
||||
|
||||
import org.bench4q.agent.datacollector.DataCollector;
|
||||
import org.bench4q.share.models.agent.statistics.BehaviorBriefModel;
|
||||
|
||||
public class UserBehavior extends Behavior {
|
||||
|
||||
@Override
|
||||
public void compile() {
|
||||
this.baseCompile();
|
||||
}
|
||||
|
||||
@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;
|
||||
|
|
Loading…
Reference in New Issue