now compile the scenario over

now compile the scenario over
This commit is contained in:
coderfengyun 2014-04-15 11:03:35 +08:00
parent 131812d917
commit 8980b2d01c
10 changed files with 104 additions and 21 deletions

View File

@ -78,7 +78,7 @@ public class TestController {
.unmarshal(RunScenarioModel.class, scenarioModel);
this.getScenarioEngine().submitScenario(runId,
Scenario.scenarioBuilder(runScenarioModel),
Scenario.scenarioBuilderWithCompile(runScenarioModel),
runScenarioModel.getPoolSize());
return MarshalHelper.tryMarshal(buildWith(runId));
} catch (Exception e) {
@ -105,7 +105,7 @@ public class TestController {
public RunScenarioResultModel run(
@RequestBody RunScenarioModel runScenarioModel)
throws UnknownHostException {
Scenario scenario = Scenario.scenarioBuilder(runScenarioModel);
Scenario scenario = Scenario.scenarioBuilderWithCompile(runScenarioModel);
UUID runId = UUID.randomUUID();
System.out.println(runScenarioModel.getPoolSize());
this.getLogger().info(MarshalHelper.tryMarshal(runScenarioModel));
@ -219,7 +219,7 @@ public class TestController {
return null;
}
for (Behavior behavior : scenarioContext.getScenario()
.getAllBehaviorsInScenario()) {
.getAllBehaviors()) {
int behaviorId = behavior.getId();
Map<Integer, BehaviorStatusCodeResult> map = behavior
.getBehaviorBriefResult(scenarioContext.getDataStatistics());

View File

@ -57,7 +57,7 @@ public class Scenario {
this.setBehaviors(new ArrayList<Behavior>());
}
public List<Behavior> getAllBehaviorsInScenario() {
public List<Behavior> getAllBehaviors() {
if (this.getBehaviors().size() > 0) {
return Collections.unmodifiableList(this.getBehaviors());
}
@ -72,16 +72,24 @@ public class Scenario {
return Collections.unmodifiableList(behaviors);
}
public static Scenario scenarioBuilder(String scenarioContent) {
return extractScenario((RunScenarioModel) MarshalHelper.tryUnmarshal(
RunScenarioModel.class, scenarioContent));
public void compile() {
for (Behavior behavior : this.getAllBehaviors()) {
behavior.compile();
}
}
public static Scenario scenarioBuilder(RunScenarioModel scenarioModel) {
public static Scenario scenarioBuilder(String scenarioContent) {
return scenarioBuilderWithCompile((RunScenarioModel) MarshalHelper
.tryUnmarshal(RunScenarioModel.class, scenarioContent));
}
public static Scenario scenarioBuilderWithCompile(
RunScenarioModel scenarioModel) {
if (scenarioModel == null) {
throw new NullPointerException();
}
Scenario scenario = extractScenario(scenarioModel);
scenario.compile();
return scenario;
}

View File

@ -20,7 +20,7 @@ public class ExtractScenarioTest {
RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper
.unmarshal(RunScenarioModel.class, FileUtils
.readFileToString(new File("Scripts/goodForPage.xml")));
Scenario scenario = Scenario.scenarioBuilder(runScenarioModel);
Scenario scenario = Scenario.scenarioBuilderWithCompile(runScenarioModel);
assertTrue(scenario.getPages().length > 0);
}

View File

@ -51,7 +51,7 @@ public class Test_ParameterManager extends TestBase_Parameterization {
String paramName = "param1";
createFileAndWriteContent(testId, paramName, "12;13;14;15");
Scenario scenario = Scenario
.scenarioBuilder(buildATestScenarioModelWith(new DefinedParameter(
.scenarioBuilderWithCompile(buildATestScenarioModelWith(new DefinedParameter(
paramName, "Para_List", PickOrder.SEQUENTIAL.name(),
UpdateStrategy.ONCE.name())));
ScenarioContext scenarioContext = ScenarioContext.buildScenarioContext(
@ -75,7 +75,7 @@ public class Test_ParameterManager extends TestBase_Parameterization {
String paramName = "param1";
createFileAndWriteContent(testId, paramName, "12;13;14;15");
Scenario scenario = Scenario
.scenarioBuilder(buildATestScenarioModelWith(new DefinedParameter(
.scenarioBuilderWithCompile(buildATestScenarioModelWith(new DefinedParameter(
paramName, "Para_List", PickOrder.SEQUENTIAL.name(),
UpdateStrategy.EACH_ITERATION.name())));
ScenarioContext scenarioContext = ScenarioContext.buildScenarioContext(
@ -100,7 +100,7 @@ public class Test_ParameterManager extends TestBase_Parameterization {
String paramName = "param1";
createFileAndWriteContent(testId, paramName, "12;13;14;15");
Scenario scenario = Scenario
.scenarioBuilder(buildATestScenarioModelWith(new DefinedParameter(
.scenarioBuilderWithCompile(buildATestScenarioModelWith(new DefinedParameter(
paramName, "Para_List", PickOrder.SEQUENTIAL.name(),
UpdateStrategy.EACH_OCCURRENCE.name())));
ScenarioContext scenarioContext = ScenarioContext.buildScenarioContext(

View File

@ -85,7 +85,7 @@ public class Test_CsvProvider extends TestBase_Parameterization {
public void test_InitialRightly_By_VUser() {
final String fileName = "param_csv";
RunScenarioModel runScenarioModel = buildRunScenarioModel(fileName);
Scenario scenario = Scenario.scenarioBuilder(runScenarioModel);
Scenario scenario = Scenario.scenarioBuilderWithCompile(runScenarioModel);
VUser vUser = Test_VUser.createVUser(scenario, UUID.randomUUID());
try {
HashMap<String, Object> plugins = new HashMap<String, Object>();
@ -117,7 +117,7 @@ public class Test_CsvProvider extends TestBase_Parameterization {
UUID testId = UUID.randomUUID();
createFileAndWriteContent(testId, fileName, CONTENT);
Scenario scenario = Scenario
.scenarioBuilder(buildRunScenarioModel(fileName));
.scenarioBuilderWithCompile(buildRunScenarioModel(fileName));
VUser vUser = Test_VUser.createVUser(scenario, testId);
HashMap<String, Object> plugins = new HashMap<String, Object>();
TestHelper

View File

@ -10,10 +10,10 @@ import org.bench4q.agent.scenario.dfa.ParamPart.ParamPartType;
import org.junit.Test;
public class Test_DFA {
private static final String TEST_CASE = "${csvProvider0:userName}";
public static final String TEST_CASE = "${csvProvider0:userName}";
private static final String TEST_CASE2 = "${csvProvider0:userName}$#";
private static final String TEST_CASE3 = "${csvProvider0:userName}$#okOrNot";
private static final String TEST_CASE4 = "${csvProvider0:userName}$#okOrNot${file.separator}";
static final String TEST_CASE4 = "${csvProvider0:userName}$#okOrNot${file.separator}";
private static final String TEST_CASE_NOTSUPPORT1 = "${{abc";
private static final String TEST_CASE_NOTSUPPORT2 = "${csvProvider0:adc{";

View File

@ -1,10 +1,23 @@
package org.bench4q.agent.test.scenario;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
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.test.plugin.Test_HBasePlugin;
import org.bench4q.share.models.agent.DefinedParameterModel;
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.junit.Test;
public class Test_Scenario {
@ -12,7 +25,7 @@ public class Test_Scenario {
@Test
public void testScenarioBuilderWithZeroDefinedParameter() {
RunScenarioModel inputModel = Test_HBasePlugin.buildScenario(10);
Scenario scenario = Scenario.scenarioBuilder(inputModel);
Scenario scenario = Scenario.scenarioBuilderWithCompile(inputModel);
assertNotNull(scenario.getDefinedParameters());
assertEquals(0, scenario.getDefinedParameters().length);
}
@ -23,7 +36,7 @@ public class Test_Scenario {
inputModel.getDefinedParameters().add(
buildDefinedParameterModel("param1", "table", "sequencial",
"each_iteration"));
Scenario scenario = Scenario.scenarioBuilder(inputModel);
Scenario scenario = Scenario.scenarioBuilderWithCompile(inputModel);
assertNotNull(scenario.getDefinedParameters());
assertEquals(1, scenario.getDefinedParameters().length);
}
@ -37,4 +50,65 @@ public class Test_Scenario {
result.setUpdateStrategy(updateStrategy);
return result;
}
@Test
public void test_ScenarioCompile() {
List<BehaviorModel> behaviors = new ArrayList<BehaviorModel>();
behaviors.add(BehaviorModel.UserBehaviorBuilder(0, "first", "http",
new ArrayList<ParameterModel>() {
private static final long serialVersionUID = 1L;
{
add(ParameterModel.createParameter("withParamPart",
Test_DFA.TEST_CASE4));
}
}));
RunScenarioModel inputModel = buildRunScenarioModelWith(behaviors);
Scenario scenario = Scenario.scenarioBuilderWithCompile(inputModel);
assertNotNull(scenario.getDefinedParameters());
for (Behavior behavior : scenario.getAllBehaviors()) {
for (Parameter parameter : behavior.getParameters()) {
assertNotNull(parameter.getParamParts());
List<ParamPart> result = Arrays.asList(parameter
.getParamParts());
assertEquals(4, result.size());
assertEquals("csvProvider0", result.get(0)
.getPluginIdForContextCallType());
assertEquals(ParamPartType.CONTEXT_CALL, result.get(0)
.getType());
assertEquals("userName", result.get(0)
.getVariableForContextCallAndProperty());
assertNull(result.get(0).getContentForStringType());
assertEquals(ParamPartType.SESSION_ID, result.get(1).getType());
assertNull(result.get(1).getContentForStringType());
assertNull(result.get(1).getPluginIdForContextCallType());
assertNull(result.get(1).getVariableForContextCallAndProperty());
assertEquals(ParamPartType.STRING, result.get(2).getType());
assertNull(result.get(2).getPluginIdForContextCallType());
assertNull(result.get(2).getVariableForContextCallAndProperty());
assertEquals("okOrNot", result.get(2).getContentForStringType());
assertEquals(ParamPartType.PROPERTY, result.get(3).getType());
assertNull(result.get(3).getPluginIdForContextCallType());
assertNull(result.get(3).getContentForStringType());
assertEquals("file.separator", result.get(3)
.getVariableForContextCallAndProperty());
}
}
}
private RunScenarioModel buildRunScenarioModelWith(
List<BehaviorModel> behaviors) {
RunScenarioModel runScenarioModel = new RunScenarioModel();
PageModel page = new PageModel();
BatchModel batch = new BatchModel();
batch.setBehaviors(new ArrayList<BehaviorModel>());
batch.getBehaviors().addAll(behaviors);
page.getBatches().add(batch);
runScenarioModel.getPages().add(page);
return runScenarioModel;
}
}

View File

@ -50,7 +50,7 @@ public class Test_ScenarioContext {
UpdateStrategy.EACH_OCCURRENCE.name()));
ScenarioContext scenarioContext = ScenarioContext.buildScenarioContext(
testId, Scenario.scenarioBuilder(model), 10);
testId, Scenario.scenarioBuilderWithCompile(model), 10);
VUser vUser = new VUser(scenarioContext);
String firstValue = vUser.getParam(param_name);

View File

@ -94,7 +94,7 @@ public class Test_VUser {
}
private static Scenario getTestScenario() {
return Scenario.scenarioBuilder(Test_HBasePlugin.buildScenario(10));
return Scenario.scenarioBuilderWithCompile(Test_HBasePlugin.buildScenario(10));
}
public static VUser createVUser(Scenario scenario, UUID testId) {

View File

@ -1,5 +1,6 @@
package org.bench4q.share.models.agent.scriptrecord;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
@ -11,7 +12,7 @@ public class BatchModel {
private int Id;
private int parentId;
private int childId;
private List<BehaviorModel> behaviors;
private List<BehaviorModel> behaviors = new ArrayList<BehaviorModel>();
@XmlElement
public int getId() {