@Test public void shouldReturnEmptyLocationFromSnitchException() { Supplier<String> badSnitchSupplier = () -> { throw new RuntimeException(); }; Supplier<Optional<HostLocation>> hostLocationSupplier = new HostLocationSupplier(badSnitchSupplier, ec2LocationSupplier, Optional.empty()); assertThat(hostLocationSupplier.get()).isNotPresent(); }
@Override public Optional<HostLocation> get() { try { if (overrideLocation.isPresent()) { return overrideLocation; } String snitch = snitchSupplier.get(); log.debug("Snitch successfully detected", SafeArg.of("snitch", snitch)); switch (snitch) { case "org.apache.cassandra.locator.Ec2Snitch": return Optional.of(ec2Supplier.get()); default: return Optional.empty(); } } catch (RuntimeException e) { log.warn("Host location supplier failed to retrieve the host location", e); return Optional.empty(); } }
HostLocationSupplier implements Supplier<Optional<HostLocation>> { @Override public Optional<HostLocation> get() { try { if (overrideLocation.isPresent()) { return overrideLocation; } String snitch = snitchSupplier.get(); log.debug("Snitch successfully detected", SafeArg.of("snitch", snitch)); switch (snitch) { case "org.apache.cassandra.locator.Ec2Snitch": return Optional.of(ec2Supplier.get()); default: return Optional.empty(); } } catch (RuntimeException e) { log.warn("Host location supplier failed to retrieve the host location", e); return Optional.empty(); } } }
HostLocationSupplier implements Supplier<Optional<HostLocation>> { @Override public Optional<HostLocation> get() { try { if (overrideLocation.isPresent()) { return overrideLocation; } String snitch = snitchSupplier.get(); log.debug("Snitch successfully detected", SafeArg.of("snitch", snitch)); switch (snitch) { case "org.apache.cassandra.locator.Ec2Snitch": return Optional.of(ec2Supplier.get()); default: return Optional.empty(); } } catch (RuntimeException e) { log.warn("Host location supplier failed to retrieve the host location", e); return Optional.empty(); } } HostLocationSupplier(Supplier<String> snitchSupplier,
            Supplier<HostLocation> ec2Supplier,
            Optional<HostLocation> overrideLocation);  HostLocationSupplier(Supplier<String> snitchSupplier,
            Optional<HostLocation> overrideLocation); }
HostLocationSupplier implements Supplier<Optional<HostLocation>> { @Override public Optional<HostLocation> get() { try { if (overrideLocation.isPresent()) { return overrideLocation; } String snitch = snitchSupplier.get(); log.debug("Snitch successfully detected", SafeArg.of("snitch", snitch)); switch (snitch) { case "org.apache.cassandra.locator.Ec2Snitch": return Optional.of(ec2Supplier.get()); default: return Optional.empty(); } } catch (RuntimeException e) { log.warn("Host location supplier failed to retrieve the host location", e); return Optional.empty(); } } HostLocationSupplier(Supplier<String> snitchSupplier,
            Supplier<HostLocation> ec2Supplier,
            Optional<HostLocation> overrideLocation);  HostLocationSupplier(Supplier<String> snitchSupplier,
            Optional<HostLocation> overrideLocation); @Override Optional<HostLocation> get(); }
HostLocationSupplier implements Supplier<Optional<HostLocation>> { @Override public Optional<HostLocation> get() { try { if (overrideLocation.isPresent()) { return overrideLocation; } String snitch = snitchSupplier.get(); log.debug("Snitch successfully detected", SafeArg.of("snitch", snitch)); switch (snitch) { case "org.apache.cassandra.locator.Ec2Snitch": return Optional.of(ec2Supplier.get()); default: return Optional.empty(); } } catch (RuntimeException e) { log.warn("Host location supplier failed to retrieve the host location", e); return Optional.empty(); } } HostLocationSupplier(Supplier<String> snitchSupplier,
            Supplier<HostLocation> ec2Supplier,
            Optional<HostLocation> overrideLocation);  HostLocationSupplier(Supplier<String> snitchSupplier,
            Optional<HostLocation> overrideLocation); @Override Optional<HostLocation> get();  }