add tests for behaviorsBrief

add  tests for behaviorsBrief
This commit is contained in:
coderfengyun 2014-09-11 17:42:55 +08:00
parent 21e3cf4f9f
commit 19170fd438
7 changed files with 64 additions and 40 deletions

View File

@ -179,7 +179,7 @@ public class TestController {
AgentPagesBriefModel result = new AgentPagesBriefModel();
List<AgentPageBriefModel> pageBrieves = new ArrayList<AgentPageBriefModel>();
if (context == null || context.isFinished()) {
if (context == null) {
return null;
}
for (int i = 0; i < context.getScenario().getPages().length; i++) {

View File

@ -161,6 +161,5 @@ public class DetailStatisticsTest {
@Test
public void test_addSomeSameUrlResult() {
}
}

View File

@ -1,9 +1,10 @@
package org.bench4q.master.domain.valueobject.datastatistics;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.bench4q.share.models.agent.BehaviorBriefModel;
import org.bench4q.share.models.agent.BehaviorStatusCodeResultModel;
import org.bench4q.share.models.agent.statistics.DataStatisticsModel;
@ -32,8 +33,8 @@ public class BehaviorsBriefStatistics extends ScriptStatistics {
}
public BehaviorsBriefStatistics() {
this.setMap(new HashMap<Integer, Map<Integer, BehaviorStatusCodeResultModel>>());
this.setIdUrlMap(new HashMap<Integer, String>());
this.setMap(new ConcurrentHashMap<Integer, Map<Integer, BehaviorStatusCodeResultModel>>());
this.setIdUrlMap(new ConcurrentHashMap<Integer, String>());
}
public ScriptBehaviorsBriefModel getStatistics() {
@ -47,7 +48,8 @@ public class BehaviorsBriefStatistics extends ScriptStatistics {
.get(behaviorId));
List<BehaviorStatusCodeResultModel> statusList = new ArrayList<BehaviorStatusCodeResultModel>();
for (int statusCode : this.getMap().get(behaviorId).keySet()) {
statusList.add(getCopy(behaviorId, statusCode));
statusList.add(this.getMap().get(behaviorId).get(statusCode)
.getCopy());
}
behaviorBriefModel.setDetailStatusCodeResultModels(statusList);
this.setBehaviorCount(behaviorBriefModel);
@ -62,13 +64,10 @@ public class BehaviorsBriefStatistics extends ScriptStatistics {
private void setBehaviorCount(BehaviorBriefModel behaviorBriefModel) {
long totalCount = 0, successfulCount = 0;
if (behaviorBriefModel.getDetailStatusCodeResultModels() == null) {
return;
}
for (BehaviorStatusCodeResultModel behaviorStatusCodeResultModel : behaviorBriefModel
.getDetailStatusCodeResultModels()) {
totalCount += behaviorStatusCodeResultModel.getCount();
if (behaviorStatusCodeResultModel.getStatusCode() == 200) {
if (behaviorStatusCodeResultModel.isSuccess()) {
successfulCount += behaviorStatusCodeResultModel.getCount();
}
}
@ -76,21 +75,6 @@ public class BehaviorsBriefStatistics extends ScriptStatistics {
behaviorBriefModel.setSuccessfulCount(successfulCount);
}
private BehaviorStatusCodeResultModel getCopy(int behaviorId, int statusCode) {
BehaviorStatusCodeResultModel statusInMap = this.getMap()
.get(behaviorId).get(statusCode);
BehaviorStatusCodeResultModel ret = new BehaviorStatusCodeResultModel();
ret.setStatusCode(statusCode);
ret.setContentLength(statusInMap.getContentLength());
ret.setContentType(statusInMap.getContentType());
ret.setCount(statusInMap.getCount());
ret.setMaxResponseTime(statusInMap.getMaxResponseTime());
ret.setMinResponseTime(statusInMap.getMinResponseTime());
ret.setTotalResponseTimeThisTime(statusInMap
.getTotalResponseTimeThisTime());
return ret;
}
public void add(DataStatisticsModel dataUnit) {
if (!(dataUnit instanceof AgentBehaviorsBriefModel)) {
return;
@ -109,18 +93,7 @@ public class BehaviorsBriefStatistics extends ScriptStatistics {
}
BehaviorStatusCodeResultModel origin = behaviorStatusMap
.get(newOne.getStatusCode());
origin.setContentLength(origin.getContentLength()
+ newOne.getContentLength());
origin.setCount(origin.getCount() + newOne.getCount());
origin.setTotalResponseTimeThisTime(origin
.getTotalResponseTimeThisTime()
+ newOne.getTotalResponseTimeThisTime());
if (newOne.getMaxResponseTime() > origin.getMaxResponseTime()) {
origin.setMaxResponseTime(newOne.getMaxResponseTime());
}
if (newOne.getMinResponseTime() < origin.getMinResponseTime()) {
origin.setMinResponseTime(newOne.getMinResponseTime());
}
origin.plus(newOne);
}
}
}
@ -128,8 +101,9 @@ public class BehaviorsBriefStatistics extends ScriptStatistics {
private synchronized void guardAllMapsKeyExists(
BehaviorBriefModel behaviorBriefModel) {
if (!this.getMap().containsKey(behaviorBriefModel.getBehaviorId())) {
this.getMap().put(behaviorBriefModel.getBehaviorId(),
new HashMap<Integer, BehaviorStatusCodeResultModel>());
this.getMap()
.put(behaviorBriefModel.getBehaviorId(),
new ConcurrentHashMap<Integer, BehaviorStatusCodeResultModel>());
}
if (!this.getIdUrlMap().containsKey(behaviorBriefModel.getBehaviorId())) {
this.getIdUrlMap().put(behaviorBriefModel.getBehaviorId(),

View File

@ -1,10 +1,17 @@
package org.bench4q.master.unitTest.datastatistics;
import org.bench4q.master.domain.valueobject.datastatistics.BehaviorsBriefStatistics;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.agent.statistics.AgentBehaviorsBriefModel;
import org.junit.Test;
public class BehaviorsBriefStatisticsTest {
@Test
public void testAddNull() {
BehaviorsBriefStatistics behaviorsBriefStatistics = new BehaviorsBriefStatistics();
AgentBehaviorsBriefModel dataUnit = new AgentBehaviorsBriefModel();
behaviorsBriefStatistics.add(dataUnit);
System.out.println(MarshalHelper.tryMarshal(behaviorsBriefStatistics
.getStatistics()));
}
}

View File

@ -1,6 +1,8 @@
package org.bench4q.share.models.agent;
import java.util.LinkedList;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
@ -60,4 +62,7 @@ public class BehaviorBriefModel {
this.successfulCount = successfulCount;
}
public BehaviorBriefModel() {
this.setDetailStatusCodeResultModels(new LinkedList<BehaviorStatusCodeResultModel>());
}
}

View File

@ -76,4 +76,39 @@ public class BehaviorStatusCodeResultModel {
this.totalResponseTimeThisTime = totalResponseTimeThisTime;
}
/**
* It's just the http's success judgement, if we'll turn to other protocal,
* we should build a inheritance system
*
* @return
*/
public boolean isSuccess() {
return this.getStatusCode() == 200;
}
public BehaviorStatusCodeResultModel getCopy() {
BehaviorStatusCodeResultModel ret = new BehaviorStatusCodeResultModel();
ret.setStatusCode(getStatusCode());
ret.setContentLength(getContentLength());
ret.setContentType(getContentType());
ret.setCount(getCount());
ret.setMaxResponseTime(getMaxResponseTime());
ret.setMinResponseTime(getMinResponseTime());
ret.setTotalResponseTimeThisTime(getTotalResponseTimeThisTime());
return ret;
}
public synchronized void plus(BehaviorStatusCodeResultModel newOne) {
this.setContentLength(this.getContentLength()
+ newOne.getContentLength());
this.setCount(this.getCount() + newOne.getCount());
this.setTotalResponseTimeThisTime(this.getTotalResponseTimeThisTime()
+ newOne.getTotalResponseTimeThisTime());
if (newOne.getMaxResponseTime() > this.getMaxResponseTime()) {
this.setMaxResponseTime(newOne.getMaxResponseTime());
}
if (newOne.getMinResponseTime() < this.getMinResponseTime()) {
this.setMinResponseTime(newOne.getMinResponseTime());
}
}
}

View File

@ -1,5 +1,6 @@
package org.bench4q.share.models.agent.statistics;
import java.util.LinkedList;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
@ -23,4 +24,7 @@ public class AgentBehaviorsBriefModel extends DataStatisticsModel {
this.behaviorBriefModels = behaviorBriefModels;
}
public AgentBehaviorsBriefModel() {
this.setBehaviorBriefModels(new LinkedList<BehaviorBriefModel>());
}
}