add more tests about statistics of behaviorResult

add more tests about statistics of behaviorResult
This commit is contained in:
coderfengyun 2014-09-10 17:10:01 +08:00
parent f030705b35
commit 21e3cf4f9f
6 changed files with 41 additions and 16 deletions

View File

@ -196,7 +196,7 @@ public class TestController {
@PathVariable int pageId) {
ScenarioContext context = this.getScenarioEngine().getRunningTests()
.get(runId);
if (context == null || context.isFinished()) {
if (context == null) {
return null;
}
return (AgentPageBriefModel) context.getDataStatistics()
@ -210,7 +210,7 @@ public class TestController {
List<BehaviorBriefModel> behaviorBriefModels = new ArrayList<BehaviorBriefModel>();
ScenarioContext scenarioContext = this.getScenarioEngine()
.getRunningTests().get(runId);
if (scenarioContext == null || scenarioContext.isFinished()) {
if (scenarioContext == null) {
return null;
}
for (Behavior behavior : scenarioContext.getScenario()

View File

@ -6,6 +6,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import org.bench4q.agent.scenario.engine.BehaviorResult;
import org.bench4q.agent.scenario.engine.PageResult;
@ -114,7 +115,7 @@ public class ScenarioResultCollector extends AbstractDataCollector {
reset();
this.setCumulativeFailCount(0);
this.setCumulativeSucessfulCount(0);
this.setDetailMap(new HashMap<Integer, Map<Integer, BehaviorStatusCodeResult>>());
this.setDetailMap(new ConcurrentHashMap<Integer, Map<Integer, BehaviorStatusCodeResult>>());
}
private void reset() {

View File

@ -158,4 +158,9 @@ public class DetailStatisticsTest {
buildCodeResult(0, 1, Long.MIN_VALUE, Long.MAX_VALUE, 0));
return retMap;
}
@Test
public void test_addSomeSameUrlResult() {
}
}

View File

@ -8,6 +8,7 @@ import java.util.List;
import java.util.UUID;
import org.bench4q.agent.datacollector.DataCollector;
import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResult;
import org.bench4q.agent.datacollector.impl.ScenarioResultCollector;
import org.bench4q.agent.scenario.engine.BehaviorResult;
import org.bench4q.agent.scenario.engine.PageResult;
@ -57,7 +58,8 @@ public class ScenarioStatisticsTest {
@Test
public void addOneBriefTest() throws InterruptedException {
for (BehaviorResult behaviorResult : makeBehaviorListWhoseBehaviorIdIsOne(1)) {
List<BehaviorResult> generatedBehaviorResults = makeBehaviorListWhoseBehaviorIdIsOne(1);
for (BehaviorResult behaviorResult : generatedBehaviorResults) {
this.getDataStatistics().add(behaviorResult);
}
@ -68,11 +70,29 @@ public class ScenarioStatisticsTest {
modelExpect.setTimeFrame(model.getTimeFrame());
makeUpStatusModelForOneBehavior(modelExpect);
assertTrue(model.equals(modelExpect));
judgeBehaviorTotalAndScenarioTotal(generatedBehaviorResults, model);
}
private void judgeBehaviorTotalAndScenarioTotal(
List<BehaviorResult> generatedBehaviorResults,
AgentBriefStatusModel model) {
int successCount = 0;
for (BehaviorResult unit : generatedBehaviorResults) {
BehaviorStatusCodeResult behaviorStatusCodeResult = this
.getDataStatistics()
.getBehaviorBriefStatistics(unit.getBehaviorId()).get(200);
if (behaviorStatusCodeResult == null) {
continue;
}
successCount += behaviorStatusCodeResult.count;
}
assertEquals(successCount, model.getSuccessCountFromBegin());
}
@Test
public void addTwoBriefTest() throws InterruptedException {
for (BehaviorResult behaviorResult : makeBehaviorListWhoseBehaviorIdIsOne(2)) {
List<BehaviorResult> behaviorResults = makeBehaviorListWhoseBehaviorIdIsOne(2);
for (BehaviorResult behaviorResult : behaviorResults) {
this.getDataStatistics().add(behaviorResult);
}
Thread.sleep(100);
@ -81,6 +101,7 @@ public class ScenarioStatisticsTest {
AgentBriefStatusModel modelExpect = makeUpStatusModelForTwoBehavior(model
.getTimeFrame());
assertTrue(model.equals(modelExpect));
judgeBehaviorTotalAndScenarioTotal(behaviorResults, model);
}
public static AgentBriefStatusModel makeUpStatusModelForTwoBehavior(
@ -141,7 +162,7 @@ public class ScenarioStatisticsTest {
for (int i = 0; i < count; i++) {
int statusCode = i % 2 == 0 ? 200 : 400;
behaviorResults.add(buildBehaviorResult(200 + 10 * i, i % 2 == 0,
statusCode, 1, 200 + 10 * i));
statusCode, i, 200 + 10 * i));
}
return behaviorResults;
}

View File

@ -1,7 +1,7 @@
package org.bench4q.master.domain.valueobject.datastatistics;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.bench4q.share.models.agent.statistics.AgentPageBriefModel;
import org.bench4q.share.models.agent.statistics.AgentPagesBriefModel;
@ -21,7 +21,7 @@ public class PagesBriefStatistics extends ScriptStatistics {
}
public PagesBriefStatistics() {
this.setMap(new HashMap<Integer, PageBriefStatistics>());
this.setMap(new ConcurrentHashMap<Integer, PageBriefStatistics>());
}
public void add(DataStatisticsModel dataUnit) {
@ -33,15 +33,14 @@ public class PagesBriefStatistics extends ScriptStatistics {
private void add(AgentPagesBriefModel agentPagesBriefModel) {
for (AgentPageBriefModel unit : agentPagesBriefModel
.getPageBriefModels()) {
this.getValueFromMap(unit.getPageId()).add(unit);
int key = unit.getPageId();
if (!this.getMap().containsKey(key)) {
guardMapKeyExists(key);
}
this.getMap().get(key).add(unit);
}
}
private PageBriefStatistics getValueFromMap(int key) {
guardMapKeyExists(key);
return this.getMap().get(key);
}
private synchronized void guardMapKeyExists(int key) {
if (!this.getMap().containsKey(key)) {
this.getMap().put(key, new PageBriefStatistics());
@ -52,7 +51,7 @@ public class PagesBriefStatistics extends ScriptStatistics {
ScriptPagesBriefModel scriptPagesBriefModel = new ScriptPagesBriefModel();
for (Integer key : this.getMap().keySet()) {
scriptPagesBriefModel.getScriptPageBriefModels().add(
(ScriptPageBriefModel) this.getValueFromMap(key)
(ScriptPageBriefModel) this.getMap().get(key)
.getStatistics());
}
return scriptPagesBriefModel;

View File

@ -60,7 +60,6 @@ public class RunningScriptSampler {
TestBriefStatusModel testBriefStatusModel = runningAgent.briefAll();
addScriptResultModelStatistics(testBriefStatusModel);
}
return getScriptResultModel();
}