ElastiCacheResolver implements Resolver { @Override public List<ResolveResult> resolve() { final Response response = resolver.resolve(); final Response effective = currentResponse.accumulateAndGet( response, (current, r) -> { if (current == null || r.getConfigurationVersion() > current.getConfigurationVersion()) { return r; } else { return current; } }); return effective .getHosts() .stream() .map(hap -> new ResolveResult(hap.getHostText(), hap.getPort(), ttl)) .collect(toList()); } ElastiCacheResolver(final Resolver resolver, final long ttl); static Builder newBuilder(final String configHost); @Override List<ResolveResult> resolve();  }
@Test public void resolve() { final Response response = new Response(123, asList(fromParts("host1", 11211), fromParts("host2", 11212))); final ElastiCacheResolver resolver = new ElastiCacheResolver(() -> response, 124); assertEquals( asList(new ResolveResult("host1", 11211, 124), new ResolveResult("host2", 11212, 124)), resolver.resolve()); }
@Test public void resolveNewerVersions() { final Response response1 = new Response(123, singletonList(fromParts("host1", 11211))); final Response response2 = new Response(124, singletonList(fromParts("host2", 11211))); final Iterator<Response> responses = cycle(response1, response2); final ElastiCacheResolver resolver = new ElastiCacheResolver(() -> responses.next(), 124); assertEquals(singletonList(new ResolveResult("host1", 11211, 124)), resolver.resolve()); assertEquals(singletonList(new ResolveResult("host2", 11211, 124)), resolver.resolve()); assertEquals(singletonList(new ResolveResult("host2", 11211, 124)), resolver.resolve()); }