@Test public void httpProxyCanBeCommissionedAndDecommissionedIfNodeAvailabilityChanges() { AtomicReference<ServerListConfig> config = new AtomicReference<>(ImmutableServerListConfig.builder().build()); TestResource testResource = AtlasDbHttpClients.createLiveReloadingProxyWithQuickFailoverForTesting( new MetricRegistry(), config::get, SslSocketFactories::createTrustContext, proxyConfiguration -> ProxySelector.getDefault(), TestResource.class, UserAgents.DEFAULT_VALUE); // At this point, there are zero nodes in the config, so we should get ServiceNotAvailable. assertThatThrownBy(testResource::getTestNumber).isInstanceOf(ServiceNotAvailableException.class); config.set(ImmutableServerListConfig.builder().addServers(getUriForPort(availablePort)).build()); Uninterruptibles.sleepUninterruptibly( PollingRefreshable.DEFAULT_REFRESH_INTERVAL.getSeconds() + 1, TimeUnit.SECONDS); assertThat(testResource.getTestNumber(), equalTo(TEST_NUMBER)); config.set(ImmutableServerListConfig.builder().build()); Uninterruptibles.sleepUninterruptibly( PollingRefreshable.DEFAULT_REFRESH_INTERVAL.getSeconds() + 1, TimeUnit.SECONDS); assertThatThrownBy(testResource::getTestNumber).isInstanceOf(ServiceNotAvailableException.class); }
mockClientConfig = getTimelockConfigForServers(ImmutableList.of(getUriForPort(availablePort))); rawRemoteServerConfig = ImmutableServerListConfig.builder() .addServers(getUriForPort(availablePort)) .build();
@Before public void setUp() { when(invalidator.backupAndInvalidate()).thenReturn(BACKUP_TIMESTAMP); wireMockRule.stubFor(PING_MAPPING.willReturn(aResponse() .withStatus(200) .withBody(TimestampManagementService.PING_RESPONSE) .withHeader("Content-Type", "text/plain")) .inScenario(SCENARIO) .whenScenarioStateIs(Scenario.STARTED) .willSetStateTo(Scenario.STARTED)); String serverUri = String.format("http://%s:%s", WireMockConfiguration.DEFAULT_BIND_ADDRESS, wireMockRule.port()); ServerListConfig defaultServerListConfig = ImmutableServerListConfig.builder().addServers(serverUri).build(); timelockConfig = ImmutableTimeLockClientConfig.builder() .client("testClient") .serversList(defaultServerListConfig) .build(); }