add pagesBrief

This commit is contained in:
coderfengyun 2014-01-02 16:33:20 +08:00
parent e64e1cf1bf
commit fec54f5eea
5 changed files with 142 additions and 55 deletions

View File

@ -27,7 +27,9 @@ import org.bench4q.master.testplan.TestPlanEngine;
import org.bench4q.share.enums.master.TestPlanStatus;
import org.bench4q.share.models.master.MonitorModel;
import org.bench4q.share.models.master.RunningScriptModel;
import org.bench4q.share.models.master.TestPlanScriptBrieResultModel;
import org.bench4q.share.models.master.TestPlanBehaviorsBriefResultModel;
import org.bench4q.share.models.master.TestPlanPagesBriefResultModel;
import org.bench4q.share.models.master.TestPlanScriptBriefResultModel;
import org.bench4q.share.models.master.TestPlanBusinessModel;
import org.bench4q.share.models.master.TestPlanDBModel;
import org.bench4q.share.models.master.TestPlanResponseModel;
@ -207,7 +209,7 @@ public class TestPlanController extends BaseController {
@RequestMapping(value = "/scriptBrief/{testPlanId}/{scriptId}/{duationBegin}", method = RequestMethod.GET)
@ResponseStatus(value = HttpStatus.OK)
@ResponseBody
public TestPlanScriptBrieResultModel getScriptBrief(
public TestPlanScriptBriefResultModel getScriptBrief(
@PathVariable UUID testPlanId, @PathVariable int scriptId,
@PathVariable long duationBegin) throws Bench4QException,
NullPointerException {
@ -223,11 +225,56 @@ public class TestPlanController extends BaseController {
List<ScriptBriefResultModel> scriptBriefResultModels = this
.getTestPlanScriptResultService().loadScriptBriefWithDuation(
testPlanId, scriptId, duationBegin);
TestPlanScriptBrieResultModel ret = new TestPlanScriptBrieResultModel();
TestPlanScriptBriefResultModel ret = new TestPlanScriptBriefResultModel();
ret.setScriptBriefResultModels(scriptBriefResultModels);
return ret;
}
@RequestMapping(value = "/getBehaviorsBrief/{testPlanRunID}/{scriptId}/{duationBegin}")
@ResponseBody
public TestPlanBehaviorsBriefResultModel getBehaviorsBrief(
@PathVariable UUID testPlanRunID, @PathVariable int scriptId,
@PathVariable long duationBegin) throws Bench4QException,
NullPointerException {
guardForTestPlan(testPlanRunID);
List<ScriptBehaviorsBriefModel> behaviorsBriefModels = this
.getTestPlanScriptResultService().loadScriptBehaviorsBriefs(
testPlanRunID, scriptId, duationBegin);
TestPlanBehaviorsBriefResultModel result = new TestPlanBehaviorsBriefResultModel();
result.setScriptBehaviorsBriefModels(behaviorsBriefModels);
return result;
}
@RequestMapping(value = "/pageBrief/{testPlanRunId}/{scriptId}/{pageId}")
@ResponseBody
public ScriptPageBriefModel getPageBrief(@PathVariable UUID testPlanRunId,
@PathVariable int scriptId, @PathVariable int pageId)
throws Bench4QException, NullPointerException {
guardForTestPlan(testPlanRunId);
// TestPlanContext context = this.getTestPlanContainer()
// .queryTestPlanContext(testPlanRunId);
// RunningScript runningScript = context.queryRunningScript(scriptId);
// if (RunningScript.notValidScript(runningScript)) {
// throw new Bench4QException(EXCEPTION_HAPPEND + " RunningScript",
// "", "/pageBrief/{testPlanRunId}/{scriptId}/{pageId}");
// }
return null;
}
@RequestMapping(value = "pagesBrief/{testPlanRunId}/{scriptId}/{duationBegin}")
@ResponseBody
public TestPlanPagesBriefResultModel getPagesBrief(
@PathVariable UUID testPlanRunId, @PathVariable int scriptId,
@PathVariable long duationBegin) throws Bench4QException {
guardForTestPlan(testPlanRunId);
List<ScriptPageBriefModel> pageBriefModels = this
.getTestPlanScriptResultService().loadScriptPageBriefs(
testPlanRunId, scriptId, duationBegin);
TestPlanPagesBriefResultModel result = new TestPlanPagesBriefResultModel();
result.setPageBriefModels(pageBriefModels);
return result;
}
@RequestMapping(value = "/loadTestPlans", method = { RequestMethod.GET,
RequestMethod.POST })
@ResponseStatus(value = HttpStatus.OK)
@ -330,27 +377,6 @@ public class TestPlanController extends BaseController {
}
}
@RequestMapping(value = "/getBehaviorsBrief/{testPlanRunID}/{scriptId}")
@ResponseBody
public ScriptBehaviorsBriefModel getBehaviorsBrief(
@PathVariable UUID testPlanRunID, @PathVariable int scriptId)
throws Bench4QException, NullPointerException {
guardForTestPlan(testPlanRunID);
ScriptBehaviorsBriefModel ret = new ScriptBehaviorsBriefModel();
TestPlanContext context = this.getTestPlanContainer()
.queryTestPlanContext(testPlanRunID);
if (context.isFinish() || !context.isContains(scriptId)) {
ret.setFinished(true);
return ret;
}
RunningScript runningScript = context.queryRunningScript(scriptId);
if (runningScript == null || runningScript.isFinished()) {
ret.setFinished(true);
return ret;
}
return runningScript.getBehaviorsBrief();
}
private void guardForTestPlan(UUID testPlanRunID) throws Bench4QException {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
throw new Bench4QException(HAVE_NO_POWER, EXCEPTION_HAPPEND
@ -362,19 +388,4 @@ public class TestPlanController extends BaseController {
}
}
@RequestMapping(value = "/pageBrief/{testPlanRunId}/{scriptId}/{pageId}")
@ResponseBody
public ScriptPageBriefModel getPageBrief(@PathVariable UUID testPlanRunId,
@PathVariable int scriptId, @PathVariable int pageId)
throws Bench4QException, NullPointerException {
guardForTestPlan(testPlanRunId);
TestPlanContext context = this.getTestPlanContainer()
.queryTestPlanContext(testPlanRunId);
RunningScript runningScript = context.queryRunningScript(scriptId);
if (RunningScript.notValidScript(runningScript)) {
throw new Bench4QException(EXCEPTION_HAPPEND + " RunningScript",
"", "/pageBrief/{testPlanRunId}/{scriptId}/{pageId}");
}
return runningScript.getPageBrief(pageId);
}
}

View File

@ -18,6 +18,7 @@ import org.bench4q.share.models.agent.StopTestModel;
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
import org.bench4q.share.models.agent.statistics.AgentBehaviorsBriefModel;
import org.bench4q.share.models.agent.statistics.AgentPageBriefModel;
import org.bench4q.share.models.agent.statistics.AgentPagesBriefModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -136,4 +137,24 @@ public class RunningAgentService {
return null;
}
}
public AgentPagesBriefModel pagesBrief(Agent agent, UUID runId) {
try {
HttpResponse httpResponse = this.getHttpRequester().sendGet(
buildBaseUrl(agent) + "/test/pagesBrief/"
+ runId.toString(), null, null);
if (HttpRequester.isInvalidResponse(httpResponse)) {
return null;
}
return (AgentPagesBriefModel) MarshalHelper.unmarshal(
AgentPagesBriefModel.class, httpResponse.getContent());
} catch (IOException e) {
logger.error(ExceptionLog.getExceptionStackTrace(e));
return null;
} catch (JAXBException e) {
logger.error(ExceptionLog.getExceptionStackTrace(e));
return null;
}
}
}

View File

@ -14,7 +14,9 @@ import org.bench4q.master.exception.ExceptionLog;
import org.bench4q.master.helper.SessionHelper;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.master.ValueTimeModel;
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
import org.bench4q.share.models.master.statistics.ScriptPageBriefModel;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
@ -103,18 +105,9 @@ public class TestPlanScriptResultService {
Session session = this.getSessionHelper().openSession();
List<ScriptBriefResultModel> result = new ArrayList<ScriptBriefResultModel>();
try {
@SuppressWarnings("unchecked")
List<TestPlanScriptResult> scriptResults = (List<TestPlanScriptResult>) session
.createCriteria(TestPlanScriptResult.class)
.add(Restrictions.eq(
"testPlanScript",
this.getTestPlanScriptService()
.doGetTestPlanScript(scriptId, testPlanId,
session)))
.add(Restrictions.eq("resultType",
ScriptBriefResultModel.class.getName()))
.add(Restrictions.ge("createDatetime", new Date(startTime)))
.list();
List<TestPlanScriptResult> scriptResults = doGetTestPlanScriptResults(
testPlanId, scriptId, startTime,
ScriptBriefResultModel.class, session);
for (TestPlanScriptResult testPlanScriptResult : scriptResults) {
result.add((ScriptBriefResultModel) MarshalHelper.unmarshal(
ScriptBriefResultModel.class,
@ -125,4 +118,58 @@ public class TestPlanScriptResultService {
}
return result;
}
private List<TestPlanScriptResult> doGetTestPlanScriptResults(
UUID testPlanId, int scriptId, long startTime, Class<?> resultType,
Session session) {
@SuppressWarnings("unchecked")
List<TestPlanScriptResult> results = (List<TestPlanScriptResult>) session
.createCriteria(TestPlanScriptResult.class)
.add(Restrictions.eq(
"testPlanScript",
this.getTestPlanScriptService().doGetTestPlanScript(
scriptId, testPlanId, session)))
.add(Restrictions.eq("resultType", resultType.getName()))
.add(Restrictions.ge("createDatetime", new Date(startTime)))
.list();
return results;
}
public List<ScriptBehaviorsBriefModel> loadScriptBehaviorsBriefs(
UUID testPlanId, int scriptId, long startTime) {
Session session = this.getSessionHelper().openSession();
List<ScriptBehaviorsBriefModel> resultModels = new ArrayList<ScriptBehaviorsBriefModel>();
try {
List<TestPlanScriptResult> results = doGetTestPlanScriptResults(
testPlanId, scriptId, startTime,
ScriptBehaviorsBriefModel.class, session);
for (TestPlanScriptResult testPlanScriptResult : results) {
resultModels.add((ScriptBehaviorsBriefModel) MarshalHelper
.unmarshal(ScriptBehaviorsBriefModel.class,
testPlanScriptResult.getResultContent()));
}
} catch (Exception e) {
logger.error(ExceptionLog.getExceptionStackTrace(e));
}
return resultModels;
}
public List<ScriptPageBriefModel> loadScriptPageBriefs(UUID testPlanId,
int scriptId, long startTime) {
Session session = this.getSessionHelper().openSession();
List<ScriptPageBriefModel> result = new ArrayList<ScriptPageBriefModel>();
try {
List<TestPlanScriptResult> testPlanScriptResults = doGetTestPlanScriptResults(
testPlanId, scriptId, startTime,
ScriptPageBriefModel.class, session);
for (TestPlanScriptResult testPlanScriptResult : testPlanScriptResults) {
result.add((ScriptPageBriefModel) MarshalHelper.unmarshal(
ScriptPageBriefModel.class,
testPlanScriptResult.getResultContent()));
}
} catch (Exception e) {
logger.error(ExceptionLog.getExceptionStackTrace(e));
}
return result;
}
}

View File

@ -73,7 +73,15 @@ public class TestTestPlanScriptResultService extends TestBase_MakeUpTestPlan {
List<ScriptBriefResultModel> results = this
.getTestPlanScriptResultService().loadScriptBriefWithDuation(
this.getTestPlanRunIdUuid(), this.getScriptId(), 0);
List<ScriptPageBriefModel> resultsPageBriefModels = this
.getTestPlanScriptResultService().loadScriptPageBriefs(
this.getTestPlanRunIdUuid(), this.getScriptId(), 0);
List<ScriptBehaviorsBriefModel> behavirosResults = this
.getTestPlanScriptResultService().loadScriptBehaviorsBriefs(
this.getTestPlanRunIdUuid(), this.getScriptId(), 0);
assertEquals(3, results.size());
assertEquals(3, resultsPageBriefModels.size());
assertEquals(3, behavirosResults.size());
}
@Before

View File

@ -24,7 +24,7 @@ import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.master.RunningScriptModel;
import org.bench4q.share.models.master.TestPlanBusinessModel;
import org.bench4q.share.models.master.TestPlanResultModel;
import org.bench4q.share.models.master.TestPlanScriptBrieResultModel;
import org.bench4q.share.models.master.TestPlanScriptBriefResultModel;
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
import org.bench4q.share.models.master.statistics.ScriptPageBriefModel;
import org.junit.Test;
@ -207,14 +207,14 @@ public class TestPlanTester extends TestBase_MakeUpTestPlan {
return ret;
}
public TestPlanScriptBrieResultModel getScriptBrief(UUID testPlanId,
public TestPlanScriptBriefResultModel getScriptBrief(UUID testPlanId,
int scriptId) throws IOException, JAXBException {
HttpResponse httpResponse = this.httpRequester.sendGet(this._url
+ "/scriptBrief/" + testPlanId.toString() + "/" + scriptId
+ "/" + 0, null, createAccessTokenMap());
System.out.println(httpResponse.getContent());
TestPlanScriptBrieResultModel ret = (TestPlanScriptBrieResultModel) MarshalHelper
.unmarshal(TestPlanScriptBrieResultModel.class,
TestPlanScriptBriefResultModel ret = (TestPlanScriptBriefResultModel) MarshalHelper
.unmarshal(TestPlanScriptBriefResultModel.class,
httpResponse.getContent());
for (ScriptBriefResultModel scriptBriefResultModel : ret
.getScriptBriefResultModels()) {