add tests and faultTolerances

This commit is contained in:
coderfengyun 2014-02-27 17:32:51 +08:00
parent 067cac6ac0
commit 44f36e8a7a
2 changed files with 128 additions and 0 deletions

View File

@ -0,0 +1,17 @@
package org.bench4q.master.testplan.highavailable.faultolerence;
import org.bench4q.master.domain.entity.Agent;
import org.bench4q.share.models.agent.RunScenarioModel;
public class FaultTolerenceFactory {
private static final BriefAgentFault briefAgentFault = new BriefAgentFault();
public static FaultTolerance getBriefFaultTolerance() {
return briefAgentFault;
}
public static FaultTolerance getRunAgentFault(Agent agent,
RunScenarioModel runScenarioModel) {
return new RunAgentFault(agent, runScenarioModel);
}
}

View File

@ -0,0 +1,111 @@
package org.bench4q.master.test.service;
import org.bench4q.master.domain.entity.TestPlan;
import org.bench4q.master.domain.entity.User;
import org.bench4q.master.domain.service.TestPlanEngine;
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
import org.bench4q.share.enums.master.TestPlanStatus;
import org.bench4q.share.helper.TestHelper;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.*;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:service-test-context.xml" })
public class Test_TestPlanEngine extends TestBase_MakeUpTestPlan {
@Before
public void prepare() {
}
@After
public void cleanUp() {
}
@Test
public void testCommintComplete() throws Exception {
TestPlanStatus status = TestPlanStatus.Complete;
testForStatus(status);
}
@Test
public void testCommitError() throws Exception {
testForStatus(TestPlanStatus.Error);
}
@Test
public void testInRunning() throws Exception {
testForStatus(TestPlanStatus.InRunning);
}
@Test
public void testRunTestPlanRightly() throws InterruptedException {
System.out.println("This need 127.0.0.1 in running!!!");
assertNotNull(this.getAgentMessenger().askLiving(Test_AGENT_HOSTNAME,
TEST_PORT));
User user = this.getUserRepository().getUser("admin");
int scriptId = getUserFirstScript(user);
this.getHaPool().timerTask();
this.setTestPlanRunIdUuid(this.getTestPlanEngine().runWith(
createATestPlanWithOneScript(scriptId), user));
Thread.sleep(10000);
assertEquals(
TestPlanStatus.InRunning,
TestPlanStatus.valueOf(this.getTestPlanRepository()
.getTestPlanBy(getTestPlanRunIdUuid())
.getCurrentStatus()));
assertEquals(
TestPlanStatus.InRunning,
TestPlanStatus.valueOf(this.getTestPlanRepository()
.getRunningTestPlanBy(getTestPlanRunIdUuid())
.getCurrentStatus()));
cleanUpForTestPlanRunning();
}
@Test
public void testRunWithWronglyWhenNoEnoughLoadInPool()
throws InterruptedException {
System.out.println("This need each agent not in running");
User user = this.getUserRepository().getUser("admin");
int scriptId = getUserFirstScript(user);
this.setTestPlanRunIdUuid(this.getTestPlanEngine().runWith(
createATestPlanWithOneScript(scriptId), user));
Thread.sleep(10000);
assertEquals(
TestPlanStatus.Error,
TestPlanStatus.valueOf(this.getTestPlanRepository()
.getTestPlanBy(getTestPlanRunIdUuid())
.getCurrentStatus()));
assertNull(this.getTestPlanRepository().getRunningTestPlanBy(
getTestPlanRunIdUuid()));
deleteTestPlan();
}
private void testForStatus(TestPlanStatus status) throws Exception {
this.submitATestPlanWithOneScript();
TestPlan testPlan = this.getTestPlanRepository().getTestPlanBy(
getTestPlanRunIdUuid());
testPlan.run();
this.getTestPlanRepository().attachRunningTestPlan(testPlan);
TestHelper.invokePrivateMethod(TestPlanEngine.class, this
.getTestPlanEngine(), "commit" + status.name(),
new Class[] { TestPlan.class },
new Object[] { this.getTestPlanRepository()
.getRunningTestPlanBy(getTestPlanRunIdUuid()) });
assertEquals(status,
TestPlanStatus.valueOf(testPlan.getCurrentStatus()));
assertEquals(
status,
TestPlanStatus.valueOf(this.getTestPlanRepository()
.getRunningTestPlanBy(getTestPlanRunIdUuid())
.getCurrentStatus()));
deleteTestPlan();
}
}