@Test(groups = "unit") public void should_expose_decision_properties() throws Throwable { RetryDecision retryAtOne = RetryDecision.retry(ONE); assertThat(retryAtOne.getType()).isEqualTo(RETRY); assertThat(retryAtOne.getRetryConsistencyLevel()).isEqualTo(ONE); assertThat(retryAtOne.isRetryCurrent()).isTrue(); assertThat(retryAtOne.toString()).isEqualTo("Retry at ONE on same host."); RetryDecision tryNextAtOne = RetryDecision.tryNextHost(ONE); assertThat(tryNextAtOne.getType()).isEqualTo(RETRY); assertThat(tryNextAtOne.getRetryConsistencyLevel()).isEqualTo(ONE); assertThat(tryNextAtOne.isRetryCurrent()).isFalse(); assertThat(tryNextAtOne.toString()).isEqualTo("Retry at ONE on next host."); RetryDecision rethrow = RetryDecision.rethrow(); assertThat(rethrow.getType()).isEqualTo(RETHROW); assertThat(rethrow.toString()).isEqualTo("Rethrow"); RetryDecision ignore = RetryDecision.ignore(); assertThat(ignore.getType()).isEqualTo(IGNORE); assertThat(ignore.toString()).isEqualTo("Ignore"); } }
setFinalResult(connection, response); else { switch (retry.getType()) { case RETRY: ++queryRetries; if (logger.isTraceEnabled()) logger.trace("Doing retry {} for query {} at consistency {}", queryRetries, statement, retry.getRetryConsistencyLevel()); if (metricsEnabled()) metrics().getErrorMetrics().getRetries().inc(); retry(true, retry.getRetryConsistencyLevel()); break; case RETHROW:
private void processRetryDecision(RetryPolicy.RetryDecision retryDecision, Connection connection, Exception exceptionToReport) { switch (retryDecision.getType()) { case RETRY: retriesByPolicy++; if (logger.isDebugEnabled()) logger.debug("[{}] Doing retry {} for query {} at consistency {}", id, retriesByPolicy, statement, retryDecision.getRetryConsistencyLevel()); if (metricsEnabled()) metrics().getErrorMetrics().getRetries().inc(); // log error for the current host if we are switching to another one if (!retryDecision.isRetryCurrent()) logError(connection.address, exceptionToReport); retry(retryDecision.isRetryCurrent(), retryDecision.getRetryConsistencyLevel()); break; case RETHROW: setFinalException(connection, exceptionToReport); break; case IGNORE: if (metricsEnabled()) metrics().getErrorMetrics().getIgnores().inc(); setFinalResult(connection, new Responses.Result.Void()); break; } }
private void processRetryDecision(RetryPolicy.RetryDecision retryDecision, Connection connection, Exception exceptionToReport) { switch (retryDecision.getType()) { case RETRY: retriesByPolicy++; if (logger.isDebugEnabled()) logger.debug("[{}] Doing retry {} for query {} at consistency {}", id, retriesByPolicy, statement, retryDecision.getRetryConsistencyLevel()); if (metricsEnabled()) metrics().getErrorMetrics().getRetries().inc(); // log error for the current host if we are switching to another one if (!retryDecision.isRetryCurrent()) logError(connection.address, exceptionToReport); retry(retryDecision.isRetryCurrent(), retryDecision.getRetryConsistencyLevel()); break; case RETHROW: setFinalException(connection, exceptionToReport); break; case IGNORE: if (metricsEnabled()) metrics().getErrorMetrics().getIgnores().inc(); setFinalResult(connection, new Responses.Result.Void()); break; } }
private void processRetryDecision(RetryPolicy.RetryDecision retryDecision, Connection connection, Exception exceptionToReport) { switch (retryDecision.getType()) { case RETRY: retriesByPolicy++; if (logger.isDebugEnabled()) logger.debug("[{}] Doing retry {} for query {} at consistency {}", id, retriesByPolicy, statement, retryDecision.getRetryConsistencyLevel()); if (metricsEnabled()) metrics().getErrorMetrics().getRetries().inc(); // log error for the current host if we are switching to another one if (!retryDecision.isRetryCurrent()) logError(connection.address, exceptionToReport); retry(retryDecision.isRetryCurrent(), retryDecision.getRetryConsistencyLevel()); break; case RETHROW: setFinalException(connection, exceptionToReport); break; case IGNORE: if (metricsEnabled()) metrics().getErrorMetrics().getIgnores().inc(); setFinalResult(connection, new Responses.Result.Void()); break; } }
/** * Creates a {@link RetryDecision.Type#RETRY} retry decision using * the same host and the provided consistency level. * <p/> * If the provided consistency level is {@code null}, the retry will be done at the same consistency level as * the previous attempt. * <p/> * Beware that {@link ConsistencyLevel#isSerial() serial} consistency levels * should never be passed to this method; attempting to do so would trigger an * {@link com.datastax.driver.core.exceptions.InvalidQueryException InvalidQueryException}. * * @param consistency the consistency level to use for the retry; if {@code null}, * the same level as the previous attempt will be used. * @return a {@link RetryDecision.Type#RETRY} decision using * the same host and the provided consistency level */ public static RetryDecision retry(ConsistencyLevel consistency) { return new RetryDecision(Type.RETRY, consistency, true); }
/** * Creates a {@link RetryDecision.Type#RETRY} retry decision using the next host * in the query plan, and using the provided consistency level. * <p/> * If the provided consistency level is {@code null}, the retry will be done at the same consistency level as * the previous attempt. * <p/> * Beware that {@link ConsistencyLevel#isSerial() serial} consistency levels * should never be passed to this method; attempting to do so would trigger an * {@link com.datastax.driver.core.exceptions.InvalidQueryException InvalidQueryException}. * * @param consistency the consistency level to use for the retry; if {@code null}, * the same level as the previous attempt will be used. * @return a {@link RetryDecision.Type#RETRY} retry decision using the next host * in the query plan, and using the provided consistency level. */ public static RetryDecision tryNextHost(ConsistencyLevel consistency) { return new RetryDecision(Type.RETRY, consistency, false); }
/** * Creates a {@link RetryDecision.Type#RETRY} retry decision using the next host * in the query plan, and using the provided consistency level. * <p/> * If the provided consistency level is {@code null}, the retry will be done at the same consistency level as * the previous attempt. * <p/> * Beware that {@link ConsistencyLevel#isSerial() serial} consistency levels * should never be passed to this method; attempting to do so would trigger an * {@link com.datastax.driver.core.exceptions.InvalidQueryException InvalidQueryException}. * * @param consistency the consistency level to use for the retry; if {@code null}, * the same level as the previous attempt will be used. * @return a {@link RetryDecision.Type#RETRY} retry decision using the next host * in the query plan, and using the provided consistency level. */ public static RetryDecision tryNextHost(ConsistencyLevel consistency) { return new RetryDecision(Type.RETRY, consistency, false); }
/** * Creates a {@link RetryDecision.Type#RETRY} retry decision using * the same host and the provided consistency level. * <p/> * If the provided consistency level is {@code null}, the retry will be done at the same consistency level as * the previous attempt. * <p/> * Beware that {@link ConsistencyLevel#isSerial() serial} consistency levels * should never be passed to this method; attempting to do so would trigger an * {@link com.datastax.driver.core.exceptions.InvalidQueryException InvalidQueryException}. * * @param consistency the consistency level to use for the retry; if {@code null}, * the same level as the previous attempt will be used. * @return a {@link RetryDecision.Type#RETRY} decision using * the same host and the provided consistency level */ public static RetryDecision retry(ConsistencyLevel consistency) { return new RetryDecision(Type.RETRY, consistency, true); }
/** * Creates a {@link RetryDecision.Type#RETRY} retry decision using * the same host and the provided consistency level. * <p/> * If the provided consistency level is {@code null}, the retry will be done at the same consistency level as * the previous attempt. * <p/> * Beware that {@link ConsistencyLevel#isSerial() serial} consistency levels * should never be passed to this method; attempting to do so would trigger an * {@link com.datastax.driver.core.exceptions.InvalidQueryException InvalidQueryException}. * * @param consistency the consistency level to use for the retry; if {@code null}, * the same level as the previous attempt will be used. * @return a {@link RetryDecision.Type#RETRY} decision using * the same host and the provided consistency level */ public static RetryDecision retry(ConsistencyLevel consistency) { return new RetryDecision(Type.RETRY, consistency, true); }
/** * Creates a {@link RetryDecision.Type#RETRY} retry decision using the next host * in the query plan, and using the provided consistency level. * <p/> * If the provided consistency level is {@code null}, the retry will be done at the same consistency level as * the previous attempt. * <p/> * Beware that {@link ConsistencyLevel#isSerial() serial} consistency levels * should never be passed to this method; attempting to do so would trigger an * {@link com.datastax.driver.core.exceptions.InvalidQueryException InvalidQueryException}. * * @param consistency the consistency level to use for the retry; if {@code null}, * the same level as the previous attempt will be used. * @return a {@link RetryDecision.Type#RETRY} retry decision using the next host * in the query plan, and using the provided consistency level. */ public static RetryDecision tryNextHost(ConsistencyLevel consistency) { return new RetryDecision(Type.RETRY, consistency, false); }
@Test(groups = "unit") public void should_expose_decision_properties() throws Throwable { RetryDecision retryAtOne = RetryDecision.retry(ONE); assertThat(retryAtOne.getType()).isEqualTo(RETRY); assertThat(retryAtOne.getRetryConsistencyLevel()).isEqualTo(ONE); assertThat(retryAtOne.isRetryCurrent()).isTrue(); assertThat(retryAtOne.toString()).isEqualTo("Retry at ONE on same host."); RetryDecision tryNextAtOne = RetryDecision.tryNextHost(ONE); assertThat(tryNextAtOne.getType()).isEqualTo(RETRY); assertThat(tryNextAtOne.getRetryConsistencyLevel()).isEqualTo(ONE); assertThat(tryNextAtOne.isRetryCurrent()).isFalse(); assertThat(tryNextAtOne.toString()).isEqualTo("Retry at ONE on next host."); RetryDecision rethrow = RetryDecision.rethrow(); assertThat(rethrow.getType()).isEqualTo(RETHROW); assertThat(rethrow.toString()).isEqualTo("Rethrow"); RetryDecision ignore = RetryDecision.ignore(); assertThat(ignore.getType()).isEqualTo(IGNORE); assertThat(ignore.toString()).isEqualTo("Ignore"); } }
private static ConsistencyLevel cl(ConsistencyLevel cl, RetryDecision decision) { return decision.getRetryConsistencyLevel() == null ? cl : decision.getRetryConsistencyLevel(); }
private static String host(RetryDecision decision) { return decision.isRetryCurrent() ? "same host" : "next host"; }
private static String host(RetryDecision decision) { return decision.isRetryCurrent() ? "same host" : "next host"; }
private static ConsistencyLevel cl(ConsistencyLevel cl, RetryDecision decision) { return decision.getRetryConsistencyLevel() == null ? cl : decision.getRetryConsistencyLevel(); }
private static String host(RetryDecision decision) { return decision.isRetryCurrent() ? "same host" : "next host"; }
private static ConsistencyLevel cl(ConsistencyLevel cl, RetryDecision decision) { return decision.getRetryConsistencyLevel() == null ? cl : decision.getRetryConsistencyLevel(); }
@Test(groups = "short") public void should_log_ignored_request_error() throws InterruptedException { simulateError(1, server_error); retryDecision = ignore(); query(); String line = appender.waitAndGet(5000); assertThat(line.trim()) .isEqualTo( expectedMessage( IGNORING_REQUEST_ERROR, defaultCL, 0, new ServerError(host1.getSocketAddress(), "Server Error").toString())); }
private static ConsistencyLevel cl(ConsistencyLevel cl, RetryDecision decision) { return decision.getRetryConsistencyLevel() == null ? cl : decision.getRetryConsistencyLevel(); }