add new Test

add new Test
This commit is contained in:
coderfengyun 2014-09-04 14:06:39 +08:00
parent c9bb8207a4
commit e67a80db8d
11 changed files with 44 additions and 16 deletions

View File

@ -179,8 +179,8 @@ public class ScenarioContext implements Observer {
}
public void stop() {
this.getSchedule().stop();
this.setFinished(true);
this.getExecutor().shutdownNow();
this.getSchedule().stop();
}
}

View File

@ -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:
}
}

View File

@ -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")
@ -180,12 +181,18 @@ public class RunningAgentDB implements RunningAgentInterface {
Script script2 = this.getTestPlanScript().getScript();
RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper
.tryUnmarshal(RunScenarioModel.class,
script2.getFilteredScriptCnt());
script2.getScriptContent());
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;
}

View File

@ -198,7 +198,6 @@ public class TestPlanScript implements RunningScriptInterface {
ExecutionOverTask executionOverTask = new ExecutionOverTask(this);
timer.schedule(executionOverTask, (testScriptConfig.getExecuteRange())
* SECOND_MILISECOND_UNIT_CONVERSION);
return true;
}
@ -301,4 +300,9 @@ public class TestPlanScript implements RunningScriptInterface {
public Date getStartTime() {
return this.getTestPlan().getCurrentStartTime();
}
@Transient
public String getScheduleContent() {
return this.getPlanedConfig().getScheduleContent();
}
}

View File

@ -219,6 +219,7 @@ public class TestPlanFactory {
private PlanedConfig createAPlanedConfigWithoutId(ScheduleModel schedule) {
PlanedConfig result = new PlanedConfig();
result.setExecuteRange(schedule.getExecuteRange());
result.setScheduleContent(MarshalHelper.tryMarshal(schedule));
return result;
}

View File

@ -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<File> paramFiles,
final RunScenarioModel runScenarioModel, Date realStartDate);
final RunScenarioModel runScenarioModel,
final ScheduleModel scheduleModel, Date realStartDate);
public RunScenarioResultModel runWithParams(Agent agent, UUID agentRunId);

View File

@ -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<File> 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<String, String> stringParts = new LinkedHashMap<String, String>();
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<RunScenarioResultModel> submitScenarioWithParamsAsync(
final Agent agent, final UUID agentRunId,
final List<File> paramFiles,
final RunScenarioModel runScenarioModel, final Date realStartDate) {
final RunScenarioModel runScenarioModel,
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, realStartDate);
paramFiles, runScenarioModel, scheduleModel,
realStartDate);
}
});
}

View File

@ -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(),

View File

@ -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);

View File

@ -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;
}

View File

@ -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<File> paramFiles,
RunScenarioModel runScenarioModel, Date realStartTime) {
RunScenarioModel runScenarioModel,
final ScheduleModel scheduleModel, Date realStartTime) {
return new RunScenarioResultModel(this.testId);
}