diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/Solution.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/Solution.java index 16010684..0d2110b1 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/Solution.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/Solution.java @@ -70,6 +70,7 @@ public class Solution { new int[] { 1, 2, 2 })); } + @Test public void test1() { - } + } } \ No newline at end of file diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/RunningAgentDB.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/RunningAgentDB.java index dcecbc76..10aab285 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/RunningAgentDB.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/RunningAgentDB.java @@ -183,9 +183,7 @@ public class RunningAgentDB implements RunningAgentInterface { .tryUnmarshal(RunScenarioModel.class, this.getTestPlanScript() .getFilteredScriptCnt()); runScenarioModel.setPoolSize(getLoadInUse()); - ScheduleModel scheduleModel = (ScheduleModel) MarshalHelper - .tryUnmarshal(ScheduleModel.class, this.getTestPlanScript() - .getScheduleContent()); + ScheduleModel scheduleModel = generateScheduleModelWithRatio(); RunScenarioResultModel runScenarioResultModel = this .getAgentMessenger().submitScenrioWithParams(this.getAgent(), this.getAgentRunId(), script2.loadParamFiles(), @@ -197,6 +195,19 @@ public class RunningAgentDB implements RunningAgentInterface { return true; } + private ScheduleModel generateScheduleModelWithRatio() { + ScheduleModel scheduleModel = (ScheduleModel) MarshalHelper + .tryUnmarshal(ScheduleModel.class, this.getTestPlanScript() + .getScheduleContent()); + int totolRequireLoad = this.getTestPlanScript().getRequireLoad(); + if (totolRequireLoad <= 0) { + throw new IllegalArgumentException( + "The require load can't be less than 0!!"); + } + double ratio = (double) this.getLoadInUse() / (double) totolRequireLoad; + return scheduleModel.ratioIntoEffect(ratio); + } + /** * * @return diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/valueobject/schedulscript/WarmUpOverTask.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/valueobject/schedulscript/WarmUpOverTask.java deleted file mode 100644 index 1a36552f..00000000 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/valueobject/schedulscript/WarmUpOverTask.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.bench4q.master.domain.valueobject.schedulscript; - -import java.util.TimerTask; - -public class WarmUpOverTask extends TimerTask { - public WarmUpOverTask() { - } - - @Override - public void run() { - System.out.println("warm up over and start to execute!"); - } -} diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/entity/Test_RunningAgent.java b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/entity/Test_RunningAgent.java index d0b9608a..04a8da9f 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/entity/Test_RunningAgent.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/entity/Test_RunningAgent.java @@ -3,6 +3,7 @@ package org.bench4q.master.unitTest.entity; import static org.junit.Assert.*; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.UUID; @@ -16,6 +17,7 @@ import org.bench4q.master.domain.valueobject.transaction.TransactionFactory; import org.bench4q.master.domain.valueobject.transaction.impl.ScriptLoadApplication; import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan; import org.bench4q.share.enums.master.TestPlanStatus; +import org.bench4q.share.models.agent.scriptrecord.ScheduleModel; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -144,4 +146,21 @@ public class Test_RunningAgent extends TestBase_MakeUpTestPlan { assertTrue(runningAgentDB.stop()); assertTrue(runningAgentDB.stop()); } + + @Test + public void test_RatioIntoEffectWithRatioHalf() { + ScheduleModel scheduleModel = new ScheduleModel(); + double ratio = 0.5; + scheduleModel.getPoints().addAll( + Arrays.asList(new ScheduleModel.PointModel(0, 0), + new ScheduleModel.PointModel(30, 100))); + ScheduleModel target = scheduleModel.ratioIntoEffect(0.5); + for (int i = 0; i < scheduleModel.getPoints().size(); i++) { + assertEquals(target.getPoints().get(i).getTimeInSecond(), + scheduleModel.getPoints().get(i).getTimeInSecond()); + assertEquals( + (int) (scheduleModel.getPoints().get(i).getLoad() * ratio), + target.getPoints().get(i).getLoad()); + } + } } 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 2b5e6c56..fe68a108 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 @@ -23,6 +23,16 @@ public class ScheduleModel { this.points = new LinkedList(); } + public ScheduleModel ratioIntoEffect(double ratio) { + ScheduleModel result = new ScheduleModel(); + for (PointModel old : this.getPoints()) { + result.getPoints().add( + new PointModel(old.getTimeInSecond(), + (int) (old.getLoad() * ratio))); + } + return result; + } + public long getExecuteRange() { if (this.points.size() == 0) { return 0;