diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/api/TestPlanController.java b/Bench4Q-Master/src/main/java/org/bench4q/master/api/TestPlanController.java index 5262bcee..993dfb11 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/api/TestPlanController.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/api/TestPlanController.java @@ -98,8 +98,8 @@ public class TestPlanController extends BaseController { this.testPlanScriptResultService = testPlanScriptResultService; } - @RequestMapping(value = "/run", method = { - RequestMethod.POST, RequestMethod.GET }) + @RequestMapping(value = "/run", method = { RequestMethod.POST, + RequestMethod.GET }) @ResponseStatus(value = HttpStatus.OK) @ResponseBody public TestPlanResultModel runTestPlanWithTestPlanModel( @@ -107,15 +107,14 @@ public class TestPlanController extends BaseController { throws Bench4QException { if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) { throw new Bench4QException(HAVE_NO_POWER, - "You don't have enough power to run a test plan!", - "/run"); + "You don't have enough power to run a test plan!", "/run"); } - UUID testPlanRunID = this.getTestPlanRunner().runWith( - testPlanBusinessModel, this.getPrincipal()); - if (testPlanRunID == null) { - throw new Bench4QException("TestPlan_Commit_Error", - "There is an exception when commit the test plan", - "/run"); + UUID testPlanRunID = null; + try { + testPlanRunID = this.getTestPlanRunner().runWith( + testPlanBusinessModel, this.getPrincipal()); + } catch (Exception e) { + throw new Bench4QException(e, "/run"); } return buildResponseModel(this.getTestPlanService() .queryTestPlanStatus(testPlanRunID), testPlanRunID, null, @@ -206,13 +205,13 @@ public class TestPlanController extends BaseController { @ResponseBody public TestPlanResponseModel loadTestPlans() { if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) { - return buildTestPlanResponseModel(false, "no scope", null,null); + return buildTestPlanResponseModel(false, "no scope", null, null); } List testPlanDBs = this.testPlanService.loadTestPlans(this .getPrincipal()); return testPlanDBs == null ? buildTestPlanResponseModel(false, - "exception", null,null) : buildTestPlanResponseModel(true, null, - testPlanDBs,null); + "exception", null, null) : buildTestPlanResponseModel(true, + null, testPlanDBs, null); } @RequestMapping(value = "/queryTestPlan/{runId}", method = RequestMethod.GET) @@ -233,14 +232,16 @@ public class TestPlanController extends BaseController { @ResponseBody public TestPlanResponseModel removeTestPlanFromPool(int testPlanId) { if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) { - return buildTestPlanResponseModel(false, "no scope", null,null); + return buildTestPlanResponseModel(false, "no scope", null, null); } return buildTestPlanResponseModel( - this.testPlanService.removeTestPlanInDB(testPlanId), null, null,null); + this.testPlanService.removeTestPlanInDB(testPlanId), null, + null, null); } private TestPlanResponseModel buildTestPlanResponseModel(boolean success, - String failCause, List testPlanDBs,String[] filterTypeList) { + String failCause, List testPlanDBs, + String[] filterTypeList) { TestPlanResponseModel result = new TestPlanResponseModel(); result.setSuccess(success); result.setFailCause(failCause); @@ -313,7 +314,7 @@ public class TestPlanController extends BaseController { guardIsTheOwner(testPlanId); return buildTestPlanResponseModel( this.getTestPlanRunner().stop(testPlanId), "", - Collections. emptyList(),null); + Collections. emptyList(), null); } private void guardIsTheOwner(UUID testPlanId) { @@ -323,9 +324,9 @@ public class TestPlanController extends BaseController { throw new Bench4QRunTimeException("You are not the owner"); } } - - @RequestMapping(value = "/loadFilterTypeList", method = { RequestMethod.POST, - RequestMethod.GET }) + + @RequestMapping(value = "/loadFilterTypeList", method = { + RequestMethod.POST, RequestMethod.GET }) @ResponseStatus(value = HttpStatus.OK) @ResponseBody public TestPlanResponseModel loadFilterTypeList() throws Bench4QException { @@ -334,7 +335,9 @@ public class TestPlanController extends BaseController { "You don't have enough power to get filter type list!", "/loadFilterTypeList"); } - String[] filterTypeList = this.getTestPlanService().loadFilterTypeList(); - return this.buildTestPlanResponseModel(true, null, null,filterTypeList); + String[] filterTypeList = this.getTestPlanService() + .loadFilterTypeList(); + return this + .buildTestPlanResponseModel(true, null, null, filterTypeList); } } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/TestPlanFactory.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/TestPlanFactory.java index dc922444..a11a8c5e 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/TestPlanFactory.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/TestPlanFactory.java @@ -103,8 +103,7 @@ public class TestPlanFactory { public TestPlan createATestPlanWithoutId(TestPlanModel testPlanModel, User user, UUID runId) throws IllegalParameterException { - Logger.getLogger(TestPlanFactory.class).info( - "testPlanName:" + testPlanModel.getName()); + this.logger.info("testPlanName:" + testPlanModel.getName()); TestPlan result = new TestPlan(); result.setCreateDateTime(new Date()); result.setCurrentStatus(TestPlanStatus.NotStart.name()); @@ -115,22 +114,24 @@ public class TestPlanFactory { result.setTestPlanRunId(runId.toString()); result.setUser(user); Set testPlanScripts = new HashSet(); - int requiredLoad = 0; + int totalRequiredLoad = 0; for (RunningScriptModel runningScriptModel : testPlanModel .getRunningScriptModels()) { - if (runningScriptModel.getRequireLoad() <= 0) { + this.logger.info(MarshalHelper.tryMarshal(runningScriptModel + .getScheduleModel())); + int scriptLoad = runningScriptModel.getScheduleModel().getMaxLoad(); + if (scriptLoad <= 0) { throw new IllegalParameterException( "runningScriptModel's requireLoad is L.T. zero where scriptId is " + runningScriptModel.getScriptId()); } - requiredLoad += runningScriptModel.getRequireLoad(); - testPlanScripts.add(createATestPlanScriptWithoutId( - runningScriptModel.getRequireLoad(), + totalRequiredLoad += scriptLoad; + testPlanScripts.add(createATestPlanScriptWithoutId(scriptLoad, runningScriptModel.getScriptId(), runningScriptModel.getScheduleModel(), result, runningScriptModel.getScriptFilterOptionsModel())); } - result.setRequiredLoad(requiredLoad); + result.setRequiredLoad(totalRequiredLoad); result.setTestPlanScripts(testPlanScripts); Set monitors = new HashSet(); diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/TestPlanEngine.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/TestPlanEngine.java index 6f5d589b..eed1ae10 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/TestPlanEngine.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/TestPlanEngine.java @@ -17,7 +17,6 @@ import org.bench4q.master.domain.entity.User; import org.bench4q.master.domain.factory.TestPlanFactory; import org.bench4q.master.domain.repository.TestPlanRepository; import org.bench4q.master.domain.valueobject.schedulscript.TaskCompleteCallback; -import org.bench4q.master.exception.ExceptionLog; import org.bench4q.master.exception.ExceptionUtils.IllegalParameterException; import org.bench4q.master.infrastructure.highavailable.CurrentLoadObserver; import org.bench4q.master.infrastructure.highavailable.HighAvailablePool; @@ -94,14 +93,13 @@ public class TestPlanEngine implements TaskCompleteCallback, }, 0, Main.PICK_CYCLE_IN_SECONDS, TimeUnit.SECONDS); } - public UUID runWith(final TestPlanModel testPlanModel, User user) { + public UUID runWith(final TestPlanModel testPlanModel, User user) + throws IllegalParameterException { ExecutorService executorService = Executors.newCachedThreadPool(); final UUID testPlanId = UUID.randomUUID(); logger.info("name:" + testPlanModel.getName() + " start to run"); logger.info(testPlanId + " start to run"); - if (!submitTestPlan(testPlanModel, user, testPlanId)) { - return null; - } + submitTestPlan(testPlanModel, user, testPlanId); Runnable runnable = new Runnable() { public void run() { doRunTestPlan(testPlanId); @@ -125,20 +123,13 @@ public class TestPlanEngine implements TaskCompleteCallback, } public boolean submitTestPlan(final TestPlanModel testPlanBusinessModel, - final User user, final UUID testPlanRunId) { - try { - TestPlan testPlan = this.getTestPlanFactory() - .createATestPlanWithoutId(testPlanBusinessModel, user, - testPlanRunId); - Logger.getLogger(TestPlanService.class).info( - "test plan name:" + testPlan.getName()); - return this.getTestPlanRepository().attach(testPlan); - } catch (IllegalParameterException e) { - // TODO: give back the message - Logger.getLogger(TestPlanService.class).error( - ExceptionLog.getStackTrace(e) + e.getMessage()); - return false; - } + final User user, final UUID testPlanRunId) + throws IllegalParameterException { + TestPlan testPlan = this.getTestPlanFactory().createATestPlanWithoutId( + testPlanBusinessModel, user, testPlanRunId); + Logger.getLogger(TestPlanService.class).info( + "test plan name:" + testPlan.getName()); + return this.getTestPlanRepository().attach(testPlan); } public void doRunTestPlan(final UUID testPlanId) { diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/exception/Bench4QException.java b/Bench4Q-Master/src/main/java/org/bench4q/master/exception/Bench4QException.java index 5b5af3cc..359c982e 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/exception/Bench4QException.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/exception/Bench4QException.java @@ -44,4 +44,8 @@ public class Bench4QException extends Exception { this.setMessage(message); this.setResource(resource); } + + public Bench4QException(Exception e, String resource) { + this("404", e.getMessage(), resource); + } } diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/TestBase_MakeUpTestPlan.java b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/TestBase_MakeUpTestPlan.java index 4d76e939..09e34598 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/TestBase_MakeUpTestPlan.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/TestBase_MakeUpTestPlan.java @@ -23,6 +23,7 @@ import org.bench4q.master.domain.service.TestPlanScriptResultService; import org.bench4q.master.domain.service.TestPlanScriptService; import org.bench4q.master.domain.service.TestPlanService; import org.bench4q.master.domain.service.UserService; +import org.bench4q.master.exception.ExceptionUtils.IllegalParameterException; import org.bench4q.master.helper.SessionHelper; import org.bench4q.master.infrastructure.communication.AgentMessenger; import org.bench4q.master.infrastructure.highavailable.HighAvailablePool; @@ -317,7 +318,11 @@ public class TestBase_MakeUpTestPlan extends TestBase { TestPlanModel model = null; model = createAtestPlanWithOneScriptAndName(load); - this.getTestPlanEngine().submitTestPlan(model, user, testPlanRunId); + try { + this.getTestPlanEngine().submitTestPlan(model, user, testPlanRunId); + } catch (IllegalParameterException e) { + e.printStackTrace(); + } this.setTestPlanRunIdUuid(testPlanRunId); return testPlanRunId; } diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/TestPlanScriptResultControllerTest.java b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/TestPlanScriptResultControllerTest.java index 35900de5..7391ea2e 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/TestPlanScriptResultControllerTest.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/TestPlanScriptResultControllerTest.java @@ -8,6 +8,7 @@ import java.util.UUID; import javax.xml.bind.JAXBException; import org.bench4q.master.domain.entity.User; +import org.bench4q.master.exception.ExceptionUtils.IllegalParameterException; import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan; import org.bench4q.share.communication.HttpRequester.HttpResponse; import org.bench4q.share.helper.MarshalHelper; @@ -51,7 +52,12 @@ public class TestPlanScriptResultControllerTest extends TestBase_MakeUpTestPlan EACH_SCRIPT_LOAD_SMALLSCALE); // TestPlanInBusiness testPlan = // BusinessModelMapFactory.toBusiness(model); - this.getTestPlanEngine().submitTestPlan(model, user, testPlanRunId); + try { + this.getTestPlanEngine().submitTestPlan(model, user, testPlanRunId); + } catch (IllegalParameterException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } this.setTestPlanRunIdUuid(testPlanRunId); for (int i = 0; i < 3; i++) { /* diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_MonitorResultService.java b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_MonitorResultService.java index 35bf6334..e6b3026a 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_MonitorResultService.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_MonitorResultService.java @@ -14,6 +14,7 @@ import org.bench4q.master.domain.repository.TestPlanRepository; import org.bench4q.master.domain.service.AgentService; import org.bench4q.master.domain.service.MonitorResultService; import org.bench4q.master.exception.Bench4QException; +import org.bench4q.master.exception.ExceptionUtils.IllegalParameterException; import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan; import org.bench4q.share.enums.master.TestPlanStatus; import org.bench4q.share.models.monitor.MemoryModel; @@ -96,9 +97,13 @@ public class Test_MonitorResultService extends TestBase_MakeUpTestPlan { User user = this.getUserRepository().getUser("admin"); int scriptId = getUserFirstScript(user); this.getHaPool().checkAllHeartBeat(); - this.setTestPlanRunIdUuid(this.getTestPlanEngine().runWith( - createATestPlanWithOneScript(scriptId, - EACH_SCRIPT_LOAD_SMALLSCALE), user)); + try { + this.setTestPlanRunIdUuid(this.getTestPlanEngine().runWith( + createATestPlanWithOneScript(scriptId, + EACH_SCRIPT_LOAD_SMALLSCALE), user)); + } catch (IllegalParameterException e) { + e.printStackTrace(); + } Thread.sleep(500); TestPlan testPlanInDomain = this.getTestPlanFactory().convertToDomain( this.getTestPlanRepository().getTestPlanInDomainBy( diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_TestPlanEngine.java b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_TestPlanEngine.java index 0aa64312..52cfb91c 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_TestPlanEngine.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_TestPlanEngine.java @@ -15,6 +15,7 @@ import org.bench4q.master.domain.entity.TestPlanScript; import org.bench4q.master.domain.entity.User; import org.bench4q.master.domain.repository.ScriptRepositoty; import org.bench4q.master.domain.service.AgentService; +import org.bench4q.master.exception.ExceptionUtils.IllegalParameterException; import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan; import org.bench4q.share.enums.master.TestPlanStatus; import org.bench4q.share.helper.TestHelper; @@ -90,9 +91,13 @@ public class Test_TestPlanEngine extends TestBase_MakeUpTestPlan { this.getHaPool().checkAllHeartBeat(); Date dateBeforeRun = new Date(); Thread.sleep(1000); - this.setTestPlanRunIdUuid(this.getTestPlanEngine().runWith( - createATestPlanWithOneScript(scriptId, - EACH_SCRIPT_LOAD_SMALLSCALE), user)); + try { + this.setTestPlanRunIdUuid(this.getTestPlanEngine().runWith( + createATestPlanWithOneScript(scriptId, + EACH_SCRIPT_LOAD_SMALLSCALE), user)); + } catch (IllegalParameterException e) { + e.printStackTrace(); + } assertNotNull(getTestPlanRunIdUuid()); Thread.sleep(10000); TestPlan testPlan = this.getTestPlanRepository().getTestPlanInDomainBy( diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_TestPlanScriptResultService.java b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_TestPlanScriptResultService.java index ec279c97..5b1ba367 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_TestPlanScriptResultService.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_TestPlanScriptResultService.java @@ -9,6 +9,7 @@ import org.bench4q.master.domain.entity.User; import org.bench4q.master.domain.factory.TestPlanFactory; import org.bench4q.master.domain.repository.TestPlanRepository; import org.bench4q.master.domain.service.TestResultSave; +import org.bench4q.master.exception.ExceptionUtils.IllegalParameterException; import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan; import org.bench4q.share.models.master.TestPlanModel; import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel; @@ -65,7 +66,11 @@ public class Test_TestPlanScriptResultService extends TestBase_MakeUpTestPlan { this.setScriptId(this.getUserFirstScript(user)); TestPlanModel model = createATestPlanWithOneScript(this.getScriptId(), EACH_SCRIPT_LOAD_SMALLSCALE); - this.getTestPlanEngine().submitTestPlan(model, user, testPlanRunId); + try { + this.getTestPlanEngine().submitTestPlan(model, user, testPlanRunId); + } catch (IllegalParameterException e) { + e.printStackTrace(); + } this.setTestPlanRunIdUuid(testPlanRunId); this.testPlanRepository.getTestPlanInDomainBy(getTestPlanRunIdUuid()); diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_TestPlanService.java b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_TestPlanService.java index febc8630..236042bb 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_TestPlanService.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_TestPlanService.java @@ -8,6 +8,7 @@ import java.util.UUID; import org.bench4q.master.domain.entity.TestPlan; import org.bench4q.master.domain.entity.TestPlanScript; import org.bench4q.master.domain.entity.User; +import org.bench4q.master.exception.ExceptionUtils.IllegalParameterException; import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan; import org.bench4q.share.enums.master.TestPlanStatus; import org.bench4q.share.models.master.TestPlanResultModel; @@ -52,9 +53,14 @@ public class Test_TestPlanService extends TestBase_MakeUpTestPlan { .loadEntities(user).size(); System.out.println(planCountBeforeSubmit); UUID randomUUID = UUID.randomUUID(); - assertTrue(this.getTestPlanEngine().submitTestPlan( - createATestPlanWithOneScript(getUserFirstScript(user), - EACH_SCRIPT_LOAD_SMALLSCALE), user, randomUUID)); + try { + assertTrue(this.getTestPlanEngine().submitTestPlan( + createATestPlanWithOneScript(getUserFirstScript(user), + EACH_SCRIPT_LOAD_SMALLSCALE), user, randomUUID)); + } catch (IllegalParameterException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } int planCountAfterSubmit = this.getTestPlanRepository() .loadEntities(user).size(); assertEquals(planCountBeforeSubmit + 1, planCountAfterSubmit); diff --git a/Bench4Q-Web/src/main/resources/ipConfig.properties b/Bench4Q-Web/src/main/resources/ipConfig.properties index 06535e4f..61377bd7 100644 --- a/Bench4Q-Web/src/main/resources/ipConfig.properties +++ b/Bench4Q-Web/src/main/resources/ipConfig.properties @@ -1 +1 @@ -masterAddress=133.133.2.100:8901 \ No newline at end of file +masterAddress=localhost:8901 \ No newline at end of file