From 8eb5ba5a543155fe918129a96951836f85e35268 Mon Sep 17 00:00:00 2001 From: coderfengyun Date: Wed, 7 May 2014 11:26:26 +0800 Subject: [PATCH] refactor and remove bug from brief refactor and remove bug from brief --- .../impl/ScenarioResultCollector.java | 6 ++-- .../agent/plugin/basic/http/HttpPlugin.java | 2 +- .../agent/test/TestWithScriptFile.java | 18 ++++++++--- .../datastatistics/DetailStatisticsTest.java | 31 ++++++++++++++++--- .../PageResultStatisticsTest.java | 14 ++++----- .../ScenarioStatisticsTest.java | 11 ++++--- 6 files changed, 57 insertions(+), 25 deletions(-) diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/datacollector/impl/ScenarioResultCollector.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/datacollector/impl/ScenarioResultCollector.java index d7306523..6a779bf0 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/datacollector/impl/ScenarioResultCollector.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/datacollector/impl/ScenarioResultCollector.java @@ -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; } diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpPlugin.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpPlugin.java index 7f37375d..27d112d4 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpPlugin.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpPlugin.java @@ -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); diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/TestWithScriptFile.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/TestWithScriptFile.java index 9a86675d..494f444e 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/TestWithScriptFile.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/TestWithScriptFile.java @@ -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 files = new ArrayList(); 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() { private static final long serialVersionUID = 1L; { diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/datastatistics/DetailStatisticsTest.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/datastatistics/DetailStatisticsTest.java index 1df3257a..d508536d 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/datastatistics/DetailStatisticsTest.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/datastatistics/DetailStatisticsTest.java @@ -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 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 map = this.detailStatistics @@ -89,7 +89,28 @@ public class DetailStatisticsTest { private Map makeExpectedMapForTwo() { Map ret = new HashMap(); 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 map = this.detailStatistics + .getBehaviorBriefStatistics(1); + assertTrue(mapEquals(map, makeExpectedMapForFour())); + + } + + private Map makeExpectedMapForFour() { + Map ret = new HashMap(); + 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 mapActual = this diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/datastatistics/PageResultStatisticsTest.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/datastatistics/PageResultStatisticsTest.java index d1e3b896..2aa57c88 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/datastatistics/PageResultStatisticsTest.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/datastatistics/PageResultStatisticsTest.java @@ -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()); diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/datastatistics/ScenarioStatisticsTest.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/datastatistics/ScenarioStatisticsTest.java index 81618e2e..9271b126 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/datastatistics/ScenarioStatisticsTest.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/datastatistics/ScenarioStatisticsTest.java @@ -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 behaviorResults = makeBehaviorList(count); + List behaviorResults = makeBehaviorListWhoseBehaviorIdIsOne(count); return PageResult.buildPageResult(2, behaviorResults); } - public static List makeBehaviorList(int count) { + public static List makeBehaviorListWhoseBehaviorIdIsOne( + int count) { List behaviorResults = new ArrayList(); for (int i = 0; i < count; i++) { int statusCode = i % 2 == 0 ? 200 : 400;