Conflicts:
	Bench4Q-Web/src/main/webapp/script/editor/behavior.js
This commit is contained in:
hmm 2014-08-21 15:06:47 +08:00
commit 2a137be83f
10 changed files with 101 additions and 16 deletions

View File

@ -1,6 +1,13 @@
package org.bench4q.master.api; package org.bench4q.master.api;
import org.bench4q.master.domain.entity.User; import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import org.bench4q.master.domain.entity.TestPlan;
import org.bench4q.master.domain.service.TestPlanService;
import org.bench4q.share.models.master.ServerStatusModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
@ -9,16 +16,27 @@ import org.springframework.web.bind.annotation.ResponseBody;
@Controller @Controller
@RequestMapping("/") @RequestMapping("/")
public class HomeController extends BaseController { public class HomeController extends BaseController {
private TestPlanService testPlanService;
private TestPlanService getTestPlanService() {
return testPlanService;
}
@Autowired
private void setTestPlanService(TestPlanService testPlanService) {
this.testPlanService = testPlanService;
}
@RequestMapping(value = { "/" }, method = RequestMethod.GET) @RequestMapping(value = { "/" }, method = RequestMethod.GET)
@ResponseBody @ResponseBody
public String index() { public ServerStatusModel currentTasks() {
User principal = this.getPrincipal(); List<UUID> tasks = new LinkedList<UUID>();
String userName; for (TestPlan testPlan : this.getTestPlanService()
if (principal == null) { .loadAllRunningTestPlans()) {
userName = "Anonymous User"; tasks.add(UUID.fromString(testPlan.getTestPlanRunId()));
} else {
userName = principal.getUserName();
} }
return "Hello [" + userName + "]"; ServerStatusModel result = new ServerStatusModel();
result.setRunningTests(tasks);
return result;
} }
} }

View File

@ -2,6 +2,7 @@ package org.bench4q.master.api;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -17,6 +18,7 @@ import org.bench4q.master.domain.service.TestPlanService;
import org.bench4q.master.domain.service.UserService; import org.bench4q.master.domain.service.UserService;
import org.bench4q.master.domain.service.report.ReportService; import org.bench4q.master.domain.service.report.ReportService;
import org.bench4q.master.exception.Bench4QException; import org.bench4q.master.exception.Bench4QException;
import org.bench4q.master.exception.Bench4QRunTimeException;
import org.bench4q.share.enums.master.TestPlanStatus; import org.bench4q.share.enums.master.TestPlanStatus;
import org.bench4q.share.models.master.MonitorModel; import org.bench4q.share.models.master.MonitorModel;
import org.bench4q.share.models.master.ScriptHandleModel; import org.bench4q.share.models.master.ScriptHandleModel;
@ -307,6 +309,17 @@ public class TestPlanController extends BaseController {
throws Bench4QException { throws Bench4QException {
guardHasAuthentication("You have no power to stop test plan", guardHasAuthentication("You have no power to stop test plan",
"/stop/{testPlanId}"); "/stop/{testPlanId}");
return null; guardIsTheOwner(testPlanId);
return buildTestPlanResponseModel(
this.getTestPlanRunner().stop(testPlanId), "",
Collections.<TestPlan> emptyList());
}
private void guardIsTheOwner(UUID testPlanId) {
if (!getPrincipal().getUserName().equals(
this.getTestPlanService().getTestPlanDBModel(testPlanId)
.getUserModel().getUserName())) {
throw new Bench4QRunTimeException("You are not the owner");
}
} }
} }

View File

@ -219,6 +219,7 @@ public class TestPlan implements IAggregate {
result = false; result = false;
} }
} }
this.setCurrentStatus(TestPlanStatus.Complete.name());
return result; return result;
} }

View File

@ -1,5 +1,6 @@
package org.bench4q.master.domain.repository; package org.bench4q.master.domain.repository;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -225,4 +226,8 @@ public class TestPlanRepository extends AbstractRepositoty {
return null; return null;
} }
} }
public Collection<TestPlan> loadRunningTestPlans() {
return this.runningTestPlans.values();
}
} }

View File

@ -1,5 +1,6 @@
package org.bench4q.master.domain.service; package org.bench4q.master.domain.service;
import java.util.Collection;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -86,4 +87,8 @@ public class TestPlanService {
"runningInfo : " + MarshalHelper.tryMarshal(resultModel)); "runningInfo : " + MarshalHelper.tryMarshal(resultModel));
return resultModel; return resultModel;
} }
public Collection<TestPlan> loadAllRunningTestPlans() {
return this.getTestPlanRepository().loadRunningTestPlans();
}
} }

View File

@ -1,8 +1,6 @@
package org.bench4q.master.unitTest.entity; package org.bench4q.master.unitTest.entity;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -133,4 +131,17 @@ public class Test_TestPlan extends TestBase_MakeUpTestPlan {
assertEquals(startLoad, this.getHaPool().getCurrentAvailableLoad()); assertEquals(startLoad, this.getHaPool().getCurrentAvailableLoad());
} }
@Test
public void test_stop() {
TestPlan testPlan = this.getTestPlanRepository().getTestPlanInDomainBy(
this.getTestPlanRunIdUuid());
testPlan.run();
assertFalse(testPlan.isFinish());
assertEquals(TestPlanStatus.InRunning.toString(),
testPlan.getCurrentStatus());
testPlan.stop();
assertEquals(TestPlanStatus.Complete.toString(),
testPlan.getCurrentStatus());
assertTrue(testPlan.isFinish());
}
} }

View File

@ -4,6 +4,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.UUID;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.bench4q.master.Main; import org.bench4q.master.Main;
@ -63,8 +64,12 @@ public class Test_TestPlanEngine extends TestBase_MakeUpTestPlan {
if ((agent = this.getAgentRepository().getAgentBy("147.0.01")) != null) { if ((agent = this.getAgentRepository().getAgentBy("147.0.01")) != null) {
this.getAgentRepository().detach(agent.getId()); this.getAgentRepository().detach(agent.getId());
} }
this.scriptRepository.detach(this.scriptRepository.getScriptByName( Script script = this.scriptRepository.getScriptByName("test1");
"test1").getId()); if (script == null) {
System.out.println("script is null");
} else {
this.scriptRepository.detach(script.getId());
}
} }
} }
@ -98,6 +103,8 @@ public class Test_TestPlanEngine extends TestBase_MakeUpTestPlan {
TestPlanStatus.valueOf(getTestPlanRepository() TestPlanStatus.valueOf(getTestPlanRepository()
.getRunningTestPlanBy(getTestPlanRunIdUuid()) .getRunningTestPlanBy(getTestPlanRunIdUuid())
.getCurrentStatus())); .getCurrentStatus()));
assertNotNull(this.getTestPlanRepository().getRunningTestPlanBy(
getTestPlanRunIdUuid()));
for (TestPlanScript testPlanScript : testPlan.getTestPlanScripts()) { for (TestPlanScript testPlanScript : testPlan.getTestPlanScripts()) {
testPlanScript.stop(); testPlanScript.stop();
} }
@ -171,4 +178,20 @@ public class Test_TestPlanEngine extends TestBase_MakeUpTestPlan {
.getCurrentStatus())); .getCurrentStatus()));
deleteTestPlan(); deleteTestPlan();
} }
@Test
public void test_Stop() {
int loadBefore = this.getHaPool().getCurrentAvailableLoad();
this.getTestPlanEngine().doRunTestPlan(this.getTestPlanRunIdUuid());
int afterLoad = this.getHaPool().getCurrentAvailableLoad();
assertEquals(0, afterLoad);
this.getTestPlanEngine().stop(this.getTestPlanRunIdUuid());
int lastLoad = this.getHaPool().getCurrentAvailableLoad();
assertEquals(loadBefore, lastLoad);
}
@Test
public void test_stopWrongTestPlanId() {
assertFalse(this.getTestPlanEngine().stop(UUID.randomUUID()));
}
} }

View File

@ -229,6 +229,7 @@ body {
<!-- <script src="script/base.js"></script> --> <!-- <script src="script/base.js"></script> -->
<script src="lib/HashMap/HashMap.js"></script> <script src="lib/HashMap/HashMap.js"></script>
<script src="lib/other/jstree.min.js"></script> <script src="lib/other/jstree.min.js"></script>
<script src="lib/other/jquery.msgbox.min.js"></script>
<script src="script/editor/pluginEditor/editorFactory.js"></script> <script src="script/editor/pluginEditor/editorFactory.js"></script>
<script src="script/editor/pluginEditor/dataFormat.js"></script> <script src="script/editor/pluginEditor/dataFormat.js"></script>

File diff suppressed because one or more lines are too long

View File

@ -202,6 +202,7 @@ function Behavior(usePlugin) {
jstreeDeleteNode(containerId); jstreeDeleteNode(containerId);
$("#behaviorEditor").html(""); $("#behaviorEditor").html("");
$("#behaviorEditor").attr("behavior", ""); $("#behaviorEditor").attr("behavior", "");
}); });
$("#clearBehavior").click(function() { $("#clearBehavior").click(function() {
$("#insertChildDiv").addClass("hide"); $("#insertChildDiv").addClass("hide");
@ -209,7 +210,7 @@ function Behavior(usePlugin) {
behaviorEditorMap.clear(); behaviorEditorMap.clear();
// clear tree // clear tree
jstreeClearNode(containerId); jstreeClearNode(containerId);
index = 0; index = 0;
}) })
function updateBehaviorEditors() { function updateBehaviorEditors() {
if ($("#behaviorEditor").attr("behavior") == undefined if ($("#behaviorEditor").attr("behavior") == undefined