AtlasDbHttpClients { public static <T> T createLiveReloadingProxyWithFailover( MetricsManager metricsManager, Supplier<ServerListConfig> serverListConfigSupplier, Class<T> type, AuxiliaryRemotingParameters clientParameters) { Supplier<T> clientFactory = () -> instrument( metricsManager.getTaggedRegistry(), ConjureJavaRuntimeTargetFactory.DEFAULT.createLiveReloadingProxyWithFailover( serverListConfigSupplier, type, clientParameters), type); return wrapWithOkHttpBugHandling(type, clientFactory); } private  AtlasDbHttpClients(); static T createProxy(
            Optional<TrustContext> trustContext,
            String uri,
            Class<T> type,
            AuxiliaryRemotingParameters parameters); static T createProxyWithFailover(
            MetricsManager metricsManager,
            ServerListConfig serverListConfig,
            Class<T> type,
            AuxiliaryRemotingParameters parameters); static T createLiveReloadingProxyWithFailover(
            MetricsManager metricsManager,
            Supplier<ServerListConfig> serverListConfigSupplier,
            Class<T> type,
            AuxiliaryRemotingParameters clientParameters); static T createDialogueProxy(TaggedMetricRegistry registry, Class<T> type, Channel channel); static T createUninstrumentedDialogueProxy(Class<T> type, Channel channel);  }
@Test public void canLiveReloadServersList() { unavailableServer.stubFor(GET_MAPPING.willReturn(aResponse().withStatus(503))); List<String> servers = Lists.newArrayList(getUriForPort(unavailablePort)); TestResource client = AtlasDbHttpClients.createLiveReloadingProxyWithFailover( MetricsManagers.createForTests(), () -> ImmutableServerListConfig.builder() .servers(servers) .sslConfiguration(SSL_CONFIG) .build(), TestResource.class, AUXILIARY_REMOTING_PARAMETERS); assertThatThrownBy(client::getTestNumber).isInstanceOf(RuntimeException.class); servers.add(getUriForPort(availablePort1)); Uninterruptibles.sleepUninterruptibly(SLEEP_TIME.getSeconds(), TimeUnit.SECONDS); int response = client.getTestNumber(); assertThat(response, equalTo(TEST_NUMBER_1)); unavailableServer.verify(getRequestedFor(urlMatching(GET_ENDPOINT))); }
@Test public void httpProxyCanBeCommissionedAndDecommissionedIfNodeAvailabilityChanges() { AtomicReference<ServerListConfig> config = new AtomicReference<>(ImmutableServerListConfig.builder() .addServers(getUriForPort(availablePort1)) .sslConfiguration(SSL_CONFIG) .build()); TestResource testResource = AtlasDbHttpClients.createLiveReloadingProxyWithFailover( MetricsManagers.createForTests(), config::get, TestResource.class, AUXILIARY_REMOTING_PARAMETERS); assertThat(testResource.getTestNumber(), equalTo(TEST_NUMBER_1)); config.set(ImmutableServerListConfig.builder() .addServers(getUriForPort(availablePort2)) .sslConfiguration(SSL_CONFIG) .build()); Uninterruptibles.sleepUninterruptibly(SLEEP_TIME.getSeconds(), TimeUnit.SECONDS); assertThat(testResource.getTestNumber(), equalTo(TEST_NUMBER_2)); }