@Test public void hostIsAutomaticallyRemovedOnStartup() { when(config.servers()).thenReturn(ImmutableSet.of(HOST_1, HOST_2, HOST_3)); when(config.autoRefreshNodes()).thenReturn(true); setCassandraServersTo(HOST_1); createClientPool(); assertThat(poolServers).containsExactlyInAnyOrder(HOST_1); }
@Test public void ifNoRuntimeConfig_resolvesToInstallConfig() { CassandraReloadableKvsConfig reloadableConfig = getReloadableConfigWithEmptyRuntimeConfig(); boolean installConfigParam = true; when(config.autoRefreshNodes()).thenReturn(installConfigParam); assertThat(reloadableConfig.autoRefreshNodes(), is(installConfigParam)); }
@Test public void hostIsAutomaticallyAddedOnStartup() { when(config.servers()).thenReturn(ImmutableSet.of(HOST_1)); when(config.autoRefreshNodes()).thenReturn(true); setCassandraServersTo(HOST_1, HOST_2); createClientPool(); assertThat(poolServers).containsExactlyInAnyOrder(HOST_1, HOST_2); }
@Test public void hostIsAutomaticallyAddedOnRefresh() { when(config.servers()).thenReturn(ImmutableSet.of(HOST_1, HOST_2)); when(config.autoRefreshNodes()).thenReturn(true); setCassandraServersTo(HOST_1, HOST_2); createClientPool(); assertThat(poolServers).containsExactlyInAnyOrder(HOST_1, HOST_2); setCassandraServersTo(HOST_1, HOST_2, HOST_3); deterministicExecutor.tick(config.poolRefreshIntervalSeconds(), TimeUnit.SECONDS); assertThat(poolServers).containsExactlyInAnyOrder(HOST_1, HOST_2, HOST_3); }
@Test public void hostIsAutomaticallyRemovedOnRefresh() { when(config.servers()).thenReturn(ImmutableSet.of(HOST_1, HOST_2, HOST_3)); when(config.autoRefreshNodes()).thenReturn(true); setCassandraServersTo(HOST_1, HOST_2, HOST_3); createClientPool(); assertThat(poolServers).containsExactlyInAnyOrder(HOST_1, HOST_2, HOST_3); setCassandraServersTo(HOST_1, HOST_2); deterministicExecutor.tick(config.poolRefreshIntervalSeconds(), TimeUnit.SECONDS); assertThat(poolServers).containsExactlyInAnyOrder(HOST_1, HOST_2); }
@Test public void hostsAreNotRemovedOrAddedWhenRefreshIsDisabled() { when(config.servers()).thenReturn(ImmutableSet.of(HOST_1, HOST_2)); when(config.autoRefreshNodes()).thenReturn(false); setCassandraServersTo(HOST_1); createClientPool(); assertThat(poolServers).containsExactlyInAnyOrder(HOST_1, HOST_2); setCassandraServersTo(HOST_1, HOST_2, HOST_3); deterministicExecutor.tick(config.poolRefreshIntervalSeconds(), TimeUnit.SECONDS); assertThat(poolServers).containsExactlyInAnyOrder(HOST_1, HOST_2); }
private synchronized void refreshPool() { blacklist.checkAndUpdate(cassandra.getPools()); if (config.autoRefreshNodes()) { setServersInPoolTo(cassandra.refreshTokenRangesAndGetServers()); } else { setServersInPoolTo(config.servers()); } cassandra.debugLogStateOfPool(); }
@Test public void hostsAreResetToConfigOnRefreshWhenRefreshIsDisabled() { when(config.servers()).thenReturn(ImmutableSet.of(HOST_1, HOST_2)); when(config.autoRefreshNodes()).thenReturn(false); setCassandraServersTo(HOST_1); createClientPool(); assertThat(poolServers).containsExactlyInAnyOrder(HOST_1, HOST_2); cassandra.addPool(HOST_3); assertThat(poolServers).containsExactlyInAnyOrder(HOST_1, HOST_2, HOST_3); deterministicExecutor.tick(config.poolRefreshIntervalSeconds(), TimeUnit.SECONDS); assertThat(poolServers).containsExactlyInAnyOrder(HOST_1, HOST_2); setCassandraServersTo(HOST_2, HOST_3); cassandra.removePool(HOST_1); assertThat(poolServers).containsExactlyInAnyOrder(HOST_2); deterministicExecutor.tick(config.poolRefreshIntervalSeconds(), TimeUnit.SECONDS); assertThat(poolServers).containsExactlyInAnyOrder(HOST_1, HOST_2); }
private synchronized void refreshPool() { blacklist.checkAndUpdate(cassandra.getPools()); if (config.autoRefreshNodes()) { setServersInPoolTo(cassandra.refreshTokenRangesAndGetServers()); } else { setServersInPoolTo(config.servers()); } cassandra.debugLogStateOfPool(); }