@Test(groups = "conn") public void noActiveUrls() throws Exception { final RandomConnectionStrategy strategy = new RandomConnectionStrategy(); strategy.initialize( "ldap: ldapURL -> true); strategy.failure(strategy.ldapURLSet.getActiveUrls().iterator().next()); strategy.failure(strategy.ldapURLSet.getActiveUrls().iterator().next()); strategy.failure(strategy.ldapURLSet.getActiveUrls().iterator().next()); strategy.iterator(); strategy.iterator(); strategy.iterator(); strategy.iterator(); }
@Override public Iterator<LdapURL> iterator() { if (!isInitialized()) { throw new IllegalStateException("Strategy is not initialized"); } return new Iterator<>() { private final List<LdapURL> active = ldapURLSet.getActiveUrls().stream().collect( Collectors.collectingAndThen( Collectors.toCollection(ArrayList::new), list -> { Collections.shuffle(list); return list; })); private final List<LdapURL> inactive = ldapURLSet.getInactiveUrls().stream().collect( Collectors.collectingAndThen( Collectors.toCollection(ArrayList::new), list -> { Collections.shuffle(list); return list; })); private int i; @Override public boolean hasNext() { return i < active.size() + inactive.size(); } @Override public LdapURL next() { final LdapURL url; if (i < active.size()) { url = active.get(i); } else { url = inactive.get(i - active.size()); } i++; return url; } }; }
RandomConnectionStrategy extends AbstractConnectionStrategy { @Override public Iterator<LdapURL> iterator() { if (!isInitialized()) { throw new IllegalStateException("Strategy is not initialized"); } return new Iterator<>() { private final List<LdapURL> active = ldapURLSet.getActiveUrls().stream().collect( Collectors.collectingAndThen( Collectors.toCollection(ArrayList::new), list -> { Collections.shuffle(list); return list; })); private final List<LdapURL> inactive = ldapURLSet.getInactiveUrls().stream().collect( Collectors.collectingAndThen( Collectors.toCollection(ArrayList::new), list -> { Collections.shuffle(list); return list; })); private int i; @Override public boolean hasNext() { return i < active.size() + inactive.size(); } @Override public LdapURL next() { final LdapURL url; if (i < active.size()) { url = active.get(i); } else { url = inactive.get(i - active.size()); } i++; return url; } }; } }
RandomConnectionStrategy extends AbstractConnectionStrategy { @Override public Iterator<LdapURL> iterator() { if (!isInitialized()) { throw new IllegalStateException("Strategy is not initialized"); } return new Iterator<>() { private final List<LdapURL> active = ldapURLSet.getActiveUrls().stream().collect( Collectors.collectingAndThen( Collectors.toCollection(ArrayList::new), list -> { Collections.shuffle(list); return list; })); private final List<LdapURL> inactive = ldapURLSet.getInactiveUrls().stream().collect( Collectors.collectingAndThen( Collectors.toCollection(ArrayList::new), list -> { Collections.shuffle(list); return list; })); private int i; @Override public boolean hasNext() { return i < active.size() + inactive.size(); } @Override public LdapURL next() { final LdapURL url; if (i < active.size()) { url = active.get(i); } else { url = inactive.get(i - active.size()); } i++; return url; } }; }  }
RandomConnectionStrategy extends AbstractConnectionStrategy { @Override public Iterator<LdapURL> iterator() { if (!isInitialized()) { throw new IllegalStateException("Strategy is not initialized"); } return new Iterator<>() { private final List<LdapURL> active = ldapURLSet.getActiveUrls().stream().collect( Collectors.collectingAndThen( Collectors.toCollection(ArrayList::new), list -> { Collections.shuffle(list); return list; })); private final List<LdapURL> inactive = ldapURLSet.getInactiveUrls().stream().collect( Collectors.collectingAndThen( Collectors.toCollection(ArrayList::new), list -> { Collections.shuffle(list); return list; })); private int i; @Override public boolean hasNext() { return i < active.size() + inactive.size(); } @Override public LdapURL next() { final LdapURL url; if (i < active.size()) { url = active.get(i); } else { url = inactive.get(i - active.size()); } i++; return url; } }; }  @Override Iterator<LdapURL> iterator(); }
RandomConnectionStrategy extends AbstractConnectionStrategy { @Override public Iterator<LdapURL> iterator() { if (!isInitialized()) { throw new IllegalStateException("Strategy is not initialized"); } return new Iterator<>() { private final List<LdapURL> active = ldapURLSet.getActiveUrls().stream().collect( Collectors.collectingAndThen( Collectors.toCollection(ArrayList::new), list -> { Collections.shuffle(list); return list; })); private final List<LdapURL> inactive = ldapURLSet.getInactiveUrls().stream().collect( Collectors.collectingAndThen( Collectors.toCollection(ArrayList::new), list -> { Collections.shuffle(list); return list; })); private int i; @Override public boolean hasNext() { return i < active.size() + inactive.size(); } @Override public LdapURL next() { final LdapURL url; if (i < active.size()) { url = active.get(i); } else { url = inactive.get(i - active.size()); } i++; return url; } }; }  @Override Iterator<LdapURL> iterator();  }