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;
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.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@ -9,16 +16,27 @@ import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/")
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)
@ResponseBody
public String index() {
User principal = this.getPrincipal();
String userName;
if (principal == null) {
userName = "Anonymous User";
} else {
userName = principal.getUserName();
public ServerStatusModel currentTasks() {
List<UUID> tasks = new LinkedList<UUID>();
for (TestPlan testPlan : this.getTestPlanService()
.loadAllRunningTestPlans()) {
tasks.add(UUID.fromString(testPlan.getTestPlanRunId()));
}
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.util.ArrayList;
import java.util.Collections;
import java.util.List;
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.report.ReportService;
import org.bench4q.master.exception.Bench4QException;
import org.bench4q.master.exception.Bench4QRunTimeException;
import org.bench4q.share.enums.master.TestPlanStatus;
import org.bench4q.share.models.master.MonitorModel;
import org.bench4q.share.models.master.ScriptHandleModel;
@ -307,6 +309,17 @@ public class TestPlanController extends BaseController {
throws Bench4QException {
guardHasAuthentication("You have no power to stop test plan",
"/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;
}
}
this.setCurrentStatus(TestPlanStatus.Complete.name());
return result;
}

View File

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

View File

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

View File

@ -1,8 +1,6 @@
package org.bench4q.master.unitTest.entity;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.List;
@ -133,4 +131,17 @@ public class Test_TestPlan extends TestBase_MakeUpTestPlan {
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.util.Collections;
import java.util.Date;
import java.util.UUID;
import org.apache.commons.io.FileUtils;
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) {
this.getAgentRepository().detach(agent.getId());
}
this.scriptRepository.detach(this.scriptRepository.getScriptByName(
"test1").getId());
Script script = this.scriptRepository.getScriptByName("test1");
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()
.getRunningTestPlanBy(getTestPlanRunIdUuid())
.getCurrentStatus()));
assertNotNull(this.getTestPlanRepository().getRunningTestPlanBy(
getTestPlanRunIdUuid()));
for (TestPlanScript testPlanScript : testPlan.getTestPlanScripts()) {
testPlanScript.stop();
}
@ -171,4 +178,20 @@ public class Test_TestPlanEngine extends TestBase_MakeUpTestPlan {
.getCurrentStatus()));
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="lib/HashMap/HashMap.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/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);
$("#behaviorEditor").html("");
$("#behaviorEditor").attr("behavior", "");
});
$("#clearBehavior").click(function() {
$("#insertChildDiv").addClass("hide");