little refa

This commit is contained in:
coderfengyun 2014-02-26 09:43:19 +08:00
parent a90688e976
commit a129411b95
10 changed files with 50 additions and 98 deletions

View File

@ -46,7 +46,6 @@ public class RunningScript extends Observable implements RunningScriptInterface
private AgentService agentService; private AgentService agentService;
private ScriptService scriptService; private ScriptService scriptService;
private static Logger logger = Logger.getLogger(RunningScript.class); private static Logger logger = Logger.getLogger(RunningScript.class);
private ScriptBriefResultModel latestScriptBriefModel;
public int getScriptId() { public int getScriptId() {
return scriptId; return scriptId;
@ -144,20 +143,7 @@ public class RunningScript extends Observable implements RunningScriptInterface
this.timer = timer; this.timer = timer;
} }
public ScriptBriefResultModel getLatestScriptBriefModel() {
return latestScriptBriefModel;
}
private void setLatestScriptBriefModel(
ScriptBriefResultModel latestScriptBriefModel) {
this.latestScriptBriefModel = latestScriptBriefModel;
}
private RunningScript() { private RunningScript() {
ScriptBriefResultModel scriptBriefResultModel = new ScriptBriefResultModel();
scriptBriefResultModel.setAverageResponseTime(-1);
this.setLatestScriptBriefModel(scriptBriefResultModel);
this.setRunningAgents(new HashSet<RunningAgent>()); this.setRunningAgents(new HashSet<RunningAgent>());
this.setTimer(new Timer()); this.setTimer(new Timer());
this.setRunningAgentService(ApplicationContextHelper.getContext() this.setRunningAgentService(ApplicationContextHelper.getContext()
@ -191,7 +177,6 @@ public class RunningScript extends Observable implements RunningScriptInterface
private ScriptBriefResultModel getScriptBrief() { private ScriptBriefResultModel getScriptBrief() {
ScriptBriefResultModel result = this.getSampler().getScriptBrief(); ScriptBriefResultModel result = this.getSampler().getScriptBrief();
result.setFinished(isFinished()); result.setFinished(isFinished());
this.setLatestScriptBriefModel(result);
notifyObserver(result); notifyObserver(result);
return result; return result;
} }

View File

@ -126,9 +126,9 @@ public class TestPlan implements IAggregate {
this.loadDistribute = loadDistribute; this.loadDistribute = loadDistribute;
} }
public TestPlanScript extracSpecifiedScript(Script script) { public TestPlanScript extracSpecifiedScript(int scriptId) {
for (TestPlanScript testPlanScript : testPlanScripts) { for (TestPlanScript testPlanScript : testPlanScripts) {
if (testPlanScript.getScript().getId() == script.getId()) { if (testPlanScript.getScript().getId() == scriptId) {
return testPlanScript; return testPlanScript;
} }
} }

View File

@ -29,7 +29,6 @@ import org.springframework.stereotype.Component;
public class TestPlanScriptResultService { public class TestPlanScriptResultService {
private TestPlanScriptService testPlanScriptService; private TestPlanScriptService testPlanScriptService;
private TestPlanRepository testPlanRepository; private TestPlanRepository testPlanRepository;
private ScriptService scriptService;
private SessionHelper sessionHelper; private SessionHelper sessionHelper;
private static Logger logger = Logger private static Logger logger = Logger
.getLogger(TestPlanScriptResultService.class); .getLogger(TestPlanScriptResultService.class);
@ -62,15 +61,6 @@ public class TestPlanScriptResultService {
this.testPlanRepository = testPlanRepository; this.testPlanRepository = testPlanRepository;
} }
private ScriptService getScriptService() {
return scriptService;
}
@Autowired
private void setScriptService(ScriptService scriptService) {
this.scriptService = scriptService;
}
/** /**
* Here I just use the Time that createDateTime in testplanscriptResult, If * Here I just use the Time that createDateTime in testplanscriptResult, If
* it's not accuracy, i just need to modify the way of pick createDateTime * it's not accuracy, i just need to modify the way of pick createDateTime
@ -145,13 +135,8 @@ public class TestPlanScriptResultService {
private List<TestPlanScriptResult> doGetTestPlanScriptResults( private List<TestPlanScriptResult> doGetTestPlanScriptResults(
UUID testPlanId, int scriptId, long startTime, Class<?> resultType, UUID testPlanId, int scriptId, long startTime, Class<?> resultType,
Session session) { Session session) {
// TestPlanScript testPlanScript = this.getTestPlanScriptService() TestPlanScript testPlanScript = this.getTestPlanRepository()
// .doGetTestPlanScript(scriptId, testPlanId, session); .getTestPlanBy(testPlanId).extracSpecifiedScript(scriptId);
TestPlanScript testPlanScript = this
.getTestPlanRepository()
.getTestPlanBy(testPlanId)
.extracSpecifiedScript(
this.getScriptService().getScript(scriptId));
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<TestPlanScriptResult> results = (List<TestPlanScriptResult>) session List<TestPlanScriptResult> results = (List<TestPlanScriptResult>) session
.createCriteria(TestPlanScriptResult.class) .createCriteria(TestPlanScriptResult.class)
@ -183,11 +168,8 @@ public class TestPlanScriptResultService {
private TestPlanScriptResult doGetLastSampleResult(UUID testPlanId, private TestPlanScriptResult doGetLastSampleResult(UUID testPlanId,
int scriptId, Class<?> resultType, Session session) { int scriptId, Class<?> resultType, Session session) {
TestPlanScript testPlanScript = this TestPlanScript testPlanScript = this.getTestPlanRepository()
.getTestPlanRepository() .getTestPlanBy(testPlanId).extracSpecifiedScript(scriptId);
.getTestPlanBy(testPlanId)
.extracSpecifiedScript(
this.getScriptService().getScript(scriptId));
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<TestPlanScriptResult> results = (List<TestPlanScriptResult>) session List<TestPlanScriptResult> results = (List<TestPlanScriptResult>) session
.createCriteria(TestPlanScriptResult.class) .createCriteria(TestPlanScriptResult.class)

View File

@ -34,7 +34,6 @@ import org.springframework.stereotype.Component;
public class TestPlanScriptService implements Observer { public class TestPlanScriptService implements Observer {
private static Logger logger = Logger.getLogger(TestPlanService.class); private static Logger logger = Logger.getLogger(TestPlanService.class);
private SessionHelper sessionHelper; private SessionHelper sessionHelper;
private ScriptService scriptService;
private TestPlanRepository testPlanRepository; private TestPlanRepository testPlanRepository;
private SessionHelper getSessionHelper() { private SessionHelper getSessionHelper() {
@ -46,15 +45,6 @@ public class TestPlanScriptService implements Observer {
this.sessionHelper = sessionHelper; this.sessionHelper = sessionHelper;
} }
private ScriptService getScriptService() {
return scriptService;
}
@Autowired
private void setScriptService(ScriptService scriptService) {
this.scriptService = scriptService;
}
private TestPlanRepository getTestPlanRepository() { private TestPlanRepository getTestPlanRepository() {
return testPlanRepository; return testPlanRepository;
} }
@ -67,8 +57,8 @@ public class TestPlanScriptService implements Observer {
public TestPlanScript getTestPlanScript(int scriptId, UUID testPlanRunId) { public TestPlanScript getTestPlanScript(int scriptId, UUID testPlanRunId) {
TestPlan testPlan = this.getTestPlanRepository().getTestPlanBy( TestPlan testPlan = this.getTestPlanRepository().getTestPlanBy(
testPlanRunId); testPlanRunId);
return testPlan == null ? null : testPlan.extracSpecifiedScript(this return testPlan == null ? null : testPlan
.getScriptService().getScript(scriptId)); .extracSpecifiedScript(scriptId);
} }
public boolean saveScriptBriefResult(final UUID testPlanRunId, public boolean saveScriptBriefResult(final UUID testPlanRunId,
@ -118,7 +108,7 @@ public class TestPlanScriptService implements Observer {
} }
TestPlanScript testPlanScript = testPlanDB TestPlanScript testPlanScript = testPlanDB
.extracSpecifiedScript(script); .extracSpecifiedScript(script.getId());
if (testPlanScript == null) { if (testPlanScript == null) {
return; return;
} }

View File

@ -203,8 +203,8 @@ public class TestBase_MakeUpTestPlan extends TestBase {
TestPlan testPlan = this.getTestPlanRepository().getTestPlanBy( TestPlan testPlan = this.getTestPlanRepository().getTestPlanBy(
getTestPlanRunIdUuid()); getTestPlanRunIdUuid());
RunningAgentDB runningAgent = testPlan.extracSpecifiedScript( RunningAgentDB runningAgent = testPlan.extracSpecifiedScript(
this.getScriptService().getScript(getScriptId())) getScriptId()).extractSpecificRunningAgentDB(
.extractSpecificRunningAgentDB(Test_AGENT_HOSTNAME); Test_AGENT_HOSTNAME);
this.getAgentMessenger().stop(runningAgent.getAgent(), this.getAgentMessenger().stop(runningAgent.getAgent(),
runningAgent.getAgentRunId()); runningAgent.getAgentRunId());
runningAgent.getAgent().setRemainLoad( runningAgent.getAgent().setRemainLoad(

View File

@ -7,49 +7,55 @@ import java.util.List;
import org.bench4q.master.domain.RunningAgent; import org.bench4q.master.domain.RunningAgent;
import org.bench4q.master.domain.RunningScript; import org.bench4q.master.domain.RunningScript;
import org.bench4q.master.domain.RunningTestPlanContainer;
import org.bench4q.master.domain.entity.Agent; import org.bench4q.master.domain.entity.Agent;
import org.bench4q.master.domain.entity.TestPlan;
import org.bench4q.master.domain.factory.BusinessModelMapFactory; import org.bench4q.master.domain.factory.BusinessModelMapFactory;
import org.bench4q.master.test.TestBase_MakeUpTestPlan; import org.bench4q.master.test.TestBase_MakeUpTestPlan;
import org.bench4q.share.helper.TestHelper;
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
import org.junit.After;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:service-test-context.xml" }) @ContextConfiguration(locations = { "classpath:service-test-context.xml" })
public class Test_RunningScript extends TestBase_MakeUpTestPlan { public class Test_RunningScript extends TestBase_MakeUpTestPlan {
private RunningTestPlanContainer runningTestPlanContainer;
private RunningScript runningScript; private RunningTestPlanContainer getRunningTestPlanContainer() {
return runningTestPlanContainer;
private RunningScript getRunningScript() {
return runningScript;
} }
private void setRunningScript(RunningScript runningScript) { @Autowired
this.runningScript = runningScript; private void setRunningTestPlanContainer(
RunningTestPlanContainer runningTestPlanContainer) {
this.runningTestPlanContainer = runningTestPlanContainer;
} }
public Test_RunningScript() { @Before
this.setRunningScript(BusinessModelMapFactory public void prepare() {
.toBusiness(buildScriptModel(USE_SCRIPT))); submitATestPlanWithOneScript();
List<RunningAgent> runningAgents = new ArrayList<RunningAgent>(); prepareForTestPlanRunning();
RunningAgent runningAgent = new RunningAgent(); }
runningAgent.setLoadInUse(40);
runningAgent.setScriptId(this.getScriptId()); @After
runningAgent.setAgent(new Agent()); public void cleanUp() {
runningAgents.add(runningAgent); cleanUpForTestPlanRunning();
this.getRunningScript().doAfterDistributeLoad(runningAgents);
} }
@Test @Test
public void testDoForComplete() { public void testGetScriptBrief() throws Exception {
assertEquals(false, this.getRunningScript().isFinished()); RunningScript runningScript = this.getRunningTestPlanContainer()
assertEquals(1, this.getRunningScript() .getRunningTestPlans().get(getTestPlanRunIdUuid())
.queryRunningAgentsUnModifiable().size()); .queryRunningScript(getScriptId());
this.getRunningScript().doForComplete(); runningScript.doPeriodicBrief();
assertEquals(0, this.getRunningScript() Thread.sleep(11000);
.queryRunningAgentsUnModifiable().size()); TestPlan testPlan = this.getTestPlanRepository().getTestPlanBy(
assertEquals(true, this.getRunningScript().isFinished()); getTestPlanRunIdUuid());
} }
} }

View File

@ -40,8 +40,7 @@ public class Test_RunningScriptSampler extends TestBase_MakeUpTestPlan {
this.getTestPlanRepository().updateEntity(testPlan); this.getTestPlanRepository().updateEntity(testPlan);
TestPlan testPlanInRunning = fetchTestPlan(); TestPlan testPlanInRunning = fetchTestPlan();
TestPlanScript testPlanScript = testPlanInRunning TestPlanScript testPlanScript = testPlanInRunning
.extracSpecifiedScript(this.getScriptService().getScript( .extracSpecifiedScript(getScriptId());
getScriptId()));
this.setRunningScriptSampler(new RunningScriptSampler(testPlanScript this.setRunningScriptSampler(new RunningScriptSampler(testPlanScript
.getRunningAgentsDB())); .getRunningAgentsDB()));
} }

View File

@ -59,8 +59,7 @@ public class Test_TestPlan extends TestBase_MakeUpTestPlan {
assertNotNull(testPlanScripts); assertNotNull(testPlanScripts);
assertEquals(1, testPlanScripts.size()); assertEquals(1, testPlanScripts.size());
TestPlanScript testPlanScript = testPlanAfterRun TestPlanScript testPlanScript = testPlanAfterRun
.extracSpecifiedScript(this.getScriptService().getScript( .extracSpecifiedScript(getScriptId());
getScriptId()));
assertNotNull(testPlanScript); assertNotNull(testPlanScript);
assertEquals(EACH_SCRIPT_LOAD_SMALLSCALE, assertEquals(EACH_SCRIPT_LOAD_SMALLSCALE,
testPlanScript.getRequireLoad()); testPlanScript.getRequireLoad());

View File

@ -60,12 +60,9 @@ public class Test_LoadDistribute extends TestBase_MakeUpTestPlan {
@After @After
public void cleanUp() { public void cleanUp() {
for (RunningAgentDB runningAgentDB : this for (RunningAgentDB runningAgentDB : this.getTestPlanRepository()
.getTestPlanRepository()
.getTestPlanBy(getTestPlanRunIdUuid()) .getTestPlanBy(getTestPlanRunIdUuid())
.extracSpecifiedScript( .extracSpecifiedScript(getScriptId()).getRunningAgentsDB()) {
this.getScriptService().getScript(getScriptId()))
.getRunningAgentsDB()) {
this.getAgentMessenger().stop(runningAgentDB.getAgent(), this.getAgentMessenger().stop(runningAgentDB.getAgent(),
runningAgentDB.getAgentRunId()); runningAgentDB.getAgentRunId());
} }
@ -86,9 +83,7 @@ public class Test_LoadDistribute extends TestBase_MakeUpTestPlan {
assertTrue(this.getLoadDistribute().generateLoadForTestPlan( assertTrue(this.getLoadDistribute().generateLoadForTestPlan(
testPlanInDomain)); testPlanInDomain));
Set<RunningAgentDB> runningAgents = testPlanInDomain Set<RunningAgentDB> runningAgents = testPlanInDomain
.extracSpecifiedScript( .extracSpecifiedScript(getScriptId()).getRunningAgentsDB();
this.getScriptService().getScript(getScriptId()))
.getRunningAgentsDB();
assertNotNull(runningAgents); assertNotNull(runningAgents);
assertTrue(runningAgents.size() > 0); assertTrue(runningAgents.size() > 0);
for (RunningAgentDB runningAgentDB : runningAgents) { for (RunningAgentDB runningAgentDB : runningAgents) {
@ -97,9 +92,7 @@ public class Test_LoadDistribute extends TestBase_MakeUpTestPlan {
testPlanInDomain = this.getTestPlanRepository().getTestPlanBy( testPlanInDomain = this.getTestPlanRepository().getTestPlanBy(
getTestPlanRunIdUuid()); getTestPlanRunIdUuid());
Set<RunningAgentDB> runningAgentsAfterRefetch = testPlanInDomain Set<RunningAgentDB> runningAgentsAfterRefetch = testPlanInDomain
.extracSpecifiedScript( .extracSpecifiedScript(getScriptId()).getRunningAgentsDB();
this.getScriptService().getScript(getScriptId()))
.getRunningAgentsDB();
assertTrue(runningAgentsAfterRefetch.size() == 0); assertTrue(runningAgentsAfterRefetch.size() == 0);
} }

View File

@ -84,11 +84,9 @@ public class Test_ScriptLoadCommand extends TestBase_MakeUpTestPlan {
@Test @Test
public void testExecuteWithTestPlanScript() { public void testExecuteWithTestPlanScript() {
submitATestPlanWithOneScript(); submitATestPlanWithOneScript();
TestPlanScript testPlanScript = this TestPlanScript testPlanScript = this.getTestPlanRepository()
.getTestPlanRepository()
.getTestPlanBy(getTestPlanRunIdUuid()) .getTestPlanBy(getTestPlanRunIdUuid())
.extracSpecifiedScript( .extracSpecifiedScript(this.getScriptId());
this.getScriptService().getScript(this.getScriptId()));
ScriptLoadCommand scriptLoadCommand = new ScriptLoadCommand( ScriptLoadCommand scriptLoadCommand = new ScriptLoadCommand(
testPlanScript, testPlanScript.getTestPlanID()); testPlanScript, testPlanScript.getTestPlanID());
List<RunningAgent> runningAgents = scriptLoadCommand.execute(); List<RunningAgent> runningAgents = scriptLoadCommand.execute();