@Test
public void testGetConnectionsFromRingWhenHostDown() throws Exception {

    HostSelectionWithFallback<Integer> selection = new HostSelectionWithFallback<Integer>(cpConfig, cpMonitor);
    Map<Host, HostConnectionPool<Integer>> pools = new HashMap<Host, HostConnectionPool<Integer>>();
    for (Host host : hosts) {
        poolStatus.put(host, new AtomicBoolean(true));
        pools.put(host, getMockHostConnectionPool(host, poolStatus.get(host)));
    }
    selection.initWithHosts(pools);
    // Put Host H1 as DOWN
    h1.setStatus(Status.Down);
    Collection<String> hostnames = runConnectionsToRingTest(selection);
    verifyPresent(hostnames, "h2");
    verifyAtLeastOnePresent(hostnames, "h3", "h5");
    // Put Host H2 as DOWN
    selection.initWithHosts(pools);
    h1.setStatus(Status.Up);
    h2.setStatus(Status.Down);
    hostnames = runConnectionsToRingTest(selection);
    verifyPresent(hostnames, "h1");
    verifyAtLeastOnePresent(hostnames, "h4", "h6");
    // Put Hosts H1 and H2 as DOWN
    selection.initWithHosts(pools);
    h1.setStatus(Status.Down);
    h2.setStatus(Status.Down);
    hostnames = runConnectionsToRingTest(selection);
    verifyAtLeastOnePresent(hostnames, "h3", "h5");
    verifyAtLeastOnePresent(hostnames, "h4", "h6");
    // Put Hosts H1,H2,H3 as DOWN
    selection.initWithHosts(pools);
    h1.setStatus(Status.Down);
    h2.setStatus(Status.Down);
    h3.setStatus(Status.Down);
    hostnames = runConnectionsToRingTest(selection);
    verifyAtLeastOnePresent(hostnames, "h4", "h6");
    verifyPresent(hostnames, "h5");
    // Put Hosts H1,H2,H3,H4 as DOWN
    selection.initWithHosts(pools);
    h1.setStatus(Status.Down);
    h2.setStatus(Status.Down);
    h3.setStatus(Status.Down);
    h4.setStatus(Status.Down);
    hostnames = runConnectionsToRingTest(selection);
    verifyExactly(hostnames, "h5", "h6");
}