diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/engine/ScenarioContext.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/engine/ScenarioContext.java index d7156598..844e8849 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/engine/ScenarioContext.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/engine/ScenarioContext.java @@ -179,8 +179,8 @@ public class ScenarioContext implements Observer { } public void stop() { - this.getSchedule().stop(); this.setFinished(true); this.getExecutor().shutdownNow(); + this.getSchedule().stop(); } } diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/engine/Test_Shedule.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/engine/Test_Shedule.java index 91cb6da5..1401a2af 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/engine/Test_Shedule.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/engine/Test_Shedule.java @@ -94,4 +94,9 @@ public class Test_Shedule { Schedule schedule = Schedule.build(TestBase.buildScheduleModel()); assertEquals(60 * 1000, schedule.getScheduleRange()); } + + @Test + public void test_WithShortScheduleLessThenOneSecond() { + // TODO: + } } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/RunningAgentDB.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/RunningAgentDB.java index 1d082a2a..909a6a50 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/RunningAgentDB.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/RunningAgentDB.java @@ -21,6 +21,7 @@ import org.bench4q.share.models.agent.RunScenarioModel; import org.bench4q.share.models.agent.RunScenarioResultModel; import org.bench4q.share.models.agent.StopTestModel; import org.bench4q.share.models.agent.TestBriefStatusModel; +import org.bench4q.share.models.agent.scriptrecord.ScheduleModel; @Entity @Table(name = "runningAgent") @@ -179,13 +180,19 @@ public class RunningAgentDB implements RunningAgentInterface { public boolean distributeScriptAndParams() { Script script2 = this.getTestPlanScript().getScript(); RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper - .tryUnmarshal(RunScenarioModel.class, - this.getTestPlanScript().getFilteredScriptCnt()); + .tryUnmarshal(RunScenarioModel.class, this.getTestPlanScript() + .getFilteredScriptCnt()); runScenarioModel.setPoolSize(getLoadInUse()); RunScenarioResultModel runScenarioResultModel = this - .getAgentMessenger().submitScenrioWithParams(this.getAgent(), - this.getAgentRunId(), script2.loadParamFiles(), - runScenarioModel, this.getRunningScript().getStartTime()); + .getAgentMessenger().submitScenrioWithParams( + this.getAgent(), + this.getAgentRunId(), + script2.loadParamFiles(), + runScenarioModel, + (ScheduleModel) MarshalHelper.tryUnmarshal( + ScheduleModel.class, this.getTestPlanScript() + .getScheduleContent()), + this.getRunningScript().getStartTime()); if (runScenarioResultModel == null) { return false; } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlanScript.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlanScript.java index 7745a4b5..5b74b635 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlanScript.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlanScript.java @@ -199,7 +199,6 @@ public class TestPlanScript implements RunningScriptInterface { ExecutionOverTask executionOverTask = new ExecutionOverTask(this); timer.schedule(executionOverTask, (testScriptConfig.getExecuteRange()) * SECOND_MILISECOND_UNIT_CONVERSION); - return true; } @@ -303,6 +302,12 @@ public class TestPlanScript implements RunningScriptInterface { return this.getTestPlan().getCurrentStartTime(); } + @Transient + public String getScheduleContent() { + return this.getPlanedConfig().getScheduleContent(); + } + + @Transient public String getFilteredScriptCnt() { return filteredScriptCnt; } 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 24a09125..2a658cc5 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 @@ -223,6 +223,7 @@ public class TestPlanFactory { private PlanedConfig createAPlanedConfigWithoutId(ScheduleModel schedule) { PlanedConfig result = new PlanedConfig(); + result.setExecuteRange(schedule.getExecuteRange()); result.setScheduleContent(MarshalHelper.tryMarshal(schedule)); return result; } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/AgentMessenger.java b/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/AgentMessenger.java index 91587541..c8f8c99f 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/AgentMessenger.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/AgentMessenger.java @@ -12,13 +12,15 @@ import org.bench4q.share.models.agent.RunScenarioResultModel; import org.bench4q.share.models.agent.ServerStatusModel; import org.bench4q.share.models.agent.StopTestModel; import org.bench4q.share.models.agent.TestBriefStatusModel; +import org.bench4q.share.models.agent.scriptrecord.ScheduleModel; public interface AgentMessenger { public RunScenarioResultModel bookTest(Agent agent, int requireLoad); public RunScenarioResultModel submitScenrioWithParams(Agent agent, UUID agentRunId, List paramFiles, - final RunScenarioModel runScenarioModel, Date realStartDate); + final RunScenarioModel runScenarioModel, + final ScheduleModel scheduleModel, Date realStartDate); public RunScenarioResultModel runWithParams(Agent agent, UUID agentRunId); diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/impl/AgentMessengerImpl.java b/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/impl/AgentMessengerImpl.java index 9fbeb71b..14bf8eb8 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/impl/AgentMessengerImpl.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/impl/AgentMessengerImpl.java @@ -23,6 +23,7 @@ import org.bench4q.share.models.agent.RunScenarioResultModel; import org.bench4q.share.models.agent.ServerStatusModel; import org.bench4q.share.models.agent.StopTestModel; import org.bench4q.share.models.agent.TestBriefStatusModel; +import org.bench4q.share.models.agent.scriptrecord.ScheduleModel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -75,15 +76,16 @@ public class AgentMessengerImpl implements AgentMessenger { public RunScenarioResultModel submitScenrioWithParams(Agent agent, UUID agentRunId, List paramFiles, - final RunScenarioModel runScenarioModel, Date realStartDate) { + final RunScenarioModel runScenarioModel, + final ScheduleModel scheduleModel, Date realStartDate) { HttpResponse httpResponse = null; try { final String modelContent = MarshalHelper .tryMarshal(runScenarioModel); final Map stringParts = new LinkedHashMap(); stringParts.put("scenarioModel", modelContent); - stringParts.put("realStartTime", - String.valueOf(realStartDate.getTime())); + stringParts.put("scheduleContent", + MarshalHelper.tryMarshal(scheduleModel)); httpResponse = this.httpRequester.postFiles(null, buildBaseUrl(agent) + "/test/submitScenarioWithParams/" + agentRunId + "/" + realStartDate.getTime(), @@ -99,13 +101,15 @@ public class AgentMessengerImpl implements AgentMessenger { public Future submitScenarioWithParamsAsync( final Agent agent, final UUID agentRunId, final List paramFiles, - final RunScenarioModel runScenarioModel, final Date realStartDate) { + final RunScenarioModel runScenarioModel, + final ScheduleModel scheduleModel, final Date realStartDate) { return this.executorService .submit(new Callable() { @Override public RunScenarioResultModel call() throws Exception { return submitScenrioWithParams(agent, agentRunId, - paramFiles, runScenarioModel, realStartDate); + paramFiles, runScenarioModel, scheduleModel, + realStartDate); } }); } diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/integrated/Test_TestPlan.java b/Bench4Q-Master/src/test/java/org/bench4q/master/integrated/Test_TestPlan.java index 697957c8..8cb830f2 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/integrated/Test_TestPlan.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/integrated/Test_TestPlan.java @@ -58,6 +58,7 @@ public class Test_TestPlan extends TestBase_MakeUpTestPlan { .getTestPlanInDomainBy(getTestPlanRunIdUuid()); TestPlan testPlanInDomain = this.getTestPlanFactory().convertToDomain( testPlanFromRepo); + this.getTestPlanRepository().attachRunningTestPlan(testPlanInDomain); testPlanInDomain.run(); this.getTestPlanRepository().attachRunningTestPlan(testPlanInDomain); assertEquals(TestPlanStatus.InRunning.name(), diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/integrated/communication/Test_AgentMessenger.java b/Bench4Q-Master/src/test/java/org/bench4q/master/integrated/communication/Test_AgentMessenger.java index d93d6242..332cc8ee 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/integrated/communication/Test_AgentMessenger.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/integrated/communication/Test_AgentMessenger.java @@ -17,6 +17,7 @@ import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan; import org.bench4q.share.helper.MarshalHelper; import org.bench4q.share.models.agent.RunScenarioModel; import org.bench4q.share.models.agent.RunScenarioResultModel; +import org.bench4q.share.models.agent.scriptrecord.ScheduleModel; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -41,6 +42,7 @@ public class Test_AgentMessenger extends TestBase_MakeUpTestPlan { this.agentMessenger = agentMessenger; } + // TODO: modify this to adapt to new code @Test public void testSubmitScenarioWithParamsAndRun() throws IOException, JAXBException { @@ -74,7 +76,7 @@ public class Test_AgentMessenger extends TestBase_MakeUpTestPlan { System.out.println(model.getRunId()); RunScenarioResultModel modelAfter = this.getAgentMessenger() .submitScenrioWithParams(agent, model.getRunId(), paramFiles, - inputModel, new Date()); + inputModel, new ScheduleModel(), new Date()); assertEquals(model.getRunId(), modelAfter.getRunId()); model = this.getAgentMessenger().runWithParams(agent, model.getRunId()); assertNotNull(model); 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 201d261a..84a4b31c 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 @@ -399,8 +399,8 @@ public class TestBase_MakeUpTestPlan extends TestBase { model.setRequireLoad(EACH_SCRIPT_LOAD_SMALLSCALE); ScheduleModel schedule = new ScheduleModel(); schedule.getPoints().add(new PointModel(0, 0)); - schedule.getPoints().add(new PointModel(20, 10)); - schedule.getPoints().add(new PointModel(60, 10)); + schedule.getPoints().add(new PointModel(20 * 1000, 10)); + schedule.getPoints().add(new PointModel(60 * 1000, 10)); model.setScheduleModel(schedule); return model; } diff --git a/Bench4Q-Master/src/test/java/stubs/Mock_AgentMessenger.java b/Bench4Q-Master/src/test/java/stubs/Mock_AgentMessenger.java index 1803d132..5d458706 100644 --- a/Bench4Q-Master/src/test/java/stubs/Mock_AgentMessenger.java +++ b/Bench4Q-Master/src/test/java/stubs/Mock_AgentMessenger.java @@ -16,6 +16,7 @@ import org.bench4q.share.models.agent.RunScenarioResultModel; import org.bench4q.share.models.agent.ServerStatusModel; import org.bench4q.share.models.agent.StopTestModel; import org.bench4q.share.models.agent.TestBriefStatusModel; +import org.bench4q.share.models.agent.scriptrecord.ScheduleModel; import org.bench4q.share.models.agent.statistics.AgentBehaviorsBriefModel; import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel; import org.bench4q.share.models.agent.statistics.AgentPagesBriefModel; @@ -35,7 +36,8 @@ public class Mock_AgentMessenger implements AgentMessenger { @Override public RunScenarioResultModel submitScenrioWithParams(Agent agent, UUID agentRunId, List paramFiles, - RunScenarioModel runScenarioModel, Date realStartTime) { + RunScenarioModel runScenarioModel, + final ScheduleModel scheduleModel, Date realStartTime) { return new RunScenarioResultModel(this.testId); }