refactor
This commit is contained in:
coderfengyun 2014-03-19 15:42:22 +08:00
parent 06f6f036ca
commit 9430e3e8aa
3 changed files with 23 additions and 20 deletions

View File

@ -42,7 +42,7 @@ public class AgentMessenger {
public RunScenarioResultModel runWithoutParams(Agent agent,
RunScenarioModel runScenarioModel) throws IOException {
HttpResponse httpResponse;
HttpResponse httpResponse = null;
try {
httpResponse = this.httpRequester.sendPostXml(buildBaseUrl(agent)
+ "/test/runWithoutParams", MarshalHelper.marshal(
@ -53,7 +53,7 @@ public class AgentMessenger {
return (RunScenarioResultModel) MarshalHelper.unmarshal(
RunScenarioResultModel.class, httpResponse.getContent());
} catch (JAXBException e) {
logger.error(ExceptionLog.getStackTrace(e));
logIt(httpResponse, e);
FaultTolerenceFactory.getRunAgentFault(agent, runScenarioModel)
.doTolerance();
return null;
@ -61,15 +61,20 @@ public class AgentMessenger {
}
private void logIt(HttpResponse httpResponse, Throwable e) {
logger.error(HttpRequester.isInvalidResponse(httpResponse) ? ""
: httpResponse.getContent(), e);
}
public RunScenarioResultModel submitScenrioWithParams(Agent agent,
List<File> paramFiles, final RunScenarioModel runScenarioModel) {
HttpResponse httpResponse = null;
try {
final String modelCOntent = MarshalHelper
.tryMarshal(runScenarioModel);
HttpResponse httpResponse = this.httpRequester.postFiles(
buildBaseUrl(agent) + "/test/submitScenarioWithParams",
"files[]", paramFiles, "scenarioModel",
new LinkedList<String>() {
httpResponse = this.httpRequester.postFiles(buildBaseUrl(agent)
+ "/test/submitScenarioWithParams", "files[]", paramFiles,
"scenarioModel", new LinkedList<String>() {
private static final long serialVersionUID = 1L;
{
add(modelCOntent);
@ -81,19 +86,20 @@ public class AgentMessenger {
return (RunScenarioResultModel) MarshalHelper.unmarshal(
RunScenarioResultModel.class, httpResponse.getContent());
} catch (Exception e) {
logger.error(e, e);
logIt(httpResponse, e);
return null;
}
}
public RunScenarioResultModel runWithParams(Agent agent, UUID agentRunId) {
HttpResponse httpResponse = null;
try {
if (agent == null || agentRunId == null) {
return null;
}
HttpResponse httpResponse = this.httpRequester.sendPost(
buildBaseUrl(agent) + "/test/runWithParams/"
+ agentRunId.toString(), null, null);
httpResponse = this.httpRequester.sendPost(buildBaseUrl(agent)
+ "/test/runWithParams/" + agentRunId.toString(), null,
null);
if (HttpRequester.isInvalidResponse(httpResponse)) {
logger.error("the response is not valid");
return null;
@ -101,13 +107,13 @@ public class AgentMessenger {
return (RunScenarioResultModel) MarshalHelper.unmarshal(
RunScenarioResultModel.class, httpResponse.getContent());
} catch (Exception e) {
logger.error("runWithParams", e);
logIt(httpResponse, e);
return null;
}
}
public AgentBriefStatusModel brief(Agent agent, UUID agentRunId) {
HttpResponse httpResponse;
HttpResponse httpResponse = null;
try {
if (agent == null || agentRunId == null) {
return null;
@ -121,6 +127,7 @@ public class AgentMessenger {
return (AgentBriefStatusModel) MarshalHelper.unmarshal(
AgentBriefStatusModel.class, httpResponse.getContent());
} catch (Exception e) {
logIt(httpResponse, e);
logger.error(e.toString() + " When brief the agent with hostName "
+ agent.getHostName());
FaultTolerenceFactory.getBriefFaultTolerance(agent).doTolerance();

View File

@ -5,7 +5,6 @@ import java.util.Date;
import org.bench4q.master.Main;
import org.bench4q.master.domain.entity.TestPlan;
import org.bench4q.master.domain.entity.User;
import org.bench4q.master.domain.service.TestPlanEngine;
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
import org.bench4q.share.enums.master.TestPlanStatus;
import org.bench4q.share.helper.TestHelper;
@ -123,9 +122,8 @@ public class Test_TestPlanEngine extends TestBase_MakeUpTestPlan {
getTestPlanRunIdUuid());
testPlan.run();
this.getTestPlanRepository().attachRunningTestPlan(testPlan);
TestHelper.invokePrivate(TestPlanEngine.class, this
.getTestPlanEngine(), "commit" + status.name(),
new Class[] { TestPlan.class },
TestHelper.invokePrivate(this.getTestPlanEngine(),
"commit" + status.name(), new Class[] { TestPlan.class },
new Object[] { this.getTestPlanRepository()
.getRunningTestPlanBy(getTestPlanRunIdUuid()) });
assertEquals(status,

View File

@ -7,7 +7,6 @@ import java.util.List;
import java.util.UUID;
import org.bench4q.master.domain.entity.User;
import org.bench4q.master.domain.service.TestPlanScriptResultService;
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
import org.bench4q.share.helper.TestHelper;
import org.bench4q.share.models.master.TestPlanModel;
@ -29,7 +28,6 @@ public class Test_TestPlanScriptResultService extends TestBase_MakeUpTestPlan {
@Test
public void testGetSpecficFieldValue() throws Exception {
long averageResponseTime = (Long) TestHelper.invokePrivate(
TestPlanScriptResultService.class,
this.getTestPlanScriptResultService(), "getSpecificFieldValue",
new Class[] { ScriptBriefResultModel.class, String.class },
new Object[] { buildScriptBriefResultModel(0),