parent
2b1fdb9f17
commit
a703ecc65c
|
@ -1,52 +0,0 @@
|
|||
package org.bench4q.agent.datacollector.impl;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class BehaviorStatusCodeResult {
|
||||
public long count;
|
||||
public long contentLength;
|
||||
public long minResponseTime;
|
||||
public long maxResponseTime;
|
||||
public long totalResponseTimeThisTime;
|
||||
public String contentType;
|
||||
|
||||
public BehaviorStatusCodeResult(String contentType) {
|
||||
this.totalResponseTimeThisTime = 0;
|
||||
this.contentType = contentType;
|
||||
this.count = 0;
|
||||
this.contentLength = 0;
|
||||
this.minResponseTime = Long.MAX_VALUE;
|
||||
this.maxResponseTime = Long.MIN_VALUE;
|
||||
}
|
||||
|
||||
public static boolean isSuccess(int statusCode) {
|
||||
return statusCode == 200;
|
||||
}
|
||||
|
||||
public boolean equals(Object expectedObj) {
|
||||
Field[] fields = this.getClass().getDeclaredFields();
|
||||
boolean equal = true;
|
||||
try {
|
||||
for (Field field : fields) {
|
||||
field.setAccessible(true);
|
||||
if (field.getName().equals("contentType")) {
|
||||
field.get(expectedObj).equals(field.get(this));
|
||||
continue;
|
||||
}
|
||||
if (field.getLong(this) != field.getLong(expectedObj)) {
|
||||
System.out.println(field.getName()
|
||||
+ " is diferent, this is " + field.getLong(this)
|
||||
+ ", and the expected is "
|
||||
+ field.getLong(expectedObj));
|
||||
equal = false;
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
equal = false;
|
||||
|
||||
}
|
||||
return equal;
|
||||
}
|
||||
}
|
|
@ -1,165 +0,0 @@
|
|||
package org.bench4q.agent.test.datastatistics;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.agent.datacollector.DataCollector;
|
||||
import org.bench4q.agent.datacollector.impl.ScenarioResultCollector;
|
||||
import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResult;
|
||||
import org.bench4q.agent.scenario.engine.BehaviorResult;
|
||||
import org.bench4q.agent.storage.StorageHelper;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class DetailStatisticsTest {
|
||||
private DataCollector detailStatistics;
|
||||
|
||||
private DataCollector getDetailStatistics() {
|
||||
return detailStatistics;
|
||||
}
|
||||
|
||||
private void setDetailStatistics(DataCollector detailStatistics) {
|
||||
this.detailStatistics = detailStatistics;
|
||||
}
|
||||
|
||||
public DetailStatisticsTest() {
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
@SuppressWarnings("resource")
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"classpath*:/org/bench4q/agent/config/application-context.xml");
|
||||
ScenarioResultCollector agentResultDataCollector = new ScenarioResultCollector(
|
||||
UUID.randomUUID());
|
||||
agentResultDataCollector.setStorageHelper((StorageHelper) context
|
||||
.getBean(StorageHelper.class));
|
||||
this.setDetailStatistics(agentResultDataCollector);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addZeroTest() {
|
||||
for (BehaviorResult behaviorResult : ScenarioStatisticsTest
|
||||
.makeBehaviorListWhoseBehaviorIdIsOne(0)) {
|
||||
this.getDetailStatistics().add(behaviorResult);
|
||||
}
|
||||
|
||||
Object object = this.detailStatistics.getBehaviorBriefStatistics(0);
|
||||
assertEquals(null, object);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addOneDetailTest() {
|
||||
for (BehaviorResult behaviorResult : ScenarioStatisticsTest
|
||||
.makeBehaviorListWhoseBehaviorIdIsOne(1)) {
|
||||
this.getDetailStatistics().add(behaviorResult);
|
||||
}
|
||||
Map<Integer, BehaviorStatusCodeResult> map = this.detailStatistics
|
||||
.getBehaviorBriefStatistics(1);
|
||||
|
||||
BehaviorStatusCodeResult actualResult = map.get(200);
|
||||
assertTrue(actualResult.equals(makeExpectedResultForOne()));
|
||||
}
|
||||
|
||||
private BehaviorStatusCodeResult makeExpectedResultForOne() {
|
||||
BehaviorStatusCodeResult ret = new BehaviorStatusCodeResult("");
|
||||
ret.contentLength = 20;
|
||||
ret.count = 1;
|
||||
ret.maxResponseTime = 200;
|
||||
ret.minResponseTime = 200;
|
||||
ret.totalResponseTimeThisTime = 200;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addTwoDetailTest() {
|
||||
for (BehaviorResult behaviorResult : ScenarioStatisticsTest
|
||||
.makeBehaviorListWhoseBehaviorIdIsOne(2)) {
|
||||
this.getDetailStatistics().add(behaviorResult);
|
||||
}
|
||||
Map<Integer, BehaviorStatusCodeResult> map = this.detailStatistics
|
||||
.getBehaviorBriefStatistics(1);
|
||||
assertTrue(mapEquals(map, makeExpectedMapForTwo()));
|
||||
}
|
||||
|
||||
private Map<Integer, BehaviorStatusCodeResult> makeExpectedMapForTwo() {
|
||||
Map<Integer, BehaviorStatusCodeResult> ret = new HashMap<Integer, BehaviorStatusCodeResult>();
|
||||
ret.put(new Integer(200), buildCodeResult(20, 1, 200, 200, 200));
|
||||
ret.put(new Integer(400),
|
||||
buildCodeResult(0, 1, Long.MIN_VALUE, Long.MAX_VALUE, 0));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addFourDetailTest() {
|
||||
for (BehaviorResult behaviorResult : ScenarioStatisticsTest
|
||||
.makeBehaviorListWhoseBehaviorIdIsOne(4)) {
|
||||
this.getDetailStatistics().add(behaviorResult);
|
||||
}
|
||||
Map<Integer, BehaviorStatusCodeResult> map = this.detailStatistics
|
||||
.getBehaviorBriefStatistics(1);
|
||||
assertTrue(mapEquals(map, makeExpectedMapForFour()));
|
||||
|
||||
}
|
||||
|
||||
private Map<Integer, BehaviorStatusCodeResult> makeExpectedMapForFour() {
|
||||
Map<Integer, BehaviorStatusCodeResult> ret = new HashMap<Integer, BehaviorStatusCodeResult>();
|
||||
ret.put(new Integer(200), buildCodeResult(40, 2, 220, 200, 420));
|
||||
ret.put(new Integer(400),
|
||||
buildCodeResult(0, 2, Long.MIN_VALUE, Long.MAX_VALUE, 0));
|
||||
return ret;
|
||||
}
|
||||
|
||||
private BehaviorStatusCodeResult buildCodeResult(long contentLength,
|
||||
long count, long maxResponseTime, long minResponseTime,
|
||||
long totalResponseTimeThisTime) {
|
||||
BehaviorStatusCodeResult ret = new BehaviorStatusCodeResult("");
|
||||
ret.contentLength = contentLength;
|
||||
ret.count = count;
|
||||
ret.maxResponseTime = maxResponseTime;
|
||||
ret.minResponseTime = minResponseTime;
|
||||
ret.totalResponseTimeThisTime = totalResponseTimeThisTime;
|
||||
return ret;
|
||||
}
|
||||
|
||||
private boolean mapEquals(Map<Integer, BehaviorStatusCodeResult> mapActual,
|
||||
Map<Integer, BehaviorStatusCodeResult> mapExpected) {
|
||||
boolean equal = true;
|
||||
if (mapActual.size() != mapExpected.size()) {
|
||||
return false;
|
||||
}
|
||||
for (int i : mapActual.keySet()) {
|
||||
if (!mapActual.get(i).equals(mapExpected.get(i))) {
|
||||
equal = false;
|
||||
}
|
||||
}
|
||||
return equal;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addThreeTest() {
|
||||
for (BehaviorResult behaviorResult : ScenarioStatisticsTest
|
||||
.makeBehaviorListWhoseBehaviorIdIsOne(3)) {
|
||||
this.getDetailStatistics().add(behaviorResult);
|
||||
}
|
||||
Map<Integer, BehaviorStatusCodeResult> mapActual = this
|
||||
.getDetailStatistics().getBehaviorBriefStatistics(1);
|
||||
assertTrue(mapEquals(mapActual, makeExpectedMapForThree()));
|
||||
}
|
||||
|
||||
private Map<Integer, BehaviorStatusCodeResult> makeExpectedMapForThree() {
|
||||
Map<Integer, BehaviorStatusCodeResult> retMap = new HashMap<Integer, BehaviorStatusCodeResult>();
|
||||
retMap.put(200, buildCodeResult(40, 2, 220, 200, 420));
|
||||
retMap.put(400,
|
||||
buildCodeResult(0, 1, Long.MIN_VALUE, Long.MAX_VALUE, 0));
|
||||
return retMap;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_addSomeSameUrlResult() {
|
||||
}
|
||||
}
|
|
@ -1,113 +0,0 @@
|
|||
package org.bench4q.master.domain.valueobject.datastatistics;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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;
|
||||
import org.bench4q.share.models.agent.statistics.AgentBehaviorsBriefModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
|
||||
|
||||
public class BehaviorsBriefStatistics extends ScriptStatistics {
|
||||
private Map<Integer, Map<Integer, BehaviorStatusCodeResultModel>> map;
|
||||
private Map<Integer, String> idUrlMap;
|
||||
|
||||
private Map<Integer, Map<Integer, BehaviorStatusCodeResultModel>> getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
private void setMap(
|
||||
Map<Integer, Map<Integer, BehaviorStatusCodeResultModel>> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
public Map<Integer, String> getIdUrlMap() {
|
||||
return idUrlMap;
|
||||
}
|
||||
|
||||
public void setIdUrlMap(Map<Integer, String> idUrlMap) {
|
||||
this.idUrlMap = idUrlMap;
|
||||
}
|
||||
|
||||
public BehaviorsBriefStatistics() {
|
||||
this.setMap(new ConcurrentHashMap<Integer, Map<Integer, BehaviorStatusCodeResultModel>>());
|
||||
this.setIdUrlMap(new ConcurrentHashMap<Integer, String>());
|
||||
}
|
||||
|
||||
public ScriptBehaviorsBriefModel getStatistics() {
|
||||
ScriptBehaviorsBriefModel result = new ScriptBehaviorsBriefModel();
|
||||
AgentBehaviorsBriefModel agentBehaviorsBriefModel = new AgentBehaviorsBriefModel();
|
||||
List<BehaviorBriefModel> list = new ArrayList<BehaviorBriefModel>();
|
||||
for (int behaviorId : this.getMap().keySet()) {
|
||||
BehaviorBriefModel behaviorBriefModel = new BehaviorBriefModel();
|
||||
behaviorBriefModel.setBehaviorId(behaviorId);
|
||||
behaviorBriefModel.setBehaviorUrl(this.getIdUrlMap()
|
||||
.get(behaviorId));
|
||||
List<BehaviorStatusCodeResultModel> statusList = new ArrayList<BehaviorStatusCodeResultModel>();
|
||||
for (int statusCode : this.getMap().get(behaviorId).keySet()) {
|
||||
statusList.add(this.getMap().get(behaviorId).get(statusCode)
|
||||
.getCopy());
|
||||
}
|
||||
behaviorBriefModel.setDetailStatusCodeResultModels(statusList);
|
||||
this.setBehaviorCount(behaviorBriefModel);
|
||||
list.add(behaviorBriefModel);
|
||||
}
|
||||
agentBehaviorsBriefModel.setBehaviorBriefModels(list);
|
||||
result.setBehaviorBriefModels(agentBehaviorsBriefModel
|
||||
.getBehaviorBriefModels());
|
||||
makeUpResultModelWithSamplingTime(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void setBehaviorCount(BehaviorBriefModel behaviorBriefModel) {
|
||||
long totalCount = 0, successfulCount = 0;
|
||||
for (BehaviorStatusCodeResultModel behaviorStatusCodeResultModel : behaviorBriefModel
|
||||
.getDetailStatusCodeResultModels()) {
|
||||
totalCount += behaviorStatusCodeResultModel.getCount();
|
||||
if (behaviorStatusCodeResultModel.isSuccess()) {
|
||||
successfulCount += behaviorStatusCodeResultModel.getCount();
|
||||
}
|
||||
}
|
||||
behaviorBriefModel.setTotalCount(totalCount);
|
||||
behaviorBriefModel.setSuccessfulCount(successfulCount);
|
||||
}
|
||||
|
||||
public void add(DataStatisticsModel dataUnit) {
|
||||
if (!(dataUnit instanceof AgentBehaviorsBriefModel)) {
|
||||
return;
|
||||
}
|
||||
AgentBehaviorsBriefModel input = (AgentBehaviorsBriefModel) dataUnit;
|
||||
for (BehaviorBriefModel behaviorBriefModel : input
|
||||
.getBehaviorBriefModels()) {
|
||||
guardAllMapsKeyExists(behaviorBriefModel);
|
||||
Map<Integer, BehaviorStatusCodeResultModel> behaviorStatusMap = this
|
||||
.getMap().get(behaviorBriefModel.getBehaviorId());
|
||||
for (BehaviorStatusCodeResultModel newOne : behaviorBriefModel
|
||||
.getDetailStatusCodeResultModels()) {
|
||||
if (!behaviorStatusMap.containsKey(newOne.getStatusCode())) {
|
||||
behaviorStatusMap.put(newOne.getStatusCode(), newOne);
|
||||
continue;
|
||||
}
|
||||
BehaviorStatusCodeResultModel origin = behaviorStatusMap
|
||||
.get(newOne.getStatusCode());
|
||||
origin.plus(newOne);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void guardAllMapsKeyExists(
|
||||
BehaviorBriefModel behaviorBriefModel) {
|
||||
if (!this.getMap().containsKey(behaviorBriefModel.getBehaviorId())) {
|
||||
this.getMap()
|
||||
.put(behaviorBriefModel.getBehaviorId(),
|
||||
new ConcurrentHashMap<Integer, BehaviorStatusCodeResultModel>());
|
||||
}
|
||||
if (!this.getIdUrlMap().containsKey(behaviorBriefModel.getBehaviorId())) {
|
||||
this.getIdUrlMap().put(behaviorBriefModel.getBehaviorId(),
|
||||
behaviorBriefModel.getBehaviorUrl());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
package org.bench4q.master.domain.valueobject.datastatistics;
|
||||
|
||||
import org.bench4q.share.models.agent.statistics.AgentPageBriefModel;
|
||||
import org.bench4q.share.models.agent.statistics.DataStatisticsModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptPageBriefModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author coderfengyun :This class is only statistics for One page, should
|
||||
* construct it once each page;
|
||||
* @Tip countFromBegin : Because of the statistics means that just accumulate
|
||||
* the "countFromBegin" field of AgentPageBriefModel, so I can just take it
|
||||
* as a temperary field for this class
|
||||
*/
|
||||
public class PageBriefStatistics extends ScriptStatistics {
|
||||
private long countFromBegin;
|
||||
private long maxResponseTimeFromBegin;
|
||||
private long minResponseTimeFromBegin;
|
||||
private long totalResponseTimeThisTime;
|
||||
private long countThisTime;
|
||||
private long latestResponseTime;
|
||||
|
||||
public PageBriefStatistics() {
|
||||
resetTemperaryFields();
|
||||
this.maxResponseTimeFromBegin = Long.MIN_VALUE;
|
||||
this.minResponseTimeFromBegin = Long.MAX_VALUE;
|
||||
}
|
||||
|
||||
private void resetTemperaryFields() {
|
||||
this.totalResponseTimeThisTime = 0;
|
||||
this.countThisTime = 0;
|
||||
this.countFromBegin = 0;
|
||||
}
|
||||
|
||||
public void add(DataStatisticsModel dataUnit) {
|
||||
if (!(dataUnit instanceof AgentPageBriefModel)) {
|
||||
return;
|
||||
}
|
||||
add((AgentPageBriefModel) dataUnit);
|
||||
}
|
||||
|
||||
private void add(AgentPageBriefModel pageBriefModel) {
|
||||
this.countFromBegin += pageBriefModel.getCountFromBegin();
|
||||
this.countThisTime += pageBriefModel.getCountThisTime();
|
||||
this.totalResponseTimeThisTime += pageBriefModel
|
||||
.getTotalResponseTimeThisTime();
|
||||
this.latestResponseTime = pageBriefModel.getLatestResponseTime();
|
||||
if (pageBriefModel.getMaxResponseTimeFromBegin() > this.maxResponseTimeFromBegin) {
|
||||
this.maxResponseTimeFromBegin = pageBriefModel
|
||||
.getMaxResponseTimeFromBegin();
|
||||
}
|
||||
if (pageBriefModel.getMinResponseTimeFromBegin() < this.minResponseTimeFromBegin) {
|
||||
this.minResponseTimeFromBegin = pageBriefModel
|
||||
.getMinResponseTimeFromBegin();
|
||||
}
|
||||
}
|
||||
|
||||
public Object getStatistics() {
|
||||
ScriptPageBriefModel result = new ScriptPageBriefModel();
|
||||
result.setCountFromBegin(this.countFromBegin);
|
||||
result.setLatestResponseTime(this.latestResponseTime);
|
||||
result.setMaxResponseTimeFromBegin(this.maxResponseTimeFromBegin);
|
||||
result.setMinResponseTimeFromBegin(this.minResponseTimeFromBegin);
|
||||
if (this.countThisTime > 0) {
|
||||
result.setAverageResponseTimeThisTime(this.totalResponseTimeThisTime
|
||||
/ this.countThisTime);
|
||||
}
|
||||
resetTemperaryFields();
|
||||
makeUpResultModelWithSamplingTime(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
package org.bench4q.master.domain.valueobject.datastatistics;
|
||||
|
||||
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;
|
||||
import org.bench4q.share.models.agent.statistics.DataStatisticsModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptPageBriefModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptPagesBriefModel;
|
||||
|
||||
public class PagesBriefStatistics extends ScriptStatistics {
|
||||
private Map<Integer, PageBriefStatistics> map;
|
||||
|
||||
private Map<Integer, PageBriefStatistics> getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
private void setMap(Map<Integer, PageBriefStatistics> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
public PagesBriefStatistics() {
|
||||
this.setMap(new ConcurrentHashMap<Integer, PageBriefStatistics>());
|
||||
}
|
||||
|
||||
public void add(DataStatisticsModel dataUnit) {
|
||||
if (dataUnit instanceof AgentPagesBriefModel) {
|
||||
add((AgentPagesBriefModel) dataUnit);
|
||||
}
|
||||
}
|
||||
|
||||
private void add(AgentPagesBriefModel agentPagesBriefModel) {
|
||||
for (AgentPageBriefModel unit : agentPagesBriefModel
|
||||
.getPageBriefModels()) {
|
||||
int key = unit.getPageId();
|
||||
if (!this.getMap().containsKey(key)) {
|
||||
guardMapKeyExists(key);
|
||||
}
|
||||
this.getMap().get(key).add(unit);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void guardMapKeyExists(int key) {
|
||||
if (!this.getMap().containsKey(key)) {
|
||||
this.getMap().put(key, new PageBriefStatistics());
|
||||
}
|
||||
}
|
||||
|
||||
public Object getStatistics() {
|
||||
ScriptPagesBriefModel scriptPagesBriefModel = new ScriptPagesBriefModel();
|
||||
for (Integer key : this.getMap().keySet()) {
|
||||
scriptPagesBriefModel.getScriptPageBriefModels().add(
|
||||
(ScriptPageBriefModel) this.getMap().get(key)
|
||||
.getStatistics());
|
||||
}
|
||||
return scriptPagesBriefModel;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,214 +0,0 @@
|
|||
package org.bench4q.master.domain.valueobject.datastatistics;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
|
||||
import org.bench4q.share.models.agent.statistics.DataStatisticsModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
||||
|
||||
public class ScriptBriefStatistics extends ScriptStatistics {
|
||||
private long totalFailCountThisTime;
|
||||
private long totalSuccessCountThisTime;
|
||||
private long totalSquareResponseTime;
|
||||
private long totalFailThroughputThisTime;
|
||||
private long totalSuccessThroughputThisTime;
|
||||
private long minResponseTimeThisTime;
|
||||
private long maxResponseTimeThisTime;
|
||||
private long totalResponseTimeThisTime;
|
||||
private long totalFailCountFromBegin;
|
||||
private long totalSuccessCountFromBegin;
|
||||
|
||||
private long totalElapsedTime;
|
||||
private long activeVUserCountThisTime;
|
||||
private long effectiveCount;
|
||||
|
||||
private ScriptBriefResultModel lastValidBriefResultModel;
|
||||
|
||||
private void setTotalFailCountThisTime(long totalFailCountThisTime) {
|
||||
this.totalFailCountThisTime = totalFailCountThisTime;
|
||||
}
|
||||
|
||||
private void setTotalSuccessCountThisTime(long totalSuccessCountThisTime) {
|
||||
this.totalSuccessCountThisTime = totalSuccessCountThisTime;
|
||||
}
|
||||
|
||||
private void setTotalSquareResponseTime(long totalSquareResponseTime) {
|
||||
this.totalSquareResponseTime = totalSquareResponseTime;
|
||||
}
|
||||
|
||||
private void setTotalFailThroughputThisTime(long totalFailThroughputThisTime) {
|
||||
this.totalFailThroughputThisTime = totalFailThroughputThisTime;
|
||||
}
|
||||
|
||||
private void setTotalSuccessThroughputThisTime(
|
||||
long totalSuccessThroughputThisTime) {
|
||||
this.totalSuccessThroughputThisTime = totalSuccessThroughputThisTime;
|
||||
}
|
||||
|
||||
private void setMinResponseTimeThisTime(long minResponseTimeThisTime) {
|
||||
this.minResponseTimeThisTime = minResponseTimeThisTime;
|
||||
}
|
||||
|
||||
private void setMaxResponseTimeThisTime(long maxResponseTimeThisTime) {
|
||||
this.maxResponseTimeThisTime = maxResponseTimeThisTime;
|
||||
}
|
||||
|
||||
private void setTotalResponseTimeThisTime(long totalResponseTimeThisTime) {
|
||||
this.totalResponseTimeThisTime = totalResponseTimeThisTime;
|
||||
}
|
||||
|
||||
private void setTotalFailCountFromBegin(long totalFailCountFromBegin) {
|
||||
this.totalFailCountFromBegin = totalFailCountFromBegin;
|
||||
}
|
||||
|
||||
private void setTotalSuccessCoutFromBegin(long totalSuccessCoutFromBegin) {
|
||||
this.totalSuccessCountFromBegin = totalSuccessCoutFromBegin;
|
||||
}
|
||||
|
||||
private void setTotalElapsedTime(long totalElapsedTime) {
|
||||
this.totalElapsedTime = totalElapsedTime;
|
||||
}
|
||||
|
||||
private void setActiveVUserCountThisTime(long activeVUserCountThisTime) {
|
||||
this.activeVUserCountThisTime = activeVUserCountThisTime;
|
||||
}
|
||||
|
||||
private void setEffectiveCounte(long effetiveCount) {
|
||||
this.effectiveCount = effetiveCount;
|
||||
}
|
||||
|
||||
private ScriptBriefResultModel getLastValidBriefResultModel() {
|
||||
return lastValidBriefResultModel;
|
||||
}
|
||||
|
||||
private void setLastValidBriefResultModel(
|
||||
ScriptBriefResultModel lastValidBriefResultModel) {
|
||||
this.lastValidBriefResultModel = lastValidBriefResultModel;
|
||||
}
|
||||
|
||||
public ScriptBriefStatistics() {
|
||||
reset();
|
||||
initLastValidBriefResultModel();
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
this.setTotalFailCountFromBegin(0);
|
||||
this.setTotalFailCountThisTime(0);
|
||||
this.setTotalFailThroughputThisTime(0);
|
||||
this.setTotalResponseTimeThisTime(0);
|
||||
this.setTotalSquareResponseTime(0);
|
||||
this.setTotalSuccessCountThisTime(0);
|
||||
this.setTotalSuccessCoutFromBegin(0);
|
||||
this.setTotalSuccessThroughputThisTime(0);
|
||||
this.setTotalElapsedTime(0);
|
||||
this.setEffectiveCounte(0);
|
||||
this.setMaxResponseTimeThisTime(Long.MIN_VALUE);
|
||||
this.setMinResponseTimeThisTime(Long.MAX_VALUE);
|
||||
this.setActiveVUserCountThisTime(0);
|
||||
}
|
||||
|
||||
private void initLastValidBriefResultModel() {
|
||||
ScriptBriefResultModel initBriefModel = new ScriptBriefResultModel();
|
||||
initBriefModel.setAverageElapsedTime(0);
|
||||
initBriefModel.setAverageResponseTime(0);
|
||||
initBriefModel.setFailRateThisTime(0);
|
||||
initBriefModel.setFailThroughputThisTime(0);
|
||||
initBriefModel.setFinished(false);
|
||||
initBriefModel.setMaxResponseTime(0);
|
||||
initBriefModel.setMinResponseTime(0);
|
||||
initBriefModel.setPlanedRunningTime(0);
|
||||
initBriefModel.setResponseTimeDeviationThisTime(0);
|
||||
initBriefModel.setSuccessThroughputThisTime(0);
|
||||
initBriefModel.setTotalFailCountFromBegin(0);
|
||||
initBriefModel.setTotalSuccessCountFromBegin(0);
|
||||
this.setLastValidBriefResultModel(initBriefModel);
|
||||
}
|
||||
|
||||
public void add(DataStatisticsModel dataUnit) {
|
||||
if (!(dataUnit instanceof AgentBriefStatusModel)) {
|
||||
return;
|
||||
}
|
||||
add((AgentBriefStatusModel) dataUnit);
|
||||
}
|
||||
|
||||
private void add(AgentBriefStatusModel briefModel) {
|
||||
if (briefModel == null) {
|
||||
return;
|
||||
}
|
||||
this.effectiveCount++;
|
||||
if (briefModel.getMaxResponseTime() > this.maxResponseTimeThisTime) {
|
||||
this.setMaxResponseTimeThisTime(briefModel.getMaxResponseTime());
|
||||
}
|
||||
if (briefModel.getMinResponseTime() < this.minResponseTimeThisTime) {
|
||||
this.setMinResponseTimeThisTime(briefModel.getMinResponseTime());
|
||||
}
|
||||
this.totalFailCountFromBegin += briefModel.getFailCountFromBegin();
|
||||
this.totalFailCountThisTime += briefModel.getFailCountThisTime();
|
||||
this.totalFailThroughputThisTime += briefModel
|
||||
.getFailThroughputThisTime();
|
||||
this.totalResponseTimeThisTime += briefModel
|
||||
.getTotalResponseTimeThisTime();
|
||||
this.totalSquareResponseTime += briefModel
|
||||
.getTotalSqureResponseTimeThisTime();
|
||||
this.totalSuccessCountThisTime += briefModel.getSuccessCountThisTime();
|
||||
this.totalSuccessCountFromBegin += briefModel
|
||||
.getSuccessCountFromBegin();
|
||||
this.totalSuccessThroughputThisTime += briefModel
|
||||
.getSuccessThroughputThisTime();
|
||||
this.activeVUserCountThisTime += briefModel.getvUserCount();
|
||||
}
|
||||
|
||||
public ScriptBriefResultModel getStatistics() {
|
||||
ScriptBriefResultModel result = new ScriptBriefResultModel();
|
||||
long averageResponseTime = 0;
|
||||
if (this.totalSuccessCountThisTime == 0) {
|
||||
result.setAverageResponseTime(0);
|
||||
result.setMaxResponseTime(0);
|
||||
result.setMinResponseTime(0);
|
||||
result.setResponseTimeDeviationThisTime(0);
|
||||
if (this.totalFailCountThisTime == 0) {
|
||||
result.setFailRateThisTime(0);
|
||||
} else {
|
||||
result.setFailRateThisTime(100);
|
||||
}
|
||||
} else {
|
||||
averageResponseTime = this.totalResponseTimeThisTime
|
||||
/ this.totalSuccessCountThisTime;
|
||||
result.setAverageResponseTime(averageResponseTime);
|
||||
result.setMaxResponseTime(this.maxResponseTimeThisTime);
|
||||
result.setMinResponseTime(this.minResponseTimeThisTime);
|
||||
result.setResponseTimeDeviationThisTime(Math.round(Math
|
||||
.sqrt(this.totalSquareResponseTime
|
||||
/ this.totalSuccessCountThisTime
|
||||
- averageResponseTime * averageResponseTime)));
|
||||
result.setFailRateThisTime(this.totalFailCountThisTime
|
||||
* 100
|
||||
/ (this.totalFailCountThisTime + this.totalSuccessCountThisTime));
|
||||
}
|
||||
result.setFailThroughputThisTime(this.totalFailThroughputThisTime);
|
||||
result.setSuccessThroughputThisTime(this.totalSuccessThroughputThisTime);
|
||||
result.setTotalFailCountFromBegin(this.totalFailCountFromBegin);
|
||||
result.setTotalSuccessCountFromBegin(this.totalSuccessCountFromBegin);
|
||||
if (this.effectiveCount == 0) {
|
||||
result.setAverageElapsedTime(0);
|
||||
} else {
|
||||
result.setAverageElapsedTime(this.totalElapsedTime
|
||||
/ this.effectiveCount);
|
||||
}
|
||||
result = dealWithInvalidSamplePoint(result);
|
||||
result.setSamplingTime(new Date());
|
||||
result.setvUserCount(this.activeVUserCountThisTime);
|
||||
reset();
|
||||
return result;
|
||||
}
|
||||
|
||||
private ScriptBriefResultModel dealWithInvalidSamplePoint(
|
||||
ScriptBriefResultModel inputModel) {
|
||||
if (this.totalSuccessCountFromBegin == 0
|
||||
&& this.totalFailCountFromBegin == 0) {
|
||||
return this.getLastValidBriefResultModel();
|
||||
}
|
||||
this.setLastValidBriefResultModel(inputModel);
|
||||
return inputModel;
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package org.bench4q.master.domain.valueobject.datastatistics;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.bench4q.share.models.master.statistics.SampleModel;
|
||||
|
||||
public abstract class ScriptStatistics implements DataStatistics {
|
||||
protected void makeUpResultModelWithSamplingTime(
|
||||
SampleModel resultModel) {
|
||||
resultModel.setSamplingTime(new Date());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue