Mock the httpMessenger finish

Mock the httpMessenger finish
This commit is contained in:
coderfengyun 2014-05-09 14:57:02 +08:00
parent f1d35e0d6f
commit 0d71706bbf
3 changed files with 25 additions and 4 deletions

View File

@ -175,10 +175,9 @@ public class HighAvailablePoolImpl extends CurrentLoadSubject implements
}
private void heartBeatsAndUpdateHAPool() {
this.pool.clear();
this.setCurrentAvailableLoad(0);
this.setMaxAvailableLoad((long) 0);
for (Agent agent : this.getAgentRepository().loadEntities()) {
for (Agent agent : this.getPool().values()) {
checkHeartBeat(agent);
}
this.getAgentRepository().Update(this.getPool().values());
@ -191,7 +190,6 @@ public class HighAvailablePoolImpl extends CurrentLoadSubject implements
} else {
doForHealth(model, agent);
}
this.getPool().put(agent.getHostName(), agent);
}
public ServerStatusModel queryAgentStatus(Agent agent) {

View File

@ -30,7 +30,6 @@ public class Test_HighAvailableWithActualMessenger extends
@After
public void cleanUp() {
}
@Test

View File

@ -10,6 +10,7 @@ import org.bench4q.master.domain.RunningAgentInterface;
import org.bench4q.master.domain.entity.Agent;
import org.bench4q.master.domain.factory.RunningAgentFactory;
import org.bench4q.master.domain.repository.AgentRepository;
import org.bench4q.master.domain.service.AgentService;
import org.bench4q.master.helper.SessionHelper;
import org.bench4q.master.infrastructure.highavailable.impl.HighAvailablePoolImpl;
import org.bench4q.share.communication.HttpRequester;
@ -28,6 +29,15 @@ public class Test_highAvailableWithMockMessenger {
private List<Agent> testCase1 = new ArrayList<Agent>();
{
testCase1.add(Agent.createAgentWithoutId("127.0.0.1", 6565, 500));
Agent agent = Agent.createAgentWithoutId("127.0.0.2", 6565);
agent.setCurrentStatus(AgentService.AGENT_STATUS_BreakDown);
testCase1.add(agent);
Agent agent2 = Agent.createAgentWithoutId("127.0.0.3", 6565);
agent2.setCurrentStatus(AgentService.AGENT_STATUS_InRun);
agent2.bookTest(10);
testCase1.add(agent2);
}
@Autowired
@ -38,6 +48,20 @@ public class Test_highAvailableWithMockMessenger {
assertNotNull(this.ha);
}
@Test
public void test_getCurrentAvailableLoad() {
prepareWith(this.testCase1);
assertEquals(500, this.ha.getCurrentAvailableLoad());
assertEquals(Long.valueOf(1000), this.ha.getMaxAvailableLoad());
}
private void prepareWith(List<Agent> agents) {
this.ha.getPool().clear();
for (Agent agent : this.testCase1) {
this.ha.add(agent);
}
}
@Test
public void test_applyFor() {
int loadToApply = 10;