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

  final ActivePassiveConnectionStrategy strategy = new ActivePassiveConnectionStrategy();
  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(ldapURL -> !ldapURL.getHostname().contains("-1") && !ldapURL.getHostname().contains("-2"));
  conn.setTestPredicate(ldapURL -> true);
  Assert.assertEquals(strategy.ldapURLSet.getActiveUrls().size(), 3);
  Assert.assertEquals(
    strategy.ldapURLSet.getActiveUrls(),
    Arrays.asList(
      new LdapURL("ldap://directory-1.ldaptive.org"),
      new LdapURL("ldap://directory-2.ldaptive.org"),
      new LdapURL("ldap://directory-3.ldaptive.org")));
  Assert.assertEquals(strategy.ldapURLSet.getInactiveUrls().size(), 0);
  // first and second entry should fail, list should reorder with those entries last
  conn.open();
  Assert.assertEquals(strategy.ldapURLSet.getActiveUrls().size(), 1);
  Assert.assertEquals(
    strategy.ldapURLSet.getActiveUrls().iterator().next(),
    new LdapURL("ldap://directory-3.ldaptive.org"));
  Assert.assertEquals(strategy.ldapURLSet.getInactiveUrls().size(), 2);
  Assert.assertEquals(
    strategy.ldapURLSet.getInactiveUrls(),
    Arrays.asList(
      new LdapURL("ldap://directory-1.ldaptive.org"),
      new LdapURL("ldap://directory-2.ldaptive.org")));
  // confirm the inactive entries stay at the end
  Assert.assertEquals(
    StreamSupport.stream(strategy.spliterator(), false).collect(Collectors.toList()),
    Arrays.asList(
      new LdapURL("ldap://directory-3.ldaptive.org"),
      new LdapURL("ldap://directory-1.ldaptive.org"),
      new LdapURL("ldap://directory-2.ldaptive.org")));
  Assert.assertEquals(strategy.ldapURLSet.getActiveUrls().size(), 1);
  Assert.assertEquals(
    strategy.ldapURLSet.getActiveUrls().iterator().next(),
    new LdapURL("ldap://directory-3.ldaptive.org"));
  Assert.assertEquals(strategy.ldapURLSet.getInactiveUrls().size(), 2);
  Assert.assertEquals(
    strategy.ldapURLSet.getInactiveUrls(),
    Arrays.asList(
      new LdapURL("ldap://directory-1.ldaptive.org"),
      new LdapURL("ldap://directory-2.ldaptive.org")));
  // mark first entry as active, list should reorder with that entry first
  strategy.success(strategy.ldapURLSet.getInactiveUrls().iterator().next());
  Assert.assertEquals(
    StreamSupport.stream(strategy.spliterator(), false).collect(Collectors.toList()),
    Arrays.asList(
      new LdapURL("ldap://directory-1.ldaptive.org"),
      new LdapURL("ldap://directory-3.ldaptive.org"),
      new LdapURL("ldap://directory-2.ldaptive.org")));
  Assert.assertEquals(strategy.ldapURLSet.getActiveUrls().size(), 2);
  Assert.assertEquals(
    strategy.ldapURLSet.getActiveUrls(),
    Arrays.asList(
      new LdapURL("ldap://directory-1.ldaptive.org"),
      new LdapURL("ldap://directory-3.ldaptive.org")));
  Assert.assertEquals(strategy.ldapURLSet.getInactiveUrls().size(), 1);
  Assert.assertEquals(
    strategy.ldapURLSet.getInactiveUrls().iterator().next(),
    new LdapURL("ldap://directory-2.ldaptive.org"));
  // mark second entry as active, list should reorder with that entry second
  strategy.success(strategy.ldapURLSet.getInactiveUrls().iterator().next());
  Assert.assertEquals(
    StreamSupport.stream(strategy.spliterator(), false).collect(Collectors.toList()),
    Arrays.asList(
      new LdapURL("ldap://directory-1.ldaptive.org"),
      new LdapURL("ldap://directory-2.ldaptive.org"),
      new LdapURL("ldap://directory-3.ldaptive.org")));
  Assert.assertEquals(strategy.ldapURLSet.getActiveUrls().size(), 3);
  Assert.assertEquals(
    strategy.ldapURLSet.getActiveUrls(),
    Arrays.asList(
      new LdapURL("ldap://directory-1.ldaptive.org"),
      new LdapURL("ldap://directory-2.ldaptive.org"),
      new LdapURL("ldap://directory-3.ldaptive.org")));
  Assert.assertEquals(strategy.ldapURLSet.getInactiveUrls().size(), 0);
}