add tests for behaviorsBrief
add tests for behaviorsBrief
This commit is contained in:
parent
21e3cf4f9f
commit
19170fd438
|
@ -179,7 +179,7 @@ public class TestController {
|
||||||
AgentPagesBriefModel result = new AgentPagesBriefModel();
|
AgentPagesBriefModel result = new AgentPagesBriefModel();
|
||||||
List<AgentPageBriefModel> pageBrieves = new ArrayList<AgentPageBriefModel>();
|
List<AgentPageBriefModel> pageBrieves = new ArrayList<AgentPageBriefModel>();
|
||||||
|
|
||||||
if (context == null || context.isFinished()) {
|
if (context == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < context.getScenario().getPages().length; i++) {
|
for (int i = 0; i < context.getScenario().getPages().length; i++) {
|
||||||
|
|
|
@ -161,6 +161,5 @@ public class DetailStatisticsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_addSomeSameUrlResult() {
|
public void test_addSomeSameUrlResult() {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package org.bench4q.master.domain.valueobject.datastatistics;
|
package org.bench4q.master.domain.valueobject.datastatistics;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.bench4q.share.models.agent.BehaviorBriefModel;
|
import org.bench4q.share.models.agent.BehaviorBriefModel;
|
||||||
import org.bench4q.share.models.agent.BehaviorStatusCodeResultModel;
|
import org.bench4q.share.models.agent.BehaviorStatusCodeResultModel;
|
||||||
import org.bench4q.share.models.agent.statistics.DataStatisticsModel;
|
import org.bench4q.share.models.agent.statistics.DataStatisticsModel;
|
||||||
|
@ -32,8 +33,8 @@ public class BehaviorsBriefStatistics extends ScriptStatistics {
|
||||||
}
|
}
|
||||||
|
|
||||||
public BehaviorsBriefStatistics() {
|
public BehaviorsBriefStatistics() {
|
||||||
this.setMap(new HashMap<Integer, Map<Integer, BehaviorStatusCodeResultModel>>());
|
this.setMap(new ConcurrentHashMap<Integer, Map<Integer, BehaviorStatusCodeResultModel>>());
|
||||||
this.setIdUrlMap(new HashMap<Integer, String>());
|
this.setIdUrlMap(new ConcurrentHashMap<Integer, String>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScriptBehaviorsBriefModel getStatistics() {
|
public ScriptBehaviorsBriefModel getStatistics() {
|
||||||
|
@ -47,7 +48,8 @@ public class BehaviorsBriefStatistics extends ScriptStatistics {
|
||||||
.get(behaviorId));
|
.get(behaviorId));
|
||||||
List<BehaviorStatusCodeResultModel> statusList = new ArrayList<BehaviorStatusCodeResultModel>();
|
List<BehaviorStatusCodeResultModel> statusList = new ArrayList<BehaviorStatusCodeResultModel>();
|
||||||
for (int statusCode : this.getMap().get(behaviorId).keySet()) {
|
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);
|
behaviorBriefModel.setDetailStatusCodeResultModels(statusList);
|
||||||
this.setBehaviorCount(behaviorBriefModel);
|
this.setBehaviorCount(behaviorBriefModel);
|
||||||
|
@ -62,13 +64,10 @@ public class BehaviorsBriefStatistics extends ScriptStatistics {
|
||||||
|
|
||||||
private void setBehaviorCount(BehaviorBriefModel behaviorBriefModel) {
|
private void setBehaviorCount(BehaviorBriefModel behaviorBriefModel) {
|
||||||
long totalCount = 0, successfulCount = 0;
|
long totalCount = 0, successfulCount = 0;
|
||||||
if (behaviorBriefModel.getDetailStatusCodeResultModels() == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (BehaviorStatusCodeResultModel behaviorStatusCodeResultModel : behaviorBriefModel
|
for (BehaviorStatusCodeResultModel behaviorStatusCodeResultModel : behaviorBriefModel
|
||||||
.getDetailStatusCodeResultModels()) {
|
.getDetailStatusCodeResultModels()) {
|
||||||
totalCount += behaviorStatusCodeResultModel.getCount();
|
totalCount += behaviorStatusCodeResultModel.getCount();
|
||||||
if (behaviorStatusCodeResultModel.getStatusCode() == 200) {
|
if (behaviorStatusCodeResultModel.isSuccess()) {
|
||||||
successfulCount += behaviorStatusCodeResultModel.getCount();
|
successfulCount += behaviorStatusCodeResultModel.getCount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,21 +75,6 @@ public class BehaviorsBriefStatistics extends ScriptStatistics {
|
||||||
behaviorBriefModel.setSuccessfulCount(successfulCount);
|
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) {
|
public void add(DataStatisticsModel dataUnit) {
|
||||||
if (!(dataUnit instanceof AgentBehaviorsBriefModel)) {
|
if (!(dataUnit instanceof AgentBehaviorsBriefModel)) {
|
||||||
return;
|
return;
|
||||||
|
@ -109,18 +93,7 @@ public class BehaviorsBriefStatistics extends ScriptStatistics {
|
||||||
}
|
}
|
||||||
BehaviorStatusCodeResultModel origin = behaviorStatusMap
|
BehaviorStatusCodeResultModel origin = behaviorStatusMap
|
||||||
.get(newOne.getStatusCode());
|
.get(newOne.getStatusCode());
|
||||||
origin.setContentLength(origin.getContentLength()
|
origin.plus(newOne);
|
||||||
+ 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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,8 +101,9 @@ public class BehaviorsBriefStatistics extends ScriptStatistics {
|
||||||
private synchronized void guardAllMapsKeyExists(
|
private synchronized void guardAllMapsKeyExists(
|
||||||
BehaviorBriefModel behaviorBriefModel) {
|
BehaviorBriefModel behaviorBriefModel) {
|
||||||
if (!this.getMap().containsKey(behaviorBriefModel.getBehaviorId())) {
|
if (!this.getMap().containsKey(behaviorBriefModel.getBehaviorId())) {
|
||||||
this.getMap().put(behaviorBriefModel.getBehaviorId(),
|
this.getMap()
|
||||||
new HashMap<Integer, BehaviorStatusCodeResultModel>());
|
.put(behaviorBriefModel.getBehaviorId(),
|
||||||
|
new ConcurrentHashMap<Integer, BehaviorStatusCodeResultModel>());
|
||||||
}
|
}
|
||||||
if (!this.getIdUrlMap().containsKey(behaviorBriefModel.getBehaviorId())) {
|
if (!this.getIdUrlMap().containsKey(behaviorBriefModel.getBehaviorId())) {
|
||||||
this.getIdUrlMap().put(behaviorBriefModel.getBehaviorId(),
|
this.getIdUrlMap().put(behaviorBriefModel.getBehaviorId(),
|
||||||
|
|
|
@ -1,10 +1,17 @@
|
||||||
package org.bench4q.master.unitTest.datastatistics;
|
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;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class BehaviorsBriefStatisticsTest {
|
public class BehaviorsBriefStatisticsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testAddNull() {
|
public void testAddNull() {
|
||||||
|
BehaviorsBriefStatistics behaviorsBriefStatistics = new BehaviorsBriefStatistics();
|
||||||
|
AgentBehaviorsBriefModel dataUnit = new AgentBehaviorsBriefModel();
|
||||||
|
behaviorsBriefStatistics.add(dataUnit);
|
||||||
|
System.out.println(MarshalHelper.tryMarshal(behaviorsBriefStatistics
|
||||||
|
.getStatistics()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package org.bench4q.share.models.agent;
|
package org.bench4q.share.models.agent;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
@ -60,4 +62,7 @@ public class BehaviorBriefModel {
|
||||||
this.successfulCount = successfulCount;
|
this.successfulCount = successfulCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BehaviorBriefModel() {
|
||||||
|
this.setDetailStatusCodeResultModels(new LinkedList<BehaviorStatusCodeResultModel>());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,4 +76,39 @@ public class BehaviorStatusCodeResultModel {
|
||||||
this.totalResponseTimeThisTime = totalResponseTimeThisTime;
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.bench4q.share.models.agent.statistics;
|
package org.bench4q.share.models.agent.statistics;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
@ -23,4 +24,7 @@ public class AgentBehaviorsBriefModel extends DataStatisticsModel {
|
||||||
this.behaviorBriefModels = behaviorBriefModels;
|
this.behaviorBriefModels = behaviorBriefModels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AgentBehaviorsBriefModel() {
|
||||||
|
this.setBehaviorBriefModels(new LinkedList<BehaviorBriefModel>());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue