refactor the tests

refactor the tests
This commit is contained in:
coderfengyun 2014-08-28 08:56:38 +08:00
parent aaf7f00759
commit 0d42c3e97a
1 changed files with 11 additions and 12 deletions

View File

@ -12,8 +12,6 @@ import org.bench4q.master.domain.RunningAgentInterface;
import org.bench4q.master.domain.entity.Agent; import org.bench4q.master.domain.entity.Agent;
import org.bench4q.master.domain.factory.RunningAgentFactory; import org.bench4q.master.domain.factory.RunningAgentFactory;
import org.bench4q.master.domain.valueobject.datastatistics.RunningScriptSampler; import org.bench4q.master.domain.valueobject.datastatistics.RunningScriptSampler;
import org.bench4q.share.enums.master.AgentStatus;
import org.bench4q.share.models.master.statistics.ScriptResultModel;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -31,8 +29,14 @@ public class Test_ScriptSample {
testcase2.add(Agent.createAgentWithoutId("127.0.0.2", 6565, 500)); testcase2.add(Agent.createAgentWithoutId("127.0.0.2", 6565, 500));
} }
/**
* The destiny is to justify if a runningAgent is stopped, if it will
* decrease the totalSuccessCount
*
* @throws JAXBException
*/
@Test @Test
public void test() throws JAXBException { public void testForStopOneRunningAgentWhenSample() throws JAXBException {
ArrayList<RunningAgentInterface> runningAgents = new ArrayList<RunningAgentInterface>(); ArrayList<RunningAgentInterface> runningAgents = new ArrayList<RunningAgentInterface>();
runningAgents.add(this.runningAgentFactory runningAgents.add(this.runningAgentFactory
.buildRunningAgentWithOutIdAndRunningScript( .buildRunningAgentWithOutIdAndRunningScript(
@ -41,18 +45,13 @@ public class Test_ScriptSample {
.buildRunningAgentWithOutIdAndRunningScript( .buildRunningAgentWithOutIdAndRunningScript(
this.testcase2.get(1), 20, UUID.randomUUID())); this.testcase2.get(1), 20, UUID.randomUUID()));
RunningScriptSampler sampler = new RunningScriptSampler(runningAgents); RunningScriptSampler sampler = new RunningScriptSampler(runningAgents);
long totalSuccessCountBeforeKill = sampler.getResultModelFromAgent() long totalSuccessCountBeforeStop = sampler.getResultModelFromAgent()
.getScriptBriefResultModel().getTotalSuccessCountFromBegin(); .getScriptBriefResultModel().getTotalSuccessCountFromBegin();
kill(this.testcase2.get(0)); runningAgents.get(0).stop();
long totalSuccessCountAfterKill = sampler.getResultModelFromAgent() long totalSuccessCountAfterStop = sampler.getResultModelFromAgent()
.getScriptBriefResultModel().getTotalSuccessCountFromBegin(); .getScriptBriefResultModel().getTotalSuccessCountFromBegin();
assertTrue(totalSuccessCountAfterKill >= totalSuccessCountBeforeKill); assertTrue(totalSuccessCountAfterStop >= totalSuccessCountBeforeStop);
}
private void kill(Agent agent) {
agent.setCurrentEnumStatus(AgentStatus.BreakDown);
} }
} }