}
@Test
public void testConsole() throws GrinderException, InterruptedException {
agentThread1 = new AgentDaemon(agentConfig1);
agentThread1.run(console1.getConsolePort());
agentThread2 = new AgentDaemon(agentConfig2);
agentThread2.run(console1.getConsolePort());
// Wait until all agents are started. They will connect main console.
sleep(4000);
assertThat("There must be 2 agents connecting console1", console1.getAllAttachedAgents().size(), is(2));
// if we shut down one agent.
agentThread2.addListener(new AgentShutDownSynchronizeListener(condition));
agentThread2.shutdown();
sleep(5000);
waitOnCondition(condition, 5000);
assertThat("There must be 1 agents connecting console1", console1.getAllAttachedAgents().size(), is(1));
// If we connect console1 again
agentThread2.run(console1.getConsolePort());
sleep(4000);
assertThat("There must be 2 agents connecting console1", console1.getAllAttachedAgents().size(), is(2));
// enable one agent more.
agentThread3 = new AgentDaemon(agentConfig3);
agentThread3.run(console2.getConsolePort());
Thread.sleep(4000);
// Now it should be 2 agents