when testplan is finished,stop the doAfterRun thread in testplan

This commit is contained in:
fanfuxiaoran 2014-04-04 14:31:51 +08:00
parent 3603b08369
commit cc0cdd834d
7 changed files with 37 additions and 29 deletions

View File

@ -89,9 +89,7 @@ public class Monitor extends Observable {
}
public void doAfterRun(Boolean testPlanFinished) {
if (testPlanFinished)
return;
public void doAfterRun() {
try {
MonitorMain monitorResult = getTestMonitorSampler()
.getMonitorResult(hostName, port);

View File

@ -184,18 +184,23 @@ public class TestPlan implements IAggregate {
return this.getLoadDistribute().generateLoadForTestPlan(this);
}
// need to end this thread when testPlan is finish
public void doAfterRun() {
try {
ScheduledExecutorService sheScheduledExecutorService = Executors
.newScheduledThreadPool(10);
sheScheduledExecutorService.scheduleAtFixedRate(new Runnable() {
final ScheduledExecutorService scheScheduledExecutorService = Executors
.newScheduledThreadPool(1);
scheScheduledExecutorService.scheduleAtFixedRate(new Runnable() {
public void run() {
if (isFinish()) {
scheScheduledExecutorService.shutdown();
}
for (TestPlanScript testPlanScript : getTestPlanScripts()) {
testPlanScript.doAfterRun();
}
if (getMonitors() != null) {
for (Monitor monitor : getMonitors()) {
monitor.doAfterRun(isFinish());
monitor.doAfterRun();
}
}

View File

@ -1,4 +1,4 @@
portToServe=8080
portToServe=7979
pickTestPlanCycleInSeconds=60
maxFailTime=10
minExcuteIntervalInSeconds=600

View File

@ -27,7 +27,7 @@ public class Test_Monitor extends TestBase_MakeUpTestPlan {
getTestPlanRunIdUuid());
assertEquals(1, testPlan.getMonitors().size());
for (Monitor monitor : testPlan.getMonitors()) {
monitor.doAfterRun(testPlan.isFinish());
monitor.doAfterRun();
}
}

View File

@ -1,4 +1,4 @@
package org.bench4q.mater.test.entity;
package org.bench4q.master.test.entity;
import static org.junit.Assert.*;
@ -28,7 +28,7 @@ public class Test_Monitor extends TestBase_MakeUpTestPlan {
getTestPlanRunIdUuid());
assertEquals(1, testPlan.getMonitors().size());
for (Monitor monitor : testPlan.getMonitors()) {
monitor.doAfterRun(false);
monitor.doAfterRun();
}
for (Monitor monitor : getTestPlanRepository().getTestPlanBy(
getTestPlanRunIdUuid()).getMonitors()) {

View File

@ -1,4 +1,4 @@
package org.bench4q.mater.test.entity;
package org.bench4q.master.test.entity;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@ -62,28 +62,32 @@ public class Test_TestPlan extends TestBase_MakeUpTestPlan {
@Test
public void testDoAfterRun() throws InterruptedException, JAXBException {
assertNotNull(getTestPlanRunIdUuid());
try{
TestPlan testPlanInDomain = this.getTestPlanFactory().convertToDomain(
this.getTestPlanRepository().getTestPlanBy(
getTestPlanRunIdUuid()));
assertEquals(TestPlanStatus.InRunning, testPlanInDomain.run());
Thread.sleep(4000);
for (Monitor monitor : getTestPlan().getMonitors()) {
assertTrue(monitor.getResults().size() > 0);
}
for (TestPlanScript testPlanScript : getTestPlan().getTestPlanScripts()) {
Logger.getLogger(Test_TestPlan.class)
.info("testPlanScript:"+
testPlanScript.getTestPlanScriptResults().size());
assertTrue(testPlanScript.getTestPlanScriptResults().size() > 1);
}
}catch(Exception e){
try {
TestPlan testPlanInDomain = this.getTestPlanFactory()
.convertToDomain(
this.getTestPlanRepository().getTestPlanBy(
getTestPlanRunIdUuid()));
assertEquals(TestPlanStatus.InRunning, testPlanInDomain.run());
Thread.sleep(4000);
for (Monitor monitor : getTestPlan().getMonitors()) {
assertTrue(monitor.getResults().size() > 0);
}
for (TestPlanScript testPlanScript : getTestPlan()
.getTestPlanScripts()) {
Logger.getLogger(Test_TestPlan.class).info(
"testPlanScript:"
+ testPlanScript.getTestPlanScriptResults()
.size());
assertTrue(testPlanScript.getTestPlanScriptResults().size() > 1);
}
} catch (Exception e) {
Logger.getLogger(Test_TestPlan.class).info(
ExceptionLog.getStackTrace(e));
}
}
private TestPlan getTestPlan() {
TestPlan testPlanFromRepo = this.getTestPlanRepository().getTestPlanBy(
getTestPlanRunIdUuid());

View File

@ -313,5 +313,6 @@ public class TestPlanTester extends TestBase_MakeUpTestPlan {
this.httpRequester.sendGet(this._url + "/getTestPlanReport", params,
this.makeAccessTockenMap(this.getAccessTocken()));
}
}