RedisConfiguration { public List<HostAndPort> hostsAndPorts() { List<HostAndPort> hostAndPorts = new ArrayList<>(); int defaultPort = Integer.parseInt(this.port); try { String[] servers = server.split("[/;]"); for (String aServer : servers) { String[] serverAndPort = aServer.split(":"); int portToUse = portToUse(serverAndPort, defaultPort); collectHosts(hostAndPorts, serverAndPort, portToUse); } } catch (UnknownHostException e) { throw new IllegalArgumentException("Unable to resolve cluster host for configuration " + this, e); } catch (NumberFormatException e) { throw new IllegalArgumentException( "Port paramter was in server configuration. Expecting numeric values, but it was not: " + this); } for (HostAndPort hostAndPort : hostAndPorts) { logger.info("hostAndPort Host:" + hostAndPort.getHost() + "hostAndPort Port:" + hostAndPort.getPort()); } logger.debug("Resolved hosts from '{}':{} are {}", server, port, hostAndPorts); return hostAndPorts; } RedisConfiguration(SessionConfiguration conf); ExpirationStrategy getStrategy(); Integer getTimeout(); String getPoolSize(); List<HostAndPort> hostsAndPorts(); @Override String toString(); static final String METRIC_PREFIX; static final String REDIS_USE_IPV4; static final String REDIS_USE_IPV6; static final String REDIS_EXPIRATION_STRATEGY; static final String REDIS_TIMEOUT; static final String DEFAULT_REDIS_TIMEOUT; static final String REDIS_PORT; static final String REDIS_HOST; static final String REDIS_PASSWORD; static final String REDIS_SSL; static final String REDIS_TLS; static final String REDIS_POOL_SIZE; static final String DEFAULT_REDIS_POOL_SIZE; static final String REDIS_CLUSTER_MODE; static final String REDIS_MASTER_NAME; static final String DEFAULT_REDIS_MASTER_NAME; }
@Test public void testExtractHostsAndPorts() { RedisConfiguration configuration = new RedisConfiguration(sc); List<HostAndPort> hostsAndPorts = configuration.hostsAndPorts(); assertEquals(1, hostsAndPorts.size()); assertEquals("127.0.0.1", hostsAndPorts.iterator().next().host); }
@Test public void testExtractManyHostsAndPorts() { sc.setProviderConfiguration("host=1.2.3.4:2/5.6.7.8"); RedisConfiguration configuration = new RedisConfiguration(sc); List<HostAndPort> hostsAndPorts = configuration.hostsAndPorts(); assertEquals(2, hostsAndPorts.size()); ArrayList<HostAndPort> asList = new ArrayList<>(hostsAndPorts); assertEquals("1.2.3.4", asList.get(0).host); assertEquals(2, asList.get(0).port); assertEquals("5.6.7.8", asList.get(1).host); assertEquals(6379, asList.get(1).port); }