JRTConnectionPool implements ConnectionPool { public synchronized JRTConnection setNewCurrentConnection() { List<JRTConnection> sources = getSources(); currentConnection = sources.get(ThreadLocalRandom.current().nextInt(0, sources.size())); log.log(FINE, () -> "Choosing new connection: " + currentConnection); return currentConnection; } JRTConnectionPool(ConfigSourceSet sourceSet);  JRTConnectionPool(List<String> addresses); void addSources(ConfigSourceSet sourceSet); synchronized JRTConnection getCurrent(); synchronized JRTConnection setNewCurrentConnection(); @Override void setError(Connection connection, int errorCode); JRTConnectionPool updateSources(List<String> addresses); JRTConnectionPool updateSources(ConfigSourceSet sourceSet); String toString(); void close(); @Override int getSize(); @Override Supervisor getSupervisor();  }
@Test public void testManySources() { Map<String, Integer> timesUsed = new LinkedHashMap<>(); List<String> twoSources = new ArrayList<>(); twoSources.add("host0"); twoSources.add("host1"); JRTConnectionPool sourcePool = new JRTConnectionPool(twoSources); int count = 1000; for (int i = 0; i < count; i++) { String address = sourcePool.setNewCurrentConnection().getAddress(); if (timesUsed.containsKey(address)) { int times = timesUsed.get(address); timesUsed.put(address, times + 1); } else { timesUsed.put(address, 1); } } assertConnectionDistributionIsFair(timesUsed); }