From b00cc44785731d0fdc1a2e7dc831fe2439526366 Mon Sep 17 00:00:00 2001 From: coderfengyun Date: Thu, 4 Sep 2014 09:17:04 +0800 Subject: [PATCH 1/2] add support for schedule add support for schedule --- .../master/domain/entity/PlanedConfig.java | 24 +++------ .../master/domain/entity/TestPlanScript.java | 21 +------- .../factory/BusinessModelMapFactory.java | 10 ---- .../domain/factory/TestPlanFactory.java | 16 +++--- .../unitTest/TestBase_MakeUpTestPlan.java | 13 ++--- .../service/Test_TestPlanService.java | 2 +- .../agent/scriptrecord/ScheduleModel.java | 18 ++++++- .../models/master/RunningScriptModel.java | 14 ++--- .../models/master/TestScriptConfigModel.java | 52 +++++++++++++++++++ .../bench4q/web/service/TestPlanService.java | 4 +- 10 files changed, 102 insertions(+), 72 deletions(-) create mode 100644 Bench4Q-Share/src/main/java/org/bench4q/share/models/master/TestScriptConfigModel.java diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/PlanedConfig.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/PlanedConfig.java index 558954dc..20ce9675 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/PlanedConfig.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/PlanedConfig.java @@ -11,9 +11,8 @@ import javax.persistence.Table; @Table(name = "planedConfig") public class PlanedConfig { private int id; - private long warmUp; private long executeRange; - private long coolDown; + private String scheduleContent; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -26,16 +25,7 @@ public class PlanedConfig { this.id = id; } - @Column(name = "warmUp", nullable = false) - public long getWarmUp() { - return warmUp; - } - - public void setWarmUp(long warmUp) { - this.warmUp = warmUp; - } - - @Column(name = "excuteRange", nullable = false) + @Column(name = "executeRange", nullable = false) public long getExecuteRange() { return executeRange; } @@ -44,13 +34,13 @@ public class PlanedConfig { this.executeRange = executeRange; } - @Column(name = "coolDown", nullable = false) - public long getCoolDown() { - return coolDown; + @Column(name = "scheduleContent", columnDefinition = "LONGTEXT", nullable = false) + public String getScheduleContent() { + return scheduleContent; } - public void setCoolDown(long coolDown) { - this.coolDown = coolDown; + public void setScheduleContent(String scheduleContent) { + this.scheduleContent = scheduleContent; } } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlanScript.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlanScript.java index 6d9cc1c0..fdc9f909 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlanScript.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlanScript.java @@ -5,7 +5,6 @@ import java.util.Date; import java.util.List; import java.util.Set; import java.util.Timer; -import java.util.TimerTask; import java.util.UUID; import javax.persistence.CascadeType; @@ -28,7 +27,6 @@ import org.bench4q.master.domain.RunningScriptInterface; import org.bench4q.master.domain.factory.TestPlanFactory; import org.bench4q.master.domain.valueobject.datastatistics.RunningScriptSampler; import org.bench4q.master.domain.valueobject.schedulscript.ExecutionOverTask; -import org.bench4q.master.domain.valueobject.schedulscript.WarmUpOverTask; import org.bench4q.master.domain.valueobject.transaction.Transaction; import org.bench4q.master.domain.valueobject.transaction.TransactionFactory; import org.bench4q.master.exception.ExceptionLog; @@ -197,25 +195,10 @@ public class TestPlanScript implements RunningScriptInterface { return false; } Timer timer = new Timer(); - timer.schedule(new WarmUpOverTask(), testScriptConfig.getWarmUp() + ExecutionOverTask executionOverTask = new ExecutionOverTask(this); + timer.schedule(executionOverTask, (testScriptConfig.getExecuteRange()) * SECOND_MILISECOND_UNIT_CONVERSION); - ExecutionOverTask executionOverTask = new ExecutionOverTask(this); - timer.schedule( - executionOverTask, - (testScriptConfig.getWarmUp() + testScriptConfig - .getExecuteRange()) * SECOND_MILISECOND_UNIT_CONVERSION); - - timer.schedule( - new TimerTask() { - @Override - public void run() { - System.out.println("cool down over!"); - } - }, - (testScriptConfig.getWarmUp() - + testScriptConfig.getExecuteRange() + testScriptConfig - .getCoolDown()) * SECOND_MILISECOND_UNIT_CONVERSION); return true; } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/BusinessModelMapFactory.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/BusinessModelMapFactory.java index 910acb8b..296b4350 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/BusinessModelMapFactory.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/BusinessModelMapFactory.java @@ -3,7 +3,6 @@ package org.bench4q.master.domain.factory; import org.bench4q.master.domain.RunningAgentInterface; import org.bench4q.master.domain.entity.Agent; import org.bench4q.master.domain.entity.Monitor; -import org.bench4q.master.domain.entity.PlanedConfig; import org.bench4q.master.domain.entity.Port; import org.bench4q.master.domain.entity.Script; import org.bench4q.master.domain.entity.TestPlan; @@ -14,7 +13,6 @@ import org.bench4q.share.models.master.PortModel; import org.bench4q.share.models.master.RunningAgentModel; import org.bench4q.share.models.master.ScriptModel; import org.bench4q.share.models.master.TestPlanDBModel; -import org.bench4q.share.models.master.TestScriptConfig; import org.bench4q.share.models.master.UserModel; import org.springframework.stereotype.Component; @@ -46,14 +44,6 @@ public class BusinessModelMapFactory { return ret; } - public TestScriptConfig toModel(PlanedConfig config) { - TestScriptConfig result = new TestScriptConfig(); - result.setWarmUp(config.getWarmUp()); - result.setExecuteRange(config.getExecuteRange()); - result.setCoolDown(config.getCoolDown()); - return result; - } - public static Monitor toBusiness(MonitorModel monitorModel) { Monitor monitor = new Monitor(); monitor.setHostName(monitorModel.getHostName()); diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/TestPlanFactory.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/TestPlanFactory.java index cc193885..830f5bcb 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/TestPlanFactory.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/TestPlanFactory.java @@ -36,11 +36,11 @@ import org.bench4q.share.models.agent.ScriptFilterOptionsModel; import org.bench4q.share.models.agent.scriptrecord.BatchModel; import org.bench4q.share.models.agent.scriptrecord.BehaviorModel; import org.bench4q.share.models.agent.scriptrecord.PageModel; +import org.bench4q.share.models.agent.scriptrecord.ScheduleModel; import org.bench4q.share.models.agent.scriptrecord.UsePluginModel; import org.bench4q.share.models.master.MonitorModel; import org.bench4q.share.models.master.RunningScriptModel; import org.bench4q.share.models.master.TestPlanModel; -import org.bench4q.share.models.master.TestScriptConfig; import org.bench4q.share.models.master.statistics.ScriptResultModel; import org.bench4q.share.models.monitor.MonitorMain; import org.springframework.beans.factory.annotation.Autowired; @@ -126,7 +126,7 @@ public class TestPlanFactory { testPlanScripts.add(createATestPlanScriptWithoutId( runningScriptModel.getRequireLoad(), runningScriptModel.getScriptId(), - runningScriptModel.getConfig(), result, + runningScriptModel.getScheduleModel(), result, runningScriptModel.getScriptFilterOptionsModel())); } result.setRequiredLoad(requiredLoad); @@ -150,7 +150,7 @@ public class TestPlanFactory { } public TestPlanScript createATestPlanScriptWithoutId(int requireLoad, - int scriptId, TestScriptConfig config, TestPlan testPlanDB, + int scriptId, ScheduleModel config, TestPlan testPlanDB, ScriptFilterOptionsModel scriptFilterOptionsModel) { TestPlanScript testPlanScript = new TestPlanScript(); testPlanScript.setRequireLoad(requireLoad); @@ -214,12 +214,10 @@ public class TestPlanFactory { } - private PlanedConfig createAPlanedConfigWithoutId(TestScriptConfig config) { - PlanedConfig planedConfig = new PlanedConfig(); - planedConfig.setWarmUp(config.getWarmUp()); - planedConfig.setExecuteRange(config.getExecuteRange()); - planedConfig.setCoolDown(config.getCoolDown()); - return planedConfig; + private PlanedConfig createAPlanedConfigWithoutId(ScheduleModel schedule) { + PlanedConfig result = new PlanedConfig(); + result.setScheduleContent(MarshalHelper.tryMarshal(schedule)); + return result; } public TestPlanScriptResult createScriptResultWithoutId(Object model, diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/TestBase_MakeUpTestPlan.java b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/TestBase_MakeUpTestPlan.java index 4ab39a11..9f632dab 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/TestBase_MakeUpTestPlan.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/TestBase_MakeUpTestPlan.java @@ -25,10 +25,11 @@ import org.bench4q.master.infrastructure.communication.AgentMessenger; import org.bench4q.master.infrastructure.highavailable.HighAvailablePool; import org.bench4q.master.unitTest.controller.TestBase; import org.bench4q.share.enums.master.TestPlanStatus; +import org.bench4q.share.models.agent.scriptrecord.ScheduleModel; +import org.bench4q.share.models.agent.scriptrecord.ScheduleModel.PointModel; import org.bench4q.share.models.master.MonitorModel; import org.bench4q.share.models.master.RunningScriptModel; import org.bench4q.share.models.master.TestPlanModel; -import org.bench4q.share.models.master.TestScriptConfig; import org.bench4q.share.models.master.statistics.ScriptBriefResultModel; import org.springframework.beans.factory.annotation.Autowired; @@ -374,11 +375,11 @@ public class TestBase_MakeUpTestPlan extends TestBase { RunningScriptModel model = new RunningScriptModel(); model.setScriptId(scriptID); model.setRequireLoad(EACH_SCRIPT_LOAD_SMALLSCALE); - TestScriptConfig config = new TestScriptConfig(); - config.setWarmUp(20); - config.setExecuteRange(60); - config.setCoolDown(10); - model.setConfig(config); + ScheduleModel config = new ScheduleModel(); + config.getPoints().add(new PointModel(0, 0)); + config.getPoints().add(new PointModel(20, 10)); + config.getPoints().add(new PointModel(60, 10)); + model.setScheduleModel(config); return model; } diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_TestPlanService.java b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_TestPlanService.java index d9b63e1d..303525f3 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_TestPlanService.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_TestPlanService.java @@ -67,7 +67,7 @@ public class Test_TestPlanService extends TestBase_MakeUpTestPlan { assertEquals(1, testPlan.getMonitors().size()); for (TestPlanScript testPlanScript : testPlanScripts) { assertEquals(getScriptId(), testPlanScript.getScript().getId()); - assertEquals(20, testPlanScript.getPlanedConfig().getWarmUp()); + assertEquals(20, testPlanScript.getPlanedConfig().getExecuteRange()); } assertTrue(this.getTestPlanRepository().detach(testPlan.getId())); } diff --git a/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/ScheduleModel.java b/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/ScheduleModel.java index f8f0a3b3..978f586a 100644 --- a/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/ScheduleModel.java +++ b/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/ScheduleModel.java @@ -25,6 +25,18 @@ public class ScheduleModel { this.points = new LinkedList(); } + public long getExecuteRange() { + if (this.points.size() == 0) { + return 0; + } + long startTime = this.points.get(0).getTime(), endTime = startTime; + for (PointModel point : this.getPoints()) { + startTime = Math.min(point.getTime(), startTime); + endTime = Math.max(point.getTime(), endTime); + } + return endTime - startTime; + } + @XmlRootElement public static class PointModel { private long time; @@ -48,8 +60,10 @@ public class ScheduleModel { this.load = load; } - public PointModel(){} - public PointModel(long time, int load){ + public PointModel() { + } + + public PointModel(long time, int load) { this.time = time; this.load = load; } diff --git a/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/RunningScriptModel.java b/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/RunningScriptModel.java index b1d3e74d..26a16776 100644 --- a/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/RunningScriptModel.java +++ b/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/RunningScriptModel.java @@ -10,12 +10,13 @@ import javax.xml.bind.annotation.XmlRootElement; import org.bench4q.share.models.agent.RunScenarioModel; import org.bench4q.share.models.agent.ScriptFilterOptionsModel; +import org.bench4q.share.models.agent.scriptrecord.ScheduleModel; @XmlRootElement(name = "runningScripModel") public class RunningScriptModel { private int scriptId; private int requireLoad; - private TestScriptConfig config; + private ScheduleModel scheduleModel; private ScriptFilterOptionsModel scriptFilterOptionsModel; private RunScenarioModel scenarioModel; private String scriptName; @@ -42,12 +43,12 @@ public class RunningScriptModel { } @XmlElement - public TestScriptConfig getConfig() { - return config; + public ScheduleModel getScheduleModel() { + return scheduleModel; } - public void setConfig(TestScriptConfig config) { - this.config = config; + public void setScheduleModel(ScheduleModel scheduleModel) { + this.scheduleModel = scheduleModel; } @XmlElement @@ -100,7 +101,8 @@ public class RunningScriptModel { return scriptFilterOptionsModel; } - public void setScriptFilterOptionsModel(ScriptFilterOptionsModel scriptFilterOptionsModel) { + public void setScriptFilterOptionsModel( + ScriptFilterOptionsModel scriptFilterOptionsModel) { this.scriptFilterOptionsModel = scriptFilterOptionsModel; } } diff --git a/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/TestScriptConfigModel.java b/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/TestScriptConfigModel.java new file mode 100644 index 00000000..e2008bec --- /dev/null +++ b/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/TestScriptConfigModel.java @@ -0,0 +1,52 @@ +package org.bench4q.share.models.master; + +import java.util.LinkedList; +import java.util.List; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +public class TestScriptConfigModel { + private List points; + + @XmlElementWrapper(name = "points") + @XmlElement(name = "point") + public List getPoints() { + return points; + } + + private void setPoints(List points) { + this.points = points; + } + + public TestScriptConfigModel() { + this.setPoints(new LinkedList()); + } + + @XmlRootElement + public static class PointModel { + private int load; + private long relativeTime; + + @XmlElement + public int getLoad() { + return load; + } + + public void setLoad(int load) { + this.load = load; + } + + @XmlElement + public long getRelativeTime() { + return relativeTime; + } + + public void setRelativeTime(long relativeTime) { + this.relativeTime = relativeTime; + } + + } +} diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/service/TestPlanService.java b/Bench4Q-Web/src/main/java/org/bench4q/web/service/TestPlanService.java index 0549c02a..1af8a672 100644 --- a/Bench4Q-Web/src/main/java/org/bench4q/web/service/TestPlanService.java +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/service/TestPlanService.java @@ -18,7 +18,7 @@ import org.bench4q.share.models.master.ScriptHandleModel; import org.bench4q.share.models.master.TestPlanModel; import org.bench4q.share.models.master.TestPlanResultModel; import org.bench4q.share.models.master.TestPlanScriptBriefResultModel; -import org.bench4q.share.models.master.TestScriptConfig; +import org.bench4q.share.models.master.TestScriptConfigModel; import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel; import org.bench4q.share.models.master.statistics.ScriptBriefResultModel; import org.bench4q.web.masterMessager.TestPlanMessager; @@ -73,7 +73,7 @@ public class TestPlanService { scriptFilterOptionsModel.setFilterTypeMatches(scriptModel.getFilterTypeMatches()); scriptFilterOptionsModel.setFilterTimer(scriptModel.isFilterTimer()); - TestScriptConfig testScriptConfig = new TestScriptConfig(); + TestScriptConfigModel testScriptConfig = new TestScriptConfigModel(); testScriptConfig.setCoolDown(scriptModel.getCooldown()); testScriptConfig.setExecuteRange(scriptModel.getExecuteRange()); testScriptConfig.setWarmUp(scriptModel.getWarmup()); From b943800a02593259a0704472c32a5771898988fb Mon Sep 17 00:00:00 2001 From: coderfengyun Date: Thu, 4 Sep 2014 09:17:45 +0800 Subject: [PATCH 2/2] remove redundant code remove redundant code --- .../share/models/master/TestScriptConfig.java | 39 ------------------- 1 file changed, 39 deletions(-) delete mode 100644 Bench4Q-Share/src/main/java/org/bench4q/share/models/master/TestScriptConfig.java diff --git a/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/TestScriptConfig.java b/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/TestScriptConfig.java deleted file mode 100644 index 40c1d1a5..00000000 --- a/Bench4Q-Share/src/main/java/org/bench4q/share/models/master/TestScriptConfig.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.bench4q.share.models.master; - -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - -@XmlRootElement -public class TestScriptConfig { - private long warmUp; - private long executeRange; - private long coolDown; - - @XmlElement - public long getWarmUp() { - return warmUp; - } - - public void setWarmUp(long warmUp) { - this.warmUp = warmUp; - } - - @XmlElement - public long getExecuteRange() { - return executeRange; - } - - public void setExecuteRange(long executeRange) { - this.executeRange = executeRange; - } - - @XmlElement - public long getCoolDown() { - return coolDown; - } - - public void setCoolDown(long coolDown) { - this.coolDown = coolDown; - } - -}