@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)); }
@SuppressWarnings("unchecked") <K extends Exception> void handleExceptionFromRequest( RetryableCassandraRequest<?, K> req, InetSocketAddress hostTried, Exception ex) throws K { if (!isRetryable(ex)) { throw (K) ex; } RequestExceptionHandlerStrategy strategy = getStrategy(); req.triedOnHost(hostTried); req.registerException(ex); int numberOfAttempts = req.getNumberOfAttempts(); int numberOfAttemptsOnHost = req.getNumberOfAttemptsOnHost(hostTried); if (numberOfAttempts >= maxTriesTotal.get()) { throw logAndThrowException(numberOfAttempts, ex, req); } if (shouldBlacklist(ex, numberOfAttemptsOnHost)) { blacklist.add(hostTried); } logNumberOfAttempts(ex, numberOfAttempts); handleBackoff(req, hostTried, ex, strategy); handleRetryOnDifferentHosts(req, hostTried, ex, strategy); }
@SuppressWarnings("unchecked") <K extends Exception> void handleExceptionFromRequest( RetryableCassandraRequest<?, K> req, InetSocketAddress hostTried, Exception ex) throws K { if (!isRetryable(ex)) { throw (K) ex; } RequestExceptionHandlerStrategy strategy = getStrategy(); req.triedOnHost(hostTried); req.registerException(ex); int numberOfAttempts = req.getNumberOfAttempts(); int numberOfAttemptsOnHost = req.getNumberOfAttemptsOnHost(hostTried); if (numberOfAttempts >= maxTriesTotal.get()) { throw logAndThrowException(numberOfAttempts, ex, req); } if (shouldBlacklist(ex, numberOfAttemptsOnHost)) { blacklist.add(hostTried); } logNumberOfAttempts(ex, numberOfAttempts); handleBackoff(req, hostTried, ex, strategy); handleRetryOnDifferentHosts(req, hostTried, ex, strategy); }