add test to agent messenger

This commit is contained in:
fanfuxiaoran 2014-03-26 11:36:45 +08:00
parent 80ec2e9228
commit 6e7b6fbb8c
15 changed files with 122 additions and 42 deletions

View File

@ -104,7 +104,6 @@ public class Monitor extends Observable {
try {
this.setChanged();
this.notifyObservers(monitorMain);
logger.info("enter update");
} catch (Exception e) {
logger.error(ExceptionLog.getStackTrace(e));
}

View File

@ -39,6 +39,7 @@ 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")
@ -266,12 +267,11 @@ public class TestPlanScript extends Observable implements
private void doPeriodicalBrief() {
try {
this.setChanged();
notifyObserver(getSampler().getTestBriefStatusModelFromAgent()
.getScriptBriefResultModel());
notifyObserver(getSampler().getTestBriefStatusModelFromAgent()
.getScriptPagesBriefModel());
notifyObserver(getSampler().getTestBriefStatusModelFromAgent()
.getScriptBehaviorsBriefModel());
ScriptResultModel scriptResultModel = this.getSampler()
.getResultModelFromAgent();
notifyObserver(scriptResultModel.getScriptBriefResultModel());
notifyObserver(scriptResultModel.getScriptPagesBriefModel());
notifyObserver(scriptResultModel.getScriptBehaviorsBriefModel());
} catch (Exception e) {
logger.info(ExceptionLog.getStackTrace(e));
}

View File

@ -116,6 +116,8 @@ public class TestPlanFactory {
public TestPlan createATestPlanWithoutIdentity(TestPlanModel testPlanModel,
User user, UUID runId) throws IllegalParameterException {
Logger.getLogger(TestPlanFactory.class).info(
"testPlanName:" + testPlanModel.getName());
TestPlan result = new TestPlan();
result.setCreateDateTime(new Date());
result.setCurrentStatus(TestPlanStatus.NotStart.name());

View File

@ -65,7 +65,7 @@ public class MonitorResultService {
.addOrder(Order.asc("createDatetime")).list();
} catch (Exception e) {
logger.info(e, e.fillInStackTrace());
logger.info(ExceptionLog.getStackTrace(e));
throw new Bench4QException("", "get MonitorResult from db failed",
"monitor service");
} finally {
@ -94,7 +94,6 @@ public class MonitorResultService {
private List<MonitorResult> doGetMonitorResultsByeTypeAndBeginDate(
UUID testPlanRunId, String hostName, long beginTime,
Session session, Class<?> resultClass) {
logger.info(resultClass.getName());
return session
.createCriteria(MonitorResult.class)
.add(Restrictions.eq("testPlanDB", this.getTestPlanRepository()
@ -140,7 +139,6 @@ public class MonitorResultService {
List<MonitorResult> monitorResults = doGetMonitorResultsByeTypeAndBeginDate(
testPlanRunId, hostName, beginTime, session,
fromMonitorClass);
logger.info("minitor result size:" + monitorResults.size());
for (MonitorResult monitorResult : monitorResults) {
assert (fromMonitorClass.getName().equals(monitorResult

View File

@ -94,7 +94,7 @@ public class TestPlanEngine implements TaskCompleteCallback,
public UUID runWith(final TestPlanModel testPlanModel, User user) {
ExecutorService executorService = Executors.newCachedThreadPool();
final UUID testPlanId = UUID.randomUUID();
logger.info("name:" + testPlanModel.getName());
if (!this.getTestPlanService().submitTestPlan(testPlanModel, user,
testPlanId)) {
return null;

View File

@ -60,9 +60,12 @@ public class TestPlanService {
public boolean submitTestPlan(final TestPlanModel testPlanBusinessModel,
final User user, final UUID testPlanRunId) {
try {
return this.getTestPlanRepository().attach(
this.getTestPlanFactory().createATestPlanWithoutIdentity(
testPlanBusinessModel, user, testPlanRunId));
TestPlan testPlan = this.getTestPlanFactory()
.createATestPlanWithoutIdentity(testPlanBusinessModel,
user, testPlanRunId);
Logger.getLogger(TestPlanService.class).info(
"test plan name:" + testPlan.getName());
return this.getTestPlanRepository().attach(testPlan);
} catch (IllegalParameterException e) {
// TODO: give back the message
Logger.getLogger(TestPlanService.class).error(

View File

@ -68,7 +68,7 @@ public class RunningScriptSampler {
this.getRunningAgents().addAll(runningAgents);
}
public ScriptResultModel getTestBriefStatusModelFromAgent() {
public ScriptResultModel getResultModelFromAgent() {
for (RunningAgentInterface runningAgent : getRunningAgents()) {
if (runningAgent.isBreakDown()) {
continue;

View File

@ -11,7 +11,6 @@ import java.util.UUID;
import javax.xml.bind.JAXBException;
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;
@ -26,7 +25,6 @@ import org.springframework.stereotype.Component;
@Component
public class TestMoniorResultSave implements Observer {
private Logger logger = Logger.getLogger(TestMoniorResultSave.class);
private SessionHelper sessionHelper;
private TestPlanRepository testPlanRepository;
@ -51,7 +49,6 @@ public class TestMoniorResultSave implements Observer {
public void update(Observable o, Object arg) {
// TODO Auto-generated method stub
Monitor monitor = (Monitor) o;
logger.info("enter monitor update:" + monitor.getHostName());
this.saveMonitorResult(
UUID.fromString(monitor.getTestPlan().getTestPlanRunId()),
(MonitorMain) arg, ((SampleModel) arg).getSamplingTime(),
@ -75,7 +72,6 @@ public class TestMoniorResultSave implements Observer {
if (monitorResults == null)
return false;
if (monitorResults.size() == 0) {
System.out.println("size is 0 ");
return false;
}
@ -84,7 +80,6 @@ public class TestMoniorResultSave implements Observer {
return false;
monitorResultToAdd.add(monitorResult);
}
logger.info("monitor ressult size:" + monitorResultToAdd.size());
return this.getTestPlanRepository().doUpdateEntity(session,
testPlan);
} catch (Exception e) {
@ -114,7 +109,6 @@ public class TestMoniorResultSave implements Observer {
monitorResult.setCreateDatetime(createDatetime);
monitorResult.setHostNameUnderMonitor(monitor.getHostName());
fields[i].setAccessible(true);
logger.info(fields[i].getType().getName());
monitorResult.setType(fields[i].getType().getName());
monitorResult.setContent(MarshalHelper.marshal(fields[i].getType(),
fields[i].get(monitorMain)));

View File

@ -108,7 +108,6 @@ public class HighAvailablePool extends CurrentLoadSubject {
doSubstituteIfRequired();
}
}
logger.info("Rotation Over");
}
private void doSubstituteIfRequired() {

View File

@ -53,7 +53,7 @@ public class TestBase_MakeUpTestPlan extends TestBase {
private static String Monitor_Host_Name = "133.133.12.3";
private static String monitor_port = "5556";
protected static final String Test_AGENT_HOSTNAME = "127.0.0.1";
protected static final String Test_AGENT_HOSTNAME = "133.133.12.4";
protected static final int TEST_PORT = 6565;
public TestPlanScriptResultService getTestPlanScriptResultService() {
@ -225,7 +225,7 @@ public class TestBase_MakeUpTestPlan extends TestBase {
RunningAgentDB runningAgent = testPlan.extracSpecifiedScript(
getScriptId()).extractSpecificRunningAgentDB(
Test_AGENT_HOSTNAME);
if(runningAgent==null)
if (runningAgent == null)
return;
this.getAgentMessenger().stop(runningAgent.getAgent(),
runningAgent.getAgentRunId());
@ -271,6 +271,29 @@ public class TestBase_MakeUpTestPlan extends TestBase {
return testPlanBusinessModel;
}
public UUID submitATestPlanWithScriptName() {
UUID testPlanRunId = UUID.randomUUID();
User user = this.getUserRepository().getUser("admin");
int scriptOne = getUserFirstScript(user);
this.setScriptId(scriptOne);
TestPlanModel model = null;
model = createAtestPlanWithOneScriptAndName();
this.getTestPlanService().submitTestPlan(model, user, testPlanRunId);
this.setTestPlanRunIdUuid(testPlanRunId);
return testPlanRunId;
}
public TestPlanModel createAtestPlanWithOneScriptAndName() {
TestPlanModel testPlanBusinessModel = new TestPlanModel();
testPlanBusinessModel.setName("testName");
testPlanBusinessModel.setMonitorModels(createOneMonitorList());
testPlanBusinessModel
.setRunningScriptModels(createOneScriptList(scriptId));
this.setScriptId(scriptId);
return testPlanBusinessModel;
}
protected TestPlanModel createATestPlanWithTwoScript(int scriptIdForOne,
int scriptIdForTwo) {
TestPlanModel testPlanBusinessModel = new TestPlanModel();

View File

@ -11,12 +11,19 @@ import javax.xml.bind.JAXBException;
import org.apache.commons.io.FileUtils;
import org.bench4q.master.domain.entity.Agent;
import org.bench4q.master.domain.entity.TestPlan;
import org.bench4q.master.domain.entity.TestPlanScript;
import org.bench4q.master.infrastructure.communication.AgentMessenger;
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
import org.bench4q.share.enums.master.TestPlanStatus;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.agent.RunScenarioModel;
import org.bench4q.share.models.agent.RunScenarioResultModel;
import org.bench4q.share.models.agent.TestBriefStatusModel;
import org.junit.After;
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;
@ -25,9 +32,20 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
public class Test_AgentMessenger extends TestBase_MakeUpTestPlan {
private static final String FILE_SEPARATOR = System
.getProperty("file.separator");
private static final String Test_HOSTNAME = "http://127.0.0.1";
private static final String Test_HOSTNAME = "http://133.133.12.4";
private static final int Test_PORT = 6565;
private AgentMessenger agentMessenger;
public AgentMessenger getAgentMessenger() {
return agentMessenger;
}
@Autowired
public void setAgentMessenger(AgentMessenger agentMessenger) {
this.agentMessenger = agentMessenger;
}
@Test
public void testSubmitScenarioWithParamsAndRun() throws IOException,
JAXBException {
@ -76,4 +94,39 @@ public class Test_AgentMessenger extends TestBase_MakeUpTestPlan {
}
return paramFile;
}
@Test
public void testGetScriptResult() throws InterruptedException,
JAXBException {
this.submitATestPlanWithOneScript();
this.getHaPool().timerTask();
assertEquals(Long.valueOf(500), this.getHaPool().getMaxAvailableLoad());
TestPlan testPlan = this.getTestPlanRepository().getTestPlanBy(
this.getTestPlanRunIdUuid());
assertEquals(TestPlanStatus.InRunning, testPlan.run());
Thread.sleep(2000);
TestPlanScript testPlanScript = testPlan.getTestPlanScripts()
.iterator().next();
Agent agent = testPlanScript.getRunningAgents().iterator().next()
.getAgent();
TestBriefStatusModel testBriefStatusModel = this.getAgentMessenger()
.scriptBriefAll(agent, this.getTestPlanRunIdUuid());
assertNotNull(testBriefStatusModel.getScenarioBriefModel());
assertNotNull(testBriefStatusModel);
assertNotNull(testBriefStatusModel.getBehaviorsBriefModel());
assertNotNull(testBriefStatusModel.getPagesBriefModel());
assertTrue(testBriefStatusModel.getBehaviorsBriefModel()
.getBehaviorBriefModels().size() > 0);
assertTrue(testBriefStatusModel.getPagesBriefModel()
.getPageBriefModels().size() > 0);
cleanUpForTestPlanRunning();
}
@After
public void clear() {
cleanUpForTestPlanRunning();
}
}

View File

@ -2,7 +2,6 @@ package org.bench4q.master.test.domain;
import static org.junit.Assert.*;
import org.bench4q.master.domain.entity.TestPlan;
import org.bench4q.master.domain.entity.TestPlanScript;
import org.bench4q.master.domain.testplan.RunningScriptSampler;
@ -52,15 +51,17 @@ public class Test_RunningScriptSampler extends TestBase_MakeUpTestPlan {
return this.getTestPlanRepository().getTestPlanBy(
getTestPlanRunIdUuid());
}
@Test
@Test
public void testGetScriptResult() throws InterruptedException {
ScriptResultModel scriptResultModel = this.getRunningScriptSampler()
.getTestBriefStatusModelFromAgent();
.getResultModelFromAgent();
Thread.sleep(1000);
assertNotNull(scriptResultModel);
assertNotNull(scriptResultModel.getScriptBehaviorsBriefModel());
assertTrue(scriptResultModel.getScriptBehaviorsBriefModel()
.getTestBehaviorsBriefModel().getBehaviorBriefModels().size() > 0);
assertNotNull(scriptResultModel.getScriptBriefResultModel());
assertNotNull(scriptResultModel.getScriptPagesBriefModel());
assertTrue(scriptResultModel.getScriptPagesBriefModel()
.getScriptPageBriefModels().size() >0);
}
}

View File

@ -1,12 +1,15 @@
package org.bench4q.master.test.domain;
import static org.junit.Assert.*;
import java.util.UUID;
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.models.master.statistics.ScriptResultModel;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -52,13 +55,23 @@ public class Test_TestScriptResultSave extends TestBase_MakeUpTestPlan {
@Test
public void testDoSaveResult() {
ScriptResultModel scriptResultModel = this.runningScriptSampler
.getResultModelFromAgent();
assertNotNull(scriptResultModel);
assertNotNull(scriptResultModel.getScriptBehaviorsBriefModel());
assertNotNull(scriptResultModel.getScriptBriefResultModel());
assertNotNull(scriptResultModel.getScriptPagesBriefModel());
assertTrue(scriptResultModel.getScriptPagesBriefModel()
.getScriptPageBriefModels().size() > 0);
assertTrue(this.getTestScriptResultSave().doSaveResult(
this.testPlanRunId,
this.scriptId,
this.runningScriptSampler.getTestBriefStatusModelFromAgent()
.getScriptBriefResultModel(),
this.runningScriptSampler.getTestBriefStatusModelFromAgent()
.getSamplingTime()));
this.testPlanRunId, this.scriptId,
scriptResultModel.getScriptPagesBriefModel(),
scriptResultModel.getSamplingTime()));
TestPlanScript testPlanScript = this.getTestPlanRepository()
.getTestPlanBy(this.getTestPlanRunIdUuid())
.getTestPlanScripts().iterator().next();
assertTrue(testPlanScript.getTestPlanScriptResults().size() > 1);
}
@After

View File

@ -43,10 +43,7 @@ public class Test_TestPlanEngine extends TestBase_MakeUpTestPlan {
testForStatus(TestPlanStatus.InRunning);
}
@Test
public void testPickTestPlan(){
}
@Test
public void testRunTestPlanRightly() throws InterruptedException {
assertNotNull(this.getAgentMessenger().askLiving(Test_AGENT_HOSTNAME,

View File

@ -72,8 +72,6 @@ public class TestPlanTester extends TestBase_MakeUpTestPlan {
this.setScriptSumNum(1);
this.setAccessTocken(this.login());
this.runAndGetBrief();
// tester.loadTestPlans();
// tester.runTestWithoutLogin();
}
@Test