@Test(groups = "conn")
public void firstAndSecondUrlInactive()
  throws Exception
{

  final RandomConnectionStrategy strategy = new RandomConnectionStrategy();
  final ConnectionConfig cc = new ConnectionConfig();
  cc.setLdapUrl("ldap://directory-1.ldaptive.org ldap://directory-2.ldaptive.org ldap://directory-3.ldaptive.org");
  cc.setConnectionStrategy(strategy);
  final MockConnection conn = new MockConnection(cc);
  conn.setOpenPredicate(new Predicate<>() {
    private int count;
    @Override
    public boolean test(final LdapURL url)
    {
      if (count == 0 || count == 1) {
        count++;
        return false;
      }
      return true;
    }
  });
  conn.setTestPredicate(ldapURL -> true);
  Assert.assertEquals(strategy.ldapURLSet.getActiveUrls().size(), 3);
  Assert.assertEquals(strategy.ldapURLSet.getInactiveUrls().size(), 0);
  // first and second entry should fail
  conn.open();
  Assert.assertEquals(strategy.ldapURLSet.getActiveUrls().size(), 1);
  Assert.assertEquals(strategy.ldapURLSet.getInactiveUrls().size(), 2);
  // confirm the inactive entries stay at the end
  List<LdapURL> applyList = StreamSupport.stream(strategy.spliterator(), false).collect(Collectors.toList());
  Assert.assertEquals(applyList.size(), 3);
  Assert.assertTrue(strategy.ldapURLSet.getActiveUrls().contains(applyList.get(0)));
  Assert.assertTrue(
    strategy.ldapURLSet.getInactiveUrls().contains(applyList.get(1)));
  Assert.assertTrue(
    strategy.ldapURLSet.getInactiveUrls().contains(applyList.get(2)));
  // mark first entry as active
  strategy.success(strategy.ldapURLSet.getInactiveUrls().iterator().next());
  applyList = StreamSupport.stream(strategy.spliterator(), false).collect(Collectors.toList());
  Assert.assertEquals(applyList.size(), 3);
  Assert.assertEquals(strategy.ldapURLSet.getActiveUrls().size(), 2);
  Assert.assertEquals(strategy.ldapURLSet.getInactiveUrls().size(), 1);
  Assert.assertTrue(strategy.ldapURLSet.getActiveUrls().contains(applyList.get(0)));
  Assert.assertTrue(strategy.ldapURLSet.getActiveUrls().contains(applyList.get(1)));
  Assert.assertTrue(
    strategy.ldapURLSet.getInactiveUrls().contains(applyList.get(2)));
  // mark second entry as active
  strategy.success(strategy.ldapURLSet.getInactiveUrls().iterator().next());
  applyList = StreamSupport.stream(strategy.spliterator(), false).collect(Collectors.toList());
  Assert.assertEquals(applyList.size(), 3);
  Assert.assertEquals(strategy.ldapURLSet.getActiveUrls().size(), 3);
  Assert.assertEquals(strategy.ldapURLSet.getInactiveUrls().size(), 0);
  Assert.assertTrue(strategy.ldapURLSet.getActiveUrls().contains(applyList.get(0)));
  Assert.assertTrue(strategy.ldapURLSet.getActiveUrls().contains(applyList.get(1)));
  Assert.assertTrue(strategy.ldapURLSet.getActiveUrls().contains(applyList.get(2)));
}