change the save result
This commit is contained in:
parent
dac113a4f5
commit
93e7ea5ccc
|
@ -1,7 +1,9 @@
|
|||
package org.bench4q.master.domain.entity;
|
||||
|
||||
import java.util.Observable;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
|
@ -16,20 +18,27 @@ import javax.persistence.Table;
|
|||
import javax.persistence.Transient;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.domain.factory.TestPlanFactory;
|
||||
import org.bench4q.master.domain.testplan.TestMonitorSampler;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.master.helper.ApplicationContextHelper;
|
||||
import org.bench4q.share.models.monitor.MonitorMain;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@Entity
|
||||
@Table(name = "monitor")
|
||||
public class Monitor extends Observable {
|
||||
public class Monitor {
|
||||
private int id;
|
||||
private String hostName;
|
||||
private int port;
|
||||
private TestPlan testPlan;
|
||||
private Set<MonitorResult> results;
|
||||
private Logger logger = Logger.getLogger(Monitor.class);
|
||||
private TestPlanFactory testPlanFactory;
|
||||
|
||||
public Monitor() {
|
||||
this.results = new HashSet<MonitorResult>();
|
||||
}
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
|
@ -85,28 +94,37 @@ public class Monitor extends Observable {
|
|||
TestMonitorSampler.class);
|
||||
}
|
||||
|
||||
@Transient
|
||||
public TestPlanFactory getTestPlanFactory() {
|
||||
return testPlanFactory;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTestPlanFactory(TestPlanFactory testPlanFactory) {
|
||||
this.testPlanFactory = testPlanFactory;
|
||||
}
|
||||
|
||||
public void doRunInit() {
|
||||
|
||||
}
|
||||
|
||||
public void doAfterRun() {
|
||||
System.out.println("enter do run after");
|
||||
try {
|
||||
MonitorMain monitorResult = getTestMonitorSampler()
|
||||
.getMonitorResult(hostName, port);
|
||||
collectResult(monitorResult);
|
||||
MonitorMain monitorMain = getTestMonitorSampler().getMonitorResult(
|
||||
hostName, port);
|
||||
List<MonitorResult> monitorResults = this.getTestPlanFactory()
|
||||
.createMonitorResultListWithOutId(monitorMain, testPlan,
|
||||
this, monitorMain.getSamplingTime());
|
||||
System.out.println(monitorResults.size());
|
||||
this.getResults().addAll(monitorResults);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error(ExceptionLog.getStackTrace(e));
|
||||
}
|
||||
}
|
||||
|
||||
private void collectResult(MonitorMain monitorMain) {
|
||||
try {
|
||||
this.setChanged();
|
||||
this.notifyObservers(monitorMain);
|
||||
} catch (Exception e) {
|
||||
logger.error(ExceptionLog.getStackTrace(e));
|
||||
}
|
||||
|
||||
public void clearResult() {
|
||||
this.getResults().clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.bench4q.master.domain.entity;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Observable;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
@ -26,7 +27,7 @@ import org.bench4q.share.enums.master.TestPlanStatus;
|
|||
|
||||
@Entity
|
||||
@Table(name = "testplan")
|
||||
public class TestPlan implements IAggregate {
|
||||
public class TestPlan extends Observable implements IAggregate {
|
||||
private int id;
|
||||
private String name;
|
||||
private int sampleCycleInSeconds;
|
||||
|
@ -184,7 +185,6 @@ public class TestPlan implements IAggregate {
|
|||
return this.getLoadDistribute().generateLoadForTestPlan(this);
|
||||
}
|
||||
|
||||
// need to end this thread when testPlan is finish
|
||||
public void doAfterRun() {
|
||||
try {
|
||||
final ScheduledExecutorService scheScheduledExecutorService = Executors
|
||||
|
@ -194,16 +194,9 @@ public class TestPlan implements IAggregate {
|
|||
if (isFinish()) {
|
||||
scheScheduledExecutorService.shutdown();
|
||||
}
|
||||
|
||||
for (TestPlanScript testPlanScript : getTestPlanScripts()) {
|
||||
testPlanScript.doAfterRun();
|
||||
}
|
||||
if (getMonitors() != null) {
|
||||
for (Monitor monitor : getMonitors()) {
|
||||
monitor.doAfterRun();
|
||||
}
|
||||
}
|
||||
|
||||
collectResult();
|
||||
flushResultToRepo();
|
||||
clearResult();
|
||||
}
|
||||
}, 0, this.getSampleCycleInSeconds(), TimeUnit.SECONDS);
|
||||
} catch (Exception e) {
|
||||
|
@ -213,6 +206,36 @@ public class TestPlan implements IAggregate {
|
|||
|
||||
}
|
||||
|
||||
public void flushResultToRepo() {
|
||||
this.setChanged();
|
||||
this.notifyObservers(this);
|
||||
}
|
||||
|
||||
public void collectResult() {
|
||||
|
||||
for (TestPlanScript testPlanScript : getTestPlanScripts()) {
|
||||
testPlanScript.doAfterRun();
|
||||
}
|
||||
if (getMonitors() != null) {
|
||||
for (Monitor monitor : getMonitors()) {
|
||||
monitor.doAfterRun();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void clearResult() {
|
||||
for (TestPlanScript testPlanScript : getTestPlanScripts()) {
|
||||
testPlanScript.clearResult();
|
||||
}
|
||||
if (getMonitors() != null) {
|
||||
for (Monitor monitor : getMonitors()) {
|
||||
monitor.clearResult();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Transient
|
||||
public boolean isFinish() {
|
||||
for (TestPlanScript testPlanScript : this.getTestPlanScripts()) {
|
||||
|
|
|
@ -2,12 +2,10 @@ package org.bench4q.master.domain.entity;
|
|||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Observable;
|
||||
import java.util.Set;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
|
@ -21,7 +19,6 @@ import javax.persistence.OneToMany;
|
|||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.domain.RunningAgentInterface;
|
||||
import org.bench4q.master.domain.RunningScriptInterface;
|
||||
|
@ -38,13 +35,11 @@ import org.bench4q.master.testplan.schedulscript.WarmUpOverTask;
|
|||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
import org.bench4q.share.models.agent.StopTestModel;
|
||||
import org.bench4q.share.models.master.statistics.SampleModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptResultModel;
|
||||
|
||||
@Entity
|
||||
@Table(name = "TestPlanScript")
|
||||
public class TestPlanScript extends Observable implements
|
||||
RunningScriptInterface {
|
||||
public class TestPlanScript implements RunningScriptInterface {
|
||||
private int id;
|
||||
private Script script;
|
||||
private int requireLoad;
|
||||
|
@ -241,27 +236,18 @@ public class TestPlanScript extends Observable implements
|
|||
}
|
||||
|
||||
public void doAfterRun() {
|
||||
doPeriodicalBrief();
|
||||
}
|
||||
|
||||
private void doPeriodicalBrief() {
|
||||
try {
|
||||
ScriptResultModel scriptResultModel = isFinish() ? ScriptResultModel
|
||||
.buildFinishedResult() : this.getSampler()
|
||||
.getResultModelFromAgent();
|
||||
notifyObserver(scriptResultModel.getScriptPagesBriefModel());
|
||||
notifyObserver(scriptResultModel.getScriptBriefResultModel());
|
||||
notifyObserver(scriptResultModel.getScriptBehaviorsBriefModel());
|
||||
List<TestPlanScriptResult> testPlanScriptResultList = this
|
||||
.getTestPlanFactory().createScriptResultsWithoutId(
|
||||
scriptResultModel, testPlan, this,
|
||||
scriptResultModel.getSamplingTime());
|
||||
this.getTestPlanScriptResults().addAll(testPlanScriptResultList);
|
||||
} catch (Exception e) {
|
||||
logger.info(ExceptionLog.getStackTrace(e));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void notifyObserver(SampleModel sample) {
|
||||
this.setChanged();
|
||||
this.notifyObservers(sample);
|
||||
|
||||
}
|
||||
|
||||
public TestPlanScript doForComplete() {
|
||||
|
@ -306,4 +292,8 @@ public class TestPlanScript extends Observable implements
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void clearResult() {
|
||||
this.getTestPlanScriptResults().clear();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,8 +26,7 @@ import org.bench4q.master.domain.repository.AgentRepository;
|
|||
import org.bench4q.master.domain.service.AgentService;
|
||||
import org.bench4q.master.domain.service.ScriptService;
|
||||
import org.bench4q.master.domain.testplan.LoadDistribute;
|
||||
import org.bench4q.master.domain.testplan.TestMoniorResultSave;
|
||||
import org.bench4q.master.domain.testplan.TestScriptResultSave;
|
||||
import org.bench4q.master.domain.testplan.TestResultSave;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.master.exception.ExceptionUtils.IllegalParameterException;
|
||||
import org.bench4q.master.infrastructure.communication.AgentMessenger;
|
||||
|
@ -51,8 +50,7 @@ public class TestPlanFactory {
|
|||
private LoadDistribute loadDistribute;
|
||||
private AgentMessenger agentMessenger;
|
||||
private AgentService agentService;
|
||||
private TestScriptResultSave testScriptResultSave;
|
||||
private TestMoniorResultSave testMoniorResultSave;
|
||||
private TestResultSave testResultSave;
|
||||
|
||||
public LoadDistribute getLoadDistribute() {
|
||||
return loadDistribute;
|
||||
|
@ -81,14 +79,13 @@ public class TestPlanFactory {
|
|||
this.agentService = agentService;
|
||||
}
|
||||
|
||||
public TestScriptResultSave getTestScriptResultSave() {
|
||||
return testScriptResultSave;
|
||||
public TestResultSave getTestResultSave() {
|
||||
return testResultSave;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTestScriptResultSave(
|
||||
TestScriptResultSave testScriptResultSave) {
|
||||
this.testScriptResultSave = testScriptResultSave;
|
||||
public void setTestResultSave(TestResultSave testResultSave) {
|
||||
this.testResultSave = testResultSave;
|
||||
}
|
||||
|
||||
private ScriptService getScriptService() {
|
||||
|
@ -109,16 +106,6 @@ public class TestPlanFactory {
|
|||
this.agentRepository = agentRepository;
|
||||
}
|
||||
|
||||
public TestMoniorResultSave getTestMoniorResultSave() {
|
||||
return testMoniorResultSave;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTestMoniorResultSave(
|
||||
TestMoniorResultSave testMoniorResultSave) {
|
||||
this.testMoniorResultSave = testMoniorResultSave;
|
||||
}
|
||||
|
||||
public TestPlan createATestPlanWithoutIdentity(TestPlanModel testPlanModel,
|
||||
User user, UUID runId) throws IllegalParameterException {
|
||||
Logger.getLogger(TestPlanFactory.class).info(
|
||||
|
@ -271,6 +258,7 @@ public class TestPlanFactory {
|
|||
convertToDomain(monitor);
|
||||
}
|
||||
}
|
||||
testPlanInRepo.addObserver(this.getTestResultSave());
|
||||
logger.info("convertToDomain testPlan run id:"
|
||||
+ testPlanInRepo.getTestPlanRunId());
|
||||
return testPlanInRepo;
|
||||
|
@ -280,11 +268,9 @@ public class TestPlanFactory {
|
|||
testPlanScript.setTestPlanFactory(this);
|
||||
testPlanScript.setAgentMessenger(this.getAgentMessenger());
|
||||
testPlanScript.setAgentService(this.getAgentService());
|
||||
testPlanScript.addObserver(this.getTestScriptResultSave());
|
||||
}
|
||||
|
||||
private void convertToDomain(Monitor monitor) {
|
||||
monitor.addObserver(this.getTestMoniorResultSave());
|
||||
}
|
||||
|
||||
public List<RunningAgentDB> createRunningAgentDBsWithoutId(
|
||||
|
|
|
@ -7,7 +7,11 @@ import java.util.Map;
|
|||
import java.util.UUID;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.domain.entity.Monitor;
|
||||
import org.bench4q.master.domain.entity.MonitorResult;
|
||||
import org.bench4q.master.domain.entity.TestPlan;
|
||||
import org.bench4q.master.domain.entity.TestPlanScript;
|
||||
import org.bench4q.master.domain.entity.TestPlanScriptResult;
|
||||
import org.bench4q.master.domain.entity.User;
|
||||
import org.bench4q.master.domain.factory.TestPlanFactory;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
|
@ -56,6 +60,27 @@ public class TestPlanRepository extends AbstractRepositoty {
|
|||
}
|
||||
}
|
||||
|
||||
// public TestPlan getTestPlanWithOneMonitorResult(String
|
||||
// testPlanRunId,Monitor monitor){
|
||||
//
|
||||
// Session session = this.getSessionHelper().openSession();
|
||||
// try{
|
||||
// TestPlan testPlan=(TestPlan) session
|
||||
// .createCriteria(TestPlan.class)
|
||||
// .add(Restrictions.eq("testPlanRunId", testPlanRunId))
|
||||
// .uniqueResult();
|
||||
// monitor=testPlan.extractSpecifiedMonitor(monitor.getHostName());
|
||||
// List<MonitorResult> monitorResults=session
|
||||
// .createCriteria(MonitorResult.class)
|
||||
// .add(Restrictions.eq("testPlanRunId", monitor))
|
||||
// .uniqueResult();
|
||||
//
|
||||
// }catch(Exception e){
|
||||
// logger.info(ExceptionLog.getStackTrace(e));
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
protected void guardOtherUniqueConditionForEntity(
|
||||
String uniquePropertyName, String value)
|
||||
|
@ -122,8 +147,7 @@ public class TestPlanRepository extends AbstractRepositoty {
|
|||
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();
|
||||
return ret;
|
||||
} catch (Exception e) {
|
||||
logger.error("loadEntities");
|
||||
logger.error(e, e.fillInStackTrace());
|
||||
logger.error(ExceptionLog.getStackTrace(e));
|
||||
return null;
|
||||
} finally {
|
||||
releaseSession(session);
|
||||
|
@ -192,4 +216,34 @@ public class TestPlanRepository extends AbstractRepositoty {
|
|||
public void detachRunningTestPlan(UUID testPlanRunId) {
|
||||
this.getRunningTestPlans().remove(testPlanRunId);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<MonitorResult> getMonitorResultsByMonitor(Monitor monitor) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
try {
|
||||
|
||||
return session.createCriteria(MonitorResult.class)
|
||||
.add(Restrictions.eq("monitor", monitor)).list();
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error(ExceptionLog.getStackTrace(e));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<TestPlanScriptResult> getMonitorResultsByMonitor(
|
||||
TestPlanScript testPlanScript) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
try {
|
||||
|
||||
return session.createCriteria(TestPlanScriptResult.class)
|
||||
.add(Restrictions.eq("testPlanScript", testPlanScript))
|
||||
.list();
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error(ExceptionLog.getStackTrace(e));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,120 +0,0 @@
|
|||
package org.bench4q.master.domain.testplan;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.bench4q.master.domain.entity.Monitor;
|
||||
import org.bench4q.master.domain.entity.MonitorResult;
|
||||
import org.bench4q.master.domain.entity.TestPlan;
|
||||
import org.bench4q.master.domain.repository.TestPlanRepository;
|
||||
import org.bench4q.master.helper.SessionHelper;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.statistics.SampleModel;
|
||||
import org.bench4q.share.models.monitor.MonitorMain;
|
||||
import org.hibernate.Session;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class TestMoniorResultSave implements Observer {
|
||||
private SessionHelper sessionHelper;
|
||||
private TestPlanRepository testPlanRepository;
|
||||
|
||||
public SessionHelper getSessionHelper() {
|
||||
return sessionHelper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setSessionHelper(SessionHelper sessionHelper) {
|
||||
this.sessionHelper = sessionHelper;
|
||||
}
|
||||
|
||||
private TestPlanRepository getTestPlanRepository() {
|
||||
return testPlanRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setTestPlanRepository(TestPlanRepository testPlanRepository) {
|
||||
this.testPlanRepository = testPlanRepository;
|
||||
}
|
||||
|
||||
public void update(Observable o, Object arg) {
|
||||
// TODO Auto-generated method stub
|
||||
Monitor monitor = (Monitor) o;
|
||||
this.saveMonitorResult(
|
||||
UUID.fromString(monitor.getTestPlan().getTestPlanRunId()),
|
||||
(MonitorMain) arg, ((SampleModel) arg).getSamplingTime(),
|
||||
monitor);
|
||||
}
|
||||
|
||||
public boolean saveMonitorResult(UUID testPlanRunId, MonitorMain mainModel,
|
||||
Date createDatetime, Monitor monitor) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
try {
|
||||
TestPlan testPlan = this.getTestPlanRepository().doGetTestPlanBy(
|
||||
session, testPlanRunId);
|
||||
if (testPlan == null) {
|
||||
return false;
|
||||
}
|
||||
monitor = testPlan.extractSpecifiedMonitor(monitor.getHostName());
|
||||
Set<MonitorResult> monitorResultToAdd = monitor.getResults();
|
||||
List<MonitorResult> monitorResults = this
|
||||
.extractMonitorResultFromMonitorModel(mainModel, testPlan,
|
||||
monitor, createDatetime);
|
||||
if (monitorResults == null)
|
||||
return false;
|
||||
if (monitorResults.size() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (MonitorResult monitorResult : monitorResults) {
|
||||
if (session == null)
|
||||
return false;
|
||||
monitorResultToAdd.add(monitorResult);
|
||||
}
|
||||
return this.getTestPlanRepository().doUpdateEntity(session,
|
||||
testPlan);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} finally {
|
||||
if (session.isConnected()) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private List<MonitorResult> extractMonitorResultFromMonitorModel(
|
||||
MonitorMain monitorMain, TestPlan testPlan, Monitor monitor,
|
||||
Date createDatetime) throws IllegalArgumentException,
|
||||
IllegalAccessException, JAXBException {
|
||||
|
||||
List<MonitorResult> monitorResults = new LinkedList<MonitorResult>();
|
||||
|
||||
Field[] fields = monitorMain.getClass().getDeclaredFields();
|
||||
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
MonitorResult monitorResult = new MonitorResult();
|
||||
monitorResult.setTestPlanDB(testPlan);
|
||||
monitorResult.setMonitor(monitor);
|
||||
monitorResult.setCreateDatetime(createDatetime);
|
||||
monitorResult.setHostNameUnderMonitor(monitor.getHostName());
|
||||
fields[i].setAccessible(true);
|
||||
monitorResult.setType(fields[i].getType().getName());
|
||||
monitorResult.setContent(MarshalHelper.marshal(fields[i].getType(),
|
||||
fields[i].get(monitorMain)));
|
||||
monitorResults.add(monitorResult);
|
||||
}
|
||||
return monitorResults;
|
||||
|
||||
}
|
||||
}
|
|
@ -1,45 +1,27 @@
|
|||
package org.bench4q.master.domain.testplan;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Observable;
|
||||
import java.util.Set;
|
||||
import java.util.Observer;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.domain.entity.Monitor;
|
||||
import org.bench4q.master.domain.entity.MonitorResult;
|
||||
import org.bench4q.master.domain.entity.TestPlan;
|
||||
import org.bench4q.master.domain.entity.TestPlanScript;
|
||||
import org.bench4q.master.domain.entity.TestPlanScriptResult;
|
||||
import org.bench4q.master.domain.factory.TestPlanFactory;
|
||||
import org.bench4q.master.domain.repository.TestPlanRepository;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.master.helper.SessionHelper;
|
||||
import org.bench4q.share.models.master.statistics.ScriptResultModel;
|
||||
import org.bench4q.share.models.monitor.MonitorMain;
|
||||
import org.hibernate.Session;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@Component
|
||||
public class TestResultSave {
|
||||
private TestPlanFactory testPlanFactory;
|
||||
public class TestResultSave implements Observer {
|
||||
private SessionHelper sessionHelper;
|
||||
private TestPlanRepository testPlanRepository;
|
||||
private Logger logger = Logger.getLogger(TestScriptResultSave.class);
|
||||
private ConcurrentHashMap<String, TestPlan> runningTestPlans;
|
||||
|
||||
private final int SAVEINTERVAL = 5;
|
||||
private Logger logger = Logger.getLogger(TestResultSave.class);
|
||||
|
||||
public TestResultSave() {
|
||||
this.setRunningTestPlans(new ConcurrentHashMap<String, TestPlan>());
|
||||
}
|
||||
|
||||
private TestPlanRepository getTestPlanRepository() {
|
||||
|
@ -60,119 +42,69 @@ public class TestResultSave {
|
|||
this.sessionHelper = sessionHelper;
|
||||
}
|
||||
|
||||
private TestPlanFactory getTestPlanFactory() {
|
||||
return testPlanFactory;
|
||||
@Override
|
||||
public void update(Observable o, Object arg) {
|
||||
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
TestPlan testPlan = (TestPlan) o;
|
||||
TestPlan testPlanFromRepo = this.getTestPlanRepository()
|
||||
.doGetTestPlanBy(session,
|
||||
UUID.fromString(testPlan.getTestPlanRunId()));
|
||||
updateTestPlanResult(session, testPlan, testPlanFromRepo);
|
||||
saveUpdatedResult(testPlanFromRepo, session);
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setTestPlanFactory(TestPlanFactory testPlanFactory) {
|
||||
this.testPlanFactory = testPlanFactory;
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<String, TestPlan> getRunningTestPlans() {
|
||||
return runningTestPlans;
|
||||
}
|
||||
|
||||
public void setRunningTestPlans(
|
||||
ConcurrentHashMap<String, TestPlan> runningTestPlans) {
|
||||
this.runningTestPlans = runningTestPlans;
|
||||
}
|
||||
|
||||
public void doSaveTestPlanResult() {
|
||||
try {
|
||||
ScheduledExecutorService sheScheduledExecutorService = Executors
|
||||
.newScheduledThreadPool(10);
|
||||
sheScheduledExecutorService.scheduleAtFixedRate(new Runnable() {
|
||||
public void run() {
|
||||
Session session = getSessionHelper().openSession();
|
||||
Set<String> testPlanRunIdSet = getRunningTestPlans()
|
||||
.keySet();
|
||||
for (String testPlanRunId : testPlanRunIdSet) {
|
||||
getTestPlanRepository().doUpdateEntity(session,
|
||||
getRunningTestPlans().get(testPlanRunId));
|
||||
}
|
||||
runningTestPlans.clear();
|
||||
session.close();
|
||||
}
|
||||
}, 0, SAVEINTERVAL, TimeUnit.SECONDS);
|
||||
} catch (Exception e) {
|
||||
Logger.getLogger(TestPlan.class).info(e, e.fillInStackTrace());
|
||||
private void updateTestPlanResult(Session session,TestPlan testPlan,
|
||||
TestPlan testPlanFromRepo) {
|
||||
for (TestPlanScript testPlanScript : testPlan.getTestPlanScripts()) {
|
||||
updateTestPlanScriptResult(testPlanScript, testPlanFromRepo);
|
||||
}
|
||||
}
|
||||
|
||||
private TestPlan getTestPlan(String testPlanRunId) {
|
||||
if (this.getRunningTestPlans().get(testPlanRunId) != null)
|
||||
return this.getRunningTestPlans().get(testPlanRunId);
|
||||
else {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
TestPlan testPlan = this.getTestPlanRepository().doGetTestPlanBy(
|
||||
session, UUID.fromString(testPlanRunId));
|
||||
session.close();
|
||||
if (testPlan == null) {
|
||||
logger.error("get testPlan:" + testPlanRunId
|
||||
+ " from dataBase failed");
|
||||
return null;
|
||||
if (testPlan.getMonitors() != null)
|
||||
for (Monitor monitor : testPlan.getMonitors()) {
|
||||
updateTestplanMonitorResult(session,monitor, testPlanFromRepo);
|
||||
}
|
||||
|
||||
this.getRunningTestPlans().put(testPlanRunId, testPlan);
|
||||
return testPlan;
|
||||
}
|
||||
}
|
||||
|
||||
public void update(Observable messageSender, Object arg) {
|
||||
if (messageSender instanceof Monitor) {
|
||||
Monitor monitor = (Monitor) messageSender;
|
||||
this.updateTestplanMonitorResult(monitor.getTestPlan()
|
||||
.getTestPlanRunId(), monitor.getHostName(),
|
||||
(MonitorMain) arg);
|
||||
} else if (messageSender instanceof TestPlanScript) {
|
||||
TestPlanScript testPlanScript = (TestPlanScript) messageSender;
|
||||
this.updateTestPlanScriptResult(testPlanScript.getTestPlan()
|
||||
.getTestPlanRunId(), testPlanScript.getScriptId(),
|
||||
(ScriptResultModel) arg);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTestPlanScriptResult(String testPlanRunId, int scriptId,
|
||||
ScriptResultModel scriptResultModel) {
|
||||
private void updateTestPlanScriptResult(TestPlanScript testPlanScript,
|
||||
TestPlan testPlanFromRepo) {
|
||||
try {
|
||||
TestPlan testPlan = this.getTestPlan(testPlanRunId);
|
||||
if (testPlan == null)
|
||||
TestPlanScript testPlanScriptFromRepo = testPlanFromRepo
|
||||
.extracSpecifiedScript(testPlanScript.getScriptId());
|
||||
if (testPlanScript.getTestPlanScriptResults().size() == 0)
|
||||
return;
|
||||
TestPlanScript testPlanScript = testPlan
|
||||
.extracSpecifiedScript(scriptId);
|
||||
List<TestPlanScriptResult> testPlanScriptResults = this
|
||||
.getTestPlanFactory().createScriptResultsWithoutId(
|
||||
scriptResultModel, testPlan, testPlanScript,
|
||||
scriptResultModel.getSamplingTime());
|
||||
if (testPlanScript.getTestPlanScriptResults() == null)
|
||||
testPlanScript
|
||||
.setTestPlanScriptResults(new HashSet<TestPlanScriptResult>());
|
||||
testPlanScript.getTestPlanScriptResults().addAll(
|
||||
testPlanScriptResults);
|
||||
testPlanScriptFromRepo.getTestPlanScriptResults().addAll(
|
||||
testPlanScript.getTestPlanScriptResults());
|
||||
} catch (Exception e) {
|
||||
logger.info(ExceptionLog.getStackTrace(e));
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTestplanMonitorResult(String testPlanRunId,
|
||||
String hostName, MonitorMain monitorMain) {
|
||||
System.out.println(testPlanRunId);
|
||||
TestPlan testPlan = this.getTestPlan(testPlanRunId);
|
||||
if (testPlan == null)
|
||||
return;
|
||||
Monitor monitor = testPlan.extractSpecifiedMonitor(hostName);
|
||||
List<MonitorResult> monitorResults = this.getTestPlanFactory()
|
||||
.createMonitorResultListWithOutId(monitorMain, testPlan,
|
||||
monitor, monitorMain.getSamplingTime());
|
||||
if (monitorResults == null || monitorResults.size() == 0)
|
||||
return;
|
||||
private void updateTestplanMonitorResult(Session session, Monitor monitor,
|
||||
TestPlan testPlanFromRepo) {
|
||||
try {
|
||||
monitor.getResults().addAll(monitorResults);
|
||||
logger.info("session:"+session.isOpen());
|
||||
logger.info("currentSession:"+this.getSessionHelper().getCurrentSession().isOpen());
|
||||
Monitor monitorFromRepo = testPlanFromRepo
|
||||
.extractSpecifiedMonitor(monitor.getHostName());
|
||||
if (monitor.getResults().size() == 0)
|
||||
return;
|
||||
monitorFromRepo.getResults().addAll(monitor.getResults());
|
||||
} catch (Exception e) {
|
||||
monitor.setResults(new HashSet<MonitorResult>());
|
||||
monitor.getResults().addAll(monitorResults);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean saveUpdatedResult(TestPlan testPlan, Session session) {
|
||||
try {
|
||||
|
||||
getTestPlanRepository().doUpdateEntity(session, testPlan);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
logger.info(ExceptionLog.getStackTrace(e));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,90 +0,0 @@
|
|||
package org.bench4q.master.domain.testplan;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.domain.RunningScriptInterface;
|
||||
import org.bench4q.master.domain.entity.TestPlan;
|
||||
import org.bench4q.master.domain.entity.TestPlanScript;
|
||||
import org.bench4q.master.domain.factory.TestPlanFactory;
|
||||
import org.bench4q.master.domain.repository.TestPlanRepository;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.master.helper.SessionHelper;
|
||||
import org.bench4q.share.models.master.statistics.SampleModel;
|
||||
import org.hibernate.Session;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class TestScriptResultSave implements Observer {
|
||||
private TestPlanFactory testPlanFactory;
|
||||
private SessionHelper sessionHelper;
|
||||
private TestPlanRepository testPlanRepository;
|
||||
private Logger logger = Logger.getLogger(TestScriptResultSave.class);
|
||||
|
||||
private TestPlanRepository getTestPlanRepository() {
|
||||
return testPlanRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setTestPlanRepository(TestPlanRepository testPlanRepository) {
|
||||
this.testPlanRepository = testPlanRepository;
|
||||
}
|
||||
|
||||
private SessionHelper getSessionHelper() {
|
||||
return sessionHelper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setSessionHelper(SessionHelper sessionHelper) {
|
||||
this.sessionHelper = sessionHelper;
|
||||
}
|
||||
|
||||
private TestPlanFactory getTestPlanFactory() {
|
||||
return testPlanFactory;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setTestPlanFactory(TestPlanFactory testPlanFactory) {
|
||||
this.testPlanFactory = testPlanFactory;
|
||||
}
|
||||
|
||||
public void update(Observable o, Object arg) {
|
||||
// TODO Auto-generated method stub
|
||||
RunningScriptInterface runningScript = (RunningScriptInterface) o;
|
||||
this.doSaveResult(runningScript.getTestPlanID(),
|
||||
runningScript.getScriptId(), arg,
|
||||
((SampleModel) arg).getSamplingTime());
|
||||
}
|
||||
|
||||
public boolean doSaveResult(UUID testPlanRunId, int scriptId,
|
||||
Object resultModel, Date now) {
|
||||
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
try {
|
||||
TestPlan testPlan = this.getTestPlanRepository().doGetTestPlanBy(
|
||||
session, testPlanRunId);
|
||||
if (testPlan == null) {
|
||||
return false;
|
||||
}
|
||||
TestPlanScript specifiedScript = testPlan
|
||||
.extracSpecifiedScript(scriptId);
|
||||
specifiedScript.getTestPlanScriptResults().add(
|
||||
this.getTestPlanFactory().createScriptResultWithoutId(
|
||||
resultModel, specifiedScript, now));
|
||||
this.getTestPlanRepository().doUpdateEntity(session, testPlan);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
logger.error(ExceptionLog.getStackTrace(e));
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -30,6 +30,10 @@ public final class SessionHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public Session getCurrentSession(){
|
||||
return this.getSessionFactory().getCurrentSession();
|
||||
|
||||
}
|
||||
public Session openSession() {
|
||||
return this.getSessionFactory().openSession();
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package org.bench4q.master.test;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.domain.entity.RunningAgentDB;
|
||||
import org.bench4q.master.domain.entity.TestPlan;
|
||||
import org.bench4q.master.domain.entity.User;
|
||||
|
@ -16,8 +15,6 @@ import org.bench4q.master.domain.service.TestPlanScriptResultService;
|
|||
import org.bench4q.master.domain.service.TestPlanScriptService;
|
||||
import org.bench4q.master.domain.service.TestPlanService;
|
||||
import org.bench4q.master.domain.service.UserService;
|
||||
import org.bench4q.master.domain.testplan.TestMoniorResultSave;
|
||||
import org.bench4q.master.domain.testplan.TestScriptResultSave;
|
||||
import org.bench4q.master.helper.SessionHelper;
|
||||
import org.bench4q.master.infrastructure.communication.AgentMessenger;
|
||||
import org.bench4q.master.test.controller.TestBase;
|
||||
|
@ -47,8 +44,6 @@ public class TestBase_MakeUpTestPlan extends TestBase {
|
|||
private int scriptId;
|
||||
private int scriptIdForSecond;
|
||||
private User testUser;
|
||||
private TestScriptResultSave testScriptResultSave;
|
||||
private TestMoniorResultSave testMoniorResultSave;
|
||||
protected static final int USE_SCRIPT = 61;
|
||||
// private static int EACH_SCRIPT_LOAD_LargeSCALE = 12000;
|
||||
protected static int EACH_SCRIPT_LOAD_SMALLSCALE = 10;
|
||||
|
@ -169,25 +164,7 @@ public class TestBase_MakeUpTestPlan extends TestBase {
|
|||
this.testPlanEngine = testPlanEngine;
|
||||
}
|
||||
|
||||
protected TestScriptResultSave getTestScriptResultSave() {
|
||||
return testScriptResultSave;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setTestScriptResultSave(
|
||||
TestScriptResultSave testScriptResultSave) {
|
||||
this.testScriptResultSave = testScriptResultSave;
|
||||
}
|
||||
|
||||
protected TestMoniorResultSave getTestMoniorResultSave() {
|
||||
return testMoniorResultSave;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setTestMoniorResultSave(
|
||||
TestMoniorResultSave testMoniorResultSave) {
|
||||
this.testMoniorResultSave = testMoniorResultSave;
|
||||
}
|
||||
|
||||
public UUID getTestPlanRunIdUuid() {
|
||||
return testPlanRunIdUuid;
|
||||
|
|
|
@ -58,4 +58,10 @@ public class TestPlanControllerTest extends TestBase_MakeUpTestPlan {
|
|||
System.out.println(httpResponse.getContent());
|
||||
assertEquals(200, httpResponse.getCode());
|
||||
}
|
||||
@Test
|
||||
public void testLoadTestPlans() throws IOException, JAXBException{
|
||||
HttpResponse httpResponse = this.httpRequester.sendGet(this.url
|
||||
+ "/loadTestPlans",null, this.makeAccessTockenMap(this.login()));
|
||||
System.out.println(httpResponse.getContent());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package org.bench4q.master.test.controller;
|
|||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
@ -14,8 +13,6 @@ import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
|||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.ResultLoadModel;
|
||||
import org.bench4q.share.models.master.TestPlanModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptPageBriefModel;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -51,16 +48,15 @@ public class TestPlanScriptResultControllerTest extends TestBase_MakeUpTestPlan
|
|||
this.getTestPlanService().submitTestPlan(model, user, testPlanRunId);
|
||||
this.setTestPlanRunIdUuid(testPlanRunId);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
this.getTestScriptResultSave().doSaveResult(testPlanRunId,
|
||||
this.getScriptId(), buildScriptBriefResultModel(i),
|
||||
new Date());
|
||||
this.getTestScriptResultSave().doSaveResult(testPlanRunId,
|
||||
this.getScriptId(), new ScriptBehaviorsBriefModel(),
|
||||
new Date());
|
||||
|
||||
this.getTestScriptResultSave().doSaveResult(testPlanRunId,
|
||||
this.getScriptId(), new ScriptPageBriefModel(), new Date());
|
||||
|
||||
/*
|
||||
* this.getTestScriptResultSave().doSaveResult(testPlanRunId,
|
||||
* this.getScriptId(), buildScriptBriefResultModel(i), new Date());
|
||||
* this.getTestScriptResultSave().doSaveResult(testPlanRunId,
|
||||
* this.getScriptId(), new ScriptBehaviorsBriefModel(), new Date());
|
||||
*
|
||||
* this.getTestScriptResultSave().doSaveResult(testPlanRunId,
|
||||
* this.getScriptId(), new ScriptPageBriefModel(), new Date());
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,111 +0,0 @@
|
|||
package org.bench4q.master.test.domain;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.domain.entity.Monitor;
|
||||
import org.bench4q.master.domain.entity.MonitorResult;
|
||||
import org.bench4q.master.domain.entity.TestPlan;
|
||||
import org.bench4q.master.domain.factory.TestPlanFactory;
|
||||
import org.bench4q.master.domain.testplan.TestMoniorResultSave;
|
||||
import org.bench4q.master.domain.testplan.TestMonitorSampler;
|
||||
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
|
||||
import org.bench4q.share.models.monitor.MonitorMain;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
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_TestMonitorResultSave extends TestBase_MakeUpTestPlan {
|
||||
|
||||
private TestMoniorResultSave testMoniorResultSave;
|
||||
private UUID testPlanRunId;
|
||||
private TestMonitorSampler testMonitorSampler;
|
||||
private TestPlanFactory testPlanFactory;
|
||||
|
||||
public TestPlanFactory getTestPlanFactory() {
|
||||
return testPlanFactory;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTestPlanFactory(TestPlanFactory testPlanFactory) {
|
||||
this.testPlanFactory = testPlanFactory;
|
||||
}
|
||||
|
||||
public TestMoniorResultSave getTestMoniorResultSave() {
|
||||
return testMoniorResultSave;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTestMoniorResultSave(
|
||||
TestMoniorResultSave testMoniorResultSave) {
|
||||
this.testMoniorResultSave = testMoniorResultSave;
|
||||
}
|
||||
|
||||
public TestMonitorSampler getTestMonitorSampler() {
|
||||
return testMonitorSampler;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTestMonitorSampler(TestMonitorSampler testMonitorSampler) {
|
||||
this.testMonitorSampler = testMonitorSampler;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
prepareForTestPlanRunning();
|
||||
this.submitATestPlanWithOneScript();
|
||||
TestPlan testPlan = fetchTestPlan();
|
||||
this.testPlanRunId = UUID.fromString(testPlan.getTestPlanRunId());
|
||||
testPlan.run();
|
||||
this.getTestPlanRepository().updateEntity(testPlan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoSaveResult() {
|
||||
TestPlan testPlan = fetchTestPlan();
|
||||
Monitor monitor = testPlan.getMonitors().iterator().next();
|
||||
int beforeMonitorResultSize = loadMonitorResults(monitor).size();
|
||||
MonitorMain monitorMain = monitor.getTestMonitorSampler()
|
||||
.getMonitorResult(monitor.getHostName(), monitor.getPort());
|
||||
Assert.assertNotNull(monitorMain);
|
||||
|
||||
assertTrue(this.getTestMoniorResultSave().saveMonitorResult(
|
||||
this.testPlanRunId, monitorMain, monitorMain.getSamplingTime(),
|
||||
monitor));
|
||||
testPlan = fetchTestPlan();
|
||||
monitor = testPlan.getMonitors().iterator().next();
|
||||
Assert.assertEquals(beforeMonitorResultSize + 5,
|
||||
loadMonitorResults(monitor).size());
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<MonitorResult> loadMonitorResults(Monitor monitor) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
List<MonitorResult> results = session
|
||||
.createCriteria(MonitorResult.class)
|
||||
.add(Restrictions.eq("monitor", monitor)).list();
|
||||
|
||||
session.close();
|
||||
return results;
|
||||
}
|
||||
|
||||
@After
|
||||
public void clean() {
|
||||
cleanUpForTestPlanRunning();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
package org.bench4q.master.test.domain;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.domain.entity.TestPlan;
|
||||
import org.bench4q.master.domain.entity.TestPlanScript;
|
||||
import org.bench4q.master.domain.testplan.RunningScriptSampler;
|
||||
import org.bench4q.master.domain.testplan.TestScriptResultSave;
|
||||
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.statistics.ScriptResultModel;
|
||||
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_TestScriptResultSave extends TestBase_MakeUpTestPlan {
|
||||
|
||||
private Logger logger = Logger.getLogger(Test_TestScriptResultSave.class);
|
||||
private TestScriptResultSave testScriptResultSave;
|
||||
private RunningScriptSampler runningScriptSampler;
|
||||
private UUID testPlanRunId;
|
||||
private int scriptId;
|
||||
|
||||
public TestScriptResultSave getTestScriptResultSave() {
|
||||
return testScriptResultSave;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTestScriptResultSave(
|
||||
TestScriptResultSave testScriptResultSave) {
|
||||
this.testScriptResultSave = testScriptResultSave;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
prepareForTestPlanRunning();
|
||||
this.submitATestPlanWithOneScript();
|
||||
TestPlan testPlan = fetchTestPlan();
|
||||
this.testPlanRunId = UUID.fromString(testPlan.getTestPlanRunId());
|
||||
testPlan.run();
|
||||
this.getTestPlanRepository().updateEntity(testPlan);
|
||||
TestPlan testPlanInRunning = fetchTestPlan();
|
||||
TestPlanScript testPlanScript = testPlanInRunning
|
||||
.extracSpecifiedScript(getScriptId());
|
||||
this.scriptId = getScriptId();
|
||||
this.runningScriptSampler = new RunningScriptSampler(
|
||||
testPlanScript.getRunningAgentsDB());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoSaveResult() throws InterruptedException, JAXBException {
|
||||
Thread.sleep(2000);
|
||||
ScriptResultModel scriptResultModel = this.runningScriptSampler
|
||||
.getResultModelFromAgent();
|
||||
assertNotNull(scriptResultModel);
|
||||
assertNotNull(scriptResultModel.getScriptBehaviorsBriefModel());
|
||||
assertNotNull(scriptResultModel.getScriptBriefResultModel());
|
||||
assertNotNull(scriptResultModel.getScriptPagesBriefModel());
|
||||
logger.info(MarshalHelper.marshal(ScriptResultModel.class,
|
||||
scriptResultModel));
|
||||
assertTrue(scriptResultModel.getScriptPagesBriefModel()
|
||||
.getScriptPageBriefModels().size() > 0);
|
||||
assertTrue(this.getTestScriptResultSave().doSaveResult(
|
||||
this.testPlanRunId,
|
||||
this.scriptId,
|
||||
scriptResultModel.getScriptPagesBriefModel()
|
||||
.getScriptPageBriefModels().get(0),
|
||||
scriptResultModel.getScriptPagesBriefModel()
|
||||
.getScriptPageBriefModels().get(0).getSamplingTime()));
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void clean() {
|
||||
cleanUpForTestPlanRunning();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.master.test.domain;
|
||||
package org.bench4q.master.test.domain.testPlan;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.master.test.domain;
|
||||
package org.bench4q.master.test.domain.testPlan;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.master.test.domain;
|
||||
package org.bench4q.master.test.domain.testPlan;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.master.test.domain;
|
||||
package org.bench4q.master.test.domain.testPlan;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.bench4q.master.domain.entity.Monitor;
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.master.test.domain;
|
||||
package org.bench4q.master.test.domain.testPlan;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
|
@ -2,7 +2,6 @@ package org.bench4q.master.test.service;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -13,7 +12,6 @@ import org.bench4q.share.models.master.TestPlanModel;
|
|||
import org.bench4q.share.models.master.ValueTimeModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptPageBriefModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptPagesBriefModel;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
@ -116,7 +114,7 @@ public class Test_TestPlanScriptResultService extends TestBase_MakeUpTestPlan {
|
|||
TestPlanModel model = createATestPlanWithOneScript(this.getScriptId());
|
||||
this.getTestPlanService().submitTestPlan(model, user, testPlanRunId);
|
||||
this.setTestPlanRunIdUuid(testPlanRunId);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
/*for (int i = 0; i < 3; i++) {
|
||||
this.getTestScriptResultSave().doSaveResult(testPlanRunId,
|
||||
this.getScriptId(), buildScriptBriefResultModel(i),
|
||||
new Date());
|
||||
|
@ -127,19 +125,20 @@ public class Test_TestPlanScriptResultService extends TestBase_MakeUpTestPlan {
|
|||
this.getTestScriptResultSave().doSaveResult(testPlanRunId,
|
||||
this.getScriptId(), makeUpScriptPagesBriefModel(i),
|
||||
new Date());
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
private ScriptPagesBriefModel makeUpScriptPagesBriefModel(int i) {
|
||||
ScriptPagesBriefModel scriptPagesBriefModel = new ScriptPagesBriefModel();
|
||||
ScriptPageBriefModel scriptPageBriefModel = new ScriptPageBriefModel();
|
||||
scriptPageBriefModel.setMaxResponseTimeFromBegin(200 + 10 * i);
|
||||
scriptPageBriefModel.setMinResponseTimeFromBegin(200 - 10 * i);
|
||||
scriptPagesBriefModel.getScriptPageBriefModels().add(
|
||||
scriptPageBriefModel);
|
||||
return scriptPagesBriefModel;
|
||||
}
|
||||
// private ScriptPagesBriefModel makeUpScriptPagesBriefModel(int i) {
|
||||
// ScriptPagesBriefModel scriptPagesBriefModel = new
|
||||
// ScriptPagesBriefModel();
|
||||
// ScriptPageBriefModel scriptPageBriefModel = new ScriptPageBriefModel();
|
||||
// scriptPageBriefModel.setMaxResponseTimeFromBegin(200 + 10 * i);
|
||||
// scriptPageBriefModel.setMinResponseTimeFromBegin(200 - 10 * i);
|
||||
// scriptPagesBriefModel.getScriptPageBriefModels().add(
|
||||
// scriptPageBriefModel);
|
||||
// return scriptPagesBriefModel;
|
||||
// }
|
||||
|
||||
@After
|
||||
public void cleanUp() {
|
||||
|
|
|
@ -2,7 +2,6 @@ package org.bench4q.master.test.service;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -27,8 +26,10 @@ public class Test_TestPlanScriptService extends TestBase_MakeUpTestPlan {
|
|||
public void prepare() {
|
||||
submitATestPlanWithOneScript();
|
||||
System.out.println(getScriptId());
|
||||
this.getTestScriptResultSave().doSaveResult(getTestPlanRunIdUuid(),
|
||||
getScriptId(), new ScriptBriefResultModel(), new Date());
|
||||
/*
|
||||
* this.getTestScriptResultSave().doSaveResult(getTestPlanRunIdUuid(),
|
||||
* getScriptId(), new ScriptBriefResultModel(), new Date());
|
||||
*/
|
||||
}
|
||||
|
||||
@After
|
||||
|
@ -66,9 +67,11 @@ public class Test_TestPlanScriptService extends TestBase_MakeUpTestPlan {
|
|||
briefResultModel.setFailRateThisTime(0);
|
||||
briefResultModel.setFailThroughputThisTime(0);
|
||||
briefResultModel.setFinished(true);
|
||||
this.getTestScriptResultSave().doSaveResult(
|
||||
UUID.fromString(WRONG_TEST_PLAN_RUN_ID), WRONG_SCRIPT_ID,
|
||||
briefResultModel, new Date());
|
||||
/*
|
||||
* this.getTestScriptResultSave().doSaveResult(
|
||||
* UUID.fromString(WRONG_TEST_PLAN_RUN_ID), WRONG_SCRIPT_ID,
|
||||
* briefResultModel, new Date());
|
||||
*/
|
||||
TestPlanScript testPlanScript = this.getTestPlanScriptService()
|
||||
.getTestPlanScript(WRONG_SCRIPT_ID,
|
||||
UUID.fromString(WRONG_TEST_PLAN_RUN_ID));
|
||||
|
|
Loading…
Reference in New Issue