Merge branch 'master' of https://github.com/lostcharlie/Bench4Q
This commit is contained in:
commit
8bf1705460
|
@ -108,7 +108,7 @@ public class ScenarioContext implements Observer {
|
|||
realStartTime), this.executor, this.dataCollector,
|
||||
this.pluginManager);
|
||||
result.setSchedule(schedule);
|
||||
result.setEndDate(new Date(result.getSchedule().getScheduleRange()
|
||||
result.setEndDate(new Date(result.getSchedule().getScheduleRangeInMilliSecond()
|
||||
+ result.getStartDate().getTime()));
|
||||
result.setFinished(this.isFinished());
|
||||
result.setScenario(scenario);
|
||||
|
|
|
@ -53,9 +53,10 @@ public class Schedule extends Observable {
|
|||
this.timer = new Timer();
|
||||
}
|
||||
|
||||
public long getScheduleRange() {
|
||||
public long getScheduleRangeInMilliSecond() {
|
||||
return this.getSegments().get(this.getSegments().size() - 1).end
|
||||
.getTime() - this.getSegments().get(0).start.getTime();
|
||||
.getTimeInMilliSecond()
|
||||
- this.getSegments().get(0).start.getTimeInMilliSecond();
|
||||
}
|
||||
|
||||
public void begin() {
|
||||
|
@ -85,27 +86,29 @@ public class Schedule extends Observable {
|
|||
|
||||
/**
|
||||
*
|
||||
* @param time
|
||||
* @param timeInMilliSecond
|
||||
* , is the relative time from begin
|
||||
* @return get the segment by binary search
|
||||
*/
|
||||
public Segment getSegment(long time) {
|
||||
if (this.getSegments() == null || this.getSegments().size() < 1
|
||||
|| time < this.getSegments().get(0).start.getTime()) {
|
||||
public Segment getSegment(long timeInMilliSecond) {
|
||||
if (this.getSegments() == null
|
||||
|| this.getSegments().size() < 1
|
||||
|| timeInMilliSecond < this.getSegments().get(0).start
|
||||
.getTimeInMilliSecond()) {
|
||||
throw new Bench4QRunTimeException(
|
||||
"can't getSegment when segments' size is LT 2");
|
||||
}
|
||||
if (time >= this.getSegments().get(this.getSegments().size() - 1).end
|
||||
.getTime()) {
|
||||
if (timeInMilliSecond >= this.getSegments().get(
|
||||
this.getSegments().size() - 1).end.getTimeInMilliSecond()) {
|
||||
this.reachEnd();
|
||||
return null;
|
||||
}
|
||||
int begin = 0, end = this.getSegments().size(), mid = (begin + end) / 2;
|
||||
while (begin <= end) {
|
||||
Segment midSegment = this.getSegments().get(mid);
|
||||
if (midSegment.end.getTime() < time) {
|
||||
if (midSegment.end.getTimeInMilliSecond() < timeInMilliSecond) {
|
||||
begin = mid + 1;
|
||||
} else if (midSegment.start.getTime() > time) {
|
||||
} else if (midSegment.start.getTimeInMilliSecond() > timeInMilliSecond) {
|
||||
end = mid - 1;
|
||||
} else {
|
||||
return midSegment;
|
||||
|
@ -132,16 +135,17 @@ public class Schedule extends Observable {
|
|||
public static class Segment {
|
||||
private final Point start;
|
||||
private final Point end;
|
||||
// growthUnit is the amount that'll increase per second
|
||||
// growthUnit is the amount that'll increase per second, its unit is
|
||||
// /second
|
||||
private final float growthUnit;
|
||||
|
||||
public Segment(Point startPoint, Point endPoint) {
|
||||
this.start = startPoint.copy();
|
||||
this.end = endPoint.copy();
|
||||
long timeDifference = this.end.getTime() / 1000
|
||||
- this.start.getTime() / 1000;
|
||||
if (timeDifference < 0 || this.start.getTime() < 0l
|
||||
|| this.end.getTime() < 0l) {
|
||||
long timeDifference = this.end.getTimeInSecond()
|
||||
- this.start.getTimeInSecond();
|
||||
if (timeDifference < 0 || this.start.getTimeInMilliSecond() < 0l
|
||||
|| this.end.getTimeInMilliSecond() < 0l) {
|
||||
throw new Bench4QRunTimeException(
|
||||
"The end time in TestScehdul cannot be less than start time");
|
||||
}
|
||||
|
@ -150,23 +154,30 @@ public class Schedule extends Observable {
|
|||
/ (double) (timeDifference));
|
||||
}
|
||||
|
||||
public int loadFor(long timeFromBegin) {
|
||||
if (timeFromBegin < this.start.getTime()
|
||||
|| timeFromBegin > this.end.getTime()) {
|
||||
public int loadFor(long timeFromBeginInMilliSecond) {
|
||||
if (timeFromBeginInMilliSecond < this.start.getTimeInMilliSecond()
|
||||
|| timeFromBeginInMilliSecond > this.end
|
||||
.getTimeInMilliSecond()) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
long diffFromStart = timeFromBegin - this.start.getTime();
|
||||
long diffFromStart = timeFromBeginInMilliSecond
|
||||
- this.start.getTimeInMilliSecond();
|
||||
return (int) (this.start.getLoad() + (diffFromStart * growthUnit / 1000));
|
||||
}
|
||||
}
|
||||
|
||||
public static class Point {
|
||||
// This time is the relative value from begin
|
||||
private final long time;
|
||||
public static final int SECOND_TO_MS_CONVERTOR = 1000;
|
||||
private final long timeInSecond;
|
||||
private final int load;
|
||||
|
||||
public long getTime() {
|
||||
return time;
|
||||
public long getTimeInMilliSecond() {
|
||||
return timeInSecond * SECOND_TO_MS_CONVERTOR;
|
||||
}
|
||||
|
||||
public long getTimeInSecond() {
|
||||
return timeInSecond;
|
||||
}
|
||||
|
||||
public int getLoad() {
|
||||
|
@ -178,12 +189,12 @@ public class Schedule extends Observable {
|
|||
throw new IllegalArgumentException(
|
||||
"Load can't be negtive number!");
|
||||
}
|
||||
this.time = time;
|
||||
this.timeInSecond = time;
|
||||
this.load = load;
|
||||
}
|
||||
|
||||
public Point copy() {
|
||||
return new Point(this.getTime(), this.getLoad());
|
||||
return new Point(this.getTimeInSecond(), this.getLoad());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -201,12 +212,13 @@ public class Schedule extends Observable {
|
|||
List<Point> points = new LinkedList<Schedule.Point>();
|
||||
for (PointModel model : pointModels) {
|
||||
maxLoad = Math.max(maxLoad, model.getLoad());
|
||||
points.add(new Point(model.getTime(), model.getLoad()));
|
||||
points.add(new Point(model.getTimeInSecond(), model.getLoad()));
|
||||
}
|
||||
Collections.sort(points, new Comparator<Point>() {
|
||||
@Override
|
||||
public int compare(Point o1, Point o2) {
|
||||
return (int) (o1.getTime() - o2.getTime());
|
||||
return (int) (o1.getTimeInMilliSecond() - o2
|
||||
.getTimeInMilliSecond());
|
||||
}
|
||||
});
|
||||
for (int i = 0; i < points.size() - 1; i++) {
|
||||
|
|
|
@ -15,7 +15,7 @@ public class Supervisor extends Observable {
|
|||
|
||||
void start() {
|
||||
this.context.getSchedule().begin();
|
||||
long time = context.getSchedule().getScheduleRange()
|
||||
long time = context.getSchedule().getScheduleRangeInMilliSecond()
|
||||
+ context.getStartDate().getTime();
|
||||
this.timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
|
|
|
@ -121,23 +121,25 @@ public abstract class TestBase {
|
|||
}
|
||||
|
||||
public VUser createVUser(Scenario scenario, UUID testId) {
|
||||
return new VUser(buildScenarioContext(testId, scenario,
|
||||
10, pluginManager), 1, this.getPluginManager());
|
||||
return new VUser(buildScenarioContext(testId, scenario, 10,
|
||||
pluginManager), 1, this.getPluginManager());
|
||||
}
|
||||
|
||||
|
||||
public static ScenarioContext buildScenarioContext(UUID testId,
|
||||
final Scenario scenario, int poolSize, PluginManager pluginManager) {
|
||||
ScenarioContext scenarioContext = ScenarioContext.buildScenarioContextWithoutScenario(
|
||||
testId, poolSize, pluginManager);
|
||||
return scenarioContext.addScenrio(scenario, Schedule.build(buildScheduleModel()), new Date().getTime());
|
||||
ScenarioContext scenarioContext = ScenarioContext
|
||||
.buildScenarioContextWithoutScenario(testId, poolSize,
|
||||
pluginManager);
|
||||
return scenarioContext.addScenrio(scenario,
|
||||
Schedule.build(buildScheduleModel()), new Date().getTime());
|
||||
}
|
||||
|
||||
public static ScheduleModel buildScheduleModel(){
|
||||
|
||||
public static ScheduleModel buildScheduleModel() {
|
||||
ScheduleModel scheduleModel = new ScheduleModel();
|
||||
List<PointModel> points = new LinkedList<ScheduleModel.PointModel>();
|
||||
points.add(new PointModel(0, 0));
|
||||
points.add(new PointModel(20 * 1000, 20));
|
||||
points.add(new PointModel(60 * 1000, 20));
|
||||
points.add(new PointModel(20, 20));
|
||||
points.add(new PointModel(60, 20));
|
||||
scheduleModel.setPoints(points);
|
||||
return scheduleModel;
|
||||
}
|
||||
|
|
|
@ -53,16 +53,16 @@ public class Test_Shedule {
|
|||
public void test_InitWith_MinusTime() {
|
||||
long firstTime = -1000000000;
|
||||
ScheduleModel model = new ScheduleModel();
|
||||
model.getPoints().add(new PointModel(firstTime, 100));
|
||||
model.getPoints().add(new PointModel(firstTime / 1000, 100));
|
||||
Schedule.build(model);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void test_LoadFor_WithIlegalArgument() {
|
||||
ScheduleModel model = new ScheduleModel();
|
||||
long firstTime = new Date().getTime();
|
||||
long firstTime = new Date().getTime() / 1000;
|
||||
model.getPoints().add(new PointModel(firstTime, 100));
|
||||
model.getPoints().add(new PointModel(firstTime - 1000000, 50));
|
||||
model.getPoints().add(new PointModel(firstTime - 1000, 50));
|
||||
Schedule schedule = Schedule.build(model);
|
||||
schedule.getSegments().get(0).loadFor(-1000);
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ public class Test_Shedule {
|
|||
@Test
|
||||
public void test_loadFor() {
|
||||
ScheduleModel model = new ScheduleModel();
|
||||
model.getPoints().add(new PointModel(1000000, 100));
|
||||
model.getPoints().add(new PointModel(1000, 100));
|
||||
model.getPoints().add(new PointModel(0, 50));
|
||||
Schedule schedule = Schedule.build(model);
|
||||
int load = schedule.getSegments().get(0).loadFor(500 * 1000);
|
||||
|
@ -80,10 +80,10 @@ public class Test_Shedule {
|
|||
@Test
|
||||
public void test_getSegment() {
|
||||
ScheduleModel model = new ScheduleModel();
|
||||
model.getPoints().add(new PointModel(1000000, 100));
|
||||
model.getPoints().add(new PointModel(100, 100));
|
||||
model.getPoints().add(new PointModel(0, 50));
|
||||
Schedule schedule = Schedule.build(model);
|
||||
Segment segment = schedule.getSegment(500 * 1000);
|
||||
Segment segment = schedule.getSegment(50 * 1000);
|
||||
assertNotNull(segment);
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ public class Test_Shedule {
|
|||
@Test
|
||||
public void test_getScheduleRange() {
|
||||
Schedule schedule = Schedule.build(TestBase.buildScheduleModel());
|
||||
assertEquals(60 * 1000, schedule.getScheduleRange());
|
||||
assertEquals(60 * 1000, schedule.getScheduleRangeInMilliSecond());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -183,15 +183,13 @@ public class RunningAgentDB implements RunningAgentInterface {
|
|||
.tryUnmarshal(RunScenarioModel.class, this.getTestPlanScript()
|
||||
.getFilteredScriptCnt());
|
||||
runScenarioModel.setPoolSize(getLoadInUse());
|
||||
ScheduleModel scheduleModel = (ScheduleModel) MarshalHelper
|
||||
.tryUnmarshal(ScheduleModel.class, this.getTestPlanScript()
|
||||
.getScheduleContent());
|
||||
RunScenarioResultModel runScenarioResultModel = this
|
||||
.getAgentMessenger().submitScenrioWithParams(
|
||||
this.getAgent(),
|
||||
this.getAgentRunId(),
|
||||
script2.loadParamFiles(),
|
||||
runScenarioModel,
|
||||
(ScheduleModel) MarshalHelper.tryUnmarshal(
|
||||
ScheduleModel.class, this.getTestPlanScript()
|
||||
.getScheduleContent()),
|
||||
.getAgentMessenger().submitScenrioWithParams(this.getAgent(),
|
||||
this.getAgentRunId(), script2.loadParamFiles(),
|
||||
runScenarioModel, scheduleModel,
|
||||
this.getRunningScript().getStartTime());
|
||||
if (runScenarioResultModel == null) {
|
||||
return false;
|
||||
|
|
|
@ -205,8 +205,9 @@ public class TestPlanScript implements RunningScriptInterface {
|
|||
return false;
|
||||
}
|
||||
Timer timer = new Timer();
|
||||
timer.schedule(new ExecutionOverTask(this),
|
||||
(testScriptConfig.getExecuteRange()));
|
||||
timer.schedule(
|
||||
new ExecutionOverTask(this),
|
||||
(testScriptConfig.getExecuteRange() * SECOND_MILISECOND_UNIT_CONVERSION));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -399,8 +399,8 @@ public class TestBase_MakeUpTestPlan extends TestBase {
|
|||
model.setRequireLoad(EACH_SCRIPT_LOAD_SMALLSCALE);
|
||||
ScheduleModel schedule = new ScheduleModel();
|
||||
schedule.getPoints().add(new PointModel(0, 0));
|
||||
schedule.getPoints().add(new PointModel(20 * 1000, 10));
|
||||
schedule.getPoints().add(new PointModel(60 * 1000, 10));
|
||||
schedule.getPoints().add(new PointModel(20, 10));
|
||||
schedule.getPoints().add(new PointModel(60, 10));
|
||||
model.setScheduleModel(schedule);
|
||||
return model;
|
||||
}
|
||||
|
|
|
@ -29,10 +29,10 @@ public class ScheduleModel {
|
|||
if (this.points.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
long startTime = this.points.get(0).getTime(), endTime = startTime;
|
||||
long startTime = this.points.get(0).getTimeInSecond(), endTime = startTime;
|
||||
for (PointModel point : this.getPoints()) {
|
||||
startTime = Math.min(point.getTime(), startTime);
|
||||
endTime = Math.max(point.getTime(), endTime);
|
||||
startTime = Math.min(point.getTimeInSecond(), startTime);
|
||||
endTime = Math.max(point.getTimeInSecond(), endTime);
|
||||
}
|
||||
return endTime - startTime;
|
||||
}
|
||||
|
@ -47,16 +47,17 @@ public class ScheduleModel {
|
|||
|
||||
@XmlRootElement
|
||||
public static class PointModel {
|
||||
private long time;
|
||||
// Time Unit is second
|
||||
private long timeInSecond;
|
||||
private int load;
|
||||
|
||||
@XmlElement
|
||||
public long getTime() {
|
||||
return time;
|
||||
public long getTimeInSecond() {
|
||||
return timeInSecond;
|
||||
}
|
||||
|
||||
public void setTime(long time) {
|
||||
this.time = time;
|
||||
public void setTimeInSecond(long time) {
|
||||
this.timeInSecond = time;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
|
@ -71,8 +72,8 @@ public class ScheduleModel {
|
|||
public PointModel() {
|
||||
}
|
||||
|
||||
public PointModel(long time, int load) {
|
||||
this.time = time;
|
||||
public PointModel(long timeInSecond, int load) {
|
||||
this.timeInSecond = timeInSecond;
|
||||
this.load = load;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue