refactor runningScript with runningScriptSampler
This commit is contained in:
parent
b978922294
commit
ef19610328
|
@ -46,7 +46,7 @@ public class TestPlanController extends BaseController {
|
||||||
private ReportService reportService;
|
private ReportService reportService;
|
||||||
private TestPlanScriptResultService testPlanScriptResultService;
|
private TestPlanScriptResultService testPlanScriptResultService;
|
||||||
private BusinessModelMapFactory businessMapFactory;
|
private BusinessModelMapFactory businessMapFactory;
|
||||||
private Logger logger;
|
private Logger logger = Logger.getLogger(TestPlanController.class);
|
||||||
|
|
||||||
private TestPlanEngine getTestPlanRunner() {
|
private TestPlanEngine getTestPlanRunner() {
|
||||||
return testPlanRunner;
|
return testPlanRunner;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.bench4q.master.domain;
|
package org.bench4q.master.domain;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -16,22 +15,17 @@ import org.bench4q.master.domain.interfaces.RunningScriptInterface;
|
||||||
import org.bench4q.master.domain.service.AgentService;
|
import org.bench4q.master.domain.service.AgentService;
|
||||||
import org.bench4q.master.domain.service.ScriptService;
|
import org.bench4q.master.domain.service.ScriptService;
|
||||||
import org.bench4q.master.domain.service.TestPlanEngine;
|
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.service.TestPlanService;
|
||||||
|
import org.bench4q.master.domain.testplan.RunningScriptSampler;
|
||||||
import org.bench4q.master.helper.ApplicationContextHelper;
|
import org.bench4q.master.helper.ApplicationContextHelper;
|
||||||
import org.bench4q.master.infrastructure.communication.AgentMessenger;
|
import org.bench4q.master.infrastructure.communication.AgentMessenger;
|
||||||
import org.bench4q.master.testplan.datastatistics.BehaviorsBriefStatistics;
|
|
||||||
import org.bench4q.master.testplan.datastatistics.DataStatistics;
|
|
||||||
import org.bench4q.master.testplan.datastatistics.PagesBriefStatistics;
|
|
||||||
import org.bench4q.master.testplan.datastatistics.ScriptBriefStatistics;
|
|
||||||
import org.bench4q.master.testplan.datastatistics.ScriptStatistics;
|
|
||||||
import org.bench4q.master.testplan.highavailable.AgentRunBlotter;
|
import org.bench4q.master.testplan.highavailable.AgentRunBlotter;
|
||||||
import org.bench4q.master.testplan.highavailable.faultolerence.StopAgentFault;
|
import org.bench4q.master.testplan.highavailable.faultolerence.StopAgentFault;
|
||||||
import org.bench4q.master.testplan.schedulscript.ExecutionOverTask;
|
import org.bench4q.master.testplan.schedulscript.ExecutionOverTask;
|
||||||
import org.bench4q.master.testplan.schedulscript.WarmUpOverTask;
|
import org.bench4q.master.testplan.schedulscript.WarmUpOverTask;
|
||||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||||
import org.bench4q.share.models.agent.StopTestModel;
|
import org.bench4q.share.models.agent.StopTestModel;
|
||||||
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
|
|
||||||
import org.bench4q.share.models.agent.statistics.DataStatisticsModel;
|
|
||||||
import org.bench4q.share.models.master.TestScriptConfig;
|
import org.bench4q.share.models.master.TestScriptConfig;
|
||||||
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
|
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
|
||||||
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
||||||
|
@ -48,7 +42,8 @@ public class RunningScript extends Observable implements RunningScriptInterface
|
||||||
private Set<RunningAgent> runningAgents;
|
private Set<RunningAgent> runningAgents;
|
||||||
|
|
||||||
private Timer timer;
|
private Timer timer;
|
||||||
private List<DataStatistics> dataStatisticsList;
|
private RunningScriptSampler sampler;
|
||||||
|
// private List<DataStatistics> dataStatisticsList;
|
||||||
private AgentMessenger runningAgentService;
|
private AgentMessenger runningAgentService;
|
||||||
private AgentService agentService;
|
private AgentService agentService;
|
||||||
private ScriptService scriptService;
|
private ScriptService scriptService;
|
||||||
|
@ -111,12 +106,12 @@ public class RunningScript extends Observable implements RunningScriptInterface
|
||||||
this.testPlanID = testPlanID;
|
this.testPlanID = testPlanID;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<DataStatistics> getDataStatisticsList() {
|
private RunningScriptSampler getSampler() {
|
||||||
return dataStatisticsList;
|
return sampler;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDataStatisticsList(List<DataStatistics> dataStatisticsList) {
|
private void setSampler(RunningScriptSampler sampler) {
|
||||||
this.dataStatisticsList = dataStatisticsList;
|
this.sampler = sampler;
|
||||||
}
|
}
|
||||||
|
|
||||||
private AgentMessenger getRunningAgentService() {
|
private AgentMessenger getRunningAgentService() {
|
||||||
|
@ -166,10 +161,6 @@ public class RunningScript extends Observable implements RunningScriptInterface
|
||||||
this.setLatestScriptBriefModel(scriptBriefResultModel);
|
this.setLatestScriptBriefModel(scriptBriefResultModel);
|
||||||
|
|
||||||
this.setRunningAgents(new HashSet<RunningAgent>());
|
this.setRunningAgents(new HashSet<RunningAgent>());
|
||||||
this.setDataStatisticsList(new ArrayList<DataStatistics>());
|
|
||||||
this.getDataStatisticsList().add(new ScriptBriefStatistics());
|
|
||||||
this.getDataStatisticsList().add(new BehaviorsBriefStatistics());
|
|
||||||
this.getDataStatisticsList().add(new PagesBriefStatistics());
|
|
||||||
this.setTimer(new Timer());
|
this.setTimer(new Timer());
|
||||||
this.setRunningAgentService(ApplicationContextHelper.getContext()
|
this.setRunningAgentService(ApplicationContextHelper.getContext()
|
||||||
.getBean(AgentMessenger.class));
|
.getBean(AgentMessenger.class));
|
||||||
|
@ -177,6 +168,9 @@ public class RunningScript extends Observable implements RunningScriptInterface
|
||||||
AgentService.class));
|
AgentService.class));
|
||||||
this.setScriptService(ApplicationContextHelper.getContext().getBean(
|
this.setScriptService(ApplicationContextHelper.getContext().getBean(
|
||||||
ScriptService.class));
|
ScriptService.class));
|
||||||
|
this.addObserver(ApplicationContextHelper.getContext().getBean(
|
||||||
|
TestPlanScriptService.class));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public RunningScript(TestScriptConfig config, int requireLoad,
|
public RunningScript(TestScriptConfig config, int requireLoad,
|
||||||
|
@ -196,67 +190,17 @@ public class RunningScript extends Observable implements RunningScriptInterface
|
||||||
return Collections.unmodifiableCollection(this.runningAgents);
|
return Collections.unmodifiableCollection(this.runningAgents);
|
||||||
}
|
}
|
||||||
|
|
||||||
private DataStatistics getScriptBriefStatistics() {
|
|
||||||
return getSpecificDataStatistics(ScriptBriefStatistics.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
private DataStatistics getBehaviorsBriefStatistics() {
|
|
||||||
return getSpecificDataStatistics(BehaviorsBriefStatistics.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DataStatistics getPagesBriefStatistics() {
|
|
||||||
return getSpecificDataStatistics(PagesBriefStatistics.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
private DataStatistics getSpecificDataStatistics(
|
|
||||||
Class<? extends DataStatistics> dataStatisticsClass) {
|
|
||||||
for (DataStatistics dataStatistics : this.getDataStatisticsList()) {
|
|
||||||
if (dataStatistics.getClass().equals(dataStatisticsClass)) {
|
|
||||||
return dataStatistics;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new ScriptStatistics() {
|
|
||||||
public void add(DataStatisticsModel dataUnit) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getStatistics() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private ScriptBriefResultModel getScriptBrief() {
|
private ScriptBriefResultModel getScriptBrief() {
|
||||||
for (RunningAgent runningAgent : getRunningAgents()) {
|
ScriptBriefResultModel result = this.getSampler().getScriptBrief();
|
||||||
if (runningAgent.isBreakDown()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
AgentBriefStatusModel briefStatusModel = getRunningAgentService()
|
|
||||||
.brief(runningAgent.getAgent(),
|
|
||||||
runningAgent.getAgentRunId());
|
|
||||||
if (briefStatusModel == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
getScriptBriefStatistics().add(briefStatusModel);
|
|
||||||
}
|
|
||||||
ScriptBriefResultModel result = (ScriptBriefResultModel) getScriptBriefStatistics()
|
|
||||||
.getStatistics();
|
|
||||||
result.setFinished(isFinished());
|
result.setFinished(isFinished());
|
||||||
this.setLatestScriptBriefModel(result);
|
this.setLatestScriptBriefModel(result);
|
||||||
this.setChanged();
|
notifyObserver(result);
|
||||||
this.notifyObservers(result);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScriptBehaviorsBriefModel getBehaviorsBrief() {
|
private ScriptBehaviorsBriefModel getBehaviorsBrief() {
|
||||||
for (RunningAgent runningAgent : getRunningAgents()) {
|
ScriptBehaviorsBriefModel result = this.getSampler()
|
||||||
getBehaviorsBriefStatistics().add(
|
.getBehaviorsBrief();
|
||||||
this.getRunningAgentService().behaviorsBrief(
|
|
||||||
runningAgent.getAgent(),
|
|
||||||
runningAgent.getAgentRunId()));
|
|
||||||
}
|
|
||||||
|
|
||||||
ScriptBehaviorsBriefModel result = (ScriptBehaviorsBriefModel) getBehaviorsBriefStatistics()
|
|
||||||
.getStatistics();
|
|
||||||
result.setFinished(isFinished());
|
result.setFinished(isFinished());
|
||||||
notifyObserver(result);
|
notifyObserver(result);
|
||||||
return result;
|
return result;
|
||||||
|
@ -268,14 +212,7 @@ public class RunningScript extends Observable implements RunningScriptInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScriptPagesBriefModel getPagesBrief() {
|
private ScriptPagesBriefModel getPagesBrief() {
|
||||||
for (RunningAgent runningAgent : getRunningAgents()) {
|
ScriptPagesBriefModel result = this.getSampler().getPagesBrief();
|
||||||
this.getPagesBriefStatistics().add(
|
|
||||||
this.getRunningAgentService().pagesBrief(
|
|
||||||
runningAgent.getAgent(),
|
|
||||||
runningAgent.getAgentRunId()));
|
|
||||||
}
|
|
||||||
ScriptPagesBriefModel result = (ScriptPagesBriefModel) this
|
|
||||||
.getPagesBriefStatistics().getStatistics();
|
|
||||||
notifyObserver(result);
|
notifyObserver(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -310,6 +247,7 @@ public class RunningScript extends Observable implements RunningScriptInterface
|
||||||
|
|
||||||
public void doAfterDistributeLoad(List<RunningAgent> agentsAfterDistribute) {
|
public void doAfterDistributeLoad(List<RunningAgent> agentsAfterDistribute) {
|
||||||
this.getRunningAgents().addAll(agentsAfterDistribute);
|
this.getRunningAgents().addAll(agentsAfterDistribute);
|
||||||
|
this.setSampler(new RunningScriptSampler(this));
|
||||||
doPeriodicBrief();
|
doPeriodicBrief();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,6 @@ import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bench4q.master.domain.factory.BusinessModelMapFactory;
|
import org.bench4q.master.domain.factory.BusinessModelMapFactory;
|
||||||
import org.bench4q.master.domain.service.TestPlanScriptService;
|
|
||||||
import org.bench4q.master.helper.ApplicationContextHelper;
|
|
||||||
import org.bench4q.share.models.master.RunningScriptModel;
|
import org.bench4q.share.models.master.RunningScriptModel;
|
||||||
import org.bench4q.share.models.master.TestPlanBusinessModel;
|
import org.bench4q.share.models.master.TestPlanBusinessModel;
|
||||||
|
|
||||||
|
@ -61,18 +59,11 @@ public class TestPlanContext {
|
||||||
}
|
}
|
||||||
for (RunningScript runningScript : list) {
|
for (RunningScript runningScript : list) {
|
||||||
runningScript.setTestPlanID(testPlanID);
|
runningScript.setTestPlanID(testPlanID);
|
||||||
runningScript.addObserver(ApplicationContextHelper.getContext()
|
|
||||||
.getBean(TestPlanScriptService.class));
|
|
||||||
this.getRunningScriptMap().put(
|
this.getRunningScriptMap().put(
|
||||||
new Integer(runningScript.getScriptId()), runningScript);
|
new Integer(runningScript.getScriptId()), runningScript);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void addToScriptMap(RunningScript runningScript) {
|
|
||||||
// this.runningScriptMap.put(new Integer(runningScript.getScriptId()),
|
|
||||||
// runningScript);
|
|
||||||
// }
|
|
||||||
|
|
||||||
public RunningScript queryRunningScript(int scriptId) {
|
public RunningScript queryRunningScript(int scriptId) {
|
||||||
return this.getRunningScriptMap() == null ? null
|
return this.getRunningScriptMap() == null ? null
|
||||||
: this.runningScriptMap.get(new Integer(scriptId));
|
: this.runningScriptMap.get(new Integer(scriptId));
|
||||||
|
|
|
@ -110,11 +110,11 @@ public class AgentMessenger {
|
||||||
if (HttpRequester.isInvalidResponse(httpResponse)) {
|
if (HttpRequester.isInvalidResponse(httpResponse)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
logger.info(httpResponse.getContent());
|
||||||
return (AgentBehaviorsBriefModel) MarshalHelper.unmarshal(
|
return (AgentBehaviorsBriefModel) MarshalHelper.unmarshal(
|
||||||
AgentBehaviorsBriefModel.class, httpResponse.getContent());
|
AgentBehaviorsBriefModel.class, httpResponse.getContent());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error(ExceptionLog.getStackTrace(e)
|
logger.error(ExceptionLog.getStackTrace(e) + " When behaviorsBrief");
|
||||||
+ " When behaviorsBrief");
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ import org.bench4q.master.domain.RunningScript;
|
||||||
import org.bench4q.master.domain.entity.Agent;
|
import org.bench4q.master.domain.entity.Agent;
|
||||||
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.master.testplan.datastatistics.PagesBriefStatistics;
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
@ -56,17 +55,4 @@ public class Test_RunningScript extends TestBase_MakeUpTestPlan {
|
||||||
assertEquals(true, this.getRunningScript().isFinished());
|
assertEquals(true, this.getRunningScript().isFinished());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testForBriefByCycle() throws InterruptedException {
|
|
||||||
this.getRunningScript().doPeriodicBrief();
|
|
||||||
Thread.sleep(20000);
|
|
||||||
assertEquals(0, this.getRunningScript().getLatestScriptBriefModel()
|
|
||||||
.getAverageResponseTime());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testForGetPagesBriefStatistics() {
|
|
||||||
assertNotNull(this.getRunningScript().getPagesBriefStatistics());
|
|
||||||
assertTrue(this.getRunningScript().getPagesBriefStatistics() instanceof PagesBriefStatistics);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@ package org.bench4q.master.test.service;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bench4q.master.report.ReportService;
|
import org.bench4q.master.report.ReportService;
|
||||||
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
|
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -31,4 +33,9 @@ public class Test_ReportService extends TestBase_MakeUpTestPlan {
|
||||||
getTestPlanRunIdUuid()));
|
getTestPlanRunIdUuid()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateReport() {
|
||||||
|
this.getReportService().createReport(
|
||||||
|
UUID.fromString("4097990c-7163-4da2-b2e1-609c1d9b66a1"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue