CassandraRequestExceptionHandler { @VisibleForTesting boolean shouldBlacklist(Exception ex, int numberOfAttempts) { return isConnectionException(ex) && numberOfAttempts >= maxTriesSameHost.get() && !isExceptionNotImplicatingThisParticularNode(ex); } CassandraRequestExceptionHandler(
            Supplier<Integer> maxTriesSameHost,
            Supplier<Integer> maxTriesTotal,
            Supplier<Boolean> useConservativeHandler,
            Blacklist blacklist); private  CassandraRequestExceptionHandler(
            Supplier<Integer> maxTriesSameHost,
            Supplier<Integer> maxTriesTotal,
            Blacklist blacklist);   }
@Test public void connectionExceptionsWithSufficientAttemptsShouldBlacklistDefault() { for (Exception ex : CONNECTION_EXCEPTIONS) { assertFalse("MAX_RETRIES_PER_HOST - 1 attempts should not blacklist", handlerLegacy.shouldBlacklist(ex, MAX_RETRIES_PER_HOST - 1)); } for (Exception ex : CONNECTION_EXCEPTIONS) { assertTrue(String.format("MAX_RETRIES_PER_HOST attempts with exception %s should blacklist", ex), handlerLegacy.shouldBlacklist(ex, MAX_RETRIES_PER_HOST)); } Exception ffException = Iterables.get(FAST_FAILOVER_EXCEPTIONS, 0); assertFalse(String.format("Exception %s should not blacklist", ffException), handlerLegacy.shouldBlacklist(ffException, MAX_RETRIES_PER_HOST)); }
@Test public void connectionExceptionsWithSufficientAttemptsShouldBlacklistConservative() { for (Exception ex : CONNECTION_EXCEPTIONS) { assertFalse("MAX_RETRIES_PER_HOST - 1 attempts should not blacklist", handlerConservative.shouldBlacklist(ex, MAX_RETRIES_PER_HOST - 1)); } for (Exception ex : CONNECTION_EXCEPTIONS) { assertTrue(String.format("MAX_RETRIES_PER_HOST attempts with exception %s should blacklist", ex), handlerConservative.shouldBlacklist(ex, MAX_RETRIES_PER_HOST)); } Exception ffException = Iterables.get(FAST_FAILOVER_EXCEPTIONS, 0); assertFalse(String.format("Exception %s should not blacklist", ffException), handlerConservative.shouldBlacklist(ffException, MAX_RETRIES_PER_HOST)); }
@Test public void nonImplicatingExceptionsShouldNeverBlacklist() { NOT_IMPLICATING_NODES_EXCEPTIONS.forEach(ex -> { assertFalse(handlerConservative.shouldBlacklist(ex, MAX_RETRIES_PER_HOST + 1)); assertFalse(handlerLegacy.shouldBlacklist(ex, MAX_RETRIES_PER_HOST + 1)); }); }
@Test public void nonImplicatingExceptionWithConnectionAsCauseShouldNeverBlacklist() { Exception ex = new InsufficientConsistencyException("insufficient consistency", new SocketTimeoutException()); assertFalse(handlerConservative.shouldBlacklist(ex, MAX_RETRIES_PER_HOST + 1)); assertFalse(handlerLegacy.shouldBlacklist(ex, MAX_RETRIES_PER_HOST + 1)); }