little refa
This commit is contained in:
parent
a90688e976
commit
a129411b95
|
@ -46,7 +46,6 @@ public class RunningScript extends Observable implements RunningScriptInterface
|
|||
private AgentService agentService;
|
||||
private ScriptService scriptService;
|
||||
private static Logger logger = Logger.getLogger(RunningScript.class);
|
||||
private ScriptBriefResultModel latestScriptBriefModel;
|
||||
|
||||
public int getScriptId() {
|
||||
return scriptId;
|
||||
|
@ -144,20 +143,7 @@ public class RunningScript extends Observable implements RunningScriptInterface
|
|||
this.timer = timer;
|
||||
}
|
||||
|
||||
public ScriptBriefResultModel getLatestScriptBriefModel() {
|
||||
return latestScriptBriefModel;
|
||||
}
|
||||
|
||||
private void setLatestScriptBriefModel(
|
||||
ScriptBriefResultModel latestScriptBriefModel) {
|
||||
this.latestScriptBriefModel = latestScriptBriefModel;
|
||||
}
|
||||
|
||||
private RunningScript() {
|
||||
ScriptBriefResultModel scriptBriefResultModel = new ScriptBriefResultModel();
|
||||
scriptBriefResultModel.setAverageResponseTime(-1);
|
||||
this.setLatestScriptBriefModel(scriptBriefResultModel);
|
||||
|
||||
this.setRunningAgents(new HashSet<RunningAgent>());
|
||||
this.setTimer(new Timer());
|
||||
this.setRunningAgentService(ApplicationContextHelper.getContext()
|
||||
|
@ -191,7 +177,6 @@ public class RunningScript extends Observable implements RunningScriptInterface
|
|||
private ScriptBriefResultModel getScriptBrief() {
|
||||
ScriptBriefResultModel result = this.getSampler().getScriptBrief();
|
||||
result.setFinished(isFinished());
|
||||
this.setLatestScriptBriefModel(result);
|
||||
notifyObserver(result);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -126,9 +126,9 @@ public class TestPlan implements IAggregate {
|
|||
this.loadDistribute = loadDistribute;
|
||||
}
|
||||
|
||||
public TestPlanScript extracSpecifiedScript(Script script) {
|
||||
public TestPlanScript extracSpecifiedScript(int scriptId) {
|
||||
for (TestPlanScript testPlanScript : testPlanScripts) {
|
||||
if (testPlanScript.getScript().getId() == script.getId()) {
|
||||
if (testPlanScript.getScript().getId() == scriptId) {
|
||||
return testPlanScript;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.springframework.stereotype.Component;
|
|||
public class TestPlanScriptResultService {
|
||||
private TestPlanScriptService testPlanScriptService;
|
||||
private TestPlanRepository testPlanRepository;
|
||||
private ScriptService scriptService;
|
||||
private SessionHelper sessionHelper;
|
||||
private static Logger logger = Logger
|
||||
.getLogger(TestPlanScriptResultService.class);
|
||||
|
@ -62,15 +61,6 @@ public class TestPlanScriptResultService {
|
|||
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
|
||||
* 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(
|
||||
UUID testPlanId, int scriptId, long startTime, Class<?> resultType,
|
||||
Session session) {
|
||||
// TestPlanScript testPlanScript = this.getTestPlanScriptService()
|
||||
// .doGetTestPlanScript(scriptId, testPlanId, session);
|
||||
TestPlanScript testPlanScript = this
|
||||
.getTestPlanRepository()
|
||||
.getTestPlanBy(testPlanId)
|
||||
.extracSpecifiedScript(
|
||||
this.getScriptService().getScript(scriptId));
|
||||
TestPlanScript testPlanScript = this.getTestPlanRepository()
|
||||
.getTestPlanBy(testPlanId).extracSpecifiedScript(scriptId);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<TestPlanScriptResult> results = (List<TestPlanScriptResult>) session
|
||||
.createCriteria(TestPlanScriptResult.class)
|
||||
|
@ -183,11 +168,8 @@ public class TestPlanScriptResultService {
|
|||
|
||||
private TestPlanScriptResult doGetLastSampleResult(UUID testPlanId,
|
||||
int scriptId, Class<?> resultType, Session session) {
|
||||
TestPlanScript testPlanScript = this
|
||||
.getTestPlanRepository()
|
||||
.getTestPlanBy(testPlanId)
|
||||
.extracSpecifiedScript(
|
||||
this.getScriptService().getScript(scriptId));
|
||||
TestPlanScript testPlanScript = this.getTestPlanRepository()
|
||||
.getTestPlanBy(testPlanId).extracSpecifiedScript(scriptId);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<TestPlanScriptResult> results = (List<TestPlanScriptResult>) session
|
||||
.createCriteria(TestPlanScriptResult.class)
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.springframework.stereotype.Component;
|
|||
public class TestPlanScriptService implements Observer {
|
||||
private static Logger logger = Logger.getLogger(TestPlanService.class);
|
||||
private SessionHelper sessionHelper;
|
||||
private ScriptService scriptService;
|
||||
private TestPlanRepository testPlanRepository;
|
||||
|
||||
private SessionHelper getSessionHelper() {
|
||||
|
@ -46,15 +45,6 @@ public class TestPlanScriptService implements Observer {
|
|||
this.sessionHelper = sessionHelper;
|
||||
}
|
||||
|
||||
private ScriptService getScriptService() {
|
||||
return scriptService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setScriptService(ScriptService scriptService) {
|
||||
this.scriptService = scriptService;
|
||||
}
|
||||
|
||||
private TestPlanRepository getTestPlanRepository() {
|
||||
return testPlanRepository;
|
||||
}
|
||||
|
@ -67,8 +57,8 @@ public class TestPlanScriptService implements Observer {
|
|||
public TestPlanScript getTestPlanScript(int scriptId, UUID testPlanRunId) {
|
||||
TestPlan testPlan = this.getTestPlanRepository().getTestPlanBy(
|
||||
testPlanRunId);
|
||||
return testPlan == null ? null : testPlan.extracSpecifiedScript(this
|
||||
.getScriptService().getScript(scriptId));
|
||||
return testPlan == null ? null : testPlan
|
||||
.extracSpecifiedScript(scriptId);
|
||||
}
|
||||
|
||||
public boolean saveScriptBriefResult(final UUID testPlanRunId,
|
||||
|
@ -118,7 +108,7 @@ public class TestPlanScriptService implements Observer {
|
|||
}
|
||||
|
||||
TestPlanScript testPlanScript = testPlanDB
|
||||
.extracSpecifiedScript(script);
|
||||
.extracSpecifiedScript(script.getId());
|
||||
if (testPlanScript == null) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -203,8 +203,8 @@ public class TestBase_MakeUpTestPlan extends TestBase {
|
|||
TestPlan testPlan = this.getTestPlanRepository().getTestPlanBy(
|
||||
getTestPlanRunIdUuid());
|
||||
RunningAgentDB runningAgent = testPlan.extracSpecifiedScript(
|
||||
this.getScriptService().getScript(getScriptId()))
|
||||
.extractSpecificRunningAgentDB(Test_AGENT_HOSTNAME);
|
||||
getScriptId()).extractSpecificRunningAgentDB(
|
||||
Test_AGENT_HOSTNAME);
|
||||
this.getAgentMessenger().stop(runningAgent.getAgent(),
|
||||
runningAgent.getAgentRunId());
|
||||
runningAgent.getAgent().setRemainLoad(
|
||||
|
|
|
@ -7,49 +7,55 @@ import java.util.List;
|
|||
|
||||
import org.bench4q.master.domain.RunningAgent;
|
||||
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.TestPlan;
|
||||
import org.bench4q.master.domain.factory.BusinessModelMapFactory;
|
||||
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.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "classpath:service-test-context.xml" })
|
||||
public class Test_RunningScript extends TestBase_MakeUpTestPlan {
|
||||
private RunningTestPlanContainer runningTestPlanContainer;
|
||||
|
||||
private RunningScript runningScript;
|
||||
|
||||
private RunningScript getRunningScript() {
|
||||
return runningScript;
|
||||
private RunningTestPlanContainer getRunningTestPlanContainer() {
|
||||
return runningTestPlanContainer;
|
||||
}
|
||||
|
||||
private void setRunningScript(RunningScript runningScript) {
|
||||
this.runningScript = runningScript;
|
||||
@Autowired
|
||||
private void setRunningTestPlanContainer(
|
||||
RunningTestPlanContainer runningTestPlanContainer) {
|
||||
this.runningTestPlanContainer = runningTestPlanContainer;
|
||||
}
|
||||
|
||||
public Test_RunningScript() {
|
||||
this.setRunningScript(BusinessModelMapFactory
|
||||
.toBusiness(buildScriptModel(USE_SCRIPT)));
|
||||
List<RunningAgent> runningAgents = new ArrayList<RunningAgent>();
|
||||
RunningAgent runningAgent = new RunningAgent();
|
||||
runningAgent.setLoadInUse(40);
|
||||
runningAgent.setScriptId(this.getScriptId());
|
||||
runningAgent.setAgent(new Agent());
|
||||
runningAgents.add(runningAgent);
|
||||
this.getRunningScript().doAfterDistributeLoad(runningAgents);
|
||||
@Before
|
||||
public void prepare() {
|
||||
submitATestPlanWithOneScript();
|
||||
prepareForTestPlanRunning();
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanUp() {
|
||||
cleanUpForTestPlanRunning();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoForComplete() {
|
||||
assertEquals(false, this.getRunningScript().isFinished());
|
||||
assertEquals(1, this.getRunningScript()
|
||||
.queryRunningAgentsUnModifiable().size());
|
||||
this.getRunningScript().doForComplete();
|
||||
assertEquals(0, this.getRunningScript()
|
||||
.queryRunningAgentsUnModifiable().size());
|
||||
assertEquals(true, this.getRunningScript().isFinished());
|
||||
public void testGetScriptBrief() throws Exception {
|
||||
RunningScript runningScript = this.getRunningTestPlanContainer()
|
||||
.getRunningTestPlans().get(getTestPlanRunIdUuid())
|
||||
.queryRunningScript(getScriptId());
|
||||
runningScript.doPeriodicBrief();
|
||||
Thread.sleep(11000);
|
||||
TestPlan testPlan = this.getTestPlanRepository().getTestPlanBy(
|
||||
getTestPlanRunIdUuid());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -40,8 +40,7 @@ public class Test_RunningScriptSampler extends TestBase_MakeUpTestPlan {
|
|||
this.getTestPlanRepository().updateEntity(testPlan);
|
||||
TestPlan testPlanInRunning = fetchTestPlan();
|
||||
TestPlanScript testPlanScript = testPlanInRunning
|
||||
.extracSpecifiedScript(this.getScriptService().getScript(
|
||||
getScriptId()));
|
||||
.extracSpecifiedScript(getScriptId());
|
||||
this.setRunningScriptSampler(new RunningScriptSampler(testPlanScript
|
||||
.getRunningAgentsDB()));
|
||||
}
|
||||
|
|
|
@ -59,8 +59,7 @@ public class Test_TestPlan extends TestBase_MakeUpTestPlan {
|
|||
assertNotNull(testPlanScripts);
|
||||
assertEquals(1, testPlanScripts.size());
|
||||
TestPlanScript testPlanScript = testPlanAfterRun
|
||||
.extracSpecifiedScript(this.getScriptService().getScript(
|
||||
getScriptId()));
|
||||
.extracSpecifiedScript(getScriptId());
|
||||
assertNotNull(testPlanScript);
|
||||
assertEquals(EACH_SCRIPT_LOAD_SMALLSCALE,
|
||||
testPlanScript.getRequireLoad());
|
||||
|
|
|
@ -60,12 +60,9 @@ public class Test_LoadDistribute extends TestBase_MakeUpTestPlan {
|
|||
|
||||
@After
|
||||
public void cleanUp() {
|
||||
for (RunningAgentDB runningAgentDB : this
|
||||
.getTestPlanRepository()
|
||||
for (RunningAgentDB runningAgentDB : this.getTestPlanRepository()
|
||||
.getTestPlanBy(getTestPlanRunIdUuid())
|
||||
.extracSpecifiedScript(
|
||||
this.getScriptService().getScript(getScriptId()))
|
||||
.getRunningAgentsDB()) {
|
||||
.extracSpecifiedScript(getScriptId()).getRunningAgentsDB()) {
|
||||
this.getAgentMessenger().stop(runningAgentDB.getAgent(),
|
||||
runningAgentDB.getAgentRunId());
|
||||
}
|
||||
|
@ -86,9 +83,7 @@ public class Test_LoadDistribute extends TestBase_MakeUpTestPlan {
|
|||
assertTrue(this.getLoadDistribute().generateLoadForTestPlan(
|
||||
testPlanInDomain));
|
||||
Set<RunningAgentDB> runningAgents = testPlanInDomain
|
||||
.extracSpecifiedScript(
|
||||
this.getScriptService().getScript(getScriptId()))
|
||||
.getRunningAgentsDB();
|
||||
.extracSpecifiedScript(getScriptId()).getRunningAgentsDB();
|
||||
assertNotNull(runningAgents);
|
||||
assertTrue(runningAgents.size() > 0);
|
||||
for (RunningAgentDB runningAgentDB : runningAgents) {
|
||||
|
@ -97,9 +92,7 @@ public class Test_LoadDistribute extends TestBase_MakeUpTestPlan {
|
|||
testPlanInDomain = this.getTestPlanRepository().getTestPlanBy(
|
||||
getTestPlanRunIdUuid());
|
||||
Set<RunningAgentDB> runningAgentsAfterRefetch = testPlanInDomain
|
||||
.extracSpecifiedScript(
|
||||
this.getScriptService().getScript(getScriptId()))
|
||||
.getRunningAgentsDB();
|
||||
.extracSpecifiedScript(getScriptId()).getRunningAgentsDB();
|
||||
assertTrue(runningAgentsAfterRefetch.size() == 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -84,11 +84,9 @@ public class Test_ScriptLoadCommand extends TestBase_MakeUpTestPlan {
|
|||
@Test
|
||||
public void testExecuteWithTestPlanScript() {
|
||||
submitATestPlanWithOneScript();
|
||||
TestPlanScript testPlanScript = this
|
||||
.getTestPlanRepository()
|
||||
TestPlanScript testPlanScript = this.getTestPlanRepository()
|
||||
.getTestPlanBy(getTestPlanRunIdUuid())
|
||||
.extracSpecifiedScript(
|
||||
this.getScriptService().getScript(this.getScriptId()));
|
||||
.extracSpecifiedScript(this.getScriptId());
|
||||
ScriptLoadCommand scriptLoadCommand = new ScriptLoadCommand(
|
||||
testPlanScript, testPlanScript.getTestPlanID());
|
||||
List<RunningAgent> runningAgents = scriptLoadCommand.execute();
|
||||
|
|
Loading…
Reference in New Issue