This commit is contained in:
hmm 2014-09-15 16:33:07 +08:00
commit dbe8f46088
74 changed files with 1543 additions and 928 deletions

View File

@ -2,20 +2,17 @@ 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;
import org.bench4q.agent.scenario.behavior.UserBehavior;
import org.bench4q.agent.scenario.engine.ScenarioContext;
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;
@ -26,6 +23,7 @@ import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
import org.bench4q.share.models.agent.statistics.AgentBehaviorsBriefModel;
import org.bench4q.share.models.agent.statistics.AgentPageBriefModel;
import org.bench4q.share.models.agent.statistics.AgentPagesBriefModel;
import org.bench4q.share.models.agent.statistics.BehaviorBriefModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
@ -95,7 +93,7 @@ public class TestController {
ScheduleModel scheduleModel = (ScheduleModel) MarshalHelper
.unmarshal(ScheduleModel.class, scheduleContent);
this.getScenarioEngine().submitScenario(runId,
Scenario.scenarioBuilderWithCompile(runScenarioModel),
Scenario.scenarioCompiler(runScenarioModel),
Schedule.build(scheduleModel), realStartTime);
return MarshalHelper.tryMarshal(buildWith(runId));
} catch (Exception e) {
@ -127,50 +125,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) {
@ -179,30 +133,17 @@ public class TestController {
AgentPagesBriefModel result = new AgentPagesBriefModel();
List<AgentPageBriefModel> pageBrieves = new ArrayList<AgentPageBriefModel>();
if (context == null || context.isFinished()) {
if (context == null) {
return null;
}
for (int i = 0; i < context.getScenario().getPages().length; i++) {
pageBrieves.add((AgentPageBriefModel) context.getDataStatistics()
pageBrieves.add((AgentPageBriefModel) context.getDataCollector()
.getPageBriefStatistics(i));
}
result.setPageBriefModels(pageBrieves);
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 +156,21 @@ public class TestController {
}
for (Behavior behavior : scenarioContext.getScenario()
.getAllBehaviors()) {
int behaviorId = behavior.getId();
Map<Integer, BehaviorStatusCodeResult> map = behavior
.getBehaviorBriefResult(scenarioContext.getDataStatistics());
if (map == null) {
if (!(behavior instanceof UserBehavior)) {
continue;
}
behaviorBriefModels.add(buildBehaviorBrief(runId, behaviorId,
behavior.getSpecificParamValue("url"), map));
try {
BehaviorBriefModel briefModel = behavior
.getBehaviorBriefResult(scenarioContext
.getDataCollector());
logger.info(behavior.getId());
briefModel
.setBehaviorUrl(behavior.getSpecificParamValue("url"));
behaviorBriefModels.add(briefModel);
} catch (Exception e) {
logger.info("where behaviorId is " + behavior.getId(), e);
}
}
ret.setBehaviorBriefModels(behaviorBriefModels);
return ret;
@ -237,7 +185,7 @@ public class TestController {
return null;
}
AgentBriefStatusModel agentStatusModel = (AgentBriefStatusModel) scenarioContext
.getDataStatistics().getScenarioBriefStatistics();
.getDataCollector().getScenarioBriefStatistics();
agentStatusModel.setvUserCount(scenarioContext.getExecutor()
.getActiveCount());
return agentStatusModel;

View File

@ -1,8 +1,5 @@
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;
@ -13,8 +10,7 @@ public interface DataCollector {
public Object getScenarioBriefStatistics();
public Map<Integer, BehaviorStatusCodeResult> getBehaviorBriefStatistics(
int behaviorId);
public Object getBehaviorBriefStatistics(int behaviorId);
public Object getPageBriefStatistics(int pageId);
}

View File

@ -0,0 +1,9 @@
package org.bench4q.agent.datacollector;
import org.bench4q.agent.scenario.engine.UnderStatistics;
public interface DataStatistics {
public void add(UnderStatistics unit);
public Object getStatistics();
}

View File

@ -1,5 +0,0 @@
package org.bench4q.agent.datacollector.impl;
public class BehaviorResultCollector {
}

View File

@ -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.statistics.BehaviorStatusCodeResultModel;
public class BehaviorStatusCodeCollector {
private int behaviorId;
private int statusCode;
private long count;
private long countThisTime;
private long contentLength;
private long minResponseTime;
private long maxResponseTime;
private long totalResponseTimeThisTime;
private String contentType;
public BehaviorStatusCodeCollector(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;
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1,101 @@
package org.bench4q.agent.datacollector.impl;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.bench4q.agent.datacollector.DataStatistics;
import org.bench4q.agent.scenario.engine.BehaviorResult;
import org.bench4q.agent.scenario.engine.UnderStatistics;
import org.bench4q.share.models.agent.statistics.BehaviorBriefModel;
import org.bench4q.share.models.agent.statistics.BehaviorStatusCodeResultModel;
public class BehaviorsResultCollector {
private final Map<Integer, BehaviorResultCollector> behaviorResultMap;
public BehaviorsResultCollector() {
this.behaviorResultMap = new HashMap<Integer, BehaviorResultCollector>();
}
public void add(BehaviorResult behaviorResult) {
if (!this.behaviorResultMap.containsKey(behaviorResult.getBehaviorId())) {
synchronized (this) {
this.behaviorResultMap.put(
behaviorResult.getBehaviorId(),
new BehaviorResultCollector(behaviorResult
.getBehaviorId()));
}
}
this.behaviorResultMap.get(behaviorResult.getBehaviorId()).add(
behaviorResult);
}
public Object getStatistics(int behaviorId) {
if (!this.behaviorResultMap.containsKey(behaviorId)) {
return null;
}
BehaviorResultCollector m = this.behaviorResultMap.get(behaviorId);
return m.getStatistics();
}
public static class BehaviorResultCollector implements DataStatistics {
private int behaviorId;
private long successCountFromBegin;
private long failCountFromBegin;
// statusCode - BehaviorStatusCodeResultCollector
private final Map<Integer, BehaviorStatusCodeCollector> detailStatusMap;
public BehaviorResultCollector(int behaviorId) {
this.behaviorId = behaviorId;
this.detailStatusMap = new HashMap<Integer, BehaviorStatusCodeCollector>();
}
@Override
public void add(UnderStatistics unit) {
if (!(unit instanceof BehaviorResult)) {
return;
}
addCore((BehaviorResult) unit);
}
public void addCore(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();
BehaviorStatusCodeCollector 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 BehaviorStatusCodeCollector(this.behaviorId,
statusCode, contentType));
}
}
public Object getStatistics() {
BehaviorBriefModel result = new BehaviorBriefModel();
List<BehaviorStatusCodeResultModel> list = new LinkedList<BehaviorStatusCodeResultModel>();
for (BehaviorStatusCodeCollector 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;
}
}
}

View File

@ -1,18 +1,24 @@
package org.bench4q.agent.datacollector.impl;
import java.util.Map;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.bench4q.agent.Main;
import org.bench4q.agent.datacollector.DataCollector;
import org.bench4q.agent.helper.ApplicationContextHelper;
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.BehaviorResultModel;
public abstract class AbstractDataCollector implements DataCollector {
public class DataCollectorImpl implements DataCollector {
protected StorageHelper storageHelper;
private final UUID testId;
private final PagesResultCollector pagesResultCollector;
private final ScenarioResultCollector scenarioResultCollector;
private final BehaviorsResultCollector behaviorsResultCollector;
protected StorageHelper getStorageHelper() {
return storageHelper;
@ -22,20 +28,25 @@ public abstract class AbstractDataCollector implements DataCollector {
this.storageHelper = storageHelper;
}
public AbstractDataCollector() {
mustDoWhenIniti();
}
protected void mustDoWhenIniti() {
this.setStorageHelper(ApplicationContextHelper.getContext().getBean(
StorageHelper.class));
public DataCollectorImpl(UUID testId, StorageHelper storageHelper) {
this.storageHelper = storageHelper;
this.testId = testId;
this.pagesResultCollector = new PagesResultCollector();
this.behaviorsResultCollector = new BehaviorsResultCollector();
this.scenarioResultCollector = new ScenarioResultCollector();
}
public void add(final BehaviorResult behaviorResult) {
if (!Main.IS_TO_SAVE_DETAIL) {
if (behaviorResult == null) {
return;
}
if (behaviorResult == null) {
saveItAsync(behaviorResult);
this.scenarioResultCollector.add(behaviorResult);
this.behaviorsResultCollector.add(behaviorResult);
}
private void saveItAsync(final BehaviorResult behaviorResult) {
if (!Main.IS_TO_SAVE_DETAIL) {
return;
}
Runnable runnable = new Runnable() {
@ -72,11 +83,29 @@ public abstract class AbstractDataCollector implements DataCollector {
return resultModel;
}
protected abstract String calculateSavePath(BehaviorResult behaviorResult);
public void add(PageResult pageResult) {
this.pagesResultCollector.add(pageResult);
}
public abstract Object getScenarioBriefStatistics();
public Object getPageBriefStatistics(int pageId) {
return this.pagesResultCollector.getPageBriefStatistics(pageId);
}
public abstract Map<Integer, BehaviorStatusCodeResult> getBehaviorBriefStatistics(
int id);
protected String calculateSavePath(BehaviorResult behaviorResult) {
Date now = new Date();
return "DetailResults" + System.getProperty("file.separator")
+ new SimpleDateFormat("yyyyMMdd").format(now)
+ System.getProperty("file.separator") + this.testId + "_"
+ behaviorResult.getBehaviorId() + "_"
+ new SimpleDateFormat("hhmm") + ".txt";
}
public Object getScenarioBriefStatistics() {
return this.scenarioResultCollector.getScenarioBriefStatistics();
}
public Object getBehaviorBriefStatistics(int id) {
return this.behaviorsResultCollector.getStatistics(id);
}
}

View File

@ -1,110 +0,0 @@
package org.bench4q.agent.datacollector.impl;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.bench4q.agent.scenario.engine.BehaviorResult;
import org.bench4q.agent.scenario.engine.PageResult;
import org.bench4q.share.models.agent.statistics.AgentPageBriefModel;
public class PageResultCollector extends AbstractDataCollector {
Map<Integer, PageBrief> pageBriefMap;
private Map<Integer, PageBrief> getPageBriefMap() {
return pageBriefMap;
}
private void setPageBriefMap(Map<Integer, PageBrief> pageBriefMap) {
this.pageBriefMap = pageBriefMap;
}
public PageResultCollector() {
this.setPageBriefMap(new HashMap<Integer, PageBrief>());
}
public void add(PageResult pageResult) {
if (pageResult == null || pageResult.getPageId() < 0) {
return;
}
PageBrief pageBrief = guardTheValueOfThePageIdExists(pageResult
.getPageId());
pageBrief.countThisTime++;
pageBrief.countFromBegin++;
pageBrief.totalResponseTimeThisTime += pageResult.getExecuteRange();
pageBrief.latesTimeResponseTime = pageResult.getExecuteRange();
if (pageResult.getExecuteRange() > pageBrief.maxResponseTimeFromBegin) {
pageBrief.maxResponseTimeFromBegin = pageResult.getExecuteRange();
}
if (pageResult.getExecuteRange() < pageBrief.minResponseTimeFromBegin) {
pageBrief.minResponseTimeFromBegin = pageResult.getExecuteRange();
}
}
private synchronized PageBrief guardTheValueOfThePageIdExists(int pageId) {
if (!this.getPageBriefMap().containsKey(pageId)) {
this.getPageBriefMap().put(pageId, new PageBrief());
}
return this.getPageBriefMap().get(pageId);
}
public Object getPageBriefStatistics(int pageId) {
PageBrief pageBrief = guardTheValueOfThePageIdExists(pageId);
AgentPageBriefModel result = new AgentPageBriefModel();
result.setCountFromBegin(pageBrief.countFromBegin);
result.setCountThisTime(pageBrief.countThisTime);
result.setMaxResponseTimeFromBegin(pageBrief.maxResponseTimeFromBegin);
result.setMinResponseTimeFromBegin(pageBrief.minResponseTimeFromBegin);
result.setTotalResponseTimeThisTime(pageBrief.totalResponseTimeThisTime);
result.setPageId(pageId);
long nowTime = new Date().getTime();
result.setTimeFrame(nowTime - pageBrief.lastSampleTime);
result.setLatestResponseTime(pageBrief.latesTimeResponseTime);
pageBrief.resetTemperatyField();
return result;
}
@Override
public void add(BehaviorResult behaviorResult) {
}
@Override
protected String calculateSavePath(BehaviorResult behaviorResult) {
return null;
}
@Override
public Object getScenarioBriefStatistics() {
return null;
}
@Override
public Map<Integer, BehaviorStatusCodeResult> getBehaviorBriefStatistics(
int id) {
return null;
}
public class PageBrief {
public long lastSampleTime;
public long countThisTime;
public long totalResponseTimeThisTime;
public long maxResponseTimeFromBegin;
public long minResponseTimeFromBegin;
public long countFromBegin;
public long latesTimeResponseTime;
public PageBrief() {
resetTemperatyField();
this.maxResponseTimeFromBegin = Long.MIN_VALUE;
this.minResponseTimeFromBegin = Long.MAX_VALUE;
this.countFromBegin = 0;
this.latesTimeResponseTime = 0;
}
public void resetTemperatyField() {
this.lastSampleTime = new Date().getTime();
this.countThisTime = 0;
this.totalResponseTimeThisTime = 0;
}
}
}

View File

@ -0,0 +1,116 @@
package org.bench4q.agent.datacollector.impl;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.bench4q.agent.datacollector.DataStatistics;
import org.bench4q.agent.scenario.engine.PageResult;
import org.bench4q.agent.scenario.engine.UnderStatistics;
import org.bench4q.share.models.agent.statistics.AgentPageBriefModel;
public class PagesResultCollector {
Map<Integer, PageResultCollector> pageBriefMap;
private Map<Integer, PageResultCollector> getPageBriefMap() {
return pageBriefMap;
}
private void setPageBriefMap(Map<Integer, PageResultCollector> pageBriefMap) {
this.pageBriefMap = pageBriefMap;
}
public PagesResultCollector() {
this.setPageBriefMap(new HashMap<Integer, PageResultCollector>());
}
public void add(PageResult pageResult) {
if (pageResult == null || pageResult.getPageId() < 0) {
return;
}
PageResultCollector pageBrief = this.getPageBriefMap().get(
pageResult.getPageId());
if (!this.getPageBriefMap().containsKey(pageResult.getPageId())) {
pageBrief = guardTheValueOfThePageIdExists(pageResult.getPageId());
}
pageBrief.addCore(pageResult);
}
private synchronized PageResultCollector guardTheValueOfThePageIdExists(
int pageId) {
if (!this.getPageBriefMap().containsKey(pageId)) {
this.getPageBriefMap().put(pageId, new PageResultCollector(pageId));
}
return this.getPageBriefMap().get(pageId);
}
public Object getPageBriefStatistics(int pageId) {
PageResultCollector pageBrief = guardTheValueOfThePageIdExists(pageId);
return pageBrief.getStatistics();
}
public class PageResultCollector implements DataStatistics {
private long lastSampleTime;
private long countThisTime;
private long totalResponseTimeThisTime;
private long maxResponseTimeFromBegin;
private long minResponseTimeFromBegin;
private long countFromBegin;
private long latestTimeResponseTime;
private final int pageId;
public PageResultCollector(int pageId) {
resetTemperatyField();
this.maxResponseTimeFromBegin = Long.MIN_VALUE;
this.minResponseTimeFromBegin = Long.MAX_VALUE;
this.countFromBegin = 0;
this.latestTimeResponseTime = 0;
this.pageId = pageId;
}
public void resetTemperatyField() {
this.lastSampleTime = new Date().getTime();
this.countThisTime = 0;
this.totalResponseTimeThisTime = 0;
}
public void add(UnderStatistics unit) {
if (!(unit instanceof PageResult)) {
return;
}
addCore((PageResult) unit);
}
public void addCore(PageResult pageResult) {
if (pageResult == null || pageResult.getPageId() != this.pageId) {
return;
}
this.countThisTime++;
this.countFromBegin++;
this.totalResponseTimeThisTime += pageResult.getExecuteRange();
this.latestTimeResponseTime = pageResult.getExecuteRange();
if (pageResult.getExecuteRange() > this.maxResponseTimeFromBegin) {
this.maxResponseTimeFromBegin = pageResult.getExecuteRange();
}
if (pageResult.getExecuteRange() < this.minResponseTimeFromBegin) {
this.minResponseTimeFromBegin = pageResult.getExecuteRange();
}
}
public Object getStatistics() {
AgentPageBriefModel result = new AgentPageBriefModel();
result.setCountFromBegin(countFromBegin);
result.setCountThisTime(countThisTime);
result.setMaxResponseTimeFromBegin(maxResponseTimeFromBegin);
result.setMinResponseTimeFromBegin(minResponseTimeFromBegin);
result.setTotalResponseTimeThisTime(totalResponseTimeThisTime);
result.setPageId(pageId);
long nowTime = new Date().getTime();
result.setTimeFrame(nowTime - lastSampleTime);
result.setLatestResponseTime(latestTimeResponseTime);
this.resetTemperatyField();
return result;
}
}
}

View File

@ -1,15 +1,6 @@
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.statistics.AgentBriefStatusModel;
/**
@ -18,7 +9,7 @@ import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
* @author coderfengyun
*
*/
public class ScenarioResultCollector extends AbstractDataCollector {
public class ScenarioResultCollector {
private long timeOfPreviousCall;
private long failCountOfThisCall;
private long successCountOfThisCall;
@ -29,11 +20,6 @@ public class ScenarioResultCollector extends AbstractDataCollector {
private long cumulativeSucessfulCount;
private long cumulativeFailCount;
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;
private void setTimeOfPreviousCall(long timeOfPreviousCall) {
this.timeOfPreviousCall = timeOfPreviousCall;
@ -84,30 +70,7 @@ public class ScenarioResultCollector extends AbstractDataCollector {
this.cumulativeFailCount = cumulativeFailCount;
}
private String getTestID() {
return testID == null ? "default" : testID.toString();
}
private void setTestID(UUID testID) {
this.testID = testID;
}
private void setDetailMap(
Map<Integer, Map<Integer, BehaviorStatusCodeResult>> detailMap) {
this.detailMap = detailMap;
}
private PageResultCollector getPageResultCollector() {
return pageResultCollector;
}
private void setPageResultCollector(PageResultCollector pageResultCollector) {
this.pageResultCollector = pageResultCollector;
}
public ScenarioResultCollector(UUID testId) {
this.setTestID(testId);
this.setPageResultCollector(new PageResultCollector());
public ScenarioResultCollector() {
init();
}
@ -115,7 +78,6 @@ public class ScenarioResultCollector extends AbstractDataCollector {
reset();
this.setCumulativeFailCount(0);
this.setCumulativeSucessfulCount(0);
this.setDetailMap(new ConcurrentHashMap<Integer, Map<Integer, BehaviorStatusCodeResult>>());
}
private void reset() {
@ -132,6 +94,24 @@ public class ScenarioResultCollector extends AbstractDataCollector {
// DataStatistics Interface start
// ///////////////////////////////
public void add(BehaviorResult behaviorResult) {
this.successCountOfThisCall += behaviorResult.getSuccessCount();
this.failCountOfThisCall += behaviorResult.getFailCount();
if (behaviorResult.getSuccessCount() == 0)
return;
this.totalResponseTimeOfThisCall += behaviorResult.getResponseTime();
this.totalSqureResponseTimeOfThisCall += Math.pow(
behaviorResult.getResponseTime(), 2);
if (behaviorResult.getResponseTime() > this
.getMaxResponseTimeOfThisCall()) {
this.setMaxResponseTimeOfThisCall(behaviorResult.getResponseTime());
}
if (behaviorResult.getResponseTime() < this
.getMinResponseTimeOfThisCall()) {
this.setMinResponseTimeOfThisCall(behaviorResult.getResponseTime());
}
}
public AgentBriefStatusModel getScenarioBriefStatistics() {
AgentBriefStatusModel result = new AgentBriefStatusModel();
result.setTimeFrame(System.currentTimeMillis()
@ -174,100 +154,4 @@ public class ScenarioResultCollector extends AbstractDataCollector {
* @param behaviorResult
*/
private void statisticScenarioBriefResult(BehaviorResult behaviorResult) {
this.successCountOfThisCall += behaviorResult.getSuccessCount();
this.failCountOfThisCall += behaviorResult.getFailCount();
if (behaviorResult.getSuccessCount() == 0)
return;
this.totalResponseTimeOfThisCall += behaviorResult.getResponseTime();
this.totalSqureResponseTimeOfThisCall += Math.pow(
behaviorResult.getResponseTime(), 2);
if (behaviorResult.getResponseTime() > this
.getMaxResponseTimeOfThisCall()) {
this.setMaxResponseTimeOfThisCall(behaviorResult.getResponseTime());
}
if (behaviorResult.getResponseTime() < this
.getMinResponseTimeOfThisCall()) {
this.setMinResponseTimeOfThisCall(behaviorResult.getResponseTime());
}
}
private void statisticBehaviorBriefResult(BehaviorResult behaviorResult) {
insertWhenNotExist(behaviorResult);
Map<Integer, BehaviorStatusCodeResult> detailStatusMap = this.detailMap
.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>());
}
}
@Override
protected String calculateSavePath(BehaviorResult behaviorResult) {
Date now = new Date();
return "DetailResults" + System.getProperty("file.separator")
+ new SimpleDateFormat("yyyyMMdd").format(now)
+ System.getProperty("file.separator") + this.getTestID() + "_"
+ behaviorResult.getBehaviorId() + "_"
+ new SimpleDateFormat("hhmm") + ".txt";
}
public synchronized void add(PageResult pageResult) {
this.getPageResultCollector().add(pageResult);
}
@Override
public synchronized void add(BehaviorResult behaviorResult) {
super.add(behaviorResult);
statisticScenarioBriefResult(behaviorResult);
statisticBehaviorBriefResult(behaviorResult);
}
@Override
public Map<Integer, BehaviorStatusCodeResult> getBehaviorBriefStatistics(
int behaviorId) {
if (!this.detailMap.containsKey(behaviorId)) {
return null;
}
return Collections.unmodifiableMap(this.detailMap.get(behaviorId));
}
public Object getPageBriefStatistics(int pageId) {
return this.getPageResultCollector().getPageBriefStatistics(pageId);
}
}

View File

@ -67,11 +67,11 @@ public class Scenario {
}
public static Scenario scenarioBuilderWithCompile(String scenarioContent) {
return scenarioBuilderWithCompile((RunScenarioModel) MarshalHelper
return scenarioCompiler((RunScenarioModel) MarshalHelper
.tryUnmarshal(RunScenarioModel.class, scenarioContent));
}
public static Scenario scenarioBuilderWithCompile(
public static Scenario scenarioCompiler(
RunScenarioModel scenarioModel) {
if (scenarioModel == null) {
throw new NullPointerException();

View File

@ -1,12 +1,10 @@
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.ParameterModel;
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
import org.bench4q.share.models.agent.statistics.BehaviorBriefModel;
public abstract class Behavior {
private static final String CONTROL_BEHAVIOR = "CONTROLBEHAVIOR";
@ -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) {

View File

@ -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.statistics.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;
}

View File

@ -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.statistics.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;
}

View File

@ -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.statistics.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;
}

View File

@ -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.statistics.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;
}

View File

@ -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.statistics.BehaviorBriefModel;
public class UserBehavior extends Behavior {
@Override
@ -12,9 +10,9 @@ public class UserBehavior extends Behavior {
}
@Override
public Map<Integer, BehaviorStatusCodeResult> getBehaviorBriefResult(
public BehaviorBriefModel getBehaviorBriefResult(
DataCollector dataStatistics) {
return dataStatistics.getBehaviorBriefStatistics(this.getId());
return (BehaviorBriefModel) dataStatistics.getBehaviorBriefStatistics(this.getId());
}
}

View File

@ -2,7 +2,7 @@ package org.bench4q.agent.scenario.engine;
import java.util.Date;
public class BehaviorResult {
public class BehaviorResult implements UnderStatistics {
private String pluginId;
private String pluginName;
private int behaviorId;

View File

@ -3,7 +3,7 @@ package org.bench4q.agent.scenario.engine;
import java.util.ArrayList;
import java.util.List;
public class PageResult {
public class PageResult implements UnderStatistics {
private int pageId;
private long pageStartTime;
private long pageEndTime;

View File

@ -11,9 +11,10 @@ import java.util.concurrent.ThreadPoolExecutor.DiscardPolicy;
import org.apache.log4j.Logger;
import org.bench4q.agent.datacollector.DataCollector;
import org.bench4q.agent.datacollector.impl.ScenarioResultCollector;
import org.bench4q.agent.datacollector.impl.DataCollectorImpl;
import org.bench4q.agent.plugin.PluginManager;
import org.bench4q.agent.scenario.Scenario;
import org.bench4q.agent.storage.StorageHelper;
public class ScenarioContext implements Observer {
private static final long keepAliveTime = 10;
@ -73,7 +74,7 @@ public class ScenarioContext implements Observer {
this.finished = finished;
}
public DataCollector getDataStatistics() {
public DataCollector getDataCollector() {
return dataCollector;
}
@ -90,15 +91,16 @@ public class ScenarioContext implements Observer {
}
public static ScenarioContext buildScenarioContextWithoutScenario(
UUID testId, int poolSize, PluginManager pluginManager) {
UUID testId, int poolSize, PluginManager pluginManager,
StorageHelper storageHelper) {
final ArrayBlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<Runnable>(
poolSize);
ThreadPoolExecutor executor = new ThreadPoolExecutor(poolSize,
poolSize, keepAliveTime, TimeUnit.MINUTES, workQueue,
new DiscardPolicy());
ScenarioContext scenarioContext = new ScenarioContext(testId, new Date(
System.currentTimeMillis()), executor,
new ScenarioResultCollector(testId), pluginManager);
System.currentTimeMillis()), executor, new DataCollectorImpl(
testId, storageHelper), pluginManager);
return scenarioContext;
}
@ -108,7 +110,8 @@ public class ScenarioContext implements Observer {
realStartTime), this.executor, this.dataCollector,
this.pluginManager);
result.setSchedule(schedule);
result.setEndDate(new Date(result.getSchedule().getScheduleRangeInMilliSecond()
result.setEndDate(new Date(result.getSchedule()
.getScheduleRangeInMilliSecond()
+ result.getStartDate().getTime()));
result.setFinished(this.isFinished());
result.setScenario(scenario);

View File

@ -9,6 +9,7 @@ import java.util.UUID;
import org.apache.log4j.Logger;
import org.bench4q.agent.plugin.PluginManager;
import org.bench4q.agent.scenario.Scenario;
import org.bench4q.agent.storage.StorageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -17,6 +18,7 @@ public class ScenarioEngine implements Observer {
private Map<UUID, ScenarioContext> runningTests;
private final Logger logger = Logger.getLogger(ScenarioEngine.class);
private PluginManager pluginManager;
private StorageHelper storageHelper;
public ScenarioEngine() {
this.setRunningTests(new HashMap<UUID, ScenarioContext>());
@ -39,11 +41,20 @@ public class ScenarioEngine implements Observer {
this.pluginManager = pluginManager;
}
private StorageHelper getStorageHelper() {
return storageHelper;
}
@Autowired
private void setStorageHelper(StorageHelper storageHelper) {
this.storageHelper = storageHelper;
}
public void addRunningTestWithoutScenario(UUID runId, int poolSize) {
try {
final ScenarioContext scenarioContext = ScenarioContext
.buildScenarioContextWithoutScenario(runId, poolSize,
getPluginManager());
getPluginManager(), this.getStorageHelper());
this.getRunningTests().put(runId, scenarioContext);
} catch (Exception e) {
e.printStackTrace();

View File

@ -0,0 +1,5 @@
package org.bench4q.agent.scenario.engine;
public interface UnderStatistics {
}

View File

@ -74,10 +74,10 @@ public class VUser implements Runnable {
Page page = context.getScenario().getPages()[i];
long startTime = System.currentTimeMillis();
for (Batch batch : page.getBatches()) {
doRunBatch(plugins, batch, context.getDataStatistics());
doRunBatch(plugins, batch, context.getDataCollector());
}
long endTime = System.currentTimeMillis();
context.getDataStatistics().add(
context.getDataCollector().add(
PageResult.buildPageResult(i, startTime, endTime));
}
}

View File

@ -20,7 +20,7 @@ public class ExtractScenarioTest {
RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper
.unmarshal(RunScenarioModel.class, FileUtils
.readFileToString(new File("Scripts/goodForPage.xml")));
Scenario scenario = Scenario.scenarioBuilderWithCompile(runScenarioModel);
Scenario scenario = Scenario.scenarioCompiler(runScenarioModel);
assertTrue(scenario.getPages().length > 0);
}

View File

@ -15,6 +15,7 @@ import org.bench4q.agent.scenario.Scenario;
import org.bench4q.agent.scenario.engine.ScenarioContext;
import org.bench4q.agent.scenario.engine.Schedule;
import org.bench4q.agent.scenario.engine.VUser;
import org.bench4q.agent.storage.StorageHelper;
import org.bench4q.share.helper.TestHelper;
import org.bench4q.share.models.agent.ParameterModel;
import org.bench4q.share.models.agent.RunScenarioModel;
@ -29,6 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired;
public abstract class TestBase {
private ParameterBarn basePara;
private PluginManager pluginManager;
private StorageHelper storageHelper;
private PluginManager getPluginManager() {
return pluginManager;
@ -39,6 +41,11 @@ public abstract class TestBase {
this.pluginManager = pluginManager;
}
@Autowired
private void setStorageHelper(StorageHelper storageHelper) {
this.storageHelper = storageHelper;
}
protected void createFileAndWriteContent(UUID testId, String paramName,
String content) throws IOException {
basePara = new ParameterBarn(testId.toString()) {
@ -122,14 +129,15 @@ public abstract class TestBase {
public VUser createVUser(Scenario scenario, UUID testId) {
return new VUser(buildScenarioContext(testId, scenario, 10,
pluginManager), 1, this.getPluginManager());
pluginManager, this.storageHelper), 1, this.getPluginManager());
}
public static ScenarioContext buildScenarioContext(UUID testId,
final Scenario scenario, int poolSize, PluginManager pluginManager) {
final Scenario scenario, int poolSize, PluginManager pluginManager,
StorageHelper storageHelper) {
ScenarioContext scenarioContext = ScenarioContext
.buildScenarioContextWithoutScenario(testId, poolSize,
pluginManager);
pluginManager, storageHelper);
return scenarioContext.addScenrio(scenario,
Schedule.build(buildScheduleModel()), new Date().getTime());
}

View File

@ -23,12 +23,12 @@ import org.bench4q.share.communication.HttpRequester;
import org.bench4q.share.communication.HttpRequester.HttpResponse;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.helper.TestHelper;
import org.bench4q.share.models.agent.BehaviorBriefModel;
import org.bench4q.share.models.agent.RunScenarioModel;
import org.bench4q.share.models.agent.RunScenarioResultModel;
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
import org.bench4q.share.models.agent.statistics.AgentBehaviorsBriefModel;
import org.bench4q.share.models.agent.statistics.AgentPageBriefModel;
import org.bench4q.share.models.agent.statistics.BehaviorBriefModel;
import org.junit.Test;
public class TestWithScriptFile extends TestBase {

View File

@ -1,166 +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() {
}
}

View File

@ -1,7 +1,6 @@
package org.bench4q.agent.test.datastatistics;
import org.bench4q.agent.datacollector.DataCollector;
import org.bench4q.agent.datacollector.impl.PageResultCollector;
import org.bench4q.agent.datacollector.impl.PagesResultCollector;
import org.bench4q.agent.scenario.engine.PageResult;
import org.bench4q.share.models.agent.statistics.AgentPageBriefModel;
import org.junit.Test;
@ -16,13 +15,13 @@ import static org.junit.Assert.*;
@ContextConfiguration(locations = { "classpath:test-storage-context.xml",
"classpath*:/org/bench4q/agent/config/application-context.xml" })
public class PageResultStatisticsTest {
private DataCollector dataCollector;
private PagesResultCollector dataCollector;
private DataCollector getDataCollector() {
private PagesResultCollector getDataCollector() {
return dataCollector;
}
private void setDataCollector(DataCollector dataCollector) {
private void setDataCollector(PagesResultCollector dataCollector) {
this.dataCollector = dataCollector;
}
@ -30,13 +29,13 @@ public class PageResultStatisticsTest {
public PageResultStatisticsTest() {
new ClassPathXmlApplicationContext(
"classpath*:/org/bench4q/agent/config/application-context.xml");
this.setDataCollector(new PageResultCollector());
this.setDataCollector(new PagesResultCollector());
}
@Test
public void pageResultTest() {
PageResult pageResult = PageResult.buildPageResult(2,
ScenarioStatisticsTest.makeBehaviorListWhoseBehaviorIdIsOne(1));
Test_ScenarioBriefCollector.makeBehaviorList(1, 1));
assertEquals(2, pageResult.getPageId());
assertEquals(200, pageResult.getExecuteRange());
}
@ -44,7 +43,7 @@ public class PageResultStatisticsTest {
@Test
public void pageResultWithTwoBehaviorTest() {
PageResult pageResult = PageResult.buildPageResult(2,
ScenarioStatisticsTest.makeBehaviorListWhoseBehaviorIdIsOne(2));
Test_ScenarioBriefCollector.makeBehaviorList(2, 1));
assertEquals(2, pageResult.getPageId());
assertEquals(220, pageResult.getExecuteRange());
assertEquals(420, pageResult.getPageEndTime());
@ -60,7 +59,7 @@ public class PageResultStatisticsTest {
public void testOnePaegWithOneBehaviorResult() {
this.getDataCollector().add(
PageResult.buildPageResult(2,
ScenarioStatisticsTest.makeBehaviorListWhoseBehaviorIdIsOne(1)));
Test_ScenarioBriefCollector.makeBehaviorList(1, 1)));
AgentPageBriefModel pageBriefModel = (AgentPageBriefModel) this
.getDataCollector().getPageBriefStatistics(2);
assertEquals(2, pageBriefModel.getPageId());
@ -77,7 +76,7 @@ public class PageResultStatisticsTest {
public void testOnePageWithTwoBehaviorResult() {
this.getDataCollector().add(
PageResult.buildPageResult(2,
ScenarioStatisticsTest.makeBehaviorListWhoseBehaviorIdIsOne(2)));
Test_ScenarioBriefCollector.makeBehaviorList(2, 1)));
AgentPageBriefModel pageBriefModel = (AgentPageBriefModel) this
.getDataCollector().getPageBriefStatistics(2);
System.out.println(pageBriefModel.getCountFromBegin());
@ -95,10 +94,10 @@ public class PageResultStatisticsTest {
public void testTwoPageWithStatisticsAtLast() {
this.getDataCollector().add(
PageResult.buildPageResult(2,
ScenarioStatisticsTest.makeBehaviorListWhoseBehaviorIdIsOne(1)));
Test_ScenarioBriefCollector.makeBehaviorList(1, 1)));
this.getDataCollector().add(
PageResult.buildPageResult(2,
ScenarioStatisticsTest.makeBehaviorListWhoseBehaviorIdIsOne(2)));
Test_ScenarioBriefCollector.makeBehaviorList(2, 2)));
AgentPageBriefModel pageBriefModel = (AgentPageBriefModel) this
.getDataCollector().getPageBriefStatistics(2);
assertEquals(2, pageBriefModel.getPageId());
@ -116,7 +115,7 @@ public class PageResultStatisticsTest {
testOnePaegWithOneBehaviorResult();
this.getDataCollector().add(
PageResult.buildPageResult(2,
ScenarioStatisticsTest.makeBehaviorListWhoseBehaviorIdIsOne(2)));
Test_ScenarioBriefCollector.makeBehaviorList(2, 1)));
AgentPageBriefModel model = (AgentPageBriefModel) this
.getDataCollector().getPageBriefStatistics(2);
assertEquals(2, model.getPageId());

View File

@ -0,0 +1,115 @@
package org.bench4q.agent.test.datastatistics;
import static org.junit.Assert.*;
import org.bench4q.agent.datacollector.impl.BehaviorsResultCollector;
import org.bench4q.agent.datacollector.impl.BehaviorsResultCollector.BehaviorResultCollector;
import org.bench4q.agent.scenario.engine.BehaviorResult;
import org.bench4q.share.models.agent.statistics.BehaviorBriefModel;
import org.bench4q.share.models.agent.statistics.BehaviorStatusCodeResultModel;
import org.junit.Test;
public class Test_BehaviorResultCollector {
private BehaviorsResultCollector detailStatistics = new BehaviorsResultCollector();
private BehaviorsResultCollector 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 : Test_ScenarioBriefCollector
.makeBehaviorList(0, 1)) {
this.getDetailStatistics().add(behaviorResult);
}
Object object = this.detailStatistics.getStatistics(0);
assertEquals(null, object);
}
@Test
public void addOneDetailTest() {
BehaviorResultCollector collector = new BehaviorResultCollector(1);
for (BehaviorResult behaviorResult : Test_ScenarioBriefCollector
.makeBehaviorList(1, 1)) {
collector.add(behaviorResult);
}
BehaviorBriefModel briefModel = (BehaviorBriefModel) 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 : Test_ScenarioBriefCollector
.makeBehaviorList(2, behaviorId)) {
collector.add(behaviorResult);
}
BehaviorBriefModel briefModel = (BehaviorBriefModel) 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() {
}
}

View File

@ -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.BehaviorStatusCodeCollector;
import org.bench4q.agent.scenario.engine.BehaviorResult;
import org.bench4q.share.models.agent.statistics.BehaviorStatusCodeResultModel;
import org.junit.Test;
public class Test_BehaviorStatusResultStatistics {
@Test
public void addOneDetailTest() {
BehaviorStatusCodeCollector statusCodeResultCollector = new BehaviorStatusCodeCollector(
0, 200, "text/html");
for (BehaviorResult behaviorResult : Test_ScenarioBriefCollector
.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 {
BehaviorStatusCodeCollector statusCodeResultCollector = new BehaviorStatusCodeCollector(
1, 200, "text/html");
statusCodeResultCollector.add(Test_ScenarioBriefCollector
.buildBehaviorResult(300, true, 200, 1, new Date().getTime()));
Thread.sleep(100);
statusCodeResultCollector.add(Test_ScenarioBriefCollector
.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() {
BehaviorStatusCodeCollector collector = new BehaviorStatusCodeCollector(
1, 302, "text/html");
collector.add(Test_ScenarioBriefCollector.buildBehaviorResult(210, true,
302, 1, new Date().getTime()));
collector.add(Test_ScenarioBriefCollector.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(Test_ScenarioBriefCollector.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);
}
}

View File

@ -0,0 +1,83 @@
package org.bench4q.agent.test.datastatistics;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
import org.bench4q.agent.datacollector.impl.DataCollectorImpl;
import org.bench4q.agent.scenario.engine.BehaviorResult;
import org.bench4q.agent.storage.StorageHelper;
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
import org.bench4q.share.models.agent.statistics.BehaviorBriefModel;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:application-context.xml" })
public class Test_DataCollectorImpl {
private DataCollectorImpl dataCollectorImpl;
public Test_DataCollectorImpl() {
init();
}
private void init() {
@SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext(
"classpath*:/org/bench4q/agent/config/application-context.xml");
DataCollectorImpl agentResultDataCollector = new DataCollectorImpl(
UUID.randomUUID(),
(StorageHelper) context.getBean(StorageHelper.class));
this.dataCollectorImpl = agentResultDataCollector;
}
@Test
public void test() {
BehaviorResult buildBehaviorResult = Test_ScenarioBriefCollector
.buildBehaviorResult(200, true, 200, 1, new Date().getTime());
this.dataCollectorImpl.add(buildBehaviorResult);
BehaviorResult buildBehaviorResult2 = Test_ScenarioBriefCollector
.buildBehaviorResult(400, false, 200, 1, new Date().getTime());
this.dataCollectorImpl.add(buildBehaviorResult2);
AgentBriefStatusModel model = (AgentBriefStatusModel) this.dataCollectorImpl
.getScenarioBriefStatistics();
judgeBehaviorTotalAndScenarioTotal(
Arrays.asList(buildBehaviorResult, buildBehaviorResult2), model);
this.dataCollectorImpl.add(Test_ScenarioBriefCollector
.buildBehaviorResult(230, true, 200, 1, new Date().getTime()));
model = (AgentBriefStatusModel) this.dataCollectorImpl
.getScenarioBriefStatistics();
judgeBehaviorTotalAndScenarioTotal(
Arrays.asList(buildBehaviorResult, buildBehaviorResult2), model);
}
private void judgeBehaviorTotalAndScenarioTotal(
List<BehaviorResult> generatedBehaviorResults,
AgentBriefStatusModel model) {
int successCount = 0, totalCount = 0;
HashSet<Integer> set = new HashSet<Integer>();
for (BehaviorResult unit : generatedBehaviorResults) {
BehaviorBriefModel briefModel = (BehaviorBriefModel) this.dataCollectorImpl
.getBehaviorBriefStatistics(unit.getBehaviorId());
if (set.contains(unit.getBehaviorId()) || briefModel == null) {
continue;
}
set.add(unit.getBehaviorId());
successCount += briefModel.getSuccessfulCount();
totalCount += briefModel.getTotalCount();
}
assertEquals((long) successCount, model.getSuccessCountFromBegin());
assertEquals(
totalCount,
model.getSuccessCountFromBegin()
+ model.getFailCountFromBegin());
}
}

View File

@ -5,48 +5,26 @@ import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Date;
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.statistics.AgentBriefStatusModel;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class ScenarioStatisticsTest {
private DataCollector dataStatistics;
public class Test_ScenarioBriefCollector {
private ScenarioResultCollector dataStatistics = new ScenarioResultCollector();
protected DataCollector getDataStatistics() {
protected ScenarioResultCollector getDataStatistics() {
return dataStatistics;
}
private void setDataStatistics(DataCollector dataStatistics) {
this.dataStatistics = dataStatistics;
}
public ScenarioStatisticsTest() {
init();
}
public 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.setDataStatistics(agentResultDataCollector);
public Test_ScenarioBriefCollector() {
}
@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 +36,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();
@ -70,28 +47,11 @@ public class ScenarioStatisticsTest {
modelExpect.setTimeFrame(model.getTimeFrame());
makeUpStatusModelForOneBehavior(modelExpect);
assertTrue(model.equals(modelExpect));
judgeBehaviorTotalAndScenarioTotal(generatedBehaviorResults, model);
}
private void judgeBehaviorTotalAndScenarioTotal(
List<BehaviorResult> generatedBehaviorResults,
AgentBriefStatusModel model) {
int successCount = 0;
for (BehaviorResult unit : generatedBehaviorResults) {
BehaviorStatusCodeResult behaviorStatusCodeResult = this
.getDataStatistics()
.getBehaviorBriefStatistics(unit.getBehaviorId()).get(200);
if (behaviorStatusCodeResult == null) {
continue;
}
successCount += behaviorStatusCodeResult.count;
}
assertEquals(successCount, model.getSuccessCountFromBegin());
}
@Test
public void addTwoBriefTest() throws InterruptedException {
List<BehaviorResult> behaviorResults = makeBehaviorListWhoseBehaviorIdIsOne(2);
List<BehaviorResult> behaviorResults = makeBehaviorList(2, 1);
for (BehaviorResult behaviorResult : behaviorResults) {
this.getDataStatistics().add(behaviorResult);
}
@ -101,7 +61,6 @@ public class ScenarioStatisticsTest {
AgentBriefStatusModel modelExpect = makeUpStatusModelForTwoBehavior(model
.getTimeFrame());
assertTrue(model.equals(modelExpect));
judgeBehaviorTotalAndScenarioTotal(behaviorResults, model);
}
public static AgentBriefStatusModel makeUpStatusModelForTwoBehavior(
@ -152,17 +111,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;
}

View File

@ -54,7 +54,7 @@ public class Test_ContextPlugin extends TestBase {
batchModel.getBehaviors().add(logIt);
// System.out.println(MarshalHelper.tryMarshal(scenarioModel));
VUser vuser = createVUser(
Scenario.scenarioBuilderWithCompile(scenarioModel),
Scenario.scenarioCompiler(scenarioModel),
UUID.randomUUID());
vuser.run();
}

View File

@ -87,7 +87,7 @@ public class Test_CsvProvider extends TestBase {
createFileAndWriteContent(testId, fileName, CONTENT);
RunScenarioModel runScenarioModel = buildRunScenarioModel(fileName);
Scenario scenario = Scenario
.scenarioBuilderWithCompile(runScenarioModel);
.scenarioCompiler(runScenarioModel);
VUser vUser = createVUser(scenario, testId);
try {
HashMap<String, Object> plugins = new HashMap<String, Object>();
@ -120,7 +120,7 @@ public class Test_CsvProvider extends TestBase {
UUID testId = UUID.randomUUID();
createFileAndWriteContent(testId, fileName, CONTENT);
Scenario scenario = Scenario
.scenarioBuilderWithCompile(buildRunScenarioModel(fileName));
.scenarioCompiler(buildRunScenarioModel(fileName));
VUser vUser = createVUser(scenario, testId);
HashMap<String, Object> plugins = new HashMap<String, Object>();
TestHelper

View File

@ -95,7 +95,7 @@ public class Test_HBasePlugin extends TestBase {
TestHelper.createFileIfNotExist(file);
FileUtils.writeStringToFile(file,
MarshalHelper.tryMarshal(runScenarioModel));
createVUser(Scenario.scenarioBuilderWithCompile(runScenarioModel),
createVUser(Scenario.scenarioCompiler(runScenarioModel),
UUID.randomUUID()).run();
}
}

View File

@ -154,7 +154,7 @@ public class Test_HttpPlugin extends TestBase {
.readFileToString(new File(
"Scripts/httpWithoutTimer.xml")));
VUser vUser = createVUser(
Scenario.scenarioBuilderWithCompile(scenarioMode),
Scenario.scenarioCompiler(scenarioMode),
UUID.randomUUID());
vUser.run();
}

View File

@ -97,7 +97,7 @@ public class Test_MongoDBPlugin extends TestBase {
@Test
public void test_BuildScenario() throws IOException {
RunScenarioModel result = buildUpMongoDBScenario();
VUser vUser = createVUser(Scenario.scenarioBuilderWithCompile(result),
VUser vUser = createVUser(Scenario.scenarioCompiler(result),
UUID.randomUUID());
vUser.run();
}

View File

@ -78,7 +78,7 @@ public class Test_Scenario extends TestBase {
TestHelper.createFileIfNotExist(file);
FileUtils.writeStringToFile(file,
MarshalHelper.tryMarshal(runScenarioModel));
createVUser(Scenario.scenarioBuilderWithCompile(runScenarioModel),
createVUser(Scenario.scenarioCompiler(runScenarioModel),
UUID.randomUUID()).run();
}
@ -101,7 +101,7 @@ public class Test_Scenario extends TestBase {
TestHelper.createFileIfNotExist(file);
FileUtils.writeStringToFile(file,
MarshalHelper.tryMarshal(runScenarioModel));
createVUser(Scenario.scenarioBuilderWithCompile(runScenarioModel),
createVUser(Scenario.scenarioCompiler(runScenarioModel),
UUID.randomUUID()).run();
}
@ -117,7 +117,7 @@ public class Test_Scenario extends TestBase {
"withParamPart", TEST_CASE));
}
}));
Scenario scenario = Scenario.scenarioBuilderWithCompile(inputModel);
Scenario scenario = Scenario.scenarioCompiler(inputModel);
for (Behavior behavior : scenario.getAllBehaviors()) {
assertEquals("first", behavior.getName());
assertEquals(0, behavior.getId());

View File

@ -11,6 +11,7 @@ import org.bench4q.agent.plugin.PluginManager;
import org.bench4q.agent.scenario.Scenario;
import org.bench4q.agent.scenario.engine.ScenarioContext;
import org.bench4q.agent.scenario.engine.Schedule;
import org.bench4q.agent.storage.StorageHelper;
import org.bench4q.agent.test.TestBase;
import org.bench4q.share.models.agent.scriptrecord.UsePluginModel;
import org.junit.Test;
@ -24,11 +25,13 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
public class Test_ScenarioContext extends TestBase {
@Autowired
private PluginManager pluginManager;
@Autowired
private StorageHelper storageHelper;
@Test
public void testBuildScenarioContext() {
ScenarioContext context = buildScenarioContext(UUID.randomUUID(),
new Scenario(), 20, this.pluginManager);
new Scenario(), 20, this.pluginManager, this.storageHelper);
assertEquals(10,
context.getExecutor().getKeepAliveTime(TimeUnit.MINUTES));
assertEquals(20, context.getExecutor().getMaximumPoolSize());
@ -46,10 +49,10 @@ public class Test_ScenarioContext extends TestBase {
private ScenarioContext getScenarioWithScenarioAndSchedule() {
ScenarioContext scenarioContext = ScenarioContext
.buildScenarioContextWithoutScenario(UUID.randomUUID(), 100,
pluginManager);
pluginManager, this.storageHelper);
scenarioContext = scenarioContext
.addScenrio(
Scenario.scenarioBuilderWithCompile(buildRunScenarioModelWith(new LinkedList<UsePluginModel>())),
Scenario.scenarioCompiler(buildRunScenarioModelWith(new LinkedList<UsePluginModel>())),
Schedule.build(buildScheduleModel()), new Date()
.getTime());
return scenarioContext;

View File

@ -12,6 +12,7 @@ import org.bench4q.agent.plugin.PluginManager;
import org.bench4q.agent.scenario.Scenario;
import org.bench4q.agent.scenario.engine.ScenarioContext;
import org.bench4q.agent.scenario.engine.ScenarioEngine;
import org.bench4q.agent.storage.StorageHelper;
import org.bench4q.agent.test.TestBase;
import org.bench4q.share.models.agent.ParameterModel;
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
@ -29,6 +30,8 @@ public class Test_ScenarioEngine extends TestBase {
private UUID testId = UUID.randomUUID();
@Autowired
private PluginManager pluginManager;
@Autowired
private StorageHelper storageHelper;
private ScenarioEngine getScenarioEngine() {
return scenarioEngine;
@ -41,13 +44,12 @@ public class Test_ScenarioEngine extends TestBase {
@Test
public void test_UpdatePopulation() {
ScenarioContext scenarioContext = buildScenarioContext(
testId,
Scenario.scenarioBuilderWithCompile(buildRunScenarioModelWith(
ScenarioContext scenarioContext = buildScenarioContext(testId,
Scenario.scenarioCompiler(buildRunScenarioModelWith(
new ArrayList<UsePluginModel>(), BehaviorModel
.UserBehaviorBuilder(1, "ok", "http",
new ArrayList<ParameterModel>()))),
100, this.pluginManager);
100, this.pluginManager, this.storageHelper);
this.getScenarioEngine().getRunningTests().put(testId, scenarioContext);
scenarioContext.updatePopulation(20);
assertEquals(20, scenarioContext.getExecutor().getMaximumPoolSize());
@ -56,11 +58,12 @@ public class Test_ScenarioEngine extends TestBase {
@Test
public void test_RunWithContext() throws IOException {
ScenarioContext scenarioContext = buildScenarioContext(
testId, Scenario.scenarioBuilderWithCompile(FileUtils
ScenarioContext scenarioContext = buildScenarioContext(testId,
Scenario.scenarioBuilderWithCompile(FileUtils
.readFileToString(new File("Scripts"
+ System.getProperty("file.separator")
+ "homepage.xml"))), 100, this.pluginManager);
+ "homepage.xml"))), 100, this.pluginManager,
this.storageHelper);
this.getScenarioEngine().getRunningTests().put(testId, scenarioContext);
this.getScenarioEngine().runWith(testId);
}

View File

@ -51,7 +51,7 @@ public class Test_VUser extends TestBase {
}
}, behaviorModel);
Scenario scenario = Scenario
.scenarioBuilderWithCompile(runScenarioModel);
.scenarioCompiler(runScenarioModel);
VUser vUser = createVUser(scenario, testId);
Map<String, Object> plugins = new HashMap<String, Object>();
TestHelper

View File

@ -0,0 +1,7 @@
<html>
<head>
<meta charset="UTF-8" />
</head>
<body>
</body>
</html

View File

@ -174,10 +174,10 @@ public class TestPlanController extends BaseController {
public ScriptBehaviorsBriefModel getBehaviorsBrief(
@PathVariable UUID testPlanRunID, @PathVariable int scriptId)
throws Bench4QException, NullPointerException {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
throw new Bench4QException(HAVE_NO_POWER, EXCEPTION_HAPPEND
+ "when get behaviors's brief", "/getBehaviorsBrief");
}
// if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
// throw new Bench4QException(HAVE_NO_POWER, EXCEPTION_HAPPEND
// + "when get behaviors's brief", "/getBehaviorsBrief");
// }
ScriptBehaviorsBriefModel result = this
.getTestPlanScriptResultService()
.getLatestScriptBehaviorsBrief(testPlanRunID, scriptId);
@ -189,10 +189,10 @@ public class TestPlanController extends BaseController {
public ScriptPagesBriefModel getPagesBrief(
@PathVariable UUID testPlanRunId, @PathVariable int scriptId)
throws Bench4QException {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
throw new Bench4QException(HAVE_NO_POWER, EXCEPTION_HAPPEND
+ "when get behaviors's brief", "/getBehaviorsBrief");
}
// if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
// throw new Bench4QException(HAVE_NO_POWER, EXCEPTION_HAPPEND
// + "when get behaviors's brief", "/getBehaviorsBrief");
// }
ScriptPagesBriefModel pagesBriefModel = this
.getTestPlanScriptResultService().getLatestScriptPagesBrief(
testPlanRunId, scriptId);

View File

@ -250,9 +250,9 @@ public class RunningAgentDB implements RunningAgentInterface {
}
public TestBriefStatusModel briefAll() {
if (this.isStoped()) {
return null;
}
// if (this.isStoped()) {
// return null;
// }
return this.getAgentMessenger().scriptBriefAll(this.getAgent(),
this.getAgentRunId());
}

View File

@ -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(

View File

@ -1,139 +0,0 @@
package org.bench4q.master.domain.valueobject.datastatistics;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
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.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 HashMap<Integer, Map<Integer, BehaviorStatusCodeResultModel>>());
this.setIdUrlMap(new HashMap<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(getCopy(behaviorId, statusCode));
}
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;
if (behaviorBriefModel.getDetailStatusCodeResultModels() == null) {
return;
}
for (BehaviorStatusCodeResultModel behaviorStatusCodeResultModel : behaviorBriefModel
.getDetailStatusCodeResultModels()) {
totalCount += behaviorStatusCodeResultModel.getCount();
if (behaviorStatusCodeResultModel.getStatusCode() == 200) {
successfulCount += behaviorStatusCodeResultModel.getCount();
}
}
behaviorBriefModel.setTotalCount(totalCount);
behaviorBriefModel.setSuccessfulCount(successfulCount);
}
private BehaviorStatusCodeResultModel getCopy(int behaviorId, int statusCode) {
BehaviorStatusCodeResultModel statusInMap = this.getMap()
.get(behaviorId).get(statusCode);
BehaviorStatusCodeResultModel ret = new BehaviorStatusCodeResultModel();
ret.setStatusCode(statusCode);
ret.setContentLength(statusInMap.getContentLength());
ret.setContentType(statusInMap.getContentType());
ret.setCount(statusInMap.getCount());
ret.setMaxResponseTime(statusInMap.getMaxResponseTime());
ret.setMinResponseTime(statusInMap.getMinResponseTime());
ret.setTotalResponseTimeThisTime(statusInMap
.getTotalResponseTimeThisTime());
return ret;
}
public void add(DataStatisticsModel dataUnit) {
if (!(dataUnit instanceof AgentBehaviorsBriefModel)) {
return;
}
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.setContentLength(origin.getContentLength()
+ newOne.getContentLength());
origin.setCount(origin.getCount() + newOne.getCount());
origin.setTotalResponseTimeThisTime(origin
.getTotalResponseTimeThisTime()
+ newOne.getTotalResponseTimeThisTime());
if (newOne.getMaxResponseTime() > origin.getMaxResponseTime()) {
origin.setMaxResponseTime(newOne.getMaxResponseTime());
}
if (newOne.getMinResponseTime() < origin.getMinResponseTime()) {
origin.setMinResponseTime(newOne.getMinResponseTime());
}
}
}
}
private synchronized void guardAllMapsKeyExists(
BehaviorBriefModel behaviorBriefModel) {
if (!this.getMap().containsKey(behaviorBriefModel.getBehaviorId())) {
this.getMap().put(behaviorBriefModel.getBehaviorId(),
new HashMap<Integer, BehaviorStatusCodeResultModel>());
}
if (!this.getIdUrlMap().containsKey(behaviorBriefModel.getBehaviorId())) {
this.getIdUrlMap().put(behaviorBriefModel.getBehaviorId(),
behaviorBriefModel.getBehaviorUrl());
}
}
}

View File

@ -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;

View File

@ -0,0 +1,74 @@
package org.bench4q.master.domain.valueobject.datastatistics.impl;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.bench4q.share.models.agent.statistics.BehaviorBriefModel;
import org.bench4q.share.models.agent.statistics.BehaviorStatusCodeResultModel;
import org.bench4q.share.models.agent.statistics.DataStatisticsModel;
import org.bench4q.share.models.master.statistics.ScriptBehaviorBriefModel;
import org.bench4q.share.models.master.statistics.ScriptBehaviorStatusCodeModel;
public class BehaviorBriefStatistics extends ScriptStatistics {
private final int behaviorId;
private final String behaviorUrl;
private long successCountFromBegin;
private long totalCountFromBegin;
private volatile Map<Integer, BehaviorStatusCodeStatistics> detailStatisticsMap;
public BehaviorBriefStatistics(int behaviorId, String behaviorUrl) {
this.behaviorId = behaviorId;
this.behaviorUrl = behaviorUrl;
this.detailStatisticsMap = new ConcurrentHashMap<Integer, BehaviorStatusCodeStatistics>();
resetTempraryFields();
}
/**
* 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.successCountFromBegin = 0;
this.totalCountFromBegin = 0;
}
@Override
public void add(DataStatisticsModel dataUnit) {
if (!(dataUnit instanceof BehaviorBriefModel)) {
return;
}
BehaviorBriefModel behaviorBriefModel = (BehaviorBriefModel) dataUnit;
this.totalCountFromBegin += behaviorBriefModel.getTotalCount();
this.successCountFromBegin += behaviorBriefModel.getSuccessfulCount();
for (BehaviorStatusCodeResultModel newOne : behaviorBriefModel
.getDetailStatusCodeResultModels()) {
if (!this.detailStatisticsMap.containsKey(newOne.getStatusCode())) {
detailStatisticsMap
.put(newOne.getStatusCode(),
new BehaviorStatusCodeStatistics(
this.behaviorId,
newOne.getStatusCode(), newOne
.getContentType()));
}
detailStatisticsMap.get(newOne.getStatusCode()).add(newOne);
}
}
@Override
public Object getStatistics() {
ScriptBehaviorBriefModel result = new ScriptBehaviorBriefModel();
result.setBehaviorId(this.behaviorId);
result.setBehaviorUrl(this.behaviorUrl);
result.setSuccessCountFromBegin(this.successCountFromBegin);
result.setTotalCountFromBegin(this.totalCountFromBegin);
for (BehaviorStatusCodeStatistics item : this.detailStatisticsMap
.values()) {
result.getDetailStatusList().add(
(ScriptBehaviorStatusCodeModel) item.getStatistics());
}
return result;
}
}

View File

@ -0,0 +1,82 @@
package org.bench4q.master.domain.valueobject.datastatistics.impl;
import org.bench4q.master.domain.valueobject.datastatistics.DataStatistics;
import org.bench4q.share.models.agent.statistics.BehaviorStatusCodeResultModel;
import org.bench4q.share.models.agent.statistics.DataStatisticsModel;
import org.bench4q.share.models.master.statistics.ScriptBehaviorStatusCodeModel;
public class BehaviorStatusCodeStatistics implements DataStatistics {
private final int behaviorId;
private final int statusCode;
private final String contentType;
private long countThisTime;
private long countFromBegin;
private long contentLengthFromBegin;
private long contentLengthThisTime;
private long minResponseTime;
private long maxResponseTime;
private long totalResponseThisTime;
public BehaviorStatusCodeStatistics(int behaviorId, int statusCode,
String contentType) {
this.behaviorId = behaviorId;
this.statusCode = statusCode;
this.contentType = contentType;
resetTemperaryField();
}
@Override
public void add(DataStatisticsModel dataUnit) {
if (dataUnit == null
|| !(dataUnit instanceof BehaviorStatusCodeResultModel)) {
return;
}
BehaviorStatusCodeResultModel statusCodeResult = (BehaviorStatusCodeResultModel) dataUnit;
this.countThisTime++;
this.countFromBegin++;
this.contentLengthFromBegin += statusCodeResult.getContentLength();
this.contentLengthThisTime += statusCodeResult
.getContentLengthThisTime();
this.maxResponseTime = Math.max(this.maxResponseTime,
statusCodeResult.getMaxResponseTime());
this.minResponseTime = Math.min(this.minResponseTime,
statusCodeResult.getMinResponseTime());
this.totalResponseThisTime += statusCodeResult
.getTotalResponseTimeThisTime();
}
/**
* 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 resetTemperaryField() {
this.totalResponseThisTime = 0;
this.countFromBegin = 0;
this.countThisTime = 0;
this.maxResponseTime = Long.MIN_VALUE;
this.minResponseTime = Long.MAX_VALUE;
this.contentLengthFromBegin = 0;
this.contentLengthThisTime = 0;
}
@Override
public Object getStatistics() {
ScriptBehaviorStatusCodeModel result = new ScriptBehaviorStatusCodeModel();
result.setBehaviorId(this.behaviorId);
result.setContentLength(this.contentLengthFromBegin);
result.setContentType(this.contentType);
result.setCount(this.countFromBegin);
result.setMaxResponseTime(this.maxResponseTime);
result.setMinResponseTime(this.minResponseTime);
result.setStatusCode(this.statusCode);
result.setAverageResponseTime(this.countThisTime == 0 ? 0
: this.totalResponseThisTime / this.countThisTime);
result.setContentLength(this.contentLengthFromBegin);
result.setContentLengthThisTime(this.contentLengthThisTime);
resetTemperaryField();
return result;
}
}

View File

@ -0,0 +1,81 @@
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.statistics.BehaviorBriefModel;
import org.bench4q.share.models.agent.statistics.DataStatisticsModel;
import org.bench4q.share.models.agent.statistics.AgentBehaviorsBriefModel;
import org.bench4q.share.models.master.statistics.ScriptBehaviorBriefModel;
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
public class BehaviorsBriefStatistics extends ScriptStatistics {
private Map<Integer, String> idUrlMap;
private Map<Integer, BehaviorBriefStatistics> behaviorStatisticsMap;
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.setIdUrlMap(new ConcurrentHashMap<Integer, String>());
this.setBehaviorStatisticsMap(new ConcurrentHashMap<Integer, BehaviorBriefStatistics>());
}
public ScriptBehaviorsBriefModel getStatistics() {
ScriptBehaviorsBriefModel result = new ScriptBehaviorsBriefModel();
List<ScriptBehaviorBriefModel> list = new ArrayList<ScriptBehaviorBriefModel>();
for (int behaviorId : this.behaviorStatisticsMap.keySet()) {
list.add((ScriptBehaviorBriefModel) this.behaviorStatisticsMap.get(
behaviorId).getStatistics());
}
result.setBehaviorBriefModels(list);
makeUpResultModelWithSamplingTime(result);
return result;
}
public void add(DataStatisticsModel dataUnit) {
if (!(dataUnit instanceof AgentBehaviorsBriefModel)) {
return;
}
AgentBehaviorsBriefModel input = (AgentBehaviorsBriefModel) dataUnit;
for (BehaviorBriefModel behaviorBriefModel : input
.getBehaviorBriefModels()) {
guardAllMapsKeyExists(behaviorBriefModel);
this.getBehaviorStatisticsMap()
.get(behaviorBriefModel.getBehaviorId())
.add(behaviorBriefModel);
}
}
private synchronized void guardAllMapsKeyExists(
BehaviorBriefModel behaviorBriefModel) {
int behaviorId = behaviorBriefModel.getBehaviorId();
if (!this.getIdUrlMap().containsKey(behaviorId)) {
this.getIdUrlMap().put(behaviorId,
behaviorBriefModel.getBehaviorUrl());
}
if (!this.getBehaviorStatisticsMap().containsKey(behaviorId)) {
this.getBehaviorStatisticsMap().put(
behaviorId,
new BehaviorBriefStatistics(behaviorId, behaviorBriefModel
.getBehaviorUrl()));
}
}
}

View File

@ -1,4 +1,4 @@
package org.bench4q.master.domain.valueobject.datastatistics;
package org.bench4q.master.domain.valueobject.datastatistics.impl;
import org.bench4q.share.models.agent.statistics.AgentPageBriefModel;
import org.bench4q.share.models.agent.statistics.DataStatisticsModel;
@ -26,6 +26,12 @@ public class PageBriefStatistics extends ScriptStatistics {
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;

View File

@ -1,4 +1,4 @@
package org.bench4q.master.domain.valueobject.datastatistics;
package org.bench4q.master.domain.valueobject.datastatistics.impl;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

View File

@ -1,4 +1,4 @@
package org.bench4q.master.domain.valueobject.datastatistics;
package org.bench4q.master.domain.valueobject.datastatistics.impl;
import java.util.Date;
@ -128,10 +128,10 @@ public class ScriptBriefStatistics extends ScriptStatistics {
if (!(dataUnit instanceof AgentBriefStatusModel)) {
return;
}
add((AgentBriefStatusModel) dataUnit);
addCore((AgentBriefStatusModel) dataUnit);
}
private void add(AgentBriefStatusModel briefModel) {
private void addCore(AgentBriefStatusModel briefModel) {
if (briefModel == null) {
return;
}

View File

@ -1,7 +1,8 @@
package org.bench4q.master.domain.valueobject.datastatistics;
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 {

View File

@ -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());

View File

@ -17,7 +17,9 @@ import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.agent.RunScenarioModel;
import org.bench4q.share.models.agent.RunScenarioResultModel;
import org.bench4q.share.models.agent.TestBriefStatusModel;
import org.bench4q.share.models.agent.scriptrecord.ScheduleModel;
import org.bench4q.share.models.agent.scriptrecord.ScheduleModel.PointModel;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@ -45,7 +47,7 @@ public class Test_AgentMessenger extends TestBase_MakeUpTestPlan {
// TODO: modify this to adapt to new code
@Test
public void testSubmitScenarioWithParamsAndRun() throws IOException,
JAXBException {
JAXBException, InterruptedException {
List<File> paramFiles = new ArrayList<File>();
int scriptId = getUserFirstScript(this.getUserRepository().getUser(
@ -60,7 +62,7 @@ public class Test_AgentMessenger extends TestBase_MakeUpTestPlan {
paramFiles.add(file1);
paramFiles.add(file2);
File scenarioFile = new File("Scripts" + FILE_SEPARATOR
+ "forGoodRecord.xml");
+ "homepage.xml");
assertTrue(scenarioFile.exists());
RunScenarioModel inputModel = (RunScenarioModel) MarshalHelper
.unmarshal(RunScenarioModel.class,
@ -74,14 +76,22 @@ public class Test_AgentMessenger extends TestBase_MakeUpTestPlan {
assertNotNull(model);
assertNotNull(model.getRunId());
System.out.println(model.getRunId());
ScheduleModel scheduleModel = new ScheduleModel();
scheduleModel.getPoints().add(new PointModel(0, 0));
scheduleModel.getPoints().add(new PointModel(20, 20));
scheduleModel.getPoints().add(new PointModel(40, 20));
RunScenarioResultModel modelAfter = this.getAgentMessenger()
.submitScenrioWithParams(agent, model.getRunId(), paramFiles,
inputModel, new ScheduleModel(), new Date());
inputModel, scheduleModel, new Date());
assertEquals(model.getRunId(), modelAfter.getRunId());
model = this.getAgentMessenger().runWithParams(agent, model.getRunId());
assertNotNull(model);
assertNotNull(model.getRunId());
System.out.println(model.getRunId());
// Thread.sleep(2000);
TestBriefStatusModel briefModel = this.getAgentMessenger()
.scriptBriefAll(agent, model.getRunId());
assertNotNull(briefModel);
}
private File createParameterFile(int scriptId, String paramName)

View File

@ -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;

View File

@ -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;

View File

@ -0,0 +1,58 @@
package org.bench4q.master.unitTest.datastatistics;
import static org.junit.Assert.*;
import java.util.ArrayList;
import org.bench4q.master.domain.valueobject.datastatistics.impl.BehaviorBriefStatistics;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.agent.statistics.BehaviorBriefModel;
import org.bench4q.share.models.agent.statistics.BehaviorStatusCodeResultModel;
import org.bench4q.share.models.master.statistics.ScriptBehaviorBriefModel;
import org.bench4q.share.models.master.statistics.ScriptBehaviorStatusCodeModel;
import org.junit.Test;
public class Test_BehaviorBriefStatistics {
@Test
public void test() {
String url = "www.baidu.com";
int behaviorId = 1;
BehaviorBriefStatistics behaviorStatistics = new BehaviorBriefStatistics(
behaviorId, url);
behaviorStatistics.add(buildBehaviorBriefModel(behaviorId, url, 2, 3));
behaviorStatistics.add(buildBehaviorBriefModel(behaviorId, url, 3, 5));
ScriptBehaviorBriefModel result = (ScriptBehaviorBriefModel) behaviorStatistics
.getStatistics();
System.out.println(MarshalHelper.tryMarshal(result));
assertEquals(5, result.getSuccessCountFromBegin());
assertEquals(8, result.getTotalCountFromBegin());
int countForAllDetail = 0;
for (ScriptBehaviorStatusCodeModel behaviorStatusCodeModel : result
.getDetailStatusList()) {
countForAllDetail += behaviorStatusCodeModel.getCount();
}
assertEquals(result.getTotalCountFromBegin(), countForAllDetail);
}
private BehaviorBriefModel buildBehaviorBriefModel(int behaviorId,
String url, int successCount, int totalCount) {
BehaviorBriefModel e = new BehaviorBriefModel();
e.setBehaviorId(behaviorId);
e.setBehaviorUrl(url);
e.setDetailStatusCodeResultModels(new ArrayList<BehaviorStatusCodeResultModel>());
for (int i = 0; i < successCount; i++) {
e.getDetailStatusCodeResultModels().add(
new BehaviorStatusCodeResultModel(1, 200, 1, i + 1,
"text/html", 320, 10, 190, 260, 450));
}
for (int i = 0; i < totalCount - successCount; i++) {
e.getDetailStatusCodeResultModels().add(
new BehaviorStatusCodeResultModel(1, 400, 1, successCount
+ i + 1, "text/html", 320, 10, 190, 260, 450));
}
e.setSuccessfulCount(successCount);
e.setTotalCount(totalCount);
return e;
}
}

View File

@ -2,9 +2,10 @@ package org.bench4q.master.unitTest.datastatistics;
import org.junit.Test;
public class BehaviorsBriefStatisticsTest {
public class Test_BehaviorStatusStatistics {
@Test
public void testAddNull() {
public void test() {
}
}

View File

@ -0,0 +1,50 @@
package org.bench4q.master.unitTest.datastatistics;
import java.util.ArrayList;
import org.bench4q.master.domain.valueobject.datastatistics.impl.BehaviorsBriefStatistics;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.agent.statistics.AgentBehaviorsBriefModel;
import org.bench4q.share.models.agent.statistics.BehaviorBriefModel;
import org.bench4q.share.models.agent.statistics.BehaviorStatusCodeResultModel;
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
import org.junit.Test;
public class Test_BehaviorsBriefStatistics {
@Test
public void testAddNull() {
BehaviorsBriefStatistics behaviorsBriefStatistics = new BehaviorsBriefStatistics();
AgentBehaviorsBriefModel dataUnit = new AgentBehaviorsBriefModel();
String url = "www.baidu.com";
dataUnit.getBehaviorBriefModels().add(
buildBehaviorBriefModel(1, url, 2, 3));
dataUnit.getBehaviorBriefModels().add(
buildBehaviorBriefModel(1, url, 3, 5));
behaviorsBriefStatistics.add(dataUnit);
ScriptBehaviorsBriefModel result = behaviorsBriefStatistics
.getStatistics();
System.out.println(MarshalHelper.tryMarshal(result));
}
private BehaviorBriefModel buildBehaviorBriefModel(int behaviorId,
String url, int successCount, int totalCount) {
BehaviorBriefModel e = new BehaviorBriefModel();
e.setBehaviorId(behaviorId);
e.setBehaviorUrl(url);
e.setDetailStatusCodeResultModels(new ArrayList<BehaviorStatusCodeResultModel>());
for (int i = 0; i < successCount; i++) {
e.getDetailStatusCodeResultModels().add(
new BehaviorStatusCodeResultModel(1, 200, 2, 10,
"text/html", 320, 10, 190, 260, 450));
}
for (int i = 0; i < totalCount - successCount; i++) {
e.getDetailStatusCodeResultModels().add(
new BehaviorStatusCodeResultModel(1, 400, 2, 10,
"text/html", 320, 10, 190, 260, 450));
}
e.setSuccessfulCount(successCount);
e.setTotalCount(totalCount);
return e;
}
}

View File

@ -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;

View File

@ -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);
}

View File

@ -10,7 +10,6 @@ import java.util.concurrent.Future;
import org.bench4q.master.domain.entity.Agent;
import org.bench4q.master.infrastructure.communication.AgentMessenger;
import org.bench4q.share.enums.master.AgentStatus;
import org.bench4q.share.models.agent.BehaviorBriefModel;
import org.bench4q.share.models.agent.RunScenarioModel;
import org.bench4q.share.models.agent.RunScenarioResultModel;
import org.bench4q.share.models.agent.ServerStatusModel;
@ -20,6 +19,7 @@ import org.bench4q.share.models.agent.scriptrecord.ScheduleModel;
import org.bench4q.share.models.agent.statistics.AgentBehaviorsBriefModel;
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
import org.bench4q.share.models.agent.statistics.AgentPagesBriefModel;
import org.bench4q.share.models.agent.statistics.BehaviorBriefModel;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

View File

@ -1,13 +1,12 @@
package org.bench4q.share.models.agent.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.BehaviorBriefModel;
@XmlRootElement(name = "testBehaviorBriefModel")
public class AgentBehaviorsBriefModel extends DataStatisticsModel {
private List<BehaviorBriefModel> behaviorBriefModels;
@ -23,4 +22,7 @@ public class AgentBehaviorsBriefModel extends DataStatisticsModel {
this.behaviorBriefModels = behaviorBriefModels;
}
public AgentBehaviorsBriefModel() {
this.setBehaviorBriefModels(new LinkedList<BehaviorBriefModel>());
}
}

View File

@ -1,12 +1,14 @@
package org.bench4q.share.models.agent;
package org.bench4q.share.models.agent.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;
@XmlRootElement(name = "BehaviorBriefModel")
public class BehaviorBriefModel {
public class BehaviorBriefModel extends DataStatisticsModel {
private int behaviorId;
private String behaviorUrl;
private long totalCount;
@ -60,4 +62,7 @@ public class BehaviorBriefModel {
this.successfulCount = successfulCount;
}
public BehaviorBriefModel() {
this.setDetailStatusCodeResultModels(new LinkedList<BehaviorStatusCodeResultModel>());
}
}

View File

@ -0,0 +1,164 @@
package org.bench4q.share.models.agent.statistics;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "BehaviorStatusCodeResultModel")
public class BehaviorStatusCodeResultModel extends DataStatisticsModel {
private int behaviorId;
private int statusCode;
private long countThisTime;
private long count;
private String contentType;
private long contentLengthThisTime;
private long contentLength;
private long minResponseTime;
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;
}
public void setStatusCode(int statusCode) {
this.statusCode = statusCode;
}
@XmlElement
public long getCount() {
return count;
}
public void setCount(long count) {
this.count = count;
}
@XmlElement
public long getCountThisTime() {
return countThisTime;
}
public void setCountThisTime(long countThisTime) {
this.countThisTime = countThisTime;
}
@XmlElement
public String getContentType() {
return contentType;
}
public void setContentType(String contentType) {
this.contentType = contentType;
}
@XmlElement
public long getContentLengthThisTime() {
return contentLengthThisTime;
}
public void setContentLengthThisTime(long contentLengthThisTime) {
this.contentLengthThisTime = contentLengthThisTime;
}
@XmlElement
public long getContentLength() {
return contentLength;
}
public void setContentLength(long contentLength) {
this.contentLength = contentLength;
}
@XmlElement
public long getMinResponseTime() {
return minResponseTime;
}
public void setMinResponseTime(long minResponseTime) {
this.minResponseTime = minResponseTime;
}
@XmlElement
public long getMaxResponseTime() {
return maxResponseTime;
}
public void setMaxResponseTime(long maxResponseTime) {
this.maxResponseTime = maxResponseTime;
}
@XmlElement
public long getTotalResponseTimeThisTime() {
return totalResponseTimeThisTime;
}
public void setTotalResponseTimeThisTime(long totalResponseTimeThisTime) {
this.totalResponseTimeThisTime = totalResponseTimeThisTime;
}
/**
* It's just the http's success judgement, if we'll turn to other protocal,
* we should build a inheritance system
*
* @return
*/
public boolean isSuccess() {
return this.getStatusCode() == 200;
}
public BehaviorStatusCodeResultModel getCopy() {
BehaviorStatusCodeResultModel ret = new BehaviorStatusCodeResultModel();
ret.setStatusCode(getStatusCode());
ret.setContentLength(getContentLength());
ret.setContentType(getContentType());
ret.setCount(getCount());
ret.setMaxResponseTime(getMaxResponseTime());
ret.setMinResponseTime(getMinResponseTime());
ret.setTotalResponseTimeThisTime(getTotalResponseTimeThisTime());
return ret;
}
public synchronized void plus(BehaviorStatusCodeResultModel newOne) {
this.setContentLength(this.getContentLength()
+ newOne.getContentLength());
this.setCount(this.getCount() + newOne.getCount());
this.setTotalResponseTimeThisTime(this.getTotalResponseTimeThisTime()
+ newOne.getTotalResponseTimeThisTime());
if (newOne.getMaxResponseTime() > this.getMaxResponseTime()) {
this.setMaxResponseTime(newOne.getMaxResponseTime());
}
if (newOne.getMinResponseTime() < this.getMinResponseTime()) {
this.setMinResponseTime(newOne.getMinResponseTime());
}
}
public BehaviorStatusCodeResultModel() {
}
public BehaviorStatusCodeResultModel(int behaviorId, int statusCode,
long countThisTime, long count, String contentType,
long contentLength, long contentLengthThisTime,
long minResponseTime, long maxResponseTime,
long totalResponseTimeThisTime) {
this.behaviorId = behaviorId;
this.statusCode = statusCode;
this.countThisTime = countThisTime;
this.count = count;
this.contentType = contentType;
this.contentLength = contentLength;
this.contentLengthThisTime = contentLengthThisTime;
this.minResponseTime = minResponseTime;
this.maxResponseTime = maxResponseTime;
this.totalResponseTimeThisTime = totalResponseTimeThisTime;
}
}

View File

@ -0,0 +1,68 @@
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;
@XmlRootElement
public class ScriptBehaviorBriefModel {
private int behaviorId;
private String BehaviorUrl;
private long successCountFromBegin;
private long totalCountFromBegin;
private List<ScriptBehaviorStatusCodeModel> detailStatusList;
public ScriptBehaviorBriefModel() {
this.setDetailStatusList(new LinkedList<ScriptBehaviorStatusCodeModel>());
}
@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 long getSuccessCountFromBegin() {
return successCountFromBegin;
}
public void setSuccessCountFromBegin(long successCountFromBegin) {
this.successCountFromBegin = successCountFromBegin;
}
@XmlElement
public long getTotalCountFromBegin() {
return totalCountFromBegin;
}
public void setTotalCountFromBegin(long totalCountFromBegin) {
this.totalCountFromBegin = totalCountFromBegin;
}
@XmlElementWrapper(name = "statusResults")
@XmlElement
public List<ScriptBehaviorStatusCodeModel> getDetailStatusList() {
return detailStatusList;
}
public void setDetailStatusList(List<ScriptBehaviorStatusCodeModel> list) {
this.detailStatusList = list;
}
}

View File

@ -1,17 +1,28 @@
package org.bench4q.share.models.agent;
package org.bench4q.share.models.master.statistics;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "BehaviorStatusCodeResultModel")
public class BehaviorStatusCodeResultModel {
@XmlRootElement
public class ScriptBehaviorStatusCodeModel {
private int behaviorId;
private int statusCode;
private long count;
private String contentType;
private long contentLength;
private long contentLengthThisTime;
private long minResponseTime;
private long maxResponseTime;
private long totalResponseTimeThisTime;
private long averageResponseTime;
@XmlElement
public int getBehaviorId() {
return behaviorId;
}
public void setBehaviorId(int behaviorId) {
this.behaviorId = behaviorId;
}
@XmlElement
public int getStatusCode() {
@ -49,6 +60,15 @@ public class BehaviorStatusCodeResultModel {
this.contentLength = contentLength;
}
@XmlElement
public long getContentLengthThisTime() {
return contentLengthThisTime;
}
public void setContentLengthThisTime(long contentLengthThisTime) {
this.contentLengthThisTime = contentLengthThisTime;
}
@XmlElement
public long getMinResponseTime() {
return minResponseTime;
@ -68,12 +88,12 @@ public class BehaviorStatusCodeResultModel {
}
@XmlElement
public long getTotalResponseTimeThisTime() {
return totalResponseTimeThisTime;
public long getAverageResponseTime() {
return averageResponseTime;
}
public void setTotalResponseTimeThisTime(long totalResponseTimeThisTime) {
this.totalResponseTimeThisTime = totalResponseTimeThisTime;
public void setAverageResponseTime(long averageResponseTime) {
this.averageResponseTime = averageResponseTime;
}
}

View File

@ -5,19 +5,19 @@ 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.BehaviorBriefModel;
@XmlRootElement(name = "scriptBehaviorsBriefModel")
public class ScriptBehaviorsBriefModel extends SampleModel {
private List<BehaviorBriefModel> behaviorBriefModels;
private List<ScriptBehaviorBriefModel> behaviorBriefModels;
@XmlElementWrapper(name = "behaviorBriefList")
@XmlElement(name = "behaviorBrief")
public List<BehaviorBriefModel> getBehaviorBriefModels() {
public List<ScriptBehaviorBriefModel> getBehaviorBriefModels() {
return behaviorBriefModels;
}
public void setBehaviorBriefModels(
List<BehaviorBriefModel> behaviorBriefModels) {
List<ScriptBehaviorBriefModel> behaviorBriefModels) {
this.behaviorBriefModels = behaviorBriefModels;
}

View File

@ -15,7 +15,6 @@ import javax.xml.bind.JAXBException;
import org.apache.log4j.Logger;
import org.bench4q.share.helper.ExceptionLog;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.agent.BehaviorStatusCodeResultModel;
import org.bench4q.share.models.master.MonitorModel;
import org.bench4q.share.models.master.ScriptHandleModel;
import org.bench4q.share.models.master.TestPlanDBModel;
@ -23,6 +22,7 @@ import org.bench4q.share.models.master.TestPlanModel;
import org.bench4q.share.models.master.TestPlanResponseModel;
import org.bench4q.share.models.master.TestPlanResultModel;
import org.bench4q.share.models.master.TestPlanScriptBriefResultModel;
import org.bench4q.share.models.master.statistics.ScriptBehaviorStatusCodeModel;
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
import org.bench4q.share.models.master.statistics.ScriptPagesBriefModel;
@ -289,6 +289,7 @@ public class TestPlanController extends BaseController {
return fail(map, "");
}
map = success(map);
System.out.println(MarshalHelper.tryMarshal(scriptBehaviorsBriefModel));
map.put("behaviors", scriptBehaviorsBriefModel);
return map;
}
@ -369,7 +370,7 @@ public class TestPlanController extends BaseController {
@PathVariable String testPlanId) {
Map<String, Object> map = new HashMap<String, Object>();
List<BehaviorStatusCodeResultModel> behaviorStatusCodeResultModels = this
List<ScriptBehaviorStatusCodeModel> behaviorStatusCodeResultModels = this
.getTestPlanService().getAllBehaviorStatusCodeResultModels(
accessToken, testPlanId);
if (behaviorStatusCodeResultModels == null) {
@ -377,7 +378,7 @@ public class TestPlanController extends BaseController {
return fail(map, "");
}
Map<String, Long> urlContentCountMap = new HashMap<String, Long>();
for (BehaviorStatusCodeResultModel behaviorStatusCodeResultModel : behaviorStatusCodeResultModels) {
for (ScriptBehaviorStatusCodeModel behaviorStatusCodeResultModel : behaviorStatusCodeResultModels) {
if (urlContentCountMap.get(behaviorStatusCodeResultModel
.getContentType()) == null)
urlContentCountMap.put(
@ -421,15 +422,16 @@ public class TestPlanController extends BaseController {
}
@RequestMapping("loadFilterTypeList")
public @ResponseBody
Map<String, Object> loadFilterTypeList(HttpServletRequest request,
public @ResponseBody Map<String, Object> loadFilterTypeList(
HttpServletRequest request,
@ModelAttribute("accessToken") String accessToken) {
TestPlanResponseModel responseModel = this.getTestPlanMessager().loadFilterTypeList(accessToken);
Map<String,Object> map = new HashMap<String, Object>();
if(responseModel.isSuccess()){
TestPlanResponseModel responseModel = this.getTestPlanMessager()
.loadFilterTypeList(accessToken);
Map<String, Object> map = new HashMap<String, Object>();
if (responseModel.isSuccess()) {
map.put("filterTypeList", responseModel.getFilterTypeList());
success(map);
}else{
} else {
fail(map, responseModel.getFailCause());
}
return map;

View File

@ -9,8 +9,6 @@ import java.util.Map;
import java.util.Set;
import org.apache.log4j.Logger;
import org.bench4q.share.models.agent.BehaviorBriefModel;
import org.bench4q.share.models.agent.BehaviorStatusCodeResultModel;
import org.bench4q.share.models.agent.ScriptFilterOptionsModel;
import org.bench4q.share.models.master.MonitorModel;
import org.bench4q.share.models.master.RunningScriptModel;
@ -18,6 +16,8 @@ import org.bench4q.share.models.master.ScriptHandleModel;
import org.bench4q.share.models.master.TestPlanModel;
import org.bench4q.share.models.master.TestPlanResultModel;
import org.bench4q.share.models.master.TestPlanScriptBriefResultModel;
import org.bench4q.share.models.master.statistics.ScriptBehaviorBriefModel;
import org.bench4q.share.models.master.statistics.ScriptBehaviorStatusCodeModel;
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
import org.bench4q.web.masterMessager.TestPlanMessager;
@ -121,7 +121,7 @@ public class TestPlanService {
}
public List<BehaviorStatusCodeResultModel> getAllBehaviorStatusCodeResultModels(
public List<ScriptBehaviorStatusCodeModel> getAllBehaviorStatusCodeResultModels(
String accessToken, String testPlanId) {
TestPlanResultModel testPlanResultModel = this.getTestPlanMessager()
.getRunningTestInfo(accessToken, testPlanId);
@ -134,7 +134,7 @@ public class TestPlanService {
if (scriptList == null) {
return null;
}
List<BehaviorStatusCodeResultModel> behaviorStatusCodeResultModels = new LinkedList<BehaviorStatusCodeResultModel>();
List<ScriptBehaviorStatusCodeModel> behaviorStatusCodeResultModels = new LinkedList<ScriptBehaviorStatusCodeModel>();
for (ScriptHandleModel scriptHandleModel : scriptList) {
ScriptBehaviorsBriefModel scriptBehaviorBriefModel = this
.getTestPlanMessager().getScriptBehaviorsBriefResult(
@ -147,19 +147,18 @@ public class TestPlanService {
}
private List<BehaviorStatusCodeResultModel> extractBehaviorStatusCodeResultModels(
private List<ScriptBehaviorStatusCodeModel> extractBehaviorStatusCodeResultModels(
ScriptBehaviorsBriefModel scriptBehaviorsBriefModel) {
List<BehaviorStatusCodeResultModel> behaviorStatusCodeResultModels = new ArrayList<BehaviorStatusCodeResultModel>();
List<ScriptBehaviorStatusCodeModel> behaviorStatusCodeResultModels = new ArrayList<ScriptBehaviorStatusCodeModel>();
if (scriptBehaviorsBriefModel == null
|| scriptBehaviorsBriefModel.getBehaviorBriefModels() == null) {
return behaviorStatusCodeResultModels;
}
for (BehaviorBriefModel behaviorBriefModel : scriptBehaviorsBriefModel
for (ScriptBehaviorBriefModel behaviorBriefModel : scriptBehaviorsBriefModel
.getBehaviorBriefModels()) {
if (behaviorBriefModel.getDetailStatusCodeResultModels() != null)
if (behaviorBriefModel.getDetailStatusList() != null)
behaviorStatusCodeResultModels.addAll(behaviorBriefModel
.getDetailStatusCodeResultModels());
.getDetailStatusList());
}
return behaviorStatusCodeResultModels;
}

View File

@ -1,11 +1,10 @@
function Behavior() {
this.table = $("#url").DataTable();
this.table.column(5).visible(false);
this.getBehaviorResultsFirstly = function(testPlanId, map,scripts) {
this.getBehaviorResultsFirstly = function(testPlanId, map, scripts) {
for(var i=0;i<scripts.length;i++){
var url = testPlanId + "/" + scripts[i].scriptId
+ "/behaviors";
for (var i = 0; i < scripts.length; i++) {
var url = testPlanId + "/" + scripts[i].scriptId + "/behaviors";
this.getBehaviorResult(url, map, scripts[i].scriptName, this.table);
}
@ -15,20 +14,21 @@ function Behavior() {
this.loadBehaviorResults = function(testPlanId, scripts) {
var map = new HashMap();
this.getBehaviorResultsFirstly(testPlanId,map,scripts);
this.getBehaviorResultsFirstly(testPlanId, map, scripts);
var behavior = this;
if (scripts == null) {
return;
}
this.intervalId = setInterval(function() {
this.intervalId = setInterval(
function() {
for ( var i = 0; i < scripts.length; i++) {
for (var i = 0; i < scripts.length; i++) {
var url = testPlanId + "/" + scripts[i].scriptId
+ "/behaviors";
behavior.getBehaviorResult(url, map, scripts[i].scriptName,
behavior.table);
behavior.getBehaviorResult(url, map,
scripts[i].scriptName, behavior.table);
}
}, 10000);
@ -44,12 +44,12 @@ function Behavior() {
map.put(scriptName, data);
behaviorResult.insertDataToTable(table, map);
if ($("#status").attr("status") == "Complete") {
if(behaviorResult.intervalId!=null){
if (behaviorResult.intervalId != null) {
clearInterval(behaviorResult.intervalId);
}
}
}, "json").error(function(){
}, "json").error(function() {
information($.i18n.prop('failed-connect-server'));
});
@ -57,20 +57,20 @@ function Behavior() {
this.insertDataToTable = function(table, map) {
table.clear();
for ( var k = 0; k < map.length(); k++) {
for (var k = 0; k < map.length(); k++) {
var names = map.getKeys();
var behaviors = map.get(names[k]).behaviorBriefModels;
if (behaviors == null) {
return;
}
for ( var j = 0; j < behaviors.length; j++) {
for (var j = 0; j < behaviors.length; j++) {
var data = behaviors[j];
var rowNode = table.row.add(
[ "", data.behaviorUrl, names[k], data.totalCount,
data.successfulCount,
data.detailStatusCodeResultModels ]).draw()
.node();
[ "", data.behaviorUrl, names[k],
data.totalCountFromBegin,
data.successCountFromBegin,
data.detailStatusList ]).draw().node();
var td = $(rowNode).find("td")[0];
$(td).addClass("details-control");
}
@ -80,14 +80,20 @@ function Behavior() {
}
this.createDetailTable = function(url, detailDatas) {
var theader=[ $.i18n.prop('result-url'), $.i18n.prop('result-url-statusCode'), $.i18n.prop('result-url-count'), $.i18n.prop('result-url-contentLength'), $.i18n.prop('result-url-minRes'), $.i18n.prop('result-url-maxRes'), $.i18n.prop('result-url-totalRes')];
var theader = [ $.i18n.prop('result-url'),
$.i18n.prop('result-url-statusCode'),
$.i18n.prop('result-url-count'),
$.i18n.prop('result-url-contentLength'),
$.i18n.prop('result-url-minRes'),
$.i18n.prop('result-url-maxRes'),
$.i18n.prop('result-url-totalRes') ];
var table = $("<table></table>");
table.addClass("innerTable");
$(table).attr("style", "width: 100%;");
var thead = $("<thead></thead>");
var tr = $("<tr></tr>");
for ( var i = 0; i < theader.length; i++) {
for (var i = 0; i < theader.length; i++) {
var th = $("<th>" + theader[i] + "</th>");
th.attr("style", "width:10% ;");
tr.append(th);
@ -96,7 +102,7 @@ function Behavior() {
table.append(thead);
var tbody = $("<tbody></tbody>");
table.append(tbody);
for ( var i = 0; i < detailDatas.length; i++) {
for (var i = 0; i < detailDatas.length; i++) {
var tr = this.createDetailRow(detailDatas[i], url, theader)
tbody.append(tr);
@ -106,9 +112,12 @@ function Behavior() {
this.createDetailRow = function(detailData, url, theader) {
var tr = $("<tr></tr>");
var dataArray = [url,detailData.statusCode,detailData.count,detailData.contentLength,detailData.minResponseTime,detailData.maxResponseTime,detailData.totalResponseTimeThisTime];
var dataArray = [ url, detailData.statusCode, detailData.count,
detailData.contentLength, detailData.minResponseTime,
detailData.maxResponseTime,
detailData.totalResponseTimeThisTime ];
dataArray[0] = url;
for ( var i = 0; i < dataArray.length; i++) {
for (var i = 0; i < dataArray.length; i++) {
var td = $("<td></td>");
td.attr("style", "width: 10%;");
td.html(dataArray[i]);