refactor
This commit is contained in:
parent
beb5cd1973
commit
112d8f1949
|
@ -13,7 +13,7 @@ import javax.xml.bind.JAXBException;
|
|||
import javax.xml.bind.Marshaller;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.agent.datacollector.impl.DetailStatusCodeResult;
|
||||
import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResult;
|
||||
import org.bench4q.agent.scenario.Batch;
|
||||
import org.bench4q.agent.scenario.Page;
|
||||
import org.bench4q.agent.scenario.Parameter;
|
||||
|
@ -205,7 +205,7 @@ public class TestController {
|
|||
for (Behavior behavior : scenarioContext.getScenario()
|
||||
.getAllBehaviorsInScenario()) {
|
||||
int behaviorId = behavior.getId();
|
||||
Map<Integer, DetailStatusCodeResult> map = behavior
|
||||
Map<Integer, BehaviorStatusCodeResult> map = behavior
|
||||
.getBehaviorBriefResult(scenarioContext.getDataStatistics());
|
||||
if (map == null) {
|
||||
continue;
|
||||
|
@ -225,17 +225,17 @@ public class TestController {
|
|||
if (scenarioContext == null) {
|
||||
return null;
|
||||
}
|
||||
Map<Integer, DetailStatusCodeResult> map = scenarioContext
|
||||
.getDataStatistics().getDetailStatistics(behaviorId);
|
||||
Map<Integer, BehaviorStatusCodeResult> map = scenarioContext
|
||||
.getDataStatistics().getBehaviorBriefStatistics(behaviorId);
|
||||
return buildBehaviorBrief(runId, behaviorId, map);
|
||||
}
|
||||
|
||||
private BehaviorBriefModel buildBehaviorBrief(UUID runId, int behaviorId,
|
||||
Map<Integer, DetailStatusCodeResult> map) {
|
||||
Map<Integer, BehaviorStatusCodeResult> map) {
|
||||
List<BehaviorStatusCodeResultModel> detailStatusCodeResultModels = new ArrayList<BehaviorStatusCodeResultModel>();
|
||||
for (int statusCode : map.keySet()) {
|
||||
BehaviorStatusCodeResultModel behaviorStatusCodeResultModel = new BehaviorStatusCodeResultModel();
|
||||
DetailStatusCodeResult detailStatusCodeResult = map.get(statusCode);
|
||||
BehaviorStatusCodeResult detailStatusCodeResult = map.get(statusCode);
|
||||
behaviorStatusCodeResultModel.setStatusCode(statusCode);
|
||||
behaviorStatusCodeResultModel
|
||||
.setCount(detailStatusCodeResult.count);
|
||||
|
@ -267,7 +267,7 @@ public class TestController {
|
|||
return null;
|
||||
}
|
||||
return (AgentBriefStatusModel) scenarioContext.getDataStatistics()
|
||||
.getBriefStatistics();
|
||||
.getScenarioBriefStatistics();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/stop/{runId}", method = { RequestMethod.GET,
|
||||
|
|
|
@ -66,9 +66,9 @@ public abstract class AbstractDataCollector implements DataStatistics {
|
|||
|
||||
protected abstract String calculateSavePath(BehaviorResult behaviorResult);
|
||||
|
||||
public abstract Object getBriefStatistics();
|
||||
public abstract Object getScenarioBriefStatistics();
|
||||
|
||||
public abstract Map<Integer, DetailStatusCodeResult> getDetailStatistics(
|
||||
public abstract Map<Integer, BehaviorStatusCodeResult> getBehaviorBriefStatistics(
|
||||
int id);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
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;
|
||||
|
@ -29,7 +30,7 @@ public class AgentResultDataCollector extends AbstractDataCollector {
|
|||
private UUID testID;
|
||||
// The first integer is the behavior's id, and the second integer is
|
||||
// the StatusCode of this behaviorResult.
|
||||
private Map<Integer, Map<Integer, DetailStatusCodeResult>> detailMap;
|
||||
private Map<Integer, Map<Integer, BehaviorStatusCodeResult>> detailMap;
|
||||
|
||||
private void setTimeOfPreviousCall(long timeOfPreviousCall) {
|
||||
this.timeOfPreviousCall = timeOfPreviousCall;
|
||||
|
@ -89,7 +90,7 @@ public class AgentResultDataCollector extends AbstractDataCollector {
|
|||
}
|
||||
|
||||
private void setDetailMap(
|
||||
Map<Integer, Map<Integer, DetailStatusCodeResult>> detailMap) {
|
||||
Map<Integer, Map<Integer, BehaviorStatusCodeResult>> detailMap) {
|
||||
this.detailMap = detailMap;
|
||||
}
|
||||
|
||||
|
@ -103,7 +104,7 @@ public class AgentResultDataCollector extends AbstractDataCollector {
|
|||
reset();
|
||||
this.setCumulativeFailCount(0);
|
||||
this.setCumulativeSucessfulCount(0);
|
||||
this.setDetailMap(new HashMap<Integer, Map<Integer, DetailStatusCodeResult>>());
|
||||
this.setDetailMap(new HashMap<Integer, Map<Integer, BehaviorStatusCodeResult>>());
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
|
@ -120,7 +121,7 @@ public class AgentResultDataCollector extends AbstractDataCollector {
|
|||
// DataStatistics Interface start
|
||||
// ///////////////////////////////
|
||||
|
||||
public AgentBriefStatusModel getBriefStatistics() {
|
||||
public AgentBriefStatusModel getScenarioBriefStatistics() {
|
||||
AgentBriefStatusModel result = new AgentBriefStatusModel();
|
||||
result.setTimeFrame(System.currentTimeMillis()
|
||||
- this.timeOfPreviousCall);
|
||||
|
@ -188,17 +189,17 @@ public class AgentResultDataCollector extends AbstractDataCollector {
|
|||
|
||||
private void dealWithDetailResult(BehaviorResult behaviorResult) {
|
||||
insertWhenNotExist(behaviorResult);
|
||||
Map<Integer, DetailStatusCodeResult> detailStatusMap = this.detailMap
|
||||
Map<Integer, BehaviorStatusCodeResult> detailStatusMap = this.detailMap
|
||||
.get(behaviorResult.getBehaviorId());
|
||||
|
||||
if (!detailStatusMap.containsKey(behaviorResult.getStatusCode())) {
|
||||
detailStatusMap
|
||||
.put(new Integer(behaviorResult.getStatusCode()),
|
||||
new DetailStatusCodeResult(behaviorResult
|
||||
.getContentType()));
|
||||
detailStatusMap.put(
|
||||
new Integer(behaviorResult.getStatusCode()),
|
||||
new BehaviorStatusCodeResult(behaviorResult
|
||||
.getContentType()));
|
||||
}
|
||||
|
||||
DetailStatusCodeResult detailResult = detailStatusMap
|
||||
BehaviorStatusCodeResult detailResult = detailStatusMap
|
||||
.get(behaviorResult.getStatusCode());
|
||||
detailResult.count++;
|
||||
if (!behaviorResult.isSuccess()) {
|
||||
|
@ -222,7 +223,7 @@ public class AgentResultDataCollector extends AbstractDataCollector {
|
|||
private void insertWhenNotExist(BehaviorResult behaviorResult) {
|
||||
if (!this.detailMap.containsKey(behaviorResult.getBehaviorId())) {
|
||||
this.detailMap.put(new Integer(behaviorResult.getBehaviorId()),
|
||||
new HashMap<Integer, DetailStatusCodeResult>());
|
||||
new HashMap<Integer, BehaviorStatusCodeResult>());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -244,12 +245,12 @@ public class AgentResultDataCollector extends AbstractDataCollector {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, DetailStatusCodeResult> getDetailStatistics(
|
||||
public Map<Integer, BehaviorStatusCodeResult> getBehaviorBriefStatistics(
|
||||
int behaviorId) {
|
||||
if (!this.detailMap.containsKey(behaviorId)) {
|
||||
return null;
|
||||
}
|
||||
return this.detailMap.get(behaviorId);
|
||||
return Collections.unmodifiableMap(this.detailMap.get(behaviorId));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.bench4q.agent.datacollector.impl;
|
|||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class DetailStatusCodeResult {
|
||||
public class BehaviorStatusCodeResult {
|
||||
public long count;
|
||||
public long contentLength;
|
||||
public long minResponseTime;
|
||||
|
@ -10,7 +10,7 @@ public class DetailStatusCodeResult {
|
|||
public long totalResponseTimeThisTime;
|
||||
public String contentType;
|
||||
|
||||
public DetailStatusCodeResult(String contentType) {
|
||||
public BehaviorStatusCodeResult(String contentType) {
|
||||
this.totalResponseTimeThisTime = 0;
|
||||
this.contentType = contentType;
|
||||
this.count = 0;
|
|
@ -2,13 +2,14 @@ package org.bench4q.agent.datacollector.interfaces;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import org.bench4q.agent.datacollector.impl.DetailStatusCodeResult;
|
||||
import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResult;
|
||||
import org.bench4q.agent.scenario.BehaviorResult;
|
||||
|
||||
public interface DataStatistics {
|
||||
public void add(BehaviorResult behaviorResult);
|
||||
|
||||
public Object getBriefStatistics();
|
||||
public Object getScenarioBriefStatistics();
|
||||
|
||||
public Map<Integer, DetailStatusCodeResult> getDetailStatistics(int id);
|
||||
public Map<Integer, BehaviorStatusCodeResult> getBehaviorBriefStatistics(
|
||||
int id);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.bench4q.agent.scenario.behavior;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import org.bench4q.agent.datacollector.impl.DetailStatusCodeResult;
|
||||
import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResult;
|
||||
import org.bench4q.agent.datacollector.interfaces.DataStatistics;
|
||||
import org.bench4q.agent.scenario.Parameter;
|
||||
|
||||
|
@ -46,6 +46,6 @@ public abstract class Behavior {
|
|||
|
||||
public abstract boolean shouldBeCountResponseTime();
|
||||
|
||||
public abstract Map<Integer, DetailStatusCodeResult> getBehaviorBriefResult(
|
||||
public abstract Map<Integer, BehaviorStatusCodeResult> getBehaviorBriefResult(
|
||||
DataStatistics dataStatistics);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.bench4q.agent.scenario.behavior;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import org.bench4q.agent.datacollector.impl.DetailStatusCodeResult;
|
||||
import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResult;
|
||||
import org.bench4q.agent.datacollector.interfaces.DataStatistics;
|
||||
|
||||
public class TimerBehavior extends Behavior {
|
||||
|
@ -13,7 +13,7 @@ public class TimerBehavior extends Behavior {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, DetailStatusCodeResult> getBehaviorBriefResult(
|
||||
public Map<Integer, BehaviorStatusCodeResult> getBehaviorBriefResult(
|
||||
DataStatistics dataStatistics) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.bench4q.agent.scenario.behavior;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import org.bench4q.agent.datacollector.impl.DetailStatusCodeResult;
|
||||
import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResult;
|
||||
import org.bench4q.agent.datacollector.interfaces.DataStatistics;
|
||||
|
||||
public class UserBehavior extends Behavior {
|
||||
|
@ -12,9 +12,9 @@ public class UserBehavior extends Behavior {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, DetailStatusCodeResult> getBehaviorBriefResult(
|
||||
public Map<Integer, BehaviorStatusCodeResult> getBehaviorBriefResult(
|
||||
DataStatistics dataStatistics) {
|
||||
return dataStatistics.getDetailStatistics(this.getId());
|
||||
return dataStatistics.getBehaviorBriefStatistics(this.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public class DataStatisticsTest {
|
|||
}
|
||||
|
||||
AgentBriefStatusModel model = (AgentBriefStatusModel) this
|
||||
.getDataStatistics().getBriefStatistics();
|
||||
.getDataStatistics().getScenarioBriefStatistics();
|
||||
AgentBriefStatusModel modelExpect = makeAllZeroModel();
|
||||
modelExpect.setTimeFrame(model.getTimeFrame());
|
||||
assertTrue(model.equals(modelExpect));
|
||||
|
@ -63,7 +63,7 @@ public class DataStatisticsTest {
|
|||
|
||||
Thread.sleep(100);
|
||||
AgentBriefStatusModel model = (AgentBriefStatusModel) this
|
||||
.getDataStatistics().getBriefStatistics();
|
||||
.getDataStatistics().getScenarioBriefStatistics();
|
||||
AgentBriefStatusModel modelExpect = new AgentBriefStatusModel();
|
||||
modelExpect.setTimeFrame(model.getTimeFrame());
|
||||
makeUpStatusModelForOneBehavior(modelExpect);
|
||||
|
@ -77,7 +77,7 @@ public class DataStatisticsTest {
|
|||
}
|
||||
Thread.sleep(100);
|
||||
AgentBriefStatusModel model = (AgentBriefStatusModel) this
|
||||
.getDataStatistics().getBriefStatistics();
|
||||
.getDataStatistics().getScenarioBriefStatistics();
|
||||
AgentBriefStatusModel modelExpect = makeUpStatusModelForTwoBehavior(model
|
||||
.getTimeFrame());
|
||||
assertTrue(model.equals(modelExpect));
|
||||
|
|
|
@ -7,7 +7,7 @@ import java.util.Map;
|
|||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.agent.datacollector.impl.AgentResultDataCollector;
|
||||
import org.bench4q.agent.datacollector.impl.DetailStatusCodeResult;
|
||||
import org.bench4q.agent.datacollector.impl.BehaviorStatusCodeResult;
|
||||
import org.bench4q.agent.datacollector.interfaces.DataStatistics;
|
||||
import org.bench4q.agent.scenario.BehaviorResult;
|
||||
import org.bench4q.agent.storage.StorageHelper;
|
||||
|
@ -48,7 +48,7 @@ public class DetailStatisticsTest {
|
|||
this.getDetailStatistics().add(behaviorResult);
|
||||
}
|
||||
|
||||
Object object = this.detailStatistics.getDetailStatistics(0);
|
||||
Object object = this.detailStatistics.getBehaviorBriefStatistics(0);
|
||||
assertEquals(null, object);
|
||||
}
|
||||
|
||||
|
@ -58,15 +58,15 @@ public class DetailStatisticsTest {
|
|||
.makeBehaviorResultList(1)) {
|
||||
this.getDetailStatistics().add(behaviorResult);
|
||||
}
|
||||
Map<Integer, DetailStatusCodeResult> map = this.detailStatistics
|
||||
.getDetailStatistics(1);
|
||||
Map<Integer, BehaviorStatusCodeResult> map = this.detailStatistics
|
||||
.getBehaviorBriefStatistics(1);
|
||||
|
||||
DetailStatusCodeResult actualResult = map.get(200);
|
||||
BehaviorStatusCodeResult actualResult = map.get(200);
|
||||
actualResult.equals(makeExpectedResultForOne());
|
||||
}
|
||||
|
||||
private DetailStatusCodeResult makeExpectedResultForOne() {
|
||||
DetailStatusCodeResult ret = new DetailStatusCodeResult("");
|
||||
private BehaviorStatusCodeResult makeExpectedResultForOne() {
|
||||
BehaviorStatusCodeResult ret = new BehaviorStatusCodeResult("");
|
||||
ret.contentLength = 20;
|
||||
ret.count = 1;
|
||||
ret.maxResponseTime = 200;
|
||||
|
@ -80,23 +80,23 @@ public class DetailStatisticsTest {
|
|||
.makeBehaviorResultList(2)) {
|
||||
this.getDetailStatistics().add(behaviorResult);
|
||||
}
|
||||
Map<Integer, DetailStatusCodeResult> map = this.detailStatistics
|
||||
.getDetailStatistics(1);
|
||||
Map<Integer, BehaviorStatusCodeResult> map = this.detailStatistics
|
||||
.getBehaviorBriefStatistics(1);
|
||||
assertTrue(mapEquals(map, makeExpectedMapForTwo()));
|
||||
// DetailResult ex
|
||||
}
|
||||
|
||||
private Map<Integer, DetailStatusCodeResult> makeExpectedMapForTwo() {
|
||||
Map<Integer, DetailStatusCodeResult> ret = new HashMap<Integer, DetailStatusCodeResult>();
|
||||
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, 0, 0, 0));
|
||||
return ret;
|
||||
}
|
||||
|
||||
private DetailStatusCodeResult buildCodeResult(long contentLength,
|
||||
private BehaviorStatusCodeResult buildCodeResult(long contentLength,
|
||||
long count, long maxResponseTime, long minResponseTime,
|
||||
long totalResponseTimeThisTime) {
|
||||
DetailStatusCodeResult ret = new DetailStatusCodeResult("");
|
||||
BehaviorStatusCodeResult ret = new BehaviorStatusCodeResult("");
|
||||
ret.contentLength = contentLength;
|
||||
ret.count = count;
|
||||
ret.maxResponseTime = maxResponseTime;
|
||||
|
@ -105,8 +105,8 @@ public class DetailStatisticsTest {
|
|||
return ret;
|
||||
}
|
||||
|
||||
private boolean mapEquals(Map<Integer, DetailStatusCodeResult> mapActual,
|
||||
Map<Integer, DetailStatusCodeResult> mapExpected) {
|
||||
private boolean mapEquals(Map<Integer, BehaviorStatusCodeResult> mapActual,
|
||||
Map<Integer, BehaviorStatusCodeResult> mapExpected) {
|
||||
boolean equal = true;
|
||||
if (mapActual.size() != mapExpected.size()) {
|
||||
return false;
|
||||
|
@ -125,13 +125,13 @@ public class DetailStatisticsTest {
|
|||
.makeBehaviorResultList(3)) {
|
||||
this.getDetailStatistics().add(behaviorResult);
|
||||
}
|
||||
Map<Integer, DetailStatusCodeResult> mapActual = this
|
||||
.getDetailStatistics().getDetailStatistics(1);
|
||||
Map<Integer, BehaviorStatusCodeResult> mapActual = this
|
||||
.getDetailStatistics().getBehaviorBriefStatistics(1);
|
||||
assertTrue(mapEquals(mapActual, makeExpectedMapForThree()));
|
||||
}
|
||||
|
||||
private Map<Integer, DetailStatusCodeResult> makeExpectedMapForThree() {
|
||||
Map<Integer, DetailStatusCodeResult> retMap = new HashMap<Integer, DetailStatusCodeResult>();
|
||||
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, 0, 0, 0));
|
||||
return retMap;
|
||||
|
|
Loading…
Reference in New Issue