/** * @deprecated Please use {@link TimeLockRuntimeConfig} to specify the {@link ServerListConfig} to be used * for connecting to TimeLock. */ @Deprecated @Value.Default public ServerListConfig serversList() { return ImmutableServerListConfig.builder().build(); }
@Test public void preservesAbsenceOfSslOnConversionToNamespacedServerListIfAbsent() { ImmutableServerListConfig serversListWithoutSsl = ImmutableServerListConfig.copyOf(SERVERS_LIST) .withSslConfiguration(Optional.empty()); TimeLockClientConfig config = ImmutableTimeLockClientConfig.copyOf(CLIENT_CONFIG) .withServersList(serversListWithoutSsl); assertThat(config.toNamespacedServerList().sslConfiguration(), equalTo(Optional.empty())); }
public static ServerListConfig namespaceUris(ServerListConfig config, String namespace) { Set<String> serversWithNamespaces = config .servers() .stream() .map(serverAddress -> serverAddress.replaceAll("/$", "") + "/" + namespace) .collect(Collectors.toSet()); return ImmutableServerListConfig.builder() .from(config) .servers(serversWithNamespaces) .build(); } }
@Value.Default public ServerListConfig serversList() { return ImmutableServerListConfig.builder().build(); } }
private static Function<ServerListConfig, ServerListConfig> addSslConfigurationToServerListFunction( Optional<SslConfiguration> sslConfiguration) { return serverList -> ImmutableServerListConfig.builder() .from(serverList) .sslConfiguration(getFirstPresentOptional(serverList.sslConfiguration(), sslConfiguration)) .build(); }
@Test public void httpProxyThrowsServiceNotAvailableExceptionIfConfiguredWithZeroNodes() { TestResource testResource = AtlasDbHttpClients.createLiveReloadingProxyWithQuickFailoverForTesting( new MetricRegistry(), () -> ImmutableServerListConfig.builder().build(), SslSocketFactories::createTrustContext, proxyConfiguration -> ProxySelector.getDefault(), TestResource.class, UserAgents.DEFAULT_VALUE); assertThatThrownBy(testResource::getTestNumber).isInstanceOf(ServiceNotAvailableException.class); }
@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); }
@Test public void cannotSpecifyZeroServersIfUsingLockBlock() { assertThatThrownBy(() -> ImmutableAtlasDbConfig.builder() .keyValueService(KVS_CONFIG_WITHOUT_NAMESPACE) .namespace(CLIENT_NAMESPACE) .timestamp(SINGLETON_SERVER_LIST) .lock(ImmutableServerListConfig.builder().build()) .build()).isInstanceOf(IllegalStateException.class); }
@Test public void cannotSpecifyZeroServersIfUsingTimestampBlock() { assertThatThrownBy(() -> ImmutableAtlasDbConfig.builder() .keyValueService(KVS_CONFIG_WITHOUT_NAMESPACE) .namespace(CLIENT_NAMESPACE) .timestamp(ImmutableServerListConfig.builder().build()) .lock(SINGLETON_SERVER_LIST) .build()).isInstanceOf(IllegalStateException.class); }
private static TimeLockClientConfig getTimelockConfigForServers(List<String> servers) { return ImmutableTimeLockClientConfig.builder() .client(CLIENT) .serversList(ImmutableServerListConfig.builder() .addAllServers(servers) .build()) .build(); } }
@Test public void canLiveReloadServersList() { unavailableServer.stubFor(ENDPOINT_MAPPING.willReturn(aResponse().withStatus(503))); List<String> servers = Lists.newArrayList(getUriForPort(unavailablePort)); TestResource client = AtlasDbHttpClients.createLiveReloadingProxyWithQuickFailoverForTesting( new MetricRegistry(), () -> ImmutableServerListConfig.builder() .servers(servers) .build(), SslSocketFactories::createTrustContext, unused -> ProxySelector.getDefault(), TestResource.class, "user (123)"); // actually a Feign RetryableException but that's not on our classpath assertThatThrownBy(client::getTestNumber).isInstanceOf(RuntimeException.class); servers.add(getUriForPort(availablePort)); Uninterruptibles.sleepUninterruptibly( PollingRefreshable.DEFAULT_REFRESH_INTERVAL.getSeconds() + 1, TimeUnit.SECONDS); int response = client.getTestNumber(); assertThat(response, equalTo(TEST_NUMBER)); unavailableServer.verify(getRequestedFor(urlMatching(TEST_ENDPOINT))); }
private static TimeLockClientConfig getTimelockConfigForServers(List<String> servers) { return ImmutableTimeLockClientConfig.builder() .client(CLIENT) .serversList(ImmutableServerListConfig.builder() .addAllServers(servers) .build()) .build(); }
rawRemoteServerConfig = ImmutableServerListConfig.builder() .addServers(getUriForPort(availablePort)) .build();
ImmutableServerListConfig serverListConfig = ImmutableServerListConfig.builder() .servers(leaderConfig.leaders()) .sslConfiguration(leaderConfig.sslConfiguration())
@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(); }
@Test public void canSpecifyZeroServersIfUsingTimelockBlock() { ImmutableAtlasDbConfig.builder() .keyValueService(KVS_CONFIG_WITHOUT_NAMESPACE) .namespace(CLIENT_NAMESPACE) .timelock(ImmutableTimeLockClientConfig.builder() .serversList(ImmutableServerListConfig.builder().build()) .build()) .build(); } }
/** * @deprecated Please use {@link TimeLockRuntimeConfig} to specify the {@link ServerListConfig} to be used * for connecting to TimeLock. */ @Deprecated @Value.Default public ServerListConfig serversList() { return ImmutableServerListConfig.builder().build(); }
public static ServerListConfig namespaceUris(ServerListConfig config, String namespace) { Set<String> serversWithNamespaces = config .servers() .stream() .map(serverAddress -> serverAddress.replaceAll("/$", "") + "/" + namespace) .collect(Collectors.toSet()); return ImmutableServerListConfig.builder() .from(config) .servers(serversWithNamespaces) .build(); } }
@Value.Default public ServerListConfig serversList() { return ImmutableServerListConfig.builder().build(); } }
private static Function<ServerListConfig, ServerListConfig> addSslConfigurationToServerListFunction( Optional<SslConfiguration> sslConfiguration) { return serverList -> ImmutableServerListConfig.builder() .from(serverList) .sslConfiguration(getFirstPresentOptional(serverList.sslConfiguration(), sslConfiguration)) .build(); }