add test about stop runningAgent twice
add test about stop runningAgent twice
This commit is contained in:
parent
ee901e8633
commit
d8cb749f6b
|
@ -22,7 +22,7 @@ public interface RunningScriptInterface {
|
|||
|
||||
public int getRequireLoad();
|
||||
|
||||
public void doForComplete();
|
||||
public boolean stop();
|
||||
|
||||
public List<TestPlanScriptResult> doAfterRun(Date sampleTime);
|
||||
|
||||
|
|
|
@ -119,123 +119,123 @@
|
|||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="15">
|
||||
<end type="SOURCE" refId="4" navigable="false">
|
||||
<attribute id="16" name="monitors"/>
|
||||
<end type="SOURCE" refId="3" navigable="false">
|
||||
<attribute id="16" name="runningAgents"/>
|
||||
<multiplicity id="17" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="5" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<realization id="18">
|
||||
<end type="SOURCE" refId="3"/>
|
||||
<end type="TARGET" refId="11"/>
|
||||
</realization>
|
||||
<association id="19">
|
||||
<end type="SOURCE" refId="5" navigable="false">
|
||||
<attribute id="20" name="results"/>
|
||||
<multiplicity id="21" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="6" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="22">
|
||||
<end type="SOURCE" refId="3" navigable="false">
|
||||
<attribute id="23" name="testPlan"/>
|
||||
<multiplicity id="24" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="4" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="25">
|
||||
<end type="SOURCE" refId="3" navigable="false">
|
||||
<attribute id="26" name="planedConfig"/>
|
||||
<multiplicity id="27" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="7" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="28">
|
||||
<end type="SOURCE" refId="2" navigable="false">
|
||||
<attribute id="29" name="script"/>
|
||||
<multiplicity id="30" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="8" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="31">
|
||||
<end type="SOURCE" refId="8" navigable="false">
|
||||
<attribute id="32" name="user"/>
|
||||
<multiplicity id="33" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="9" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="34">
|
||||
<end type="SOURCE" refId="6" navigable="false">
|
||||
<attribute id="35" name="testPlanDB"/>
|
||||
<multiplicity id="36" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="4" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="37">
|
||||
<end type="SOURCE" refId="3" navigable="false">
|
||||
<attribute id="38" name="runningAgents"/>
|
||||
<multiplicity id="39" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="2" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="40">
|
||||
<end type="SOURCE" refId="6" navigable="false">
|
||||
<attribute id="41" name="monitor"/>
|
||||
<multiplicity id="42" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="5" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="43">
|
||||
<association id="18">
|
||||
<end type="SOURCE" refId="2" navigable="false">
|
||||
<attribute id="44" name="testPlanScript"/>
|
||||
<multiplicity id="45" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="3" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<realization id="46">
|
||||
<end type="SOURCE" refId="2"/>
|
||||
<end type="TARGET" refId="10"/>
|
||||
</realization>
|
||||
<association id="47">
|
||||
<end type="SOURCE" refId="4" navigable="false">
|
||||
<attribute id="48" name="testPlanScripts"/>
|
||||
<multiplicity id="49" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="3" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="50">
|
||||
<end type="SOURCE" refId="3" navigable="false">
|
||||
<attribute id="51" name="script"/>
|
||||
<multiplicity id="52" minimum="0" maximum="1"/>
|
||||
<attribute id="19" name="script"/>
|
||||
<multiplicity id="20" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="8" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="53">
|
||||
<association id="21">
|
||||
<end type="SOURCE" refId="3" navigable="false">
|
||||
<attribute id="22" name="planedConfig"/>
|
||||
<multiplicity id="23" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="7" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<realization id="24">
|
||||
<end type="SOURCE" refId="2"/>
|
||||
<end type="TARGET" refId="10"/>
|
||||
</realization>
|
||||
<realization id="25">
|
||||
<end type="SOURCE" refId="3"/>
|
||||
<end type="TARGET" refId="11"/>
|
||||
</realization>
|
||||
<association id="26">
|
||||
<end type="SOURCE" refId="3" navigable="false">
|
||||
<attribute id="27" name="script"/>
|
||||
<multiplicity id="28" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="8" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="29">
|
||||
<end type="SOURCE" refId="2" navigable="false">
|
||||
<attribute id="30" name="testPlanScript"/>
|
||||
<multiplicity id="31" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="3" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="32">
|
||||
<end type="SOURCE" refId="5" navigable="false">
|
||||
<attribute id="54" name="testPlan"/>
|
||||
<multiplicity id="55" minimum="0" maximum="1"/>
|
||||
<attribute id="33" name="results"/>
|
||||
<multiplicity id="34" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="6" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="35">
|
||||
<end type="SOURCE" refId="4" navigable="false">
|
||||
<attribute id="36" name="user"/>
|
||||
<multiplicity id="37" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="9" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="38">
|
||||
<end type="SOURCE" refId="4" navigable="false">
|
||||
<attribute id="39" name="monitors"/>
|
||||
<multiplicity id="40" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="5" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="41">
|
||||
<end type="SOURCE" refId="8" navigable="false">
|
||||
<attribute id="42" name="user"/>
|
||||
<multiplicity id="43" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="9" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="44">
|
||||
<end type="SOURCE" refId="6" navigable="false">
|
||||
<attribute id="45" name="testPlanDB"/>
|
||||
<multiplicity id="46" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="4" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="56">
|
||||
<association id="47">
|
||||
<end type="SOURCE" refId="6" navigable="false">
|
||||
<attribute id="48" name="monitor"/>
|
||||
<multiplicity id="49" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="5" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="50">
|
||||
<end type="SOURCE" refId="3" navigable="false">
|
||||
<attribute id="51" name="testPlan"/>
|
||||
<multiplicity id="52" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="4" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="53">
|
||||
<end type="SOURCE" refId="4" navigable="false">
|
||||
<attribute id="57" name="user"/>
|
||||
<attribute id="54" name="testPlanScripts"/>
|
||||
<multiplicity id="55" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="3" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="56">
|
||||
<end type="SOURCE" refId="5" navigable="false">
|
||||
<attribute id="57" name="testPlan"/>
|
||||
<multiplicity id="58" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="9" navigable="true"/>
|
||||
<end type="TARGET" refId="4" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||
|
|
|
@ -35,6 +35,7 @@ public class RunningAgentDB implements RunningAgentInterface {
|
|||
private AgentMessenger agentMessenger;
|
||||
private AgentRepository agentRepository;
|
||||
private boolean hasSubstitute;
|
||||
private boolean stoped;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
|
@ -132,6 +133,15 @@ public class RunningAgentDB implements RunningAgentInterface {
|
|||
this.hasSubstitute = hasSubstitute;
|
||||
}
|
||||
|
||||
@Transient
|
||||
private boolean isStoped() {
|
||||
return stoped;
|
||||
}
|
||||
|
||||
private void setStoped(boolean hasStoped) {
|
||||
this.stoped = hasStoped;
|
||||
}
|
||||
|
||||
public static RunningAgentDB buildRunningAgentDBWithoutId(Agent agent,
|
||||
int loadInUse, TestPlanScript testPlanScript, UUID agentRunId) {
|
||||
RunningAgentDB runningAgentDB = new RunningAgentDB();
|
||||
|
@ -195,10 +205,16 @@ public class RunningAgentDB implements RunningAgentInterface {
|
|||
}
|
||||
|
||||
public boolean stop() {
|
||||
if (this.isStoped()) {
|
||||
return true;
|
||||
}
|
||||
StopTestModel result = this.getAgentMessenger().stop(getAgent(),
|
||||
getAgentRunId());
|
||||
this.getAgent().backLoad(this.getLoadInUse());
|
||||
this.getAgentRepository().update(this.getAgent());
|
||||
if (result != null) {
|
||||
this.setStoped(result.isSuccess());
|
||||
}
|
||||
return result != null && result.isSuccess();
|
||||
}
|
||||
|
||||
|
|
|
@ -212,6 +212,16 @@ public class TestPlan implements IAggregate {
|
|||
this.update();
|
||||
}
|
||||
|
||||
public boolean stop() {
|
||||
boolean result = true;
|
||||
for (TestPlanScript runningScript : this.getTestPlanScripts()) {
|
||||
if (!runningScript.stop()) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean applyForLoad() {
|
||||
boolean result = true;
|
||||
TestPlanStatus currentStatus = TestPlanStatus.valueOf(this
|
||||
|
|
|
@ -191,7 +191,7 @@ public class TestPlanScript implements RunningScriptInterface {
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean scheduleAsConfig() {
|
||||
private boolean scheduleAsConfig() {
|
||||
PlanedConfig testScriptConfig = this.getPlanedConfig();
|
||||
if (testScriptConfig == null) {
|
||||
return false;
|
||||
|
@ -274,7 +274,8 @@ public class TestPlanScript implements RunningScriptInterface {
|
|||
return true;
|
||||
}
|
||||
|
||||
public void doForComplete() {
|
||||
public boolean stop() {
|
||||
boolean result = true;
|
||||
for (RunningAgentInterface runningAgent : this.getRunningAgentsDB()) {
|
||||
if (runningAgent == null) {
|
||||
continue;
|
||||
|
@ -283,11 +284,13 @@ public class TestPlanScript implements RunningScriptInterface {
|
|||
logger.error("can't stop the agent with hostName"
|
||||
+ runningAgent.getAgent().getHostName()
|
||||
+ "and currentRunId is " + runningAgent.getAgentRunId());
|
||||
result = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
this.setFinish(true);
|
||||
this.getTestPlan().update();
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean run() {
|
||||
|
|
|
@ -112,12 +112,24 @@ public class TestPlanEngine implements TaskCompleteCallback,
|
|||
return testPlanId;
|
||||
}
|
||||
|
||||
public boolean stop(final UUID testPlanRunId) {
|
||||
TestPlan testPlan = this.getTestPlanRepository().getRunningTestPlanBy(
|
||||
testPlanRunId);
|
||||
if (testPlan == null) {
|
||||
return false;
|
||||
}
|
||||
boolean result = testPlan.stop();
|
||||
this.doTaskComplete(testPlanRunId);
|
||||
logger.info("The user abort this testPlan!");
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean submitTestPlan(final TestPlanModel testPlanBusinessModel,
|
||||
final User user, final UUID testPlanRunId) {
|
||||
try {
|
||||
TestPlan testPlan = this.getTestPlanFactory()
|
||||
.createATestPlanWithoutId(testPlanBusinessModel,
|
||||
user, testPlanRunId);
|
||||
.createATestPlanWithoutId(testPlanBusinessModel, user,
|
||||
testPlanRunId);
|
||||
Logger.getLogger(TestPlanService.class).info(
|
||||
"test plan name:" + testPlan.getName());
|
||||
return this.getTestPlanRepository().attach(testPlan);
|
||||
|
|
|
@ -43,7 +43,7 @@ public class ExecutionOverTask extends TimerTask {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
this.getRunningScript().doForComplete();
|
||||
this.getRunningScript().stop();
|
||||
this.getTaskCompleteCallback().doTaskComplete(
|
||||
this.getRunningScript().getTestPlanID());
|
||||
System.out.println("execute ExecutionOverTask");
|
||||
|
|
|
@ -76,7 +76,7 @@ public class TestPlanLoadApplication implements Transaction {
|
|||
public void rollBack() {
|
||||
for (TestPlanScript testPlanScript : this.getTestPlan()
|
||||
.getTestPlanScripts()) {
|
||||
testPlanScript.doForComplete();
|
||||
testPlanScript.stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -233,7 +233,7 @@ public class TestBase_MakeUpTestPlan extends TestBase {
|
|||
.extracSpecifiedScript(getScriptId()));
|
||||
RunningScriptInterface runningScript = testPlan
|
||||
.extracSpecifiedScript(getScriptId());
|
||||
runningScript.doForComplete();
|
||||
runningScript.stop();
|
||||
if (runningAgent == null)
|
||||
return;
|
||||
this.getAgentMessenger().stop(runningAgent.getAgent(),
|
||||
|
|
|
@ -4,11 +4,14 @@ import static org.junit.Assert.*;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.domain.RunningAgentInterface;
|
||||
import org.bench4q.master.domain.entity.Agent;
|
||||
import org.bench4q.master.domain.entity.RunningAgentDB;
|
||||
import org.bench4q.master.domain.entity.TestPlan;
|
||||
import org.bench4q.master.domain.entity.TestPlanScript;
|
||||
import org.bench4q.master.domain.factory.RunningAgentFactory;
|
||||
import org.bench4q.master.domain.valueobject.transaction.TransactionFactory;
|
||||
import org.bench4q.master.domain.valueobject.transaction.impl.ScriptLoadApplication;
|
||||
import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan;
|
||||
|
@ -24,6 +27,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|||
@ContextConfiguration(locations = { "classpath:mockHttpMesseger-context.xml" })
|
||||
public class Test_RunningAgent extends TestBase_MakeUpTestPlan {
|
||||
|
||||
@Autowired
|
||||
private RunningAgentFactory runningAgentFactory;
|
||||
|
||||
@Autowired
|
||||
private TransactionFactory transactionFactory;
|
||||
|
||||
|
@ -57,7 +63,7 @@ public class Test_RunningAgent extends TestBase_MakeUpTestPlan {
|
|||
assertNotNull(runningAgentDB.getAgentMessenger());
|
||||
assertTrue(runningAgentDB.distributeScriptAndParams());
|
||||
assertNotNull(runningAgentDB.distributeScriptAndParams());
|
||||
runningScript.doForComplete();
|
||||
runningScript.stop();
|
||||
this.getTestPlanEngine().doTaskComplete(getTestPlanRunIdUuid());
|
||||
}
|
||||
|
||||
|
@ -96,4 +102,47 @@ public class Test_RunningAgent extends TestBase_MakeUpTestPlan {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_stopTwiceInPractice() {
|
||||
synchronized (this.getHaPool()) {
|
||||
TestPlanScript runningScript = this.getTestPlanRepository()
|
||||
.getTestPlanInDomainBy(getTestPlanRunIdUuid())
|
||||
.extracSpecifiedScript(getScriptId());
|
||||
int currentLoadBeforeRun = this.getHaPool()
|
||||
.getCurrentAvailableLoad();
|
||||
assertEquals(1000, currentLoadBeforeRun);
|
||||
this.getTestPlanEngine().doRunTestPlan(this.getTestPlanRunIdUuid());
|
||||
RunningAgentInterface runningAgent = (RunningAgentInterface) refetchRunningScript()
|
||||
.getRunningAgents().toArray()[0];
|
||||
String hostName = runningAgent.getAgent().getHostName();
|
||||
assertTrue(runningAgent.stop());
|
||||
// refetch runningScript
|
||||
runningScript = refetchRunningScript();
|
||||
for (RunningAgentInterface runningAgentInterface : runningScript
|
||||
.getRunningAgents()) {
|
||||
if (runningAgentInterface.getAgent().getHostName()
|
||||
.equals(hostName)) {
|
||||
assertTrue(runningAgentInterface.stop());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private TestPlanScript refetchRunningScript() {
|
||||
TestPlan runningTestPlanBy = this.getTestPlanRepository()
|
||||
.getRunningTestPlanBy(getTestPlanRunIdUuid());
|
||||
return runningTestPlanBy.extracSpecifiedScript(getScriptId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_stopTwice() {
|
||||
RunningAgentDB runningAgentDB = RunningAgentDB
|
||||
.buildRunningAgentDBWithoutId(this.testcase2.get(0), 10, null,
|
||||
UUID.randomUUID());
|
||||
this.runningAgentFactory.convertToDomain(runningAgentDB);
|
||||
assertTrue(runningAgentDB.run());
|
||||
assertTrue(runningAgentDB.stop());
|
||||
assertTrue(runningAgentDB.stop());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ public class Test_TestPlan extends TestBase_MakeUpTestPlan {
|
|||
TestPlanScript script = testPlanInDomain
|
||||
.extracSpecifiedScript(getUserFirstScript(this
|
||||
.getUserRepository().getUser("admin")));
|
||||
script.doForComplete();
|
||||
script.stop();
|
||||
assertTrue(script.isFinish());
|
||||
this.getHaPool().checkAllHeartBeat();
|
||||
assertEquals(startLoad, this.getHaPool().getCurrentAvailableLoad());
|
||||
|
|
|
@ -99,7 +99,7 @@ public class Test_TestPlanEngine extends TestBase_MakeUpTestPlan {
|
|||
.getRunningTestPlanBy(getTestPlanRunIdUuid())
|
||||
.getCurrentStatus()));
|
||||
for (TestPlanScript testPlanScript : testPlan.getTestPlanScripts()) {
|
||||
testPlanScript.doForComplete();
|
||||
testPlanScript.stop();
|
||||
}
|
||||
this.getTestPlanEngine().doTaskComplete(getTestPlanRunIdUuid());
|
||||
}
|
||||
|
|
|
@ -50,10 +50,10 @@ public class Mock_AgentMessenger implements AgentMessenger {
|
|||
|
||||
@Override
|
||||
public StopTestModel stop(Agent agent, UUID runId) {
|
||||
if (runId == this.testId) {
|
||||
return new StopTestModel(true);
|
||||
}
|
||||
return new StopTestModel(false);
|
||||
// if (runId == this.testId) {
|
||||
// return new StopTestModel(true);
|
||||
// }
|
||||
return new StopTestModel(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue