@JsonIgnore public AtlasDbConfig toOfflineConfig() { return ImmutableAtlasDbConfig.builder() .from(this) .leader(Optional.empty()) .lock(Optional.empty()) .timestamp(Optional.empty()) .build(); } }
@Test public void absentNamespaceRequiresKvsNamespace() { assertThatThrownBy(() -> ImmutableAtlasDbConfig.builder() .keyValueService(KVS_CONFIG_WITHOUT_NAMESPACE) .leader(LEADER_CONFIG) .build()) .isInstanceOf(IllegalStateException.class) .satisfies((exception) -> assertThat(exception.getMessage(), containsString("config needs to be set"))); }
@Test public void configWithLeaderBlockIsValid() { AtlasDbConfig config = ImmutableAtlasDbConfig.builder() .keyValueService(KVS_CONFIG_WITH_NAMESPACE) .leader(LEADER_CONFIG) .build(); assertThat(config.getNamespaceString(), equalTo(TEST_NAMESPACE)); assertThat(config, not(nullValue())); }
public static AtlasDbConfig addFallbackSslConfigurationToAtlasDbConfig( AtlasDbConfig config, Optional<SslConfiguration> sslConfiguration) { return ImmutableAtlasDbConfig.builder() .from(config) .leader(addFallbackSslConfigurationToLeader(config.leader(), sslConfiguration)) .lock(addFallbackSslConfigurationToServerList(config.lock(), sslConfiguration)) .timestamp(addFallbackSslConfigurationToServerList(config.timestamp(), sslConfiguration)) .timelock(addFallbackSslConfigurationToTimeLockClientConfig(config.timelock(), sslConfiguration)) .build(); }
@JsonIgnore public AtlasDbConfig toOfflineConfig() { return ImmutableAtlasDbConfig.builder() .from(this) .leader(Optional.empty()) .lock(Optional.empty()) .timestamp(Optional.empty()) .build(); } }
private static AtlasDbConfig convertConfigWithLeaderBlockToClientConfig(AtlasDbConfig serverConfig) { ServerListConfig leaders = ImmutableServerListConfig.builder() .servers(serverConfig.leader().get().leaders()) .sslConfiguration(serverConfig.leader().get().sslConfiguration()) .build(); return ImmutableAtlasDbConfig.builder() .from(serverConfig) .leader(Optional.empty()) .lock(leaders) .timestamp(leaders) .build(); }
@Test(expected = IllegalStateException.class) public void leaderBlockNotPermittedWithLockBlock() { ImmutableAtlasDbConfig.builder() .keyValueService(KVS_CONFIG_WITH_NAMESPACE) .leader(LEADER_CONFIG) .lock(SINGLETON_SERVER_LIST) .build(); }
@Test(expected = IllegalStateException.class) public void timelockBlockNotPermittedWithLeaderBlock() { ImmutableAtlasDbConfig.builder() .keyValueService(KVS_CONFIG_WITH_NAMESPACE) .timelock(TIMELOCK_CONFIG) .leader(LEADER_CONFIG) .build(); }
@Test public void addingFallbackSslAddsItToLeaderBlock() { AtlasDbConfig withoutSsl = ImmutableAtlasDbConfig.builder() .keyValueService(KVS_CONFIG_WITH_NAMESPACE) .leader(LEADER_CONFIG) .build(); AtlasDbConfig withSsl = AtlasDbConfigs.addFallbackSslConfigurationToAtlasDbConfig(withoutSsl, SSL_CONFIG); assertThat(withSsl.leader().get().sslConfiguration(), is(SSL_CONFIG)); assertThat(withoutSsl.getNamespaceString(), equalTo(TEST_NAMESPACE)); }
@Test(expected = IllegalStateException.class) public void leaderBlockNotPermittedWithLockAndTimestampBlocks() { ImmutableAtlasDbConfig.builder() .keyValueService(KVS_CONFIG_WITH_NAMESPACE) .leader(LEADER_CONFIG) .lock(SINGLETON_SERVER_LIST) .timestamp(SINGLETON_SERVER_LIST) .build(); }
@Test public void addingAbsentFallbackSslWhenItDoesntExistsLeavesItAsAbsent() { AtlasDbConfig withoutSsl = ImmutableAtlasDbConfig.builder() .keyValueService(KVS_CONFIG_WITH_NAMESPACE) .leader(LEADER_CONFIG) .build(); AtlasDbConfig withSsl = AtlasDbConfigs.addFallbackSslConfigurationToAtlasDbConfig(withoutSsl, NO_SSL_CONFIG); assertThat(withSsl.leader().get().sslConfiguration(), is(NO_SSL_CONFIG)); }
@Test(expected = IllegalStateException.class) public void leaderBlockNotPermittedWithTimestampBlock() { ImmutableAtlasDbConfig.builder() .keyValueService(KVS_CONFIG_WITH_NAMESPACE) .leader(LEADER_CONFIG) .timestamp(SINGLETON_SERVER_LIST) .build(); }
@Test public void addingFallbackSslWhenItExistsDoesntOverride() { AtlasDbConfig withoutSsl = ImmutableAtlasDbConfig.builder() .keyValueService(KVS_CONFIG_WITH_NAMESPACE) .leader(ImmutableLeaderConfig.builder() .from(LEADER_CONFIG) .sslConfiguration(SSL_CONFIG) .build()) .build(); AtlasDbConfig withSsl = AtlasDbConfigs.addFallbackSslConfigurationToAtlasDbConfig(withoutSsl, OTHER_SSL_CONFIG); assertThat(withSsl.leader().get().sslConfiguration(), is(SSL_CONFIG)); }
public static AtlasDbConfig addFallbackSslConfigurationToAtlasDbConfig( AtlasDbConfig config, Optional<SslConfiguration> sslConfiguration) { return ImmutableAtlasDbConfig.builder() .from(config) .leader(addFallbackSslConfigurationToLeader(config.leader(), sslConfiguration)) .lock(addFallbackSslConfigurationToServerList(config.lock(), sslConfiguration)) .timestamp(addFallbackSslConfigurationToServerList(config.timestamp(), sslConfiguration)) .timelock(addFallbackSslConfigurationToTimeLockClientConfig(config.timelock(), sslConfiguration)) .build(); }