add test for ratio take effect

add test for ratio take effect
This commit is contained in:
coderfengyun 2014-09-09 10:04:22 +08:00
parent bc164c3ece
commit 836a4102db
5 changed files with 45 additions and 17 deletions

View File

@ -70,6 +70,7 @@ public class Solution {
new int[] { 1, 2, 2 }));
}
@Test
public void test1() {
}
}
}

View File

@ -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

View File

@ -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!");
}
}

View File

@ -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());
}
}
}

View File

@ -23,6 +23,16 @@ public class ScheduleModel {
this.points = new LinkedList<PointModel>();
}
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;