@Before public void setup() { handlerLegacy = new CassandraRequestExceptionHandler( () -> MAX_RETRIES_PER_HOST, () -> MAX_RETRIES_TOTAL, () -> false, new Blacklist(config)); handlerConservative = new CassandraRequestExceptionHandler( () -> MAX_RETRIES_PER_HOST, () -> MAX_RETRIES_TOTAL, () -> true, new Blacklist(config)); }
public static CassandraKeyValueService createForTesting( CassandraKeyValueServiceConfig config, Optional<LeaderConfig> leaderConfig) { MetricsManager metricsManager = MetricsManagers.createForTests(); CassandraClientPool clientPool = CassandraClientPoolImpl.createImplForTest(metricsManager, config, CassandraClientPoolImpl.StartupChecks.RUN, new Blacklist(config)); return createOrShutdownClientPool(metricsManager, config, clientPool, leaderConfig, CassandraMutationTimestampProviders.legacyModeForTestsOnly(), LoggerFactory.getLogger(CassandraKeyValueService.class), AtlasDbConstants.DEFAULT_INITIALIZE_ASYNC); }
public static CassandraClientPool create(MetricsManager metricsManager, CassandraKeyValueServiceConfig config, Supplier<CassandraKeyValueServiceRuntimeConfig> runtimeConfig, boolean initializeAsync) { Blacklist blacklist = new Blacklist(config); CassandraRequestExceptionHandler exceptionHandler = new CassandraRequestExceptionHandler( () -> runtimeConfig.get().numberOfRetriesOnSameHost(), () -> runtimeConfig.get().numberOfRetriesOnAllHosts(), () -> runtimeConfig.get().conservativeRequestExceptionHandler(), blacklist); CassandraClientPoolImpl cassandraClientPool = new CassandraClientPoolImpl( metricsManager, config, StartupChecks.RUN, exceptionHandler, blacklist); cassandraClientPool.wrapper.initialize(initializeAsync); return cassandraClientPool.wrapper.isInitialized() ? cassandraClientPool : cassandraClientPool.wrapper; }
@Before public void setup() { config = mock(CassandraKeyValueServiceConfig.class); when(config.poolRefreshIntervalSeconds()).thenReturn(POOL_REFRESH_INTERVAL_SECONDS); when(config.timeBetweenConnectionEvictionRunsSeconds()).thenReturn(TIME_BETWEEN_EVICTION_RUNS_SECONDS); when(config.unresponsiveHostBackoffTimeSeconds()).thenReturn(UNRESPONSIVE_HOST_BACKOFF_SECONDS); blacklist = new Blacklist(config); doAnswer(invocation -> poolServers.add(getInvocationAddress(invocation))).when(cassandra).addPool(any()); doAnswer(invocation -> poolServers.remove(getInvocationAddress(invocation))).when(cassandra).removePool(any()); doAnswer(invocation -> poolServers.stream().collect( Collectors.toMap(x -> x, x -> mock(CassandraClientPoolingContainer.class)))).when(cassandra).getPools(); when(config.socketTimeoutMillis()).thenReturn(1); }
@Test public void changingHandlerModeHasNoEffectWithoutGetStrategy() { Exception ex = Iterables.get(TRANSIENT_EXCEPTIONS, 0); CassandraRequestExceptionHandler handler = new CassandraRequestExceptionHandler( () -> MAX_RETRIES_PER_HOST, () -> MAX_RETRIES_TOTAL, this::mutableMode, new Blacklist(config)); CassandraRequestExceptionHandler.RequestExceptionHandlerStrategy conservativeStrategy = handler.getStrategy(); assertTrue(handler.shouldBackoff(ex, handler.getStrategy())); flipMode(); assertTrue(handler.shouldBackoff(ex, conservativeStrategy)); assertFalse(handler.shouldBackoff(ex, handler.getStrategy())); }
private CassandraService clientPoolWith( ImmutableSet<InetSocketAddress> servers, ImmutableSet<InetSocketAddress> serversInPool) { config = ImmutableCassandraKeyValueServiceConfig.builder() .replicationFactor(3) .addServers(servers.toArray(new InetSocketAddress[0])) .build(); blacklist = new Blacklist(config); CassandraService service = new CassandraService(MetricsManagers.createForTests(), config, blacklist); service.cacheInitialCassandraHosts(); serversInPool.forEach(service::addPool); return service; } }
public static CassandraKeyValueService createForTesting( CassandraKeyValueServiceConfig config, Optional<LeaderConfig> leaderConfig) { MetricsManager metricsManager = MetricsManagers.createForTests(); CassandraClientPool clientPool = CassandraClientPoolImpl.createImplForTest(metricsManager, config, CassandraClientPoolImpl.StartupChecks.RUN, new Blacklist(config)); return createOrShutdownClientPool(metricsManager, config, clientPool, leaderConfig, CassandraMutationTimestampProviders.legacyModeForTestsOnly(), LoggerFactory.getLogger(CassandraKeyValueService.class), AtlasDbConstants.DEFAULT_INITIALIZE_ASYNC); }
public static CassandraClientPool create(MetricsManager metricsManager, CassandraKeyValueServiceConfig config, Supplier<CassandraKeyValueServiceRuntimeConfig> runtimeConfig, boolean initializeAsync) { Blacklist blacklist = new Blacklist(config); CassandraRequestExceptionHandler exceptionHandler = new CassandraRequestExceptionHandler( () -> runtimeConfig.get().numberOfRetriesOnSameHost(), () -> runtimeConfig.get().numberOfRetriesOnAllHosts(), () -> runtimeConfig.get().conservativeRequestExceptionHandler(), blacklist); CassandraClientPoolImpl cassandraClientPool = new CassandraClientPoolImpl( metricsManager, config, StartupChecks.RUN, exceptionHandler, blacklist); cassandraClientPool.wrapper.initialize(initializeAsync); return cassandraClientPool.wrapper.isInitialized() ? cassandraClientPool : cassandraClientPool.wrapper; }