a little step towards mock test
a little step towards mock test
This commit is contained in:
parent
a031286fc6
commit
f1d35e0d6f
|
@ -14,12 +14,29 @@ import org.springframework.stereotype.Component;
|
|||
|
||||
@Component
|
||||
public class RunningAgentFactory {
|
||||
@Autowired
|
||||
|
||||
private AgentMessenger agentMessenger;
|
||||
|
||||
@Autowired
|
||||
private AgentRepository agentRepository;
|
||||
|
||||
private AgentMessenger getAgentMessenger() {
|
||||
return agentMessenger;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setAgentMessenger(AgentMessenger agentMessenger) {
|
||||
this.agentMessenger = agentMessenger;
|
||||
}
|
||||
|
||||
private AgentRepository getAgentRepository() {
|
||||
return agentRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setAgentRepository(AgentRepository agentRepository) {
|
||||
this.agentRepository = agentRepository;
|
||||
}
|
||||
|
||||
public RunningAgentInterface buildRunningAgentDBWithoutId(Agent agent,
|
||||
int loadInUse, RunningScriptInterface runningScript, UUID agentRunId) {
|
||||
RunningAgentDB runningAgent = RunningAgentDB
|
||||
|
@ -44,7 +61,7 @@ public class RunningAgentFactory {
|
|||
}
|
||||
|
||||
public void convertToDomain(RunningAgentDB fromReop) {
|
||||
fromReop.setAgentMessenger(this.agentMessenger);
|
||||
fromReop.setAgentRepository(this.agentRepository);
|
||||
fromReop.setAgentMessenger(this.getAgentMessenger());
|
||||
fromReop.setAgentRepository(this.getAgentRepository());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,6 @@ public class HighAvailablePoolImpl extends CurrentLoadSubject implements
|
|||
return agentRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setAgentRepository(AgentRepository agentRepository) {
|
||||
this.agentRepository = agentRepository;
|
||||
}
|
||||
|
@ -122,12 +121,21 @@ public class HighAvailablePoolImpl extends CurrentLoadSubject implements
|
|||
this.agentRunIdShouldBeSubstitute = agentRunIdShouldBeSubstitute;
|
||||
}
|
||||
|
||||
public HighAvailablePoolImpl() {
|
||||
@Autowired
|
||||
public HighAvailablePoolImpl(AgentRepository agentRepository) {
|
||||
this.setPool(new HashMap<String, Agent>());
|
||||
this.setAgentRunBlotters(new HashMap<UUID, RunningAgentInterface>());
|
||||
this.setAgentStatusOfPreviousBeatMap(new HashMap<String, ServerStatusModel>());
|
||||
this.setCurrentAvailableLoad(0);
|
||||
this.setAgentRunIdShouldBeSubstitute(new LinkedList<UUID>());
|
||||
this.setAgentRepository(agentRepository);
|
||||
initialPool();
|
||||
}
|
||||
|
||||
private void initialPool() {
|
||||
for (Agent agent : this.getAgentRepository().loadEntities()) {
|
||||
this.add(agent);
|
||||
}
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0,30 */1 * * * *")
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.List;
|
|||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.domain.entity.Agent;
|
||||
import org.bench4q.master.domain.service.AgentService;
|
||||
import org.bench4q.master.infrastructure.communication.AgentMessenger;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
import org.bench4q.share.models.agent.RunScenarioResultModel;
|
||||
|
@ -14,7 +15,9 @@ import org.bench4q.share.models.agent.TestBriefStatusModel;
|
|||
import org.bench4q.share.models.agent.statistics.AgentBehaviorsBriefModel;
|
||||
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
|
||||
import org.bench4q.share.models.agent.statistics.AgentPagesBriefModel;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class Mock_AgentMessenger implements AgentMessenger {
|
||||
|
||||
private UUID testId = UUID.randomUUID();
|
||||
|
@ -47,11 +50,23 @@ public class Mock_AgentMessenger implements AgentMessenger {
|
|||
|
||||
@Override
|
||||
public StopTestModel stop(Agent agent, UUID runId) {
|
||||
return new StopTestModel(true);
|
||||
if (runId == this.testId) {
|
||||
return new StopTestModel(true);
|
||||
}
|
||||
return new StopTestModel(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerStatusModel getStatus(Agent agent) {
|
||||
ServerStatusModel result = new ServerStatusModel();
|
||||
if (agent.getCurrentStatus() == AgentService.AGENT_STATUS_Idel) {
|
||||
return result;
|
||||
} else if (agent.getCurrentStatus() == AgentService.AGENT_STATUS_BreakDown) {
|
||||
return null;
|
||||
} else if (agent.getCurrentStatus() == AgentService.AGENT_STATUS_InRun) {
|
||||
result.getRunningTests().add(UUID.randomUUID());
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,11 @@ 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.factory.RunningAgentFactory;
|
||||
import org.bench4q.master.domain.repository.AgentRepository;
|
||||
import org.bench4q.master.helper.SessionHelper;
|
||||
import org.bench4q.master.infrastructure.highavailable.impl.HighAvailablePoolImpl;
|
||||
|
@ -19,7 +22,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { HighAvailablePoolImpl.class,
|
||||
AgentRepository.class, Mock_AgentMessenger.class, HttpRequester.class,
|
||||
SessionHelper.class })
|
||||
SessionHelper.class, RunningAgentFactory.class })
|
||||
public class Test_highAvailableWithMockMessenger {
|
||||
|
||||
private List<Agent> testCase1 = new ArrayList<Agent>();
|
||||
|
@ -37,6 +40,23 @@ public class Test_highAvailableWithMockMessenger {
|
|||
|
||||
@Test
|
||||
public void test_applyFor() {
|
||||
|
||||
int loadToApply = 10;
|
||||
this.ha.checkAllHeartBeat();
|
||||
List<RunningAgentInterface> result = null;
|
||||
synchronized (this.ha) {
|
||||
assertTrue(this.ha.getCurrentAvailableLoad() > loadToApply);
|
||||
result = this.ha.applyFor(loadToApply);
|
||||
}
|
||||
assertEquals(1, result.size());
|
||||
assertEquals(1, result.size());
|
||||
assertEquals(loadToApply, result.get(0).getLoadInUse());
|
||||
UUID runId = result.get(0).getAgentRunId();
|
||||
assertNotNull(runId);
|
||||
assertNull(result.get(0).getRunningScript());
|
||||
assertEquals(1, this.ha.getAgentRunBlotters().size());
|
||||
assertEquals(result.get(0), this.ha.getAgentRunBlotters().get(runId));
|
||||
for (RunningAgentInterface runningAgent : result) {
|
||||
assertTrue(runningAgent.stop());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.bench4q.share.models.agent;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -9,8 +10,8 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||
|
||||
@XmlRootElement(name = "serverStatus")
|
||||
public class ServerStatusModel {
|
||||
private List<UUID> runningTests;
|
||||
private List<UUID> finishedTests;
|
||||
private List<UUID> runningTests = new LinkedList<UUID>();
|
||||
private List<UUID> finishedTests = new LinkedList<UUID>();
|
||||
|
||||
@XmlElementWrapper(name = "runningTests")
|
||||
@XmlElement(name = "runningTest")
|
||||
|
|
Loading…
Reference in New Issue