refactor and remove bug from brief

refactor and remove bug from brief
This commit is contained in:
coderfengyun 2014-05-07 11:26:26 +08:00
parent 4f86595ddf
commit 8eb5ba5a54
6 changed files with 57 additions and 25 deletions

View File

@ -201,9 +201,9 @@ public class ScenarioResultCollector extends AbstractDataCollector {
.get(behaviorResult.getStatusCode());
statusCodeResult.count++;
if (behaviorResult.getSuccessCount() == 0) {
statusCodeResult.maxResponseTime = 0;
statusCodeResult.minResponseTime = 0;
statusCodeResult.contentLength = 0;
// statusCodeResult.maxResponseTime = 0;
// statusCodeResult.minResponseTime = 0;
statusCodeResult.contentLength += 0;
statusCodeResult.totalResponseTimeThisTime = 0;
return;
}

View File

@ -163,7 +163,7 @@ public class HttpPlugin extends ParameterBarn {
respVarsToSaveInSession,
method.getResponseBodyAsString()));
}
return new HttpReturn(responseCode > 0, responseCode,
return new HttpReturn((responseCode % 100) < 4, responseCode,
contentLength, contentType, responseHeaders);
} catch (HttpException e) {
Logger.getLogger(HttpPlugin.class).error(e, e);

View File

@ -62,7 +62,7 @@ public class TestWithScriptFile {
public TestWithScriptFile() {
this.setFilePath("Scripts" + System.getProperty("file.separator")
+ "forGoodRecord.xml");
+ "testForBrief.xml");
this.setHttpRequester(new HttpRequester());
}
@ -189,11 +189,21 @@ public class TestWithScriptFile {
public void testSubmitParamsAndRun() throws Exception {
List<File> files = new ArrayList<File>();
files.add(new File("Scripts" + System.getProperty("file.separator")
+ "forGoodRecord.xml"));
+ "testForBrief.xml"));
files.add(new File("Scripts" + System.getProperty("file.separator")
+ "testJD.xml"));
HttpResponse httpResponse = this.getHttpRequester().postFiles(null,
url + "/submitScenarioWithParams", "files[]", files,
HttpResponse httpResponse1 = this.getHttpRequester().sendPost(
url + "/bookTest/10", null, null);
RunScenarioResultModel bookResponse = (RunScenarioResultModel) MarshalHelper
.tryUnmarshal(RunScenarioResultModel.class,
httpResponse1.getContent());
assertNotNull(bookResponse);
assertNotNull(bookResponse.getRunId().toString());
System.out.println(bookResponse.getRunId().toString());
HttpResponse httpResponse = this.getHttpRequester().postFiles(
null,
url + "/submitScenarioWithParams/"
+ bookResponse.getRunId().toString(), "files[]", files,
"scenarioModel", new LinkedList<String>() {
private static final long serialVersionUID = 1L;
{

View File

@ -44,7 +44,7 @@ public class DetailStatisticsTest {
@Test
public void addZeroTest() {
for (BehaviorResult behaviorResult : ScenarioStatisticsTest
.makeBehaviorList(0)) {
.makeBehaviorListWhoseBehaviorIdIsOne(0)) {
this.getDetailStatistics().add(behaviorResult);
}
@ -55,7 +55,7 @@ public class DetailStatisticsTest {
@Test
public void addOneDetailTest() {
for (BehaviorResult behaviorResult : ScenarioStatisticsTest
.makeBehaviorList(1)) {
.makeBehaviorListWhoseBehaviorIdIsOne(1)) {
this.getDetailStatistics().add(behaviorResult);
}
Map<Integer, BehaviorStatusCodeResult> map = this.detailStatistics
@ -78,7 +78,7 @@ public class DetailStatisticsTest {
@Test
public void addTwoDetailTest() {
for (BehaviorResult behaviorResult : ScenarioStatisticsTest
.makeBehaviorList(2)) {
.makeBehaviorListWhoseBehaviorIdIsOne(2)) {
this.getDetailStatistics().add(behaviorResult);
}
Map<Integer, BehaviorStatusCodeResult> map = this.detailStatistics
@ -89,7 +89,28 @@ public class DetailStatisticsTest {
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));
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;
}
@ -122,7 +143,7 @@ public class DetailStatisticsTest {
@Test
public void addThreeTest() {
for (BehaviorResult behaviorResult : ScenarioStatisticsTest
.makeBehaviorList(3)) {
.makeBehaviorListWhoseBehaviorIdIsOne(3)) {
this.getDetailStatistics().add(behaviorResult);
}
Map<Integer, BehaviorStatusCodeResult> mapActual = this

View File

@ -36,7 +36,7 @@ public class PageResultStatisticsTest {
@Test
public void pageResultTest() {
PageResult pageResult = PageResult.buildPageResult(2,
ScenarioStatisticsTest.makeBehaviorList(1));
ScenarioStatisticsTest.makeBehaviorListWhoseBehaviorIdIsOne(1));
assertEquals(2, pageResult.getPageId());
assertEquals(200, pageResult.getExecuteRange());
}
@ -44,7 +44,7 @@ public class PageResultStatisticsTest {
@Test
public void pageResultWithTwoBehaviorTest() {
PageResult pageResult = PageResult.buildPageResult(2,
ScenarioStatisticsTest.makeBehaviorList(2));
ScenarioStatisticsTest.makeBehaviorListWhoseBehaviorIdIsOne(2));
assertEquals(2, pageResult.getPageId());
assertEquals(220, pageResult.getExecuteRange());
assertEquals(420, pageResult.getPageEndTime());
@ -60,7 +60,7 @@ public class PageResultStatisticsTest {
public void testOnePaegWithOneBehaviorResult() {
this.getDataCollector().add(
PageResult.buildPageResult(2,
ScenarioStatisticsTest.makeBehaviorList(1)));
ScenarioStatisticsTest.makeBehaviorListWhoseBehaviorIdIsOne(1)));
AgentPageBriefModel pageBriefModel = (AgentPageBriefModel) this
.getDataCollector().getPageBriefStatistics(2);
assertEquals(2, pageBriefModel.getPageId());
@ -77,7 +77,7 @@ public class PageResultStatisticsTest {
public void testOnePageWithTwoBehaviorResult() {
this.getDataCollector().add(
PageResult.buildPageResult(2,
ScenarioStatisticsTest.makeBehaviorList(2)));
ScenarioStatisticsTest.makeBehaviorListWhoseBehaviorIdIsOne(2)));
AgentPageBriefModel pageBriefModel = (AgentPageBriefModel) this
.getDataCollector().getPageBriefStatistics(2);
System.out.println(pageBriefModel.getCountFromBegin());
@ -95,10 +95,10 @@ public class PageResultStatisticsTest {
public void testTwoPageWithStatisticsAtLast() {
this.getDataCollector().add(
PageResult.buildPageResult(2,
ScenarioStatisticsTest.makeBehaviorList(1)));
ScenarioStatisticsTest.makeBehaviorListWhoseBehaviorIdIsOne(1)));
this.getDataCollector().add(
PageResult.buildPageResult(2,
ScenarioStatisticsTest.makeBehaviorList(2)));
ScenarioStatisticsTest.makeBehaviorListWhoseBehaviorIdIsOne(2)));
AgentPageBriefModel pageBriefModel = (AgentPageBriefModel) this
.getDataCollector().getPageBriefStatistics(2);
assertEquals(2, pageBriefModel.getPageId());
@ -116,7 +116,7 @@ public class PageResultStatisticsTest {
testOnePaegWithOneBehaviorResult();
this.getDataCollector().add(
PageResult.buildPageResult(2,
ScenarioStatisticsTest.makeBehaviorList(2)));
ScenarioStatisticsTest.makeBehaviorListWhoseBehaviorIdIsOne(2)));
AgentPageBriefModel model = (AgentPageBriefModel) this
.getDataCollector().getPageBriefStatistics(2);
assertEquals(2, model.getPageId());

View File

@ -45,7 +45,7 @@ public class ScenarioStatisticsTest {
@Test
public void addZeroBriefTest() {
for (BehaviorResult behaviorResult : makeBehaviorList(0)) {
for (BehaviorResult behaviorResult : makeBehaviorListWhoseBehaviorIdIsOne(0)) {
this.getDataStatistics().add(behaviorResult);
}
AgentBriefStatusModel model = (AgentBriefStatusModel) this
@ -57,7 +57,7 @@ public class ScenarioStatisticsTest {
@Test
public void addOneBriefTest() throws InterruptedException {
for (BehaviorResult behaviorResult : makeBehaviorList(1)) {
for (BehaviorResult behaviorResult : makeBehaviorListWhoseBehaviorIdIsOne(1)) {
this.getDataStatistics().add(behaviorResult);
}
@ -72,7 +72,7 @@ public class ScenarioStatisticsTest {
@Test
public void addTwoBriefTest() throws InterruptedException {
for (BehaviorResult behaviorResult : makeBehaviorList(2)) {
for (BehaviorResult behaviorResult : makeBehaviorListWhoseBehaviorIdIsOne(2)) {
this.getDataStatistics().add(behaviorResult);
}
Thread.sleep(100);
@ -131,11 +131,12 @@ public class ScenarioStatisticsTest {
}
public static PageResult makePageResultWithBehaviorResult(int count) {
List<BehaviorResult> behaviorResults = makeBehaviorList(count);
List<BehaviorResult> behaviorResults = makeBehaviorListWhoseBehaviorIdIsOne(count);
return PageResult.buildPageResult(2, behaviorResults);
}
public static List<BehaviorResult> makeBehaviorList(int count) {
public static List<BehaviorResult> makeBehaviorListWhoseBehaviorIdIsOne(
int count) {
List<BehaviorResult> behaviorResults = new ArrayList<BehaviorResult>();
for (int i = 0; i < count; i++) {
int statusCode = i % 2 == 0 ? 200 : 400;