now, i can run the scenario with page in it

This commit is contained in:
coderfengyun 2013-12-23 09:15:35 +08:00
parent 00215862ea
commit 9df9718dba
6 changed files with 97 additions and 74 deletions

View File

@ -15,6 +15,7 @@ import javax.xml.bind.Marshaller;
import org.apache.log4j.Logger;
import org.bench4q.agent.datacollector.impl.DetailStatusCodeResult;
import org.bench4q.agent.scenario.Batch;
import org.bench4q.agent.scenario.Page;
import org.bench4q.agent.scenario.Parameter;
import org.bench4q.agent.scenario.ScenarioNew;
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.scriptrecord.BatchBehavior;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@ -95,31 +97,30 @@ public class TestController {
ScenarioNew scenario = new ScenarioNew();
scenario.setUsePlugins(new UsePlugin[runScenarioModel.getUsePlugins()
.size()]);
scenario.setBatches(new Batch[runScenarioModel.getBatches().size()]);
scenario.setPages(new Page[runScenarioModel.getPages().size()]);
extractUsePlugins(runScenarioModel, scenario);
extractBatches(runScenarioModel, scenario);
extractPages(runScenarioModel, scenario);
return scenario;
}
private void extractBatches(RunScenarioModel runScenarioModel,
private void extractPages(RunScenarioModel runScenarioModel,
ScenarioNew scenario) {
int i;
List<BatchBehavior> batches = runScenarioModel.getBatches();
for (i = 0; i < runScenarioModel.getBatches().size(); i++) {
BatchBehavior batch = batches.get(i);
scenario.getBatches()[i] = extractBatch(batch);
List<PageModel> pageModels = runScenarioModel.getPages();
for (int i = 0; i < pageModels.size(); i++) {
PageModel pageModel = pageModels.get(i);
scenario.getPages()[i] = extractPage(pageModel);
}
}
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 Page extractPage(PageModel pageModel) {
Page page = new Page();
page.setBatches(new Batch[pageModel.getBatches().size()]);
List<BatchBehavior> batches = pageModel.getBatches();
for (int i = 0; i < pageModel.getBatches().size(); i++) {
BatchBehavior batch = batches.get(i);
page.getBatches()[i] = extractBatch(batch);
}
return page;
}
private Batch extractBatch(BatchBehavior batchModel) {
@ -139,6 +140,17 @@ public class TestController {
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) {
Behavior behavior = BehaviorFactory.getBuisinessObject(behaviorModel);
behavior.setName(behaviorModel.getName());
@ -190,18 +202,22 @@ public class TestController {
if (scenarioContext == null || scenarioContext.isFinished()) {
return null;
}
for (Batch batch : scenarioContext.getScenario().getBatches()) {
for (Behavior behavior : batch.getBehaviors()) {
int behaviorId = behavior.getId();
Map<Integer, DetailStatusCodeResult> map = scenarioContext
.getDataStatistics().getDetailStatistics(behaviorId);
if (map == null) {
continue;
}
behaviorBriefModels.add(buildBehaviorBrief(runId, behaviorId,
map));
for (Page page : scenarioContext.getScenario().getPages()) {
for (Batch batch : page.getBatches()) {
for (Behavior behavior : batch.getBehaviors()) {
int behaviorId = behavior.getId();
Map<Integer, DetailStatusCodeResult> map = scenarioContext
.getDataStatistics()
.getDetailStatistics(behaviorId);
if (map == null) {
continue;
}
behaviorBriefModels.add(buildBehaviorBrief(runId,
behaviorId, map));
}
}
}
ret.setBehaviorBriefModels(behaviorBriefModels);
return ret;

View File

@ -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;
}
}

View File

@ -94,23 +94,26 @@ public class ScenarioEngine {
Map<String, Object> plugins = new HashMap<String, Object>();
preparePlugins(context.getScenario(), plugins);
for (Batch batch : context.getScenario().getBatches()) {
for (Behavior behavior : batch.getBehaviors()) {
Object plugin = plugins.get(behavior.getUse());
Map<String, String> behaviorParameters = prepareBehaviorParameters(behavior);
Date startDate = new Date(System.currentTimeMillis());
PluginReturn pluginReturn = (PluginReturn) this
.getPluginManager().doBehavior(plugin,
behavior.getName(), behaviorParameters);
Date endDate = new Date(System.currentTimeMillis());
if (!behavior.shouldBeCountResponseTime()) {
continue;
for (Page page : context.getScenario().getPages()) {
for (Batch batch : page.getBatches()) {
for (Behavior behavior : batch.getBehaviors()) {
Object plugin = plugins.get(behavior.getUse());
Map<String, String> behaviorParameters = prepareBehaviorParameters(behavior);
Date startDate = new Date(System.currentTimeMillis());
PluginReturn pluginReturn = (PluginReturn) this
.getPluginManager().doBehavior(plugin,
behavior.getName(), behaviorParameters);
Date endDate = new Date(System.currentTimeMillis());
if (!behavior.shouldBeCountResponseTime()) {
continue;
}
context.getDataStatistics().add(
buildBehaviorResult(behavior, plugin, startDate,
pluginReturn, endDate));
}
context.getDataStatistics().add(
buildBehaviorResult(behavior, plugin, startDate,
pluginReturn, endDate));
}
}
}
private BehaviorResult buildBehaviorResult(Behavior behavior,

View File

@ -1,9 +1,14 @@
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 {
private UsePlugin[] usePlugins;
private Batch[] batches;
private Page[] pages;
public UsePlugin[] getUsePlugins() {
return usePlugins;
@ -13,12 +18,23 @@ public class ScenarioNew {
this.usePlugins = usePlugins;
}
public Batch[] getBatches() {
return batches;
public Page[] getPages() {
return pages;
}
public void setBatches(Batch[] batches) {
this.batches = batches;
public void setPages(Page[] pages) {
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);
}
}

View File

@ -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;
}
}

View File

@ -57,7 +57,7 @@ public class TestWithScriptFile {
public TestWithScriptFile() {
this.setFilePath("Scripts" + System.getProperty("file.separator")
+ "goodForBatch.xml");
+ "goodForPage.xml");
this.setHttpRequester(new HttpRequester());
}
@ -75,9 +75,9 @@ public class TestWithScriptFile {
System.out.println("can't execute an unvalid script");
return;
}
assertTrue(runScenarioModel.getBatches().size() > 0);
assertTrue(runScenarioModel.getBatches().get(0).getBehaviors()
.size() > 0);
assertTrue(runScenarioModel.getPages().size() > 0);
assertTrue(runScenarioModel.getPages().get(0).getBatches().get(0)
.getBehaviors().size() > 0);
runScenarioModel.setPoolSize(load);
HttpResponse httpResponse = this.getHttpRequester().sendPostXml(