little refactor

This commit is contained in:
coderfengyun 2014-02-26 09:02:17 +08:00
parent ef19610328
commit 6c050d779c
5 changed files with 26 additions and 18 deletions

View File

@ -14,7 +14,6 @@ import org.apache.log4j.Logger;
import org.bench4q.master.domain.interfaces.RunningScriptInterface;
import org.bench4q.master.domain.service.AgentService;
import org.bench4q.master.domain.service.ScriptService;
import org.bench4q.master.domain.service.TestPlanEngine;
import org.bench4q.master.domain.service.TestPlanScriptService;
import org.bench4q.master.domain.service.TestPlanService;
import org.bench4q.master.domain.testplan.RunningScriptSampler;
@ -43,7 +42,6 @@ public class RunningScript extends Observable implements RunningScriptInterface
private Timer timer;
private RunningScriptSampler sampler;
// private List<DataStatistics> dataStatisticsList;
private AgentMessenger runningAgentService;
private AgentService agentService;
private ScriptService scriptService;
@ -217,7 +215,7 @@ public class RunningScript extends Observable implements RunningScriptInterface
return result;
}
public boolean scheduleAsConfig(TestPlanEngine testPlanEngine) {
public boolean scheduleAsConfig() {
TestScriptConfig testScriptConfig = this.getConfig();
if (testScriptConfig == null) {
return false;
@ -247,7 +245,7 @@ public class RunningScript extends Observable implements RunningScriptInterface
public void doAfterDistributeLoad(List<RunningAgent> agentsAfterDistribute) {
this.getRunningAgents().addAll(agentsAfterDistribute);
this.setSampler(new RunningScriptSampler(this));
this.setSampler(new RunningScriptSampler(this.getRunningAgents()));
doPeriodicBrief();
}

View File

@ -100,7 +100,7 @@ public class TestPlanEngine implements TaskCompleteCallback,
private boolean schedulePlanConfig(TestPlanContext testPlanContext) {
for (RunningScript runningScript : testPlanContext.getAllScript()) {
runningScript.scheduleAsConfig(this);
runningScript.scheduleAsConfig();
}
return true;
}

View File

@ -1,6 +1,8 @@
package org.bench4q.master.domain.testplan;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import org.bench4q.master.domain.RunningScript;
@ -49,11 +51,24 @@ public class RunningScriptSampler {
this.agentMessenger = agentMessenger;
}
public RunningScriptSampler(RunningScriptInterface runningScript) {
private RunningScriptSampler() {
this.setDataStatisticsList(new ArrayList<DataStatistics>());
this.getDataStatisticsList().add(new ScriptBriefStatistics());
this.getDataStatisticsList().add(new BehaviorsBriefStatistics());
this.getDataStatisticsList().add(new PagesBriefStatistics());
this.setAgentMessenger(ApplicationContextHelper.getContext().getBean(
AgentMessenger.class));
this.setRunningAgents(new LinkedList<RunningAgentInterface>());
}
public RunningScriptSampler(
Collection<? extends RunningAgentInterface> runningAgents) {
this();
this.getRunningAgents().addAll(runningAgents);
}
public RunningScriptSampler(RunningScriptInterface runningScript) {
this();
List<RunningAgentInterface> runningAgentsFromParam = new ArrayList<RunningAgentInterface>();
if (runningScript instanceof RunningScript) {
for (RunningAgentInterface e : runningScript.getRunningAgents()) {
@ -65,10 +80,7 @@ public class RunningScriptSampler {
runningAgentsFromParam.add(e);
}
}
this.setRunningAgents(runningAgentsFromParam);
this.setAgentMessenger(ApplicationContextHelper.getContext().getBean(
AgentMessenger.class));
}
public ScriptBriefResultModel getScriptBrief() {

View File

@ -10,10 +10,13 @@ import org.bench4q.master.domain.RunningScript;
import org.bench4q.master.domain.entity.Agent;
import org.bench4q.master.domain.factory.BusinessModelMapFactory;
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.junit.runner.RunWith;
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 RunningScript runningScript;
@ -26,12 +29,6 @@ public class Test_RunningScript extends TestBase_MakeUpTestPlan {
this.runningScript = runningScript;
}
@SuppressWarnings("resource")
@BeforeClass
public static void beforeClass() {
new ClassPathXmlApplicationContext("classpath:service-test-context.xml");
}
public Test_RunningScript() {
this.setRunningScript(BusinessModelMapFactory
.toBusiness(buildScriptModel(USE_SCRIPT)));

View File

@ -42,7 +42,8 @@ public class Test_RunningScriptSampler extends TestBase_MakeUpTestPlan {
TestPlanScript testPlanScript = testPlanInRunning
.extracSpecifiedScript(this.getScriptService().getScript(
getScriptId()));
this.setRunningScriptSampler(new RunningScriptSampler(testPlanScript));
this.setRunningScriptSampler(new RunningScriptSampler(testPlanScript
.getRunningAgentsDB()));
}
@After