From 5c262b239b87e409b8f2e3e5770d0c33a0a5da82 Mon Sep 17 00:00:00 2001 From: Coderfengyun Date: Fri, 13 Dec 2013 17:15:58 +0800 Subject: [PATCH] refactor the TestPlanScriptResult to save the marshal scriptBriefResultMOdel --- .../entity/db/TestPlanScriptResult.java | 113 +++--------------- .../master/report/ScriptReportService.java | 10 +- .../service/db/TestPlanScriptService.java | 18 +-- .../service/TestTestPlanScriptService.java | 13 ++ 4 files changed, 36 insertions(+), 118 deletions(-) diff --git a/src/main/java/org/bench4q/master/entity/db/TestPlanScriptResult.java b/src/main/java/org/bench4q/master/entity/db/TestPlanScriptResult.java index 4fa8d65f..ff3b11e3 100644 --- a/src/main/java/org/bench4q/master/entity/db/TestPlanScriptResult.java +++ b/src/main/java/org/bench4q/master/entity/db/TestPlanScriptResult.java @@ -11,23 +11,15 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; +import org.bench4q.share.helper.MarshalHelper; +import org.bench4q.share.models.master.ScriptBriefResultModel; + @Entity @Table(name = "TestPlanScriptResult") public class TestPlanScriptResult { private int id; private TestPlanScript testPlanScript; - private long totalSuccessCountFromBegin; - private long totalFailCountFromBegin; - - private long averageResponseTime; - private long maxResponseTime; - private long minResposneTime; - private long successThroughputThisTime; - private long failThroughputThisTime; - private long responseTimeDeviationThisTime; - private long failRateThisTime; - - private long averageElapsedTime; + private String scriptBriefResultContent; private Date createDatetime; @Id @@ -51,95 +43,13 @@ public class TestPlanScriptResult { this.testPlanScript = testPlanScript; } - @Column(name = "totalSuccessCountFromBegin", nullable = false) - public long getTotalSuccessCountFromBegin() { - return totalSuccessCountFromBegin; + @Column(name = "scriptBriefResultContent", columnDefinition = "LONGTEXT", nullable = false) + public String getScriptBriefResultContent() { + return scriptBriefResultContent; } - public void setTotalSuccessCountFromBegin(long totalSuccessCountFromBegin) { - this.totalSuccessCountFromBegin = totalSuccessCountFromBegin; - } - - @Column(name = "totalFailCountFromBegin", nullable = false) - public long getTotalFailCountFromBegin() { - return totalFailCountFromBegin; - } - - public void setTotalFailCountFromBegin(long totalFailCountFromBegin) { - this.totalFailCountFromBegin = totalFailCountFromBegin; - } - - @Column(name = "averageResponseTime", nullable = false) - public long getAverageResponseTime() { - return averageResponseTime; - } - - public void setAverageResponseTime(long averageResponseTime) { - this.averageResponseTime = averageResponseTime; - } - - @Column(name = "maxResponseTime", nullable = false) - public long getMaxResponseTime() { - return maxResponseTime; - } - - public void setMaxResponseTime(long maxResponseTime) { - this.maxResponseTime = maxResponseTime; - } - - @Column(name = "minResposneTime", nullable = false) - public long getMinResposneTime() { - return minResposneTime; - } - - public void setMinResposneTime(long minResposneTime) { - this.minResposneTime = minResposneTime; - } - - @Column(name = "successThroughputThisTime", nullable = false) - public long getSuccessThroughputThisTime() { - return successThroughputThisTime; - } - - public void setSuccessThroughputThisTime(long successThroughputThisTime) { - this.successThroughputThisTime = successThroughputThisTime; - } - - @Column(name = "failThroughputThisTime", nullable = false) - public long getFailThroughputThisTime() { - return failThroughputThisTime; - } - - public void setFailThroughputThisTime(long failThroughputThisTime) { - this.failThroughputThisTime = failThroughputThisTime; - } - - @Column(name = "responseTimeDeviationThisTime", nullable = false) - public long getResponseTimeDeviationThisTime() { - return responseTimeDeviationThisTime; - } - - public void setResponseTimeDeviationThisTime( - long responseTimeDeviationThisTime) { - this.responseTimeDeviationThisTime = responseTimeDeviationThisTime; - } - - @Column(name = "failRateThisTime", nullable = false) - public long getFailRateThisTime() { - return failRateThisTime; - } - - public void setFailRateThisTime(long failRateThisTime) { - this.failRateThisTime = failRateThisTime; - } - - @Column(name = "averageElapsedTime", nullable = false) - public long getAverageElapsedTime() { - return averageElapsedTime; - } - - public void setAverageElapsedTime(long averageElapsedTime) { - this.averageElapsedTime = averageElapsedTime; + public void setScriptBriefResultContent(String scriptBriefResultContent) { + this.scriptBriefResultContent = scriptBriefResultContent; } @Column(name = "createDatetime", nullable = false) @@ -151,4 +61,9 @@ public class TestPlanScriptResult { this.createDatetime = createDatetime; } + public ScriptBriefResultModel extractScriptBriefResultModel() { + return (ScriptBriefResultModel) MarshalHelper.unmarshal( + ScriptBriefResultModel.class, + this.getScriptBriefResultContent()); + } } diff --git a/src/main/java/org/bench4q/master/report/ScriptReportService.java b/src/main/java/org/bench4q/master/report/ScriptReportService.java index 5d194d9d..d6dc7b8a 100644 --- a/src/main/java/org/bench4q/master/report/ScriptReportService.java +++ b/src/main/java/org/bench4q/master/report/ScriptReportService.java @@ -11,6 +11,7 @@ import org.bench4q.master.entity.db.TestPlanScriptResult; import org.bench4q.master.service.db.MonitorResultService; import org.bench4q.master.service.db.TestPlanScriptService; import org.bench4q.master.service.db.TestPlanService; +import org.bench4q.share.models.master.ScriptBriefResultModel; import org.jfree.data.time.Second; import org.jfree.data.time.TimeSeries; import org.springframework.beans.factory.annotation.Autowired; @@ -86,10 +87,8 @@ public class ScriptReportService { if (results == null) { return; } - addScriptSeries(results, timeSeriesList, "averageResponseTime"); addScriptSeries(results, timeSeriesList, "maxResponseTime"); - try { ReportService.writeImageIntoPdf( ReportService.buildChartStream(document, @@ -107,10 +106,13 @@ public class ScriptReportService { try { TimeSeries timeSeries = new TimeSeries(fieldName); for (TestPlanScriptResult result : results) { - Field field = result.getClass().getDeclaredField(fieldName); + ScriptBriefResultModel scriptBriefResultModel = result + .extractScriptBriefResultModel(); + Field field = scriptBriefResultModel.getClass() + .getDeclaredField(fieldName); field.setAccessible(true); timeSeries.addOrUpdate(new Second(result.getCreateDatetime()), - field.getLong(result)); + field.getLong(scriptBriefResultModel)); } timeSeriesList.add(timeSeries); } catch (Exception e) { diff --git a/src/main/java/org/bench4q/master/service/db/TestPlanScriptService.java b/src/main/java/org/bench4q/master/service/db/TestPlanScriptService.java index 742e9484..058944b4 100644 --- a/src/main/java/org/bench4q/master/service/db/TestPlanScriptService.java +++ b/src/main/java/org/bench4q/master/service/db/TestPlanScriptService.java @@ -11,6 +11,7 @@ import org.bench4q.master.entity.db.TestPlanDB; import org.bench4q.master.entity.db.TestPlanScript; import org.bench4q.master.entity.db.TestPlanScriptResult; import org.bench4q.master.helper.SessionHelper; +import org.bench4q.share.helper.MarshalHelper; import org.bench4q.share.models.master.ScriptBriefResultModel; import org.hibernate.Session; import org.hibernate.Transaction; @@ -128,21 +129,8 @@ public class TestPlanScriptService { Date createDatetime) { TestPlanScriptResult result = new TestPlanScriptResult(); result.setTestPlanScript(testPlanScript); - result.setAverageElapsedTime(model.getAverageElapsedTime()); - - result.setAverageResponseTime(model.getAverageResponseTime()); - result.setFailRateThisTime(model.getFailRateThisTime()); - result.setFailThroughputThisTime(model.getFailThroughputThisTime()); - result.setMaxResponseTime(model.getMaxResponseTime()); - result.setMinResposneTime(model.getMinResponseTime()); - result.setResponseTimeDeviationThisTime(model - .getResponseTimeDeviationThisTime()); - result.setSuccessThroughputThisTime(model - .getSuccessThroughputThisTime()); - result.setTotalFailCountFromBegin(model.getTotalFailCountFromBegin()); - result.setTotalSuccessCountFromBegin(model - .getTotalSuccessCountFromBegin()); - + result.setScriptBriefResultContent(MarshalHelper.marshal( + ScriptBriefResultModel.class, model)); result.setCreateDatetime(createDatetime); return result; } diff --git a/src/test/java/org/bench4q/master/test/service/TestTestPlanScriptService.java b/src/test/java/org/bench4q/master/test/service/TestTestPlanScriptService.java index accfde7b..d5487ee3 100644 --- a/src/test/java/org/bench4q/master/test/service/TestTestPlanScriptService.java +++ b/src/test/java/org/bench4q/master/test/service/TestTestPlanScriptService.java @@ -8,6 +8,7 @@ import java.util.UUID; import org.bench4q.master.entity.db.TestPlanScript; import org.bench4q.master.entity.db.TestPlanScriptResult; import org.bench4q.master.service.db.TestPlanScriptService; +import org.bench4q.share.models.master.ScriptBriefResultModel; import org.junit.Test; public class TestTestPlanScriptService { @@ -38,4 +39,16 @@ public class TestTestPlanScriptService { testPlanScript); assertTrue(scriptBriefResultModels.size() > 0); } + + @Test + public void testSaveScriptBriefResult() { + ScriptBriefResultModel briefResultModel = new ScriptBriefResultModel(); + briefResultModel.setAverageElapsedTime(100); + briefResultModel.setAverageResponseTime(100); + briefResultModel.setFailRateThisTime(0); + briefResultModel.setFailThroughputThisTime(0); + briefResultModel.setFinished(true); + this.getTestPlanScriptService().saveResult( + UUID.fromString(TEST_PLAN_RUN_ID), SCRIPT_ID, briefResultModel); + } }