add behaviorResultCollector and behaviorStatusResultCollector
add behaviorResultCollector and behaviorStatusResultCollector
This commit is contained in:
parent
19170fd438
commit
2b1fdb9f17
|
@ -2,11 +2,9 @@ package org.bench4q.agent.api;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResult;
|
||||
import org.bench4q.agent.plugin.ParameterFileCollector;
|
||||
import org.bench4q.agent.scenario.Scenario;
|
||||
import org.bench4q.agent.scenario.behavior.Behavior;
|
||||
|
@ -15,7 +13,6 @@ import org.bench4q.agent.scenario.engine.ScenarioEngine;
|
|||
import org.bench4q.agent.scenario.engine.Schedule;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.agent.BehaviorBriefModel;
|
||||
import org.bench4q.share.models.agent.BehaviorStatusCodeResultModel;
|
||||
import org.bench4q.share.models.agent.CleanTestResultModel;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
import org.bench4q.share.models.agent.RunScenarioResultModel;
|
||||
|
@ -127,50 +124,6 @@ public class TestController {
|
|||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/brief/{runId}/{behaviorId}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public BehaviorBriefModel behaviorBrief(@PathVariable UUID runId,
|
||||
@PathVariable int behaviorId) {
|
||||
ScenarioContext scenarioContext = this.getScenarioEngine()
|
||||
.getRunningTests().get(runId);
|
||||
if (scenarioContext == null) {
|
||||
return null;
|
||||
}
|
||||
Map<Integer, BehaviorStatusCodeResult> map = scenarioContext
|
||||
.getDataStatistics().getBehaviorBriefStatistics(behaviorId);
|
||||
return buildBehaviorBrief(runId, behaviorId, "", map);
|
||||
}
|
||||
|
||||
private BehaviorBriefModel buildBehaviorBrief(UUID runId, int behaviorId,
|
||||
String behaviorUrl, Map<Integer, BehaviorStatusCodeResult> map) {
|
||||
List<BehaviorStatusCodeResultModel> detailStatusCodeResultModels = new ArrayList<BehaviorStatusCodeResultModel>();
|
||||
for (int statusCode : map.keySet()) {
|
||||
BehaviorStatusCodeResultModel behaviorStatusCodeResultModel = new BehaviorStatusCodeResultModel();
|
||||
BehaviorStatusCodeResult detailStatusCodeResult = map
|
||||
.get(statusCode);
|
||||
behaviorStatusCodeResultModel.setStatusCode(statusCode);
|
||||
behaviorStatusCodeResultModel
|
||||
.setCount(detailStatusCodeResult.count);
|
||||
behaviorStatusCodeResultModel
|
||||
.setContentLength(detailStatusCodeResult.contentLength);
|
||||
behaviorStatusCodeResultModel
|
||||
.setMinResponseTime(detailStatusCodeResult.minResponseTime);
|
||||
behaviorStatusCodeResultModel
|
||||
.setMaxResponseTime(detailStatusCodeResult.maxResponseTime);
|
||||
behaviorStatusCodeResultModel
|
||||
.setContentType(detailStatusCodeResult.contentType);
|
||||
behaviorStatusCodeResultModel
|
||||
.setTotalResponseTimeThisTime(detailStatusCodeResult.totalResponseTimeThisTime);
|
||||
detailStatusCodeResultModels.add(behaviorStatusCodeResultModel);
|
||||
}
|
||||
BehaviorBriefModel behaviorBriefModel = new BehaviorBriefModel();
|
||||
behaviorBriefModel.setBehaviorId(behaviorId);
|
||||
behaviorBriefModel
|
||||
.setDetailStatusCodeResultModels(detailStatusCodeResultModels);
|
||||
behaviorBriefModel.setBehaviorUrl(behaviorUrl);
|
||||
return behaviorBriefModel;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/pagesBrief/{runId}")
|
||||
@ResponseBody
|
||||
public AgentPagesBriefModel pagesBrief(@PathVariable UUID runId) {
|
||||
|
@ -190,19 +143,6 @@ public class TestController {
|
|||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/pageBrief/{runId}/{pageId}")
|
||||
@ResponseBody
|
||||
public AgentPageBriefModel pageBrief(@PathVariable UUID runId,
|
||||
@PathVariable int pageId) {
|
||||
ScenarioContext context = this.getScenarioEngine().getRunningTests()
|
||||
.get(runId);
|
||||
if (context == null) {
|
||||
return null;
|
||||
}
|
||||
return (AgentPageBriefModel) context.getDataStatistics()
|
||||
.getPageBriefStatistics(pageId);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/behaviorsBrief/{runId}")
|
||||
@ResponseBody
|
||||
public AgentBehaviorsBriefModel behaviorsBrief(@PathVariable UUID runId) {
|
||||
|
@ -215,14 +155,10 @@ public class TestController {
|
|||
}
|
||||
for (Behavior behavior : scenarioContext.getScenario()
|
||||
.getAllBehaviors()) {
|
||||
int behaviorId = behavior.getId();
|
||||
Map<Integer, BehaviorStatusCodeResult> map = behavior
|
||||
BehaviorBriefModel briefModel = behavior
|
||||
.getBehaviorBriefResult(scenarioContext.getDataStatistics());
|
||||
if (map == null) {
|
||||
continue;
|
||||
}
|
||||
behaviorBriefModels.add(buildBehaviorBrief(runId, behaviorId,
|
||||
behavior.getSpecificParamValue("url"), map));
|
||||
briefModel.setBehaviorUrl(behavior.getSpecificParamValue("url"));
|
||||
behaviorBriefModels.add(briefModel);
|
||||
}
|
||||
ret.setBehaviorBriefModels(behaviorBriefModels);
|
||||
return ret;
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package org.bench4q.agent.datacollector;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResult;
|
||||
import org.bench4q.agent.scenario.engine.BehaviorResult;
|
||||
import org.bench4q.agent.scenario.engine.PageResult;
|
||||
import org.bench4q.share.models.agent.BehaviorBriefModel;
|
||||
|
||||
public interface DataCollector {
|
||||
public void add(BehaviorResult behaviorResult);
|
||||
|
@ -13,7 +11,7 @@ public interface DataCollector {
|
|||
|
||||
public Object getScenarioBriefStatistics();
|
||||
|
||||
public Map<Integer, BehaviorStatusCodeResult> getBehaviorBriefStatistics(
|
||||
public BehaviorBriefModel getBehaviorBriefStatistics(
|
||||
int behaviorId);
|
||||
|
||||
public Object getPageBriefStatistics(int pageId);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.bench4q.agent.datacollector.impl;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
|
@ -9,6 +8,7 @@ import org.bench4q.agent.datacollector.DataCollector;
|
|||
import org.bench4q.agent.helper.ApplicationContextHelper;
|
||||
import org.bench4q.agent.scenario.engine.BehaviorResult;
|
||||
import org.bench4q.agent.storage.StorageHelper;
|
||||
import org.bench4q.share.models.agent.BehaviorBriefModel;
|
||||
import org.bench4q.share.models.agent.BehaviorResultModel;
|
||||
|
||||
public abstract class AbstractDataCollector implements DataCollector {
|
||||
|
@ -76,7 +76,7 @@ public abstract class AbstractDataCollector implements DataCollector {
|
|||
|
||||
public abstract Object getScenarioBriefStatistics();
|
||||
|
||||
public abstract Map<Integer, BehaviorStatusCodeResult> getBehaviorBriefStatistics(
|
||||
public abstract BehaviorBriefModel getBehaviorBriefStatistics(
|
||||
int id);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,62 @@
|
|||
package org.bench4q.agent.datacollector.impl;
|
||||
|
||||
public class BehaviorResultCollector {
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bench4q.agent.scenario.engine.BehaviorResult;
|
||||
import org.bench4q.share.models.agent.BehaviorBriefModel;
|
||||
import org.bench4q.share.models.agent.BehaviorStatusCodeResultModel;
|
||||
|
||||
public class BehaviorResultCollector {
|
||||
private int behaviorId;
|
||||
private long successCountFromBegin;
|
||||
private long failCountFromBegin;
|
||||
// statusCode - BehaviorStatusCodeResultCollector
|
||||
private final Map<Integer, BehaviorStatusCodeResultCollector> detailStatusMap;
|
||||
|
||||
public BehaviorResultCollector(int behaviorId) {
|
||||
this.behaviorId = behaviorId;
|
||||
this.detailStatusMap = new HashMap<Integer, BehaviorStatusCodeResultCollector>();
|
||||
}
|
||||
|
||||
public void add(BehaviorResult behaviorResult) {
|
||||
if (behaviorResult == null
|
||||
|| behaviorResult.getBehaviorId() != this.behaviorId) {
|
||||
return;
|
||||
}
|
||||
if (!detailStatusMap.containsKey(behaviorResult.getStatusCode())) {
|
||||
guardExist(behaviorResult.getStatusCode(),
|
||||
behaviorResult.getContentType());
|
||||
}
|
||||
this.successCountFromBegin += behaviorResult.getSuccessCount();
|
||||
this.failCountFromBegin += behaviorResult.getFailCount();
|
||||
BehaviorStatusCodeResultCollector statusCodeResult = detailStatusMap
|
||||
.get(behaviorResult.getStatusCode());
|
||||
statusCodeResult.add(behaviorResult);
|
||||
}
|
||||
|
||||
private synchronized void guardExist(int statusCode, String contentType) {
|
||||
if (!this.detailStatusMap.containsKey(statusCode)) {
|
||||
this.detailStatusMap.put(statusCode,
|
||||
new BehaviorStatusCodeResultCollector(this.behaviorId,
|
||||
statusCode, contentType));
|
||||
}
|
||||
}
|
||||
|
||||
public BehaviorBriefModel getStatistics() {
|
||||
BehaviorBriefModel result = new BehaviorBriefModel();
|
||||
List<BehaviorStatusCodeResultModel> list = new LinkedList<BehaviorStatusCodeResultModel>();
|
||||
for (BehaviorStatusCodeResultCollector codeResultCollector : this.detailStatusMap
|
||||
.values()) {
|
||||
list.add(codeResultCollector.getStatistics());
|
||||
}
|
||||
result.setDetailStatusCodeResultModels(list);
|
||||
result.setBehaviorId(this.behaviorId);
|
||||
result.setTotalCount(this.successCountFromBegin
|
||||
+ this.failCountFromBegin);
|
||||
result.setSuccessfulCount(this.successCountFromBegin);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
package org.bench4q.agent.datacollector.impl;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.bench4q.agent.scenario.engine.BehaviorResult;
|
||||
import org.bench4q.share.models.agent.BehaviorStatusCodeResultModel;
|
||||
|
||||
public class BehaviorStatusCodeResultCollector {
|
||||
private int behaviorId;
|
||||
private int statusCode;
|
||||
public long count;
|
||||
public long countThisTime;
|
||||
public long contentLength;
|
||||
public long minResponseTime;
|
||||
public long maxResponseTime;
|
||||
public long totalResponseTimeThisTime;
|
||||
public String contentType;
|
||||
|
||||
public BehaviorStatusCodeResultCollector(int behaviorId, int statusCode,
|
||||
String contentType) {
|
||||
this.behaviorId = behaviorId;
|
||||
this.statusCode = statusCode;
|
||||
this.contentType = contentType;
|
||||
this.count = 0;
|
||||
this.contentLength = 0;
|
||||
this.minResponseTime = Long.MAX_VALUE;
|
||||
this.maxResponseTime = Long.MIN_VALUE;
|
||||
resetTempraryField();
|
||||
}
|
||||
|
||||
public void resetTempraryField() {
|
||||
this.countThisTime = 0;
|
||||
this.totalResponseTimeThisTime = 0;
|
||||
}
|
||||
|
||||
public static boolean isSuccess(int statusCode) {
|
||||
return statusCode == 200;
|
||||
}
|
||||
|
||||
public void add(BehaviorResult behaviorResult) {
|
||||
if (behaviorResult == null
|
||||
|| behaviorResult.getBehaviorId() != this.behaviorId
|
||||
|| behaviorResult.getStatusCode() != this.statusCode) {
|
||||
return;
|
||||
}
|
||||
this.count++;
|
||||
this.countThisTime++;
|
||||
if (behaviorResult.getSuccessCount() == 0) {
|
||||
this.contentLength += 0;
|
||||
this.totalResponseTimeThisTime = 0;
|
||||
return;
|
||||
}
|
||||
this.contentLength += behaviorResult.getContentLength();
|
||||
this.totalResponseTimeThisTime += behaviorResult.getResponseTime();
|
||||
if (behaviorResult.getResponseTime() > this.maxResponseTime) {
|
||||
this.maxResponseTime = behaviorResult.getResponseTime();
|
||||
}
|
||||
if (behaviorResult.getResponseTime() < this.minResponseTime) {
|
||||
this.minResponseTime = behaviorResult.getResponseTime();
|
||||
}
|
||||
}
|
||||
|
||||
private BehaviorStatusCodeResultModel buildModel() {
|
||||
BehaviorStatusCodeResultModel result = new BehaviorStatusCodeResultModel();
|
||||
result.setBehaviorId(this.behaviorId);
|
||||
result.setContentLength(this.contentLength);
|
||||
result.setContentType(this.contentType);
|
||||
result.setCount(this.count);
|
||||
result.setCountThisTime(this.countThisTime);
|
||||
result.setMaxResponseTime(this.maxResponseTime);
|
||||
result.setMinResponseTime(this.minResponseTime);
|
||||
result.setStatusCode(this.statusCode);
|
||||
result.setTotalResponseTimeThisTime(this.totalResponseTimeThisTime);
|
||||
return result;
|
||||
}
|
||||
|
||||
public BehaviorStatusCodeResultModel getStatistics() {
|
||||
BehaviorStatusCodeResultModel result = buildModel();
|
||||
this.resetTempraryField();
|
||||
return result;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ import java.util.Map;
|
|||
|
||||
import org.bench4q.agent.scenario.engine.BehaviorResult;
|
||||
import org.bench4q.agent.scenario.engine.PageResult;
|
||||
import org.bench4q.share.models.agent.BehaviorBriefModel;
|
||||
import org.bench4q.share.models.agent.statistics.AgentPageBriefModel;
|
||||
|
||||
public class PageResultCollector extends AbstractDataCollector {
|
||||
|
@ -79,8 +80,7 @@ public class PageResultCollector extends AbstractDataCollector {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, BehaviorStatusCodeResult> getBehaviorBriefStatistics(
|
||||
int id) {
|
||||
public BehaviorBriefModel getBehaviorBriefStatistics(int id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
package org.bench4q.agent.datacollector.impl;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collections;
|
||||
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;
|
||||
import org.bench4q.share.models.agent.BehaviorBriefModel;
|
||||
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
|
||||
|
||||
/**
|
||||
|
@ -31,9 +30,8 @@ public class ScenarioResultCollector extends AbstractDataCollector {
|
|||
private static long TIME_UNIT = 1000;
|
||||
private UUID testID;
|
||||
private PageResultCollector pageResultCollector;
|
||||
// The first integer is the behavior's id, and the second integer is
|
||||
// the StatusCode of this behaviorResult.
|
||||
private Map<Integer, Map<Integer, BehaviorStatusCodeResult>> detailMap;
|
||||
// behaviorId -- BehaviorResultCollector
|
||||
private final Map<Integer, BehaviorResultCollector> behaviorCollectors;
|
||||
|
||||
private void setTimeOfPreviousCall(long timeOfPreviousCall) {
|
||||
this.timeOfPreviousCall = timeOfPreviousCall;
|
||||
|
@ -92,11 +90,6 @@ public class ScenarioResultCollector extends AbstractDataCollector {
|
|||
this.testID = testID;
|
||||
}
|
||||
|
||||
private void setDetailMap(
|
||||
Map<Integer, Map<Integer, BehaviorStatusCodeResult>> detailMap) {
|
||||
this.detailMap = detailMap;
|
||||
}
|
||||
|
||||
private PageResultCollector getPageResultCollector() {
|
||||
return pageResultCollector;
|
||||
}
|
||||
|
@ -106,6 +99,7 @@ public class ScenarioResultCollector extends AbstractDataCollector {
|
|||
}
|
||||
|
||||
public ScenarioResultCollector(UUID testId) {
|
||||
this.behaviorCollectors = new HashMap<Integer, BehaviorResultCollector>();
|
||||
this.setTestID(testId);
|
||||
this.setPageResultCollector(new PageResultCollector());
|
||||
init();
|
||||
|
@ -115,7 +109,6 @@ public class ScenarioResultCollector extends AbstractDataCollector {
|
|||
reset();
|
||||
this.setCumulativeFailCount(0);
|
||||
this.setCumulativeSucessfulCount(0);
|
||||
this.setDetailMap(new ConcurrentHashMap<Integer, Map<Integer, BehaviorStatusCodeResult>>());
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
|
@ -193,46 +186,9 @@ public class ScenarioResultCollector extends AbstractDataCollector {
|
|||
}
|
||||
|
||||
private void statisticBehaviorBriefResult(BehaviorResult behaviorResult) {
|
||||
insertWhenNotExist(behaviorResult);
|
||||
Map<Integer, BehaviorStatusCodeResult> detailStatusMap = this.detailMap
|
||||
BehaviorResultCollector collector = this.behaviorCollectors
|
||||
.get(behaviorResult.getBehaviorId());
|
||||
// TODO: there's a problem about concurrency
|
||||
guardStatusMapExists(behaviorResult, detailStatusMap);
|
||||
BehaviorStatusCodeResult statusCodeResult = detailStatusMap
|
||||
.get(behaviorResult.getStatusCode());
|
||||
statusCodeResult.count++;
|
||||
if (behaviorResult.getSuccessCount() == 0) {
|
||||
statusCodeResult.contentLength += 0;
|
||||
statusCodeResult.totalResponseTimeThisTime = 0;
|
||||
return;
|
||||
}
|
||||
statusCodeResult.contentLength += behaviorResult.getContentLength();
|
||||
statusCodeResult.totalResponseTimeThisTime += behaviorResult
|
||||
.getResponseTime();
|
||||
if (behaviorResult.getResponseTime() > statusCodeResult.maxResponseTime) {
|
||||
statusCodeResult.maxResponseTime = behaviorResult.getResponseTime();
|
||||
}
|
||||
if (behaviorResult.getResponseTime() < statusCodeResult.minResponseTime) {
|
||||
statusCodeResult.minResponseTime = behaviorResult.getResponseTime();
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void guardStatusMapExists(
|
||||
BehaviorResult behaviorResult,
|
||||
Map<Integer, BehaviorStatusCodeResult> detailStatusMap) {
|
||||
if (!detailStatusMap.containsKey(behaviorResult.getStatusCode())) {
|
||||
detailStatusMap.put(
|
||||
new Integer(behaviorResult.getStatusCode()),
|
||||
new BehaviorStatusCodeResult(behaviorResult
|
||||
.getContentType()));
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void insertWhenNotExist(BehaviorResult behaviorResult) {
|
||||
if (!this.detailMap.containsKey(behaviorResult.getBehaviorId())) {
|
||||
this.detailMap.put(new Integer(behaviorResult.getBehaviorId()),
|
||||
new HashMap<Integer, BehaviorStatusCodeResult>());
|
||||
}
|
||||
collector.add(behaviorResult);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -253,17 +209,24 @@ public class ScenarioResultCollector extends AbstractDataCollector {
|
|||
@Override
|
||||
public synchronized void add(BehaviorResult behaviorResult) {
|
||||
super.add(behaviorResult);
|
||||
if (!this.behaviorCollectors
|
||||
.containsKey(behaviorResult.getBehaviorId())) {
|
||||
this.behaviorCollectors
|
||||
.put(behaviorResult.getBehaviorId(),
|
||||
new BehaviorResultCollector(behaviorResult
|
||||
.getBehaviorId()));
|
||||
}
|
||||
statisticScenarioBriefResult(behaviorResult);
|
||||
statisticBehaviorBriefResult(behaviorResult);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, BehaviorStatusCodeResult> getBehaviorBriefStatistics(
|
||||
int behaviorId) {
|
||||
if (!this.detailMap.containsKey(behaviorId)) {
|
||||
public BehaviorBriefModel getBehaviorBriefStatistics(int behaviorId) {
|
||||
if (!this.behaviorCollectors.containsKey(behaviorId)) {
|
||||
return null;
|
||||
}
|
||||
return Collections.unmodifiableMap(this.detailMap.get(behaviorId));
|
||||
BehaviorResultCollector m = this.behaviorCollectors.get(behaviorId);
|
||||
return m.getStatistics();
|
||||
}
|
||||
|
||||
public Object getPageBriefStatistics(int pageId) {
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package org.bench4q.agent.scenario.behavior;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.bench4q.agent.datacollector.DataCollector;
|
||||
import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResult;
|
||||
import org.bench4q.agent.scenario.Parameter;
|
||||
import org.bench4q.share.models.agent.BehaviorBriefModel;
|
||||
import org.bench4q.share.models.agent.ParameterModel;
|
||||
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
|
||||
|
||||
|
@ -53,7 +51,7 @@ public abstract class Behavior {
|
|||
|
||||
public abstract boolean shouldBeCount();
|
||||
|
||||
public abstract Map<Integer, BehaviorStatusCodeResult> getBehaviorBriefResult(
|
||||
public abstract BehaviorBriefModel getBehaviorBriefResult(
|
||||
DataCollector dataStatistics);
|
||||
|
||||
public String getSpecificParamValue(String paramName) {
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package org.bench4q.agent.scenario.behavior;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.bench4q.agent.datacollector.DataCollector;
|
||||
import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResult;
|
||||
import org.bench4q.share.models.agent.BehaviorBriefModel;
|
||||
|
||||
public class ControlBehavior extends Behavior {
|
||||
|
||||
|
@ -13,7 +11,7 @@ public class ControlBehavior extends Behavior {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, BehaviorStatusCodeResult> getBehaviorBriefResult(
|
||||
public BehaviorBriefModel getBehaviorBriefResult(
|
||||
DataCollector dataStatistics) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package org.bench4q.agent.scenario.behavior;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.bench4q.agent.datacollector.DataCollector;
|
||||
import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResult;
|
||||
import org.bench4q.share.models.agent.BehaviorBriefModel;
|
||||
|
||||
public class TestBehavior extends Behavior {
|
||||
|
||||
|
@ -13,7 +11,7 @@ public class TestBehavior extends Behavior {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, BehaviorStatusCodeResult> getBehaviorBriefResult(
|
||||
public BehaviorBriefModel getBehaviorBriefResult(
|
||||
DataCollector dataStatistics) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package org.bench4q.agent.scenario.behavior;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.bench4q.agent.datacollector.DataCollector;
|
||||
import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResult;
|
||||
import org.bench4q.share.models.agent.BehaviorBriefModel;
|
||||
|
||||
public class TimerBehavior extends Behavior {
|
||||
|
||||
|
@ -13,7 +11,7 @@ public class TimerBehavior extends Behavior {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, BehaviorStatusCodeResult> getBehaviorBriefResult(
|
||||
public BehaviorBriefModel getBehaviorBriefResult(
|
||||
DataCollector dataStatistics) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package org.bench4q.agent.scenario.behavior;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.bench4q.agent.datacollector.DataCollector;
|
||||
import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResult;
|
||||
import org.bench4q.share.models.agent.BehaviorBriefModel;
|
||||
|
||||
public class TransactionBehavior extends Behavior {
|
||||
|
||||
|
@ -13,7 +11,7 @@ public class TransactionBehavior extends Behavior {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, BehaviorStatusCodeResult> getBehaviorBriefResult(
|
||||
public BehaviorBriefModel getBehaviorBriefResult(
|
||||
DataCollector dataStatistics) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package org.bench4q.agent.scenario.behavior;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.bench4q.agent.datacollector.DataCollector;
|
||||
import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResult;
|
||||
import org.bench4q.share.models.agent.BehaviorBriefModel;
|
||||
|
||||
public class UserBehavior extends Behavior {
|
||||
@Override
|
||||
|
@ -12,7 +10,7 @@ public class UserBehavior extends Behavior {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, BehaviorStatusCodeResult> getBehaviorBriefResult(
|
||||
public BehaviorBriefModel getBehaviorBriefResult(
|
||||
DataCollector dataStatistics) {
|
||||
return dataStatistics.getBehaviorBriefStatistics(this.getId());
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ public class PageResultStatisticsTest {
|
|||
@Test
|
||||
public void pageResultTest() {
|
||||
PageResult pageResult = PageResult.buildPageResult(2,
|
||||
ScenarioStatisticsTest.makeBehaviorListWhoseBehaviorIdIsOne(1));
|
||||
ScenarioStatisticsTest.makeBehaviorList(1, 1));
|
||||
assertEquals(2, pageResult.getPageId());
|
||||
assertEquals(200, pageResult.getExecuteRange());
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class PageResultStatisticsTest {
|
|||
@Test
|
||||
public void pageResultWithTwoBehaviorTest() {
|
||||
PageResult pageResult = PageResult.buildPageResult(2,
|
||||
ScenarioStatisticsTest.makeBehaviorListWhoseBehaviorIdIsOne(2));
|
||||
ScenarioStatisticsTest.makeBehaviorList(2, 1));
|
||||
assertEquals(2, pageResult.getPageId());
|
||||
assertEquals(220, pageResult.getExecuteRange());
|
||||
assertEquals(420, pageResult.getPageEndTime());
|
||||
|
@ -60,7 +60,7 @@ public class PageResultStatisticsTest {
|
|||
public void testOnePaegWithOneBehaviorResult() {
|
||||
this.getDataCollector().add(
|
||||
PageResult.buildPageResult(2,
|
||||
ScenarioStatisticsTest.makeBehaviorListWhoseBehaviorIdIsOne(1)));
|
||||
ScenarioStatisticsTest.makeBehaviorList(1, 1)));
|
||||
AgentPageBriefModel pageBriefModel = (AgentPageBriefModel) this
|
||||
.getDataCollector().getPageBriefStatistics(2);
|
||||
assertEquals(2, pageBriefModel.getPageId());
|
||||
|
@ -77,7 +77,7 @@ public class PageResultStatisticsTest {
|
|||
public void testOnePageWithTwoBehaviorResult() {
|
||||
this.getDataCollector().add(
|
||||
PageResult.buildPageResult(2,
|
||||
ScenarioStatisticsTest.makeBehaviorListWhoseBehaviorIdIsOne(2)));
|
||||
ScenarioStatisticsTest.makeBehaviorList(2, 1)));
|
||||
AgentPageBriefModel pageBriefModel = (AgentPageBriefModel) this
|
||||
.getDataCollector().getPageBriefStatistics(2);
|
||||
System.out.println(pageBriefModel.getCountFromBegin());
|
||||
|
@ -95,10 +95,10 @@ public class PageResultStatisticsTest {
|
|||
public void testTwoPageWithStatisticsAtLast() {
|
||||
this.getDataCollector().add(
|
||||
PageResult.buildPageResult(2,
|
||||
ScenarioStatisticsTest.makeBehaviorListWhoseBehaviorIdIsOne(1)));
|
||||
ScenarioStatisticsTest.makeBehaviorList(1, 1)));
|
||||
this.getDataCollector().add(
|
||||
PageResult.buildPageResult(2,
|
||||
ScenarioStatisticsTest.makeBehaviorListWhoseBehaviorIdIsOne(2)));
|
||||
ScenarioStatisticsTest.makeBehaviorList(2, 2)));
|
||||
AgentPageBriefModel pageBriefModel = (AgentPageBriefModel) this
|
||||
.getDataCollector().getPageBriefStatistics(2);
|
||||
assertEquals(2, pageBriefModel.getPageId());
|
||||
|
@ -116,7 +116,7 @@ public class PageResultStatisticsTest {
|
|||
testOnePaegWithOneBehaviorResult();
|
||||
this.getDataCollector().add(
|
||||
PageResult.buildPageResult(2,
|
||||
ScenarioStatisticsTest.makeBehaviorListWhoseBehaviorIdIsOne(2)));
|
||||
ScenarioStatisticsTest.makeBehaviorList(2, 1)));
|
||||
AgentPageBriefModel model = (AgentPageBriefModel) this
|
||||
.getDataCollector().getPageBriefStatistics(2);
|
||||
assertEquals(2, model.getPageId());
|
||||
|
|
|
@ -4,15 +4,16 @@ import static org.junit.Assert.*;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
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;
|
||||
import org.bench4q.agent.storage.StorageHelper;
|
||||
import org.bench4q.share.models.agent.BehaviorBriefModel;
|
||||
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
@ -46,7 +47,7 @@ public class ScenarioStatisticsTest {
|
|||
|
||||
@Test
|
||||
public void addZeroBriefTest() {
|
||||
for (BehaviorResult behaviorResult : makeBehaviorListWhoseBehaviorIdIsOne(0)) {
|
||||
for (BehaviorResult behaviorResult : makeBehaviorList(0, 1)) {
|
||||
this.getDataStatistics().add(behaviorResult);
|
||||
}
|
||||
AgentBriefStatusModel model = (AgentBriefStatusModel) this
|
||||
|
@ -58,11 +59,10 @@ public class ScenarioStatisticsTest {
|
|||
|
||||
@Test
|
||||
public void addOneBriefTest() throws InterruptedException {
|
||||
List<BehaviorResult> generatedBehaviorResults = makeBehaviorListWhoseBehaviorIdIsOne(1);
|
||||
List<BehaviorResult> generatedBehaviorResults = makeBehaviorList(1, 1);
|
||||
for (BehaviorResult behaviorResult : generatedBehaviorResults) {
|
||||
this.getDataStatistics().add(behaviorResult);
|
||||
}
|
||||
|
||||
Thread.sleep(100);
|
||||
AgentBriefStatusModel model = (AgentBriefStatusModel) this
|
||||
.getDataStatistics().getScenarioBriefStatistics();
|
||||
|
@ -77,21 +77,22 @@ public class ScenarioStatisticsTest {
|
|||
List<BehaviorResult> generatedBehaviorResults,
|
||||
AgentBriefStatusModel model) {
|
||||
int successCount = 0;
|
||||
HashSet<Integer> set = new HashSet<Integer>();
|
||||
for (BehaviorResult unit : generatedBehaviorResults) {
|
||||
BehaviorStatusCodeResult behaviorStatusCodeResult = this
|
||||
.getDataStatistics()
|
||||
.getBehaviorBriefStatistics(unit.getBehaviorId()).get(200);
|
||||
if (behaviorStatusCodeResult == null) {
|
||||
BehaviorBriefModel briefModel = this.getDataStatistics()
|
||||
.getBehaviorBriefStatistics(unit.getBehaviorId());
|
||||
if (set.contains(unit.getBehaviorId()) || briefModel == null) {
|
||||
continue;
|
||||
}
|
||||
successCount += behaviorStatusCodeResult.count;
|
||||
set.add(unit.getBehaviorId());
|
||||
successCount += briefModel.getSuccessfulCount();
|
||||
}
|
||||
assertEquals(successCount, model.getSuccessCountFromBegin());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addTwoBriefTest() throws InterruptedException {
|
||||
List<BehaviorResult> behaviorResults = makeBehaviorListWhoseBehaviorIdIsOne(2);
|
||||
List<BehaviorResult> behaviorResults = makeBehaviorList(2, 1);
|
||||
for (BehaviorResult behaviorResult : behaviorResults) {
|
||||
this.getDataStatistics().add(behaviorResult);
|
||||
}
|
||||
|
@ -152,17 +153,17 @@ public class ScenarioStatisticsTest {
|
|||
}
|
||||
|
||||
public static PageResult makePageResultWithBehaviorResult(int count) {
|
||||
List<BehaviorResult> behaviorResults = makeBehaviorListWhoseBehaviorIdIsOne(count);
|
||||
List<BehaviorResult> behaviorResults = makeBehaviorList(count, 1);
|
||||
return PageResult.buildPageResult(2, behaviorResults);
|
||||
}
|
||||
|
||||
public static List<BehaviorResult> makeBehaviorListWhoseBehaviorIdIsOne(
|
||||
int count) {
|
||||
public static List<BehaviorResult> makeBehaviorList(int count,
|
||||
int behaviorId) {
|
||||
List<BehaviorResult> behaviorResults = new ArrayList<BehaviorResult>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
int statusCode = i % 2 == 0 ? 200 : 400;
|
||||
behaviorResults.add(buildBehaviorResult(200 + 10 * i, i % 2 == 0,
|
||||
statusCode, i, 200 + 10 * i));
|
||||
statusCode, behaviorId, 200 + 10 * i));
|
||||
}
|
||||
return behaviorResults;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,117 @@
|
|||
package org.bench4q.agent.test.datastatistics;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.agent.datacollector.DataCollector;
|
||||
import org.bench4q.agent.datacollector.impl.BehaviorResultCollector;
|
||||
import org.bench4q.agent.datacollector.impl.ScenarioResultCollector;
|
||||
import org.bench4q.agent.scenario.engine.BehaviorResult;
|
||||
import org.bench4q.agent.storage.StorageHelper;
|
||||
import org.bench4q.share.models.agent.BehaviorBriefModel;
|
||||
import org.bench4q.share.models.agent.BehaviorStatusCodeResultModel;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class Test_BehaviorResultCollector {
|
||||
private DataCollector detailStatistics;
|
||||
|
||||
private DataCollector getDetailStatistics() {
|
||||
return detailStatistics;
|
||||
}
|
||||
|
||||
private void setDetailStatistics(DataCollector detailStatistics) {
|
||||
this.detailStatistics = detailStatistics;
|
||||
}
|
||||
|
||||
public Test_BehaviorResultCollector() {
|
||||
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
|
||||
.makeBehaviorList(0, 1)) {
|
||||
this.getDetailStatistics().add(behaviorResult);
|
||||
}
|
||||
|
||||
Object object = this.detailStatistics.getBehaviorBriefStatistics(0);
|
||||
assertEquals(null, object);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addOneDetailTest() {
|
||||
BehaviorResultCollector collector = new BehaviorResultCollector(1);
|
||||
for (BehaviorResult behaviorResult : ScenarioStatisticsTest
|
||||
.makeBehaviorList(1, 1)) {
|
||||
collector.add(behaviorResult);
|
||||
}
|
||||
BehaviorBriefModel briefModel = collector.getStatistics();
|
||||
assertEquals(briefModel.getSuccessfulCount(), 1);
|
||||
assertEquals(briefModel.getTotalCount(), 1);
|
||||
assertEquals(1, briefModel.getDetailStatusCodeResultModels().size());
|
||||
BehaviorStatusCodeResultModel resultModel = briefModel
|
||||
.getDetailStatusCodeResultModels().get(0);
|
||||
assertEquals(resultModel.getContentLength(), 20);
|
||||
assertEquals(resultModel.getCountThisTime(), 1);
|
||||
assertEquals(resultModel.getCount(), 1);
|
||||
assertEquals(resultModel.getMaxResponseTime(), 200);
|
||||
assertEquals(resultModel.getMinResponseTime(), 200);
|
||||
assertEquals(resultModel.getTotalResponseTimeThisTime(), 200);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addTwoDetailTest() {
|
||||
int behaviorId = 1;
|
||||
BehaviorResultCollector collector = new BehaviorResultCollector(
|
||||
behaviorId);
|
||||
for (BehaviorResult behaviorResult : ScenarioStatisticsTest
|
||||
.makeBehaviorList(2, behaviorId)) {
|
||||
collector.add(behaviorResult);
|
||||
}
|
||||
BehaviorBriefModel briefModel = collector.getStatistics();
|
||||
assertEquals(1, briefModel.getSuccessfulCount());
|
||||
assertEquals(2, briefModel.getTotalCount());
|
||||
assertEquals(2, briefModel.getDetailStatusCodeResultModels().size());
|
||||
for (BehaviorStatusCodeResultModel statusCodeResultModel : briefModel
|
||||
.getDetailStatusCodeResultModels()) {
|
||||
if (statusCodeResultModel.getStatusCode() == 200) {
|
||||
assertEquals(statusCodeResultModel.getContentLength(), 20);
|
||||
assertEquals(statusCodeResultModel.getCount(), 1);
|
||||
assertEquals(statusCodeResultModel.getCountThisTime(), 1);
|
||||
assertEquals(statusCodeResultModel.getMaxResponseTime(), 200);
|
||||
assertEquals(statusCodeResultModel.getMinResponseTime(), 200);
|
||||
assertEquals(
|
||||
statusCodeResultModel.getTotalResponseTimeThisTime(),
|
||||
200);
|
||||
} else {
|
||||
assertEquals(statusCodeResultModel.getContentLength(), 0);
|
||||
assertEquals(statusCodeResultModel.getCount(), 1);
|
||||
assertEquals(statusCodeResultModel.getCountThisTime(), 1);
|
||||
assertEquals(statusCodeResultModel.getMaxResponseTime(),
|
||||
Long.MIN_VALUE);
|
||||
assertEquals(statusCodeResultModel.getMinResponseTime(),
|
||||
Long.MAX_VALUE);
|
||||
assertEquals(
|
||||
statusCodeResultModel.getTotalResponseTimeThisTime(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_addSomeSameUrlResult() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package org.bench4q.agent.test.datastatistics;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResultCollector;
|
||||
import org.bench4q.agent.scenario.engine.BehaviorResult;
|
||||
import org.bench4q.share.models.agent.BehaviorStatusCodeResultModel;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Test_BehaviorStatusResultStatistics {
|
||||
@Test
|
||||
public void addOneDetailTest() {
|
||||
BehaviorStatusCodeResultCollector statusCodeResultCollector = new BehaviorStatusCodeResultCollector(
|
||||
0, 200, "text/html");
|
||||
for (BehaviorResult behaviorResult : ScenarioStatisticsTest
|
||||
.makeBehaviorList(1, 0)) {
|
||||
statusCodeResultCollector.add(behaviorResult);
|
||||
}
|
||||
BehaviorStatusCodeResultModel resultModel = statusCodeResultCollector
|
||||
.getStatistics();
|
||||
assertEquals(resultModel.getContentLength(), 20);
|
||||
assertEquals(resultModel.getCountThisTime(), 1);
|
||||
assertEquals(resultModel.getCount(), 1);
|
||||
assertEquals(resultModel.getMaxResponseTime(), 200);
|
||||
assertEquals(resultModel.getMinResponseTime(), 200);
|
||||
assertEquals(resultModel.getTotalResponseTimeThisTime(), 200);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addTwoTest() throws InterruptedException {
|
||||
BehaviorStatusCodeResultCollector statusCodeResultCollector = new BehaviorStatusCodeResultCollector(
|
||||
1, 200, "text/html");
|
||||
statusCodeResultCollector.add(ScenarioStatisticsTest
|
||||
.buildBehaviorResult(300, true, 200, 1, new Date().getTime()));
|
||||
Thread.sleep(100);
|
||||
statusCodeResultCollector.add(ScenarioStatisticsTest
|
||||
.buildBehaviorResult(320, true, 200, 1, new Date().getTime()));
|
||||
BehaviorStatusCodeResultModel result = statusCodeResultCollector
|
||||
.getStatistics();
|
||||
assertEquals(result.getContentLength(), 40);
|
||||
assertEquals(result.getCountThisTime(), 2);
|
||||
assertEquals(result.getCount(), 2);
|
||||
assertEquals(result.getMaxResponseTime(), 320);
|
||||
assertEquals(result.getMinResponseTime(), 300);
|
||||
assertEquals(result.getTotalResponseTimeThisTime(), 620);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addThreeAndBriefTwice() {
|
||||
BehaviorStatusCodeResultCollector collector = new BehaviorStatusCodeResultCollector(
|
||||
1, 302, "text/html");
|
||||
collector.add(ScenarioStatisticsTest.buildBehaviorResult(210, true,
|
||||
302, 1, new Date().getTime()));
|
||||
collector.add(ScenarioStatisticsTest.buildBehaviorResult(230, true,
|
||||
302, 1, new Date().getTime()));
|
||||
BehaviorStatusCodeResultModel resultModel = collector.getStatistics();
|
||||
assertEquals(resultModel.getContentLength(), 40);
|
||||
assertEquals(resultModel.getCountThisTime(), 2);
|
||||
assertEquals(resultModel.getCount(), 2);
|
||||
assertEquals(resultModel.getMaxResponseTime(), 230);
|
||||
assertEquals(resultModel.getMinResponseTime(), 210);
|
||||
assertEquals(resultModel.getTotalResponseTimeThisTime(), 440);
|
||||
collector.add(ScenarioStatisticsTest.buildBehaviorResult(190, true,
|
||||
302, 1, new Date().getTime()));
|
||||
resultModel = collector.getStatistics();
|
||||
assertEquals(resultModel.getContentLength(), 60);
|
||||
assertEquals(resultModel.getCountThisTime(), 1);
|
||||
assertEquals(resultModel.getCount(), 3);
|
||||
assertEquals(resultModel.getMaxResponseTime(), 230);
|
||||
assertEquals(resultModel.getMinResponseTime(), 190);
|
||||
assertEquals(resultModel.getTotalResponseTimeThisTime(), 190);
|
||||
}
|
||||
}
|
|
@ -223,7 +223,7 @@ public class TestPlanScript implements RunningScriptInterface {
|
|||
public List<TestPlanScriptResult> sample(Date sampleTime) {
|
||||
try {
|
||||
ScriptResultModel scriptResultModel = this.getSampler()
|
||||
.getResultModelFromAgent();
|
||||
.briefResultFromAgent();
|
||||
|
||||
List<TestPlanScriptResult> testPlanScriptResultList = this
|
||||
.getTestPlanFactory().createScriptResultsWithoutId(
|
||||
|
|
|
@ -8,6 +8,10 @@ import java.util.List;
|
|||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.bench4q.master.domain.RunningAgentInterface;
|
||||
import org.bench4q.master.domain.valueobject.datastatistics.impl.BehaviorsBriefStatistics;
|
||||
import org.bench4q.master.domain.valueobject.datastatistics.impl.PagesBriefStatistics;
|
||||
import org.bench4q.master.domain.valueobject.datastatistics.impl.ScriptBriefStatistics;
|
||||
import org.bench4q.master.domain.valueobject.datastatistics.impl.ScriptStatistics;
|
||||
import org.bench4q.share.models.agent.TestBriefStatusModel;
|
||||
import org.bench4q.share.models.agent.statistics.AgentBehaviorsBriefModel;
|
||||
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
|
||||
|
@ -52,7 +56,7 @@ public class RunningScriptSampler {
|
|||
this.getRunningAgents().addAll(runningAgents);
|
||||
}
|
||||
|
||||
public ScriptResultModel getResultModelFromAgent() throws JAXBException {
|
||||
public ScriptResultModel briefResultFromAgent() throws JAXBException {
|
||||
for (RunningAgentInterface runningAgent : getRunningAgents()) {
|
||||
if (runningAgent.isBreakDown()) {
|
||||
continue;
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
package org.bench4q.master.domain.valueobject.datastatistics.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
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.master.statistics.ScriptBehaviorBriefModel;
|
||||
|
||||
public class BehaviorBriefStatistics extends ScriptStatistics {
|
||||
private long countFromBegin;
|
||||
private long countThisTime;
|
||||
private long successCountThisTime;
|
||||
private long successCountFromBegin;
|
||||
private long maxResponseTimeFromBegin;
|
||||
private long minResponseTimeFromBegin;
|
||||
private long totalResponseTimeThisTime;
|
||||
|
||||
private volatile Map<Integer, BehaviorStatusCodeResultModel> behaviorStatusMap;
|
||||
|
||||
public BehaviorBriefStatistics() {
|
||||
this.behaviorStatusMap = new HashMap<Integer, BehaviorStatusCodeResultModel>();
|
||||
resetTempraryFields();
|
||||
this.maxResponseTimeFromBegin = 0;
|
||||
this.minResponseTimeFromBegin = Long.MAX_VALUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Now, for totalCount, i just collect all result from agent, and add their
|
||||
* countFromBegin together. But there will be a error there. if an agent
|
||||
* doesn't give back its result, the the countFromBegin maybe less that last
|
||||
* one.
|
||||
*/
|
||||
private void resetTempraryFields() {
|
||||
this.countFromBegin = 0;
|
||||
this.countThisTime = 0;
|
||||
this.successCountThisTime = 0;
|
||||
this.successCountFromBegin = 0;
|
||||
this.totalResponseTimeThisTime = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(DataStatisticsModel dataUnit) {
|
||||
if (!(dataUnit instanceof BehaviorBriefModel)) {
|
||||
return;
|
||||
}
|
||||
BehaviorBriefModel behaviorBriefModel = (BehaviorBriefModel) dataUnit;
|
||||
this.countFromBegin += behaviorBriefModel.getTotalCount();
|
||||
this.successCountFromBegin += behaviorBriefModel.getSuccessfulCount();
|
||||
for (BehaviorStatusCodeResultModel newOne : behaviorBriefModel
|
||||
.getDetailStatusCodeResultModels()) {
|
||||
if (!this.behaviorStatusMap.containsKey(newOne.getStatusCode())) {
|
||||
behaviorStatusMap.put(newOne.getStatusCode(), newOne);
|
||||
continue;
|
||||
}
|
||||
BehaviorStatusCodeResultModel origin = behaviorStatusMap.get(newOne
|
||||
.getStatusCode());
|
||||
origin.plus(newOne);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getStatistics() {
|
||||
ScriptBehaviorBriefModel result = new ScriptBehaviorBriefModel();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,134 @@
|
|||
package org.bench4q.master.domain.valueobject.datastatistics.impl;
|
||||
|
||||
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, BehaviorBriefStatistics> behaviorStatisticsMap;
|
||||
|
||||
private Map<Integer, Map<Integer, BehaviorStatusCodeResultModel>> getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
private void setMap(
|
||||
Map<Integer, Map<Integer, BehaviorStatusCodeResultModel>> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
private Map<Integer, String> getIdUrlMap() {
|
||||
return idUrlMap;
|
||||
}
|
||||
|
||||
private void setIdUrlMap(Map<Integer, String> idUrlMap) {
|
||||
this.idUrlMap = idUrlMap;
|
||||
}
|
||||
|
||||
private Map<Integer, BehaviorBriefStatistics> getBehaviorStatisticsMap() {
|
||||
return behaviorStatisticsMap;
|
||||
}
|
||||
|
||||
private void setBehaviorStatisticsMap(
|
||||
Map<Integer, BehaviorBriefStatistics> behaviorStatisticsMap) {
|
||||
this.behaviorStatisticsMap = behaviorStatisticsMap;
|
||||
}
|
||||
|
||||
public BehaviorsBriefStatistics() {
|
||||
this.setMap(new ConcurrentHashMap<Integer, Map<Integer, BehaviorStatusCodeResultModel>>());
|
||||
this.setIdUrlMap(new ConcurrentHashMap<Integer, String>());
|
||||
this.setBehaviorStatisticsMap(new ConcurrentHashMap<Integer, BehaviorBriefStatistics>());
|
||||
}
|
||||
|
||||
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);
|
||||
// }
|
||||
this.getBehaviorStatisticsMap()
|
||||
.get(behaviorBriefModel.getBehaviorId())
|
||||
.add(behaviorBriefModel);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void guardAllMapsKeyExists(
|
||||
BehaviorBriefModel behaviorBriefModel) {
|
||||
int behaviorId = behaviorBriefModel.getBehaviorId();
|
||||
if (!this.getMap().containsKey(behaviorId)) {
|
||||
this.getMap()
|
||||
.put(behaviorId,
|
||||
new ConcurrentHashMap<Integer, BehaviorStatusCodeResultModel>());
|
||||
}
|
||||
if (!this.getIdUrlMap().containsKey(behaviorId)) {
|
||||
this.getIdUrlMap().put(behaviorId,
|
||||
behaviorBriefModel.getBehaviorUrl());
|
||||
}
|
||||
if (!this.getBehaviorStatisticsMap().containsKey(behaviorId)) {
|
||||
this.getBehaviorStatisticsMap().put(behaviorId,
|
||||
new BehaviorBriefStatistics());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package org.bench4q.master.domain.valueobject.datastatistics.impl;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Now, for totalCount, i just collect all result from agent, and add their
|
||||
* countFromBegin together. But there will be a error there. if an agent
|
||||
* doesn't give back its result, the the countFromBegin maybe less that last
|
||||
* one.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package org.bench4q.master.domain.valueobject.datastatistics.impl;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,214 @@
|
|||
package org.bench4q.master.domain.valueobject.datastatistics.impl;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package org.bench4q.master.domain.valueobject.datastatistics.impl;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.bench4q.master.domain.valueobject.datastatistics.DataStatistics;
|
||||
import org.bench4q.share.models.master.statistics.SampleModel;
|
||||
|
||||
public abstract class ScriptStatistics implements DataStatistics {
|
||||
protected void makeUpResultModelWithSamplingTime(
|
||||
SampleModel resultModel) {
|
||||
resultModel.setSamplingTime(new Date());
|
||||
}
|
||||
|
||||
}
|
|
@ -53,7 +53,7 @@ public class Test_RunningScriptSampler extends TestBase_MakeUpTestPlan {
|
|||
public void testGetScriptResult() throws InterruptedException,
|
||||
JAXBException {
|
||||
ScriptResultModel scriptResultModel = this.getRunningScriptSampler()
|
||||
.getResultModelFromAgent();
|
||||
.briefResultFromAgent();
|
||||
Thread.sleep(1000);
|
||||
assertNotNull(scriptResultModel);
|
||||
assertNotNull(scriptResultModel.getScriptBriefResultModel());
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
package org.bench4q.master.unitTest.datastatistics;
|
||||
|
||||
import org.bench4q.master.domain.valueobject.datastatistics.BehaviorsBriefStatistics;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bench4q.master.domain.valueobject.datastatistics.impl.BehaviorsBriefStatistics;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.agent.BehaviorBriefModel;
|
||||
import org.bench4q.share.models.agent.BehaviorStatusCodeResultModel;
|
||||
import org.bench4q.share.models.agent.statistics.AgentBehaviorsBriefModel;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -10,6 +14,15 @@ public class BehaviorsBriefStatisticsTest {
|
|||
public void testAddNull() {
|
||||
BehaviorsBriefStatistics behaviorsBriefStatistics = new BehaviorsBriefStatistics();
|
||||
AgentBehaviorsBriefModel dataUnit = new AgentBehaviorsBriefModel();
|
||||
BehaviorBriefModel e = new BehaviorBriefModel();
|
||||
e.setBehaviorId(1);
|
||||
e.setBehaviorUrl("www.baidu.com");
|
||||
e.setDetailStatusCodeResultModels(Arrays
|
||||
.asList(new BehaviorStatusCodeResultModel()));
|
||||
e.setSuccessfulCount(2);
|
||||
e.setTotalCount(3);
|
||||
dataUnit.getBehaviorBriefModels().add(e);
|
||||
|
||||
behaviorsBriefStatistics.add(dataUnit);
|
||||
System.out.println(MarshalHelper.tryMarshal(behaviorsBriefStatistics
|
||||
.getStatistics()));
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.bench4q.master.unitTest.datastatistics;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.bench4q.master.domain.valueobject.datastatistics.ScriptBriefStatistics;
|
||||
import org.bench4q.master.domain.valueobject.datastatistics.impl.ScriptBriefStatistics;
|
||||
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
||||
import org.junit.Test;
|
||||
|
|
|
@ -5,7 +5,7 @@ import static org.junit.Assert.*;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bench4q.master.domain.valueobject.datastatistics.PageBriefStatistics;
|
||||
import org.bench4q.master.domain.valueobject.datastatistics.impl.PageBriefStatistics;
|
||||
import org.bench4q.share.models.agent.statistics.AgentPageBriefModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptPageBriefModel;
|
||||
import org.junit.Test;
|
||||
|
|
|
@ -3,7 +3,7 @@ package org.bench4q.master.unitTest.datastatistics;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bench4q.master.domain.valueobject.datastatistics.PagesBriefStatistics;
|
||||
import org.bench4q.master.domain.valueobject.datastatistics.impl.PagesBriefStatistics;
|
||||
import org.bench4q.share.models.agent.statistics.AgentPageBriefModel;
|
||||
import org.bench4q.share.models.agent.statistics.AgentPagesBriefModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptPagesBriefModel;
|
||||
|
|
|
@ -45,12 +45,12 @@ public class Test_ScriptSample {
|
|||
.buildRunningAgentWithOutIdAndRunningScript(
|
||||
this.testcase2.get(1), 20, UUID.randomUUID()));
|
||||
RunningScriptSampler sampler = new RunningScriptSampler(runningAgents);
|
||||
long totalSuccessCountBeforeStop = sampler.getResultModelFromAgent()
|
||||
long totalSuccessCountBeforeStop = sampler.briefResultFromAgent()
|
||||
.getScriptBriefResultModel().getTotalSuccessCountFromBegin();
|
||||
|
||||
runningAgents.get(0).stop();
|
||||
|
||||
long totalSuccessCountAfterStop = sampler.getResultModelFromAgent()
|
||||
long totalSuccessCountAfterStop = sampler.briefResultFromAgent()
|
||||
.getScriptBriefResultModel().getTotalSuccessCountFromBegin();
|
||||
assertTrue(totalSuccessCountAfterStop >= totalSuccessCountBeforeStop);
|
||||
}
|
||||
|
|
|
@ -7,8 +7,10 @@ import javax.xml.bind.annotation.XmlElement;
|
|||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.bench4q.share.models.agent.statistics.DataStatisticsModel;
|
||||
|
||||
@XmlRootElement(name = "BehaviorBriefModel")
|
||||
public class BehaviorBriefModel {
|
||||
public class BehaviorBriefModel extends DataStatisticsModel {
|
||||
private int behaviorId;
|
||||
private String behaviorUrl;
|
||||
private long totalCount;
|
||||
|
|
|
@ -5,7 +5,9 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||
|
||||
@XmlRootElement(name = "BehaviorStatusCodeResultModel")
|
||||
public class BehaviorStatusCodeResultModel {
|
||||
private int behaviorId;
|
||||
private int statusCode;
|
||||
private long countThisTime;
|
||||
private long count;
|
||||
private String contentType;
|
||||
private long contentLength;
|
||||
|
@ -13,6 +15,15 @@ public class BehaviorStatusCodeResultModel {
|
|||
private long maxResponseTime;
|
||||
private long totalResponseTimeThisTime;
|
||||
|
||||
@XmlElement
|
||||
public int getBehaviorId() {
|
||||
return behaviorId;
|
||||
}
|
||||
|
||||
public void setBehaviorId(int behaviorId) {
|
||||
this.behaviorId = behaviorId;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public int getStatusCode() {
|
||||
return statusCode;
|
||||
|
@ -31,6 +42,15 @@ public class BehaviorStatusCodeResultModel {
|
|||
this.count = count;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public long getCountThisTime() {
|
||||
return countThisTime;
|
||||
}
|
||||
|
||||
public void setCountThisTime(long countThisTime) {
|
||||
this.countThisTime = countThisTime;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
|
@ -111,4 +131,8 @@ public class BehaviorStatusCodeResultModel {
|
|||
this.setMinResponseTime(newOne.getMinResponseTime());
|
||||
}
|
||||
}
|
||||
|
||||
public BehaviorStatusCodeResultModel() {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
package org.bench4q.share.models.master.statistics;
|
||||
|
||||
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;
|
||||
|
||||
import org.bench4q.share.models.agent.BehaviorStatusCodeResultModel;
|
||||
|
||||
@XmlRootElement
|
||||
public class ScriptBehaviorBriefModel {
|
||||
private int behaviorId;
|
||||
private String BehaviorUrl;
|
||||
private int successCount;
|
||||
private int totalCount;
|
||||
private List<BehaviorStatusCodeResultModel> list;
|
||||
|
||||
public ScriptBehaviorBriefModel() {
|
||||
this.setList(new LinkedList<BehaviorStatusCodeResultModel>());
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public int getBehaviorId() {
|
||||
return behaviorId;
|
||||
}
|
||||
|
||||
public void setBehaviorId(int behaviorId) {
|
||||
this.behaviorId = behaviorId;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getBehaviorUrl() {
|
||||
return BehaviorUrl;
|
||||
}
|
||||
|
||||
public void setBehaviorUrl(String behaviorUrl) {
|
||||
BehaviorUrl = behaviorUrl;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public int getSuccessCount() {
|
||||
return successCount;
|
||||
}
|
||||
|
||||
public void setSuccessCount(int successCount) {
|
||||
this.successCount = successCount;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public int getTotalCount() {
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
public void setTotalCount(int totalCount) {
|
||||
this.totalCount = totalCount;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "statusResults")
|
||||
@XmlElement
|
||||
public List<BehaviorStatusCodeResultModel> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<BehaviorStatusCodeResultModel> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package org.bench4q.share.models.master.statistics;
|
||||
|
||||
public class ScriptBehaviorStatusCodeModel {
|
||||
private int statusCode;
|
||||
private long count;
|
||||
private String contentType;
|
||||
private long contentLength;
|
||||
private long minResponseTime;
|
||||
private long maxResponseTime;
|
||||
|
||||
public int getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
public void setStatusCode(int statusCode) {
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
|
||||
public long getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setCount(long count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
public long getContentLength() {
|
||||
return contentLength;
|
||||
}
|
||||
|
||||
public void setContentLength(long contentLength) {
|
||||
this.contentLength = contentLength;
|
||||
}
|
||||
|
||||
public long getMinResponseTime() {
|
||||
return minResponseTime;
|
||||
}
|
||||
|
||||
public void setMinResponseTime(long minResponseTime) {
|
||||
this.minResponseTime = minResponseTime;
|
||||
}
|
||||
|
||||
public long getMaxResponseTime() {
|
||||
return maxResponseTime;
|
||||
}
|
||||
|
||||
public void setMaxResponseTime(long maxResponseTime) {
|
||||
this.maxResponseTime = maxResponseTime;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue