This commit is contained in:
coderfengyun 2013-12-30 09:00:41 +08:00
parent f6fc1c6d4e
commit 0c48de4325
3 changed files with 44 additions and 40 deletions

View File

@ -2,15 +2,21 @@ package org.bench4q.master.domain;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;
import org.bench4q.master.helper.ApplicationContextHelper;
import org.bench4q.master.service.communication.RunningScriptService;
import org.bench4q.master.service.infrastructure.RunningAgentService;
import org.bench4q.master.service.infrastructure.TestPlanService;
import org.bench4q.master.testplan.TestPlanEngine;
import org.bench4q.master.testplan.datastatistics.BehaviorsBriefStatistics;
import org.bench4q.master.testplan.datastatistics.DataStatistics;
import org.bench4q.master.testplan.datastatistics.PageBriefStatistics;
import org.bench4q.master.testplan.datastatistics.ScriptBriefStatistics;
import org.bench4q.master.testplan.schedulscript.ExecutionOverTask;
import org.bench4q.master.testplan.schedulscript.WarmUpOverTask;
import org.bench4q.share.models.agent.statistics.AgentBehaviorsBriefModel;
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
import org.bench4q.share.models.master.ScriptBehaviorsBriefModel;
@ -102,15 +108,15 @@ public class RunningScript {
.getBean(RunningAgentService.class));
}
public DataStatistics getScriptBriefStatistics() {
private DataStatistics getScriptBriefStatistics() {
return getSpecificStaitstics(ScriptBriefStatistics.class);
}
public DataStatistics getPageBriefStatistics() {
private DataStatistics getPageBriefStatistics() {
return getSpecificStaitstics(PageBriefStatistics.class);
}
public DataStatistics getBehaviorsBriefStatistics() {
private DataStatistics getBehaviorsBriefStatistics() {
return getSpecificStaitstics(BehaviorsBriefStatistics.class);
}
@ -183,7 +189,38 @@ public class RunningScript {
return result;
}
public boolean scheduleAsConfig(TestPlanEngine testPlanEngine,
UUID testPlanId) {
TestScriptConfig testScriptConfig = this.getConfig();
if (testScriptConfig == null) {
return false;
}
Timer timer = new Timer();
timer.schedule(new WarmUpOverTask(), testScriptConfig.getWarmUp()
* TestPlanService.TIME_UNIT);
ExecutionOverTask executionOverTask = new ExecutionOverTask(this,
testPlanEngine);
timer.schedule(
executionOverTask,
(testScriptConfig.getWarmUp() + testScriptConfig
.getExecuteRange()) * TestPlanService.TIME_UNIT);
timer.schedule(
new TimerTask() {
@Override
public void run() {
System.out.println("cool down over!");
}
},
(testScriptConfig.getWarmUp()
+ testScriptConfig.getExecuteRange() + testScriptConfig
.getCoolDown()) * TestPlanService.TIME_UNIT);
return true;
}
public static boolean notValidScript(RunningScript input) {
return input == null || input.getRunningAgents() == null;
}
}

View File

@ -24,7 +24,8 @@ public class TestPlanContext {
return runningScriptMap;
}
public void setRunningScriptMap(Map<Integer, RunningScript> runningScriptMap) {
private void setRunningScriptMap(
Map<Integer, RunningScript> runningScriptMap) {
this.runningScriptMap = runningScriptMap;
}
@ -47,6 +48,7 @@ public class TestPlanContext {
this.setFinish(true);
this.setTestPlan(null);
this.setRunningScriptMap(null);
System.gc();
}
public void fillScriptMapAndAssignTestPlanId(List<RunningScript> list,

View File

@ -1,7 +1,5 @@
package org.bench4q.master.testplan;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@ -15,10 +13,7 @@ import org.bench4q.master.entity.User;
import org.bench4q.master.service.infrastructure.TestPlanService;
import org.bench4q.master.testplan.highavailable.CurrentLoadObserver;
import org.bench4q.master.testplan.highavailable.HighAvailablePool;
import org.bench4q.master.testplan.schedulscript.ExecutionOverTask;
import org.bench4q.master.testplan.schedulscript.TaskCompleteCallback;
import org.bench4q.master.testplan.schedulscript.WarmUpOverTask;
import org.bench4q.share.models.master.TestScriptConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -107,41 +102,11 @@ public class TestPlanEngine implements TaskCompleteCallback,
private boolean schedulePlanConfig(TestPlanContext testPlanContext,
UUID testPlanId) {
for (RunningScript runningScript : testPlanContext.getAllScript()) {
scheduleScriptConfig(runningScript, testPlanId);
runningScript.scheduleAsConfig(this, testPlanId);
}
return true;
}
private boolean scheduleScriptConfig(final RunningScript runningScript,
UUID testPlanId) {
TestScriptConfig testScriptConfig = runningScript.getConfig();
if (testScriptConfig == null) {
return false;
}
Timer timer = new Timer();
timer.schedule(new WarmUpOverTask(), testScriptConfig.getWarmUp()
* TestPlanService.TIME_UNIT);
ExecutionOverTask executionOverTask = new ExecutionOverTask(
runningScript, this);
timer.schedule(
executionOverTask,
(testScriptConfig.getWarmUp() + testScriptConfig
.getExecuteRange()) * TestPlanService.TIME_UNIT);
timer.schedule(
new TimerTask() {
@Override
public void run() {
System.out.println("cool down over!");
}
},
(testScriptConfig.getWarmUp()
+ testScriptConfig.getExecuteRange() + testScriptConfig
.getCoolDown()) * TestPlanService.TIME_UNIT);
return true;
}
public void doTaskComplete(UUID testPlanID) {
if (!this.getTestPlanContainer().isTestPlanFinished(testPlanID)) {
return;