now, i can run the scenario with page in it
This commit is contained in:
parent
00215862ea
commit
9df9718dba
|
@ -15,6 +15,7 @@ import javax.xml.bind.Marshaller;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.bench4q.agent.datacollector.impl.DetailStatusCodeResult;
|
import org.bench4q.agent.datacollector.impl.DetailStatusCodeResult;
|
||||||
import org.bench4q.agent.scenario.Batch;
|
import org.bench4q.agent.scenario.Batch;
|
||||||
|
import org.bench4q.agent.scenario.Page;
|
||||||
import org.bench4q.agent.scenario.Parameter;
|
import org.bench4q.agent.scenario.Parameter;
|
||||||
import org.bench4q.agent.scenario.ScenarioNew;
|
import org.bench4q.agent.scenario.ScenarioNew;
|
||||||
import org.bench4q.agent.scenario.ScenarioContext;
|
import org.bench4q.agent.scenario.ScenarioContext;
|
||||||
|
@ -33,6 +34,7 @@ import org.bench4q.share.models.agent.StopTestModel;
|
||||||
import org.bench4q.share.models.agent.TestBehaviorsBriefModel;
|
import org.bench4q.share.models.agent.TestBehaviorsBriefModel;
|
||||||
import org.bench4q.share.models.agent.scriptrecord.BatchBehavior;
|
import org.bench4q.share.models.agent.scriptrecord.BatchBehavior;
|
||||||
import org.bench4q.share.models.agent.scriptrecord.BehaviorBaseModel;
|
import org.bench4q.share.models.agent.scriptrecord.BehaviorBaseModel;
|
||||||
|
import org.bench4q.share.models.agent.scriptrecord.PageModel;
|
||||||
import org.bench4q.share.models.agent.scriptrecord.UsePluginModel;
|
import org.bench4q.share.models.agent.scriptrecord.UsePluginModel;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
@ -95,31 +97,30 @@ public class TestController {
|
||||||
ScenarioNew scenario = new ScenarioNew();
|
ScenarioNew scenario = new ScenarioNew();
|
||||||
scenario.setUsePlugins(new UsePlugin[runScenarioModel.getUsePlugins()
|
scenario.setUsePlugins(new UsePlugin[runScenarioModel.getUsePlugins()
|
||||||
.size()]);
|
.size()]);
|
||||||
scenario.setBatches(new Batch[runScenarioModel.getBatches().size()]);
|
scenario.setPages(new Page[runScenarioModel.getPages().size()]);
|
||||||
extractUsePlugins(runScenarioModel, scenario);
|
extractUsePlugins(runScenarioModel, scenario);
|
||||||
extractBatches(runScenarioModel, scenario);
|
extractPages(runScenarioModel, scenario);
|
||||||
return scenario;
|
return scenario;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void extractBatches(RunScenarioModel runScenarioModel,
|
private void extractPages(RunScenarioModel runScenarioModel,
|
||||||
ScenarioNew scenario) {
|
ScenarioNew scenario) {
|
||||||
int i;
|
List<PageModel> pageModels = runScenarioModel.getPages();
|
||||||
List<BatchBehavior> batches = runScenarioModel.getBatches();
|
for (int i = 0; i < pageModels.size(); i++) {
|
||||||
for (i = 0; i < runScenarioModel.getBatches().size(); i++) {
|
PageModel pageModel = pageModels.get(i);
|
||||||
BatchBehavior batch = batches.get(i);
|
scenario.getPages()[i] = extractPage(pageModel);
|
||||||
scenario.getBatches()[i] = extractBatch(batch);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void extractUsePlugins(RunScenarioModel runScenarioModel,
|
private Page extractPage(PageModel pageModel) {
|
||||||
ScenarioNew scenario) {
|
Page page = new Page();
|
||||||
int i;
|
page.setBatches(new Batch[pageModel.getBatches().size()]);
|
||||||
List<UsePluginModel> usePluginModels = runScenarioModel.getUsePlugins();
|
List<BatchBehavior> batches = pageModel.getBatches();
|
||||||
for (i = 0; i < runScenarioModel.getUsePlugins().size(); i++) {
|
for (int i = 0; i < pageModel.getBatches().size(); i++) {
|
||||||
UsePluginModel usePluginModel = usePluginModels.get(i);
|
BatchBehavior batch = batches.get(i);
|
||||||
UsePlugin usePlugin = extractUsePlugin(usePluginModel);
|
page.getBatches()[i] = extractBatch(batch);
|
||||||
scenario.getUsePlugins()[i] = usePlugin;
|
|
||||||
}
|
}
|
||||||
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Batch extractBatch(BatchBehavior batchModel) {
|
private Batch extractBatch(BatchBehavior batchModel) {
|
||||||
|
@ -139,6 +140,17 @@ public class TestController {
|
||||||
return batch;
|
return batch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void extractUsePlugins(RunScenarioModel runScenarioModel,
|
||||||
|
ScenarioNew scenario) {
|
||||||
|
int i;
|
||||||
|
List<UsePluginModel> usePluginModels = runScenarioModel.getUsePlugins();
|
||||||
|
for (i = 0; i < runScenarioModel.getUsePlugins().size(); i++) {
|
||||||
|
UsePluginModel usePluginModel = usePluginModels.get(i);
|
||||||
|
UsePlugin usePlugin = extractUsePlugin(usePluginModel);
|
||||||
|
scenario.getUsePlugins()[i] = usePlugin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Behavior extractBehavior(BehaviorBaseModel behaviorModel) {
|
private Behavior extractBehavior(BehaviorBaseModel behaviorModel) {
|
||||||
Behavior behavior = BehaviorFactory.getBuisinessObject(behaviorModel);
|
Behavior behavior = BehaviorFactory.getBuisinessObject(behaviorModel);
|
||||||
behavior.setName(behaviorModel.getName());
|
behavior.setName(behaviorModel.getName());
|
||||||
|
@ -190,19 +202,23 @@ public class TestController {
|
||||||
if (scenarioContext == null || scenarioContext.isFinished()) {
|
if (scenarioContext == null || scenarioContext.isFinished()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for (Batch batch : scenarioContext.getScenario().getBatches()) {
|
for (Page page : scenarioContext.getScenario().getPages()) {
|
||||||
|
for (Batch batch : page.getBatches()) {
|
||||||
for (Behavior behavior : batch.getBehaviors()) {
|
for (Behavior behavior : batch.getBehaviors()) {
|
||||||
int behaviorId = behavior.getId();
|
int behaviorId = behavior.getId();
|
||||||
Map<Integer, DetailStatusCodeResult> map = scenarioContext
|
Map<Integer, DetailStatusCodeResult> map = scenarioContext
|
||||||
.getDataStatistics().getDetailStatistics(behaviorId);
|
.getDataStatistics()
|
||||||
|
.getDetailStatistics(behaviorId);
|
||||||
if (map == null) {
|
if (map == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
behaviorBriefModels.add(buildBehaviorBrief(runId, behaviorId,
|
behaviorBriefModels.add(buildBehaviorBrief(runId,
|
||||||
map));
|
behaviorId, map));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
ret.setBehaviorBriefModels(behaviorBriefModels);
|
ret.setBehaviorBriefModels(behaviorBriefModels);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package org.bench4q.agent.scenario;
|
||||||
|
|
||||||
|
public class Page {
|
||||||
|
private Batch[] batches;
|
||||||
|
|
||||||
|
public Batch[] getBatches() {
|
||||||
|
return batches;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBatches(Batch[] batches) {
|
||||||
|
this.batches = batches;
|
||||||
|
}
|
||||||
|
}
|
|
@ -94,7 +94,8 @@ public class ScenarioEngine {
|
||||||
Map<String, Object> plugins = new HashMap<String, Object>();
|
Map<String, Object> plugins = new HashMap<String, Object>();
|
||||||
preparePlugins(context.getScenario(), plugins);
|
preparePlugins(context.getScenario(), plugins);
|
||||||
|
|
||||||
for (Batch batch : context.getScenario().getBatches()) {
|
for (Page page : context.getScenario().getPages()) {
|
||||||
|
for (Batch batch : page.getBatches()) {
|
||||||
for (Behavior behavior : batch.getBehaviors()) {
|
for (Behavior behavior : batch.getBehaviors()) {
|
||||||
Object plugin = plugins.get(behavior.getUse());
|
Object plugin = plugins.get(behavior.getUse());
|
||||||
Map<String, String> behaviorParameters = prepareBehaviorParameters(behavior);
|
Map<String, String> behaviorParameters = prepareBehaviorParameters(behavior);
|
||||||
|
@ -113,6 +114,8 @@ public class ScenarioEngine {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private BehaviorResult buildBehaviorResult(Behavior behavior,
|
private BehaviorResult buildBehaviorResult(Behavior behavior,
|
||||||
Object plugin, Date startDate, PluginReturn pluginReturn,
|
Object plugin, Date startDate, PluginReturn pluginReturn,
|
||||||
Date endDate) {
|
Date endDate) {
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
package org.bench4q.agent.scenario;
|
package org.bench4q.agent.scenario;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bench4q.agent.scenario.behavior.Behavior;
|
||||||
|
|
||||||
public class ScenarioNew {
|
public class ScenarioNew {
|
||||||
private UsePlugin[] usePlugins;
|
private UsePlugin[] usePlugins;
|
||||||
private Batch[] batches;
|
private Page[] pages;
|
||||||
|
|
||||||
public UsePlugin[] getUsePlugins() {
|
public UsePlugin[] getUsePlugins() {
|
||||||
return usePlugins;
|
return usePlugins;
|
||||||
|
@ -13,12 +18,23 @@ public class ScenarioNew {
|
||||||
this.usePlugins = usePlugins;
|
this.usePlugins = usePlugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Batch[] getBatches() {
|
public Page[] getPages() {
|
||||||
return batches;
|
return pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBatches(Batch[] batches) {
|
public void setPages(Page[] pages) {
|
||||||
this.batches = batches;
|
this.pages = pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Behavior> getAllBehaviorsInScenario() {
|
||||||
|
List<Behavior> behaviors = new ArrayList<Behavior>();
|
||||||
|
for (Page page : this.getPages()) {
|
||||||
|
for (Batch batch : page.getBatches()) {
|
||||||
|
for (Behavior behavior : batch.getBehaviors()) {
|
||||||
|
behaviors.add(behavior);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Collections.unmodifiableList(behaviors);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
package org.bench4q.agent.scenario;
|
|
||||||
|
|
||||||
import org.bench4q.agent.scenario.behavior.Behavior;
|
|
||||||
|
|
||||||
public class ScenarioOld {
|
|
||||||
private UsePlugin[] usePlugins;
|
|
||||||
private Behavior[] behaviors;
|
|
||||||
|
|
||||||
public UsePlugin[] getUsePlugins() {
|
|
||||||
return usePlugins;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUsePlugins(UsePlugin[] usePlugins) {
|
|
||||||
this.usePlugins = usePlugins;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Behavior[] getBehaviors() {
|
|
||||||
return behaviors;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBehaviors(Behavior[] behaviors) {
|
|
||||||
this.behaviors = behaviors;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -57,7 +57,7 @@ public class TestWithScriptFile {
|
||||||
|
|
||||||
public TestWithScriptFile() {
|
public TestWithScriptFile() {
|
||||||
this.setFilePath("Scripts" + System.getProperty("file.separator")
|
this.setFilePath("Scripts" + System.getProperty("file.separator")
|
||||||
+ "goodForBatch.xml");
|
+ "goodForPage.xml");
|
||||||
this.setHttpRequester(new HttpRequester());
|
this.setHttpRequester(new HttpRequester());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,9 +75,9 @@ public class TestWithScriptFile {
|
||||||
System.out.println("can't execute an unvalid script");
|
System.out.println("can't execute an unvalid script");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assertTrue(runScenarioModel.getBatches().size() > 0);
|
assertTrue(runScenarioModel.getPages().size() > 0);
|
||||||
assertTrue(runScenarioModel.getBatches().get(0).getBehaviors()
|
assertTrue(runScenarioModel.getPages().get(0).getBatches().get(0)
|
||||||
.size() > 0);
|
.getBehaviors().size() > 0);
|
||||||
runScenarioModel.setPoolSize(load);
|
runScenarioModel.setPoolSize(load);
|
||||||
|
|
||||||
HttpResponse httpResponse = this.getHttpRequester().sendPostXml(
|
HttpResponse httpResponse = this.getHttpRequester().sendPostXml(
|
||||||
|
|
Loading…
Reference in New Issue