This commit is contained in:
hmm 2014-09-09 10:22:34 +08:00
commit 12c3248170
19 changed files with 104 additions and 67 deletions

View File

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

View File

@ -163,7 +163,6 @@ public class RunningAgentDB implements RunningAgentInterface {
return this.getTestPlanScript();
}
@Override
public RunningAgentInterface completeWithRunningScript(
RunningScriptInterface runningScript) {
this.setTestPlanScript((TestPlanScript) runningScript);
@ -183,9 +182,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 +194,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
@ -230,7 +240,6 @@ public class RunningAgentDB implements RunningAgentInterface {
this.setHasSubstitute(true);
}
@Override
public TestBriefStatusModel briefAll() {
if (this.isStoped()) {
return null;

View File

@ -305,7 +305,6 @@ public class TestPlanScript implements RunningScriptInterface {
return true;
}
@Override
@Transient
public Date getStartTime() {
return this.getTestPlan().getCurrentStartTime();

View File

@ -204,7 +204,6 @@ public class TestPlanEngine implements TaskCompleteCallback,
}
}
@Override
public void executePendingTestPlan() {
pickATestPlan();
}

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

@ -50,7 +50,6 @@ public class TestPlanLoadApplication implements Transaction {
this.getHighAvailableAgentPool().checkAllHeartBeat();
}
@Override
public TestPlanStatus execute() throws Exception {
synchronized (this.highAvailableAgentPool) {
if (!hasEnoughMaxLoad(this.getTestPlan().getRequiredLoad())) {
@ -72,7 +71,6 @@ public class TestPlanLoadApplication implements Transaction {
return TestPlanStatus.InRunning;
}
@Override
public void rollBack() {
for (TestPlanScript testPlanScript : this.getTestPlan()
.getTestPlanScripts()) {

View File

@ -67,7 +67,6 @@ public class AgentMessengerImpl implements AgentMessenger {
final int requiredLoad) {
return this.executorService
.submit(new Callable<RunScenarioResultModel>() {
@Override
public RunScenarioResultModel call() throws Exception {
return bookTest(agent, requiredLoad);
}
@ -105,7 +104,6 @@ public class AgentMessengerImpl implements AgentMessenger {
final ScheduleModel scheduleModel, final Date realStartDate) {
return this.executorService
.submit(new Callable<RunScenarioResultModel>() {
@Override
public RunScenarioResultModel call() throws Exception {
return submitScenrioWithParams(agent, agentRunId,
paramFiles, runScenarioModel, scheduleModel,
@ -139,7 +137,6 @@ public class AgentMessengerImpl implements AgentMessenger {
final UUID agentRunId) {
return this.executorService
.submit(new Callable<RunScenarioResultModel>() {
@Override
public RunScenarioResultModel call() throws Exception {
return runWithParams(agent, agentRunId);
}
@ -175,7 +172,7 @@ public class AgentMessengerImpl implements AgentMessenger {
final UUID runId) {
return this.executorService
.submit(new Callable<TestBriefStatusModel>() {
@Override
public TestBriefStatusModel call() throws Exception {
return scriptBriefAll(agent, runId);
}
@ -206,7 +203,6 @@ public class AgentMessengerImpl implements AgentMessenger {
public Future<StopTestModel> stopAsync(final Agent agent, final UUID runId) {
return this.executorService.submit(new Callable<StopTestModel>() {
@Override
public StopTestModel call() throws Exception {
return stop(agent, runId);
}
@ -235,7 +231,7 @@ public class AgentMessengerImpl implements AgentMessenger {
public Future<ServerStatusModel> getStatusAsync(final Agent agent) {
return this.executorService.submit(new Callable<ServerStatusModel>() {
@Override
public ServerStatusModel call() throws Exception {
return getStatus(agent);
}

View File

@ -337,7 +337,6 @@ public class HighAvailablePoolImpl extends CurrentLoadSubject implements
}
}
@Override
public ServerStatusModel queryAgentStatus(Agent agent) {
return this.getAgentMessenger().getStatus(agent);
}

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,12 +23,10 @@ public class HighAvailableImpl implements HighAvailablePool {
.put(hostName, Agent.createAgentWithoutId(hostName, 6565, 500));
}
@Override
public Map<String, Agent> getPool() {
return this.pool;
}
@Override
public Long getMaxAvailableLoad() {
Long result = 0L;
for (Agent agent : this.pool.values()) {
@ -37,7 +35,6 @@ public class HighAvailableImpl implements HighAvailablePool {
return result;
}
@Override
public int getCurrentAvailableLoad() {
int result = 0;
for (Agent agent : this.pool.values()) {
@ -46,58 +43,48 @@ public class HighAvailableImpl implements HighAvailablePool {
return result;
}
@Override
public void checkAllHeartBeat() {
}
@Override
public void checkHeartBeat(Agent agent) {
}
@Override
public void cleanUpAboutTestPlan(
Collection<? extends RunningScriptInterface> runningScripts) {
}
@Override
public ServerStatusModel queryAgentStatus(Agent agent) {
return null;
}
@Override
public void add(Agent agent) {
// TODO Auto-generated method stub
}
@Override
public void setObserver(CurrentLoadObserver currentLoadObserver) {
// TODO Auto-generated method stub
}
@Override
public Map<UUID, RunningAgentInterface> getAgentRunBlotters() {
// TODO Auto-generated method stub
return null;
}
@Override
public int blotterSize() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void remove(Agent agent) {
// TODO Auto-generated method stub
}
@Override
public List<RunningAgentInterface> applyFor(int load) {
// TODO Auto-generated method stub
return null;

View File

@ -28,12 +28,12 @@ public class Mock_AgentMessenger implements AgentMessenger {
private UUID testId = UUID.randomUUID();
@Override
public RunScenarioResultModel bookTest(Agent agent, int requireLoad) {
return new RunScenarioResultModel(this.testId);
}
@Override
public RunScenarioResultModel submitScenrioWithParams(Agent agent,
UUID agentRunId, List<File> paramFiles,
RunScenarioModel runScenarioModel,
@ -41,12 +41,12 @@ public class Mock_AgentMessenger implements AgentMessenger {
return new RunScenarioResultModel(this.testId);
}
@Override
public RunScenarioResultModel runWithParams(Agent agent, UUID agentRunId) {
return new RunScenarioResultModel(this.testId);
}
@Override
public TestBriefStatusModel scriptBriefAll(Agent agent, UUID runId) {
if (isDead(agent)) {
return null;
@ -67,7 +67,7 @@ public class Mock_AgentMessenger implements AgentMessenger {
return agent.getCurrentEnumStatus() == AgentStatus.BreakDown;
}
@Override
public StopTestModel stop(Agent agent, UUID runId) {
// if (runId == this.testId) {
// return new StopTestModel(true);
@ -75,7 +75,7 @@ public class Mock_AgentMessenger implements AgentMessenger {
return new StopTestModel(true);
}
@Override
public ServerStatusModel getStatus(Agent agent) {
ServerStatusModel result = new ServerStatusModel();
if (agent.getCurrentEnumStatus() == AgentStatus.InIdle) {
@ -89,7 +89,7 @@ public class Mock_AgentMessenger implements AgentMessenger {
return null;
}
@Override
public Future<ServerStatusModel> getStatusAsync(Agent agent) {
return new AsyncResult<ServerStatusModel>(getStatus(agent));
}

View File

@ -14,7 +14,6 @@ import org.springframework.stereotype.Component;
@Component
public class Mock_MonitorMessenger implements MonitorMessenger {
@Override
public MonitorMain monitorModel(String hostName, int port) {
MonitorMain result = new MonitorMain();
result.setFinished(false);
@ -27,27 +26,22 @@ public class Mock_MonitorMessenger implements MonitorMessenger {
return result;
}
@Override
public PhysicalDiskModel physicalDisk(String hostName, int port) {
return monitorModel(hostName, port).getPhysicalDiskModel();
}
@Override
public MemoryModel memory(String hostName, int port) {
return monitorModel(hostName, port).getMemoryModel();
}
@Override
public ProcessorModel processor(String hostName, int port) {
return monitorModel(hostName, port).getProcessorModel();
}
@Override
public NetworkInterfaceModel networkInterface(String hostName, int port) {
return monitorModel(hostName, port).getNetworkInterfaceModel();
}
@Override
public ProcessModel process(String hostName, int port) {
return monitorModel(hostName, port).getProcessModel();
}

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;

View File

@ -2,6 +2,7 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<html>
<head>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<meta charset="utf-8">

View File

@ -326,6 +326,10 @@ function Behavior(usePlugin, containerId) {
}
this.getBehaviorEditorMap = function(){
return behaviorEditorMap;
}
this.getPages = function() {
updateBehaviorEditors();
var treeObj = $("#" + containerId).jstree(true);

View File

@ -16,22 +16,46 @@ $(function() {
});
});
function checkPluginsInput(plugins) {
function checkPluginsInput(plugins, usePlugin) {
for (var i = 0; i < plugins.length; i++){
for (var j = 0; j < plugins[i].parameters.length; j++){
if (plugins[i].parameters[j].check =="false")
if (plugins[i].parameters[j].check =="false"){
$("#tabs").tabs("option", "active", 0 );
var usePluginEditorMap = usePlugin.getUsePluginEditorMap();
$("#pluginEditor").append(usePluginEditorMap.get(plugins[i].id));
var inputs = $("#"+ plugins[i].parameters[j].key + " input");
for (var p = 0; p < inputs.length; p++){
if ($(inputs[p]).val() == ""){
$(inputs[p]).focus();
break;
}
}
return false;
}
}
}
return true;
}
function checkPagesInput(pages) {
function checkPagesInput(pages, usePlugin) {
for (var i = 0;i < pages.length; i++){
for (var j = 0; j < pages[i].batches.length; j++){
for (var k = 0; k < pages[i].batches[j].behaviors.length; k++){
for (var q = 0; q < pages[i].batches[j].behaviors[k].parameters.length; q++){
if (pages[i].batches[j].behaviors[k].parameters[q].check == "false"){
if (pages[i].batches[j].behaviors[k].parameters[q].check =="false"){
$("#tabs").tabs("option", "active", 1 );
var behaviorEditorMap = usePlugin.getBehaviorEditorMap();
$("#behaviorEditor").append(behaviorEditorMap.get(pages[i].batches[j].behaviors[k].id));
var inputs = $("#"+ pages[i].batches[j].behaviors[k].parameters[q].key + " input");
for (var p = 0; p < inputs.length; p++){
if ($(inputs[p]).val() == ""){
$(inputs[p]).focus();
break;
}
}
return false;
}
}

View File

@ -5,11 +5,12 @@ $(function() {
$("#submitScript").click(function() {
var formData = new FormData();
var plugins = usePlugin.getPlugins( formData );
var plugins = usePlugin.getPlugins(formData);
var pages = usePlugin.getPages();
if(checkPluginsInput(plugins) && checkPagesInput(pages))
if(checkPluginsInput(plugins, usePlugin) && checkPagesInput(pages, usePlugin))
submitScript(pages, plugins, formData);
else
else{
information("Please complete the required parameters.");
}
});
});

View File

@ -39,7 +39,7 @@ $(function() {
var formData = new FormData();
var plugins = usePlugin.getPlugins(formData);
var pages = usePlugin.getPages();
if(checkPluginsInput(plugins) && checkPagesInput(pages))
if(checkPluginsInput(plugins, usePlugin) && checkPagesInput(pages, usePlugin))
updateScript(scriptId,pages,plugins,formData);
else
information("Please complete the required parameters.");

View File

@ -85,6 +85,11 @@ function UsePlugin(behaviorListContainerId) {
});
});
this.getUsePluginEditorMap = function() {
return usePluginEditorMap;
}
function getPluginList() {
var usePlugin = this;
$.post("loadPluginName", {}, function(data) {
@ -197,6 +202,10 @@ function UsePlugin(behaviorListContainerId) {
return behavior.getPages();
}
this.getBehaviorEditorMap = function(){
return behavior.getBehaviorEditorMap();
}
this.initPluginAndPages = function(scriptObj){
initPluginList(scriptObj.usePlugins);
behavior.initBehaviorList(scriptObj.pages);