From c32e58c19d5e4d7e136fb81db5ad7c46244bd855 Mon Sep 17 00:00:00 2001 From: Tienan Chen Date: Wed, 27 Nov 2013 09:40:07 +0800 Subject: [PATCH] refactor for behaviorsBrief --- .../org/bench4q/agent/api/TestController.java | 1 - .../agent/api/model/BehaviorBriefModel.java | 18 +++---------- .../impl/AgentResultDataCollector.java | 27 ++++++++++--------- .../impl/DetailStatusCodeResult.java | 3 ++- .../agent/test/DetailStatisticsTest.java | 4 +-- 5 files changed, 21 insertions(+), 32 deletions(-) diff --git a/src/main/java/org/bench4q/agent/api/TestController.java b/src/main/java/org/bench4q/agent/api/TestController.java index 8dcd179a..67efd25b 100644 --- a/src/main/java/org/bench4q/agent/api/TestController.java +++ b/src/main/java/org/bench4q/agent/api/TestController.java @@ -223,7 +223,6 @@ public class TestController { behaviorBriefModel.setBehaviorId(behaviorId); behaviorBriefModel .setDetailStatusCodeResultModels(detailStatusCodeResultModels); - behaviorBriefModel.setTestId(runId); return behaviorBriefModel; } diff --git a/src/main/java/org/bench4q/agent/api/model/BehaviorBriefModel.java b/src/main/java/org/bench4q/agent/api/model/BehaviorBriefModel.java index 94669aac..cd6a0d17 100644 --- a/src/main/java/org/bench4q/agent/api/model/BehaviorBriefModel.java +++ b/src/main/java/org/bench4q/agent/api/model/BehaviorBriefModel.java @@ -1,28 +1,16 @@ package org.bench4q.agent.api.model; import java.util.List; -import java.util.UUID; - import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement(name = "BehaviorBriefModel") public class BehaviorBriefModel { - private UUID testId; private int behaviorId; - private int behaviorUrl; + private String behaviorUrl; private List detailStatusCodeResultModels; - @XmlElement - public UUID getTestId() { - return testId; - } - - public void setTestId(UUID testId) { - this.testId = testId; - } - @XmlElement public int getBehaviorId() { return behaviorId; @@ -33,11 +21,11 @@ public class BehaviorBriefModel { } @XmlElement - public int getBehaviorUrl() { + public String getBehaviorUrl() { return behaviorUrl; } - public void setBehaviorUrl(int behaviorUrl) { + public void setBehaviorUrl(String behaviorUrl) { this.behaviorUrl = behaviorUrl; } diff --git a/src/main/java/org/bench4q/agent/datacollector/impl/AgentResultDataCollector.java b/src/main/java/org/bench4q/agent/datacollector/impl/AgentResultDataCollector.java index 28ecae55..341d7ca6 100644 --- a/src/main/java/org/bench4q/agent/datacollector/impl/AgentResultDataCollector.java +++ b/src/main/java/org/bench4q/agent/datacollector/impl/AgentResultDataCollector.java @@ -84,14 +84,10 @@ public class AgentResultDataCollector extends AbstractDataCollector { return testID == null ? "default" : testID.toString(); } - public void setTestID(UUID testID) { + private void setTestID(UUID testID) { this.testID = testID; } - public Map> getDetailMap() { - return detailMap; - } - private void setDetailMap( Map> detailMap) { this.detailMap = detailMap; @@ -103,7 +99,7 @@ public class AgentResultDataCollector extends AbstractDataCollector { init(); } - public void init() { + private void init() { reset(); this.setCumulativeFailCount(0); this.setCumulativeSucessfulCount(0); @@ -191,16 +187,15 @@ public class AgentResultDataCollector extends AbstractDataCollector { } private void dealWithDetailResult(BehaviorResult behaviorResult) { - if (!this.detailMap.containsKey(behaviorResult.getBehaviorId())) { - this.detailMap.put(new Integer(behaviorResult.getBehaviorId()), - new HashMap()); - } + insertWhenNotExist(behaviorResult); Map detailStatusMap = this.detailMap .get(behaviorResult.getBehaviorId()); if (!detailStatusMap.containsKey(behaviorResult.getStatusCode())) { - detailStatusMap.put(new Integer(behaviorResult.getStatusCode()), - new DetailStatusCodeResult()); + detailStatusMap + .put(new Integer(behaviorResult.getStatusCode()), + new DetailStatusCodeResult(behaviorResult + .getContentType())); } DetailStatusCodeResult detailResult = detailStatusMap @@ -212,7 +207,6 @@ public class AgentResultDataCollector extends AbstractDataCollector { detailResult.contentLength = 0; return; } - detailResult.contentType = behaviorResult.getContentType(); detailResult.contentLength += behaviorResult.getContentLength(); if (behaviorResult.getResponseTime() > detailResult.maxResponseTime) { detailResult.maxResponseTime = behaviorResult.getResponseTime(); @@ -222,6 +216,13 @@ 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()); + } + } + @Override public void add(BehaviorResult behaviorResult) { super.add(behaviorResult); diff --git a/src/main/java/org/bench4q/agent/datacollector/impl/DetailStatusCodeResult.java b/src/main/java/org/bench4q/agent/datacollector/impl/DetailStatusCodeResult.java index 3f23ce4e..7fda6d77 100644 --- a/src/main/java/org/bench4q/agent/datacollector/impl/DetailStatusCodeResult.java +++ b/src/main/java/org/bench4q/agent/datacollector/impl/DetailStatusCodeResult.java @@ -9,7 +9,8 @@ public class DetailStatusCodeResult { public long maxResponseTime; public String contentType; - public DetailStatusCodeResult() { + public DetailStatusCodeResult(String contentType) { + this.contentType = contentType; this.count = 0; this.contentLength = 0; this.minResponseTime = Long.MAX_VALUE; diff --git a/src/test/java/org/bench4q/agent/test/DetailStatisticsTest.java b/src/test/java/org/bench4q/agent/test/DetailStatisticsTest.java index 314c1533..d414d46f 100644 --- a/src/test/java/org/bench4q/agent/test/DetailStatisticsTest.java +++ b/src/test/java/org/bench4q/agent/test/DetailStatisticsTest.java @@ -66,7 +66,7 @@ public class DetailStatisticsTest { } private DetailStatusCodeResult makeExpectedResultForOne() { - DetailStatusCodeResult ret = new DetailStatusCodeResult(); + DetailStatusCodeResult ret = new DetailStatusCodeResult(""); ret.contentLength = 20; ret.count = 1; ret.maxResponseTime = 200; @@ -95,7 +95,7 @@ public class DetailStatisticsTest { private DetailStatusCodeResult buildCodeResult(long contentLength, long count, long maxResponseTime, long minResponseTime) { - DetailStatusCodeResult ret = new DetailStatusCodeResult(); + DetailStatusCodeResult ret = new DetailStatusCodeResult(""); ret.contentLength = contentLength; ret.count = count; ret.maxResponseTime = maxResponseTime;