@Override public ReadTimeoutException copy() { return new ReadTimeoutException( getAddress(), getMessage(), this, getConsistencyLevel(), getReceivedAcknowledgements(), getRequiredAcknowledgements(), wasDataRetrieved()); }
@Test(groups = "unit") public void should_create_proper_read_timeout_exception() { ReadTimeoutException e = new ReadTimeoutException(address1, LOCAL_QUORUM, 2, 3, true); assertThat(e.getMessage()) .isEqualTo( "Cassandra timeout during read query at consistency LOCAL_QUORUM (3 responses were required but only 2 replica responded)"); assertThat(e.getConsistencyLevel()).isEqualTo(LOCAL_QUORUM); assertThat(e.getReceivedAcknowledgements()).isEqualTo(2); assertThat(e.getRequiredAcknowledgements()).isEqualTo(3); assertThat(e.wasDataRetrieved()).isTrue(); assertThat(e.getAddress()).isEqualTo(address1); assertThat(e.getHost()).isEqualTo(address1.getAddress()); e = e.copy(address2); assertThat(e.getMessage()) .isEqualTo( "Cassandra timeout during read query at consistency LOCAL_QUORUM (3 responses were required but only 2 replica responded)"); assertThat(e.getConsistencyLevel()).isEqualTo(LOCAL_QUORUM); assertThat(e.getReceivedAcknowledgements()).isEqualTo(2); assertThat(e.getRequiredAcknowledgements()).isEqualTo(3); assertThat(e.wasDataRetrieved()).isTrue(); assertThat(e.getAddress()).isEqualTo(address2); assertThat(e.getHost()).isEqualTo(address2.getAddress()); }
@Test(groups = "short") public void should_throw_proper_read_timeout_exception() { simulateError(1, read_request_timeout); try { query(); fail("expected a ReadTimeoutException"); } catch (ReadTimeoutException e) { assertThat(e.getMessage()) .isEqualTo( "Cassandra timeout during read query at consistency LOCAL_ONE (1 responses were required but only 0 replica responded)"); assertThat(e.getConsistencyLevel()).isEqualTo(LOCAL_ONE); assertThat(e.getReceivedAcknowledgements()).isEqualTo(0); assertThat(e.getRequiredAcknowledgements()).isEqualTo(1); assertThat(e.getAddress()).isEqualTo(host1.getSocketAddress()); assertThat(e.getHost()).isEqualTo(host1.getAddress()); } }
/** * Create a copy of this exception with a nicer stack trace, and including the coordinator address * that caused this exception to be raised. * * <p>This method is mainly intended for internal use by the driver and exists mainly because: * * <ol> * <li>the original exception was decoded from a response frame and at that time, the * coordinator address was not available; and * <li>the newly-created exception will refer to the current thread in its stack trace, which * generally yields a more user-friendly stack trace that the original one. * </ol> * * @param address The full address of the host that caused this exception to be thrown. * @return a copy/clone of this exception, but with the given host address instead of the original * one. */ public ReadTimeoutException copy(InetSocketAddress address) { return new ReadTimeoutException( address, getMessage(), this, getConsistencyLevel(), getReceivedAcknowledgements(), getRequiredAcknowledgements(), wasDataRetrieved()); } }
/** * Ensures that when handling a read timeout with {@link DowngradingConsistencyRetryPolicy} that a * retry is reattempted with a {@link ConsistencyLevel} that matches min(received * acknowledgements, THREE) and is only retried once. * * @param received The number of received acknowledgements to use in read timeout. * @param expectedDowngradedCL The consistency level that is expected to be used on the retry. * @test_category retry_policy */ @Test(groups = "short", dataProvider = "consistencyLevels") public void should_retry_once_on_same_host_with_reduced_consistency_level_on_read_timeout( int received, ConsistencyLevel expectedDowngradedCL) { simulateError(1, read_request_timeout, new ReadTimeoutConfig(received, received + 1, true)); try { query(); fail("expected an ReadTimeoutException"); } catch (ReadTimeoutException e) { assertThat(e.getConsistencyLevel()).isEqualTo(expectedDowngradedCL); } assertOnReadTimeoutWasCalled(2); assertThat(errors.getRetries().getCount()).isEqualTo(1); assertThat(errors.getReadTimeouts().getCount()).isEqualTo(2); assertThat(errors.getRetriesOnReadTimeout().getCount()).isEqualTo(1); assertQueried(1, 2); assertQueried(2, 0); assertQueried(3, 0); }
/** * Ensures that when handling a read timeout with {@link DowngradingConsistencyRetryPolicy} that a * retry is reattempted with {@link ConsistencyLevel#ONE} if the consistency level on the * statement executed is {@link ConsistencyLevel#EACH_QUORUM}, even if the number of known alive * replicas was 0. * * @jira_ticket JAVA-1005 * @test_category retry_policy */ @Test(groups = "short") public void should_retry_once_on_same_host_from_each_quorum_to_one() { simulateError(1, read_request_timeout, new ReadTimeoutConfig(0, 3, false)); try { queryWithCL(ConsistencyLevel.EACH_QUORUM); } catch (ReadTimeoutException e) { assertThat(e.getConsistencyLevel()).isEqualTo(ConsistencyLevel.ONE); } assertOnReadTimeoutWasCalled(2); assertThat(errors.getRetries().getCount()).isEqualTo(1); assertThat(errors.getReadTimeouts().getCount()).isEqualTo(2); assertThat(errors.getRetriesOnReadTimeout().getCount()).isEqualTo(1); assertQueried(1, 2); assertQueried(2, 0); assertQueried(3, 0); }
retryPolicy.onReadTimeout( statement, rte.getConsistencyLevel(), rte.getRequiredAcknowledgements(), rte.getReceivedAcknowledgements(),
@Override public DriverException copy() { return new ReadTimeoutException(getMessage(), this, getConsistencyLevel(), getReceivedAcknowledgements(), getRequiredAcknowledgements(), wasDataRetrieved()); } }
@Override public ReadTimeoutException copy() { return new ReadTimeoutException( getAddress(), getMessage(), this, getConsistencyLevel(), getReceivedAcknowledgements(), getRequiredAcknowledgements(), wasDataRetrieved() ); }
@Override public ReadTimeoutException copy() { return new ReadTimeoutException( getAddress(), getMessage(), this, getConsistencyLevel(), getReceivedAcknowledgements(), getRequiredAcknowledgements(), wasDataRetrieved() ); }
@Override public ReadTimeoutException copy() { return new ReadTimeoutException( getAddress(), getMessage(), this, getConsistencyLevel(), getReceivedAcknowledgements(), getRequiredAcknowledgements(), wasDataRetrieved() ); }
@Test(groups = "short") public void should_throw_proper_read_timeout_exception() { simulateError(1, read_request_timeout); try { query(); fail("expected a ReadTimeoutException"); } catch (ReadTimeoutException e) { assertThat(e.getMessage()) .isEqualTo( "Cassandra timeout during read query at consistency LOCAL_ONE (1 responses were required but only 0 replica responded)"); assertThat(e.getConsistencyLevel()).isEqualTo(LOCAL_ONE); assertThat(e.getReceivedAcknowledgements()).isEqualTo(0); assertThat(e.getRequiredAcknowledgements()).isEqualTo(1); assertThat(e.getAddress()).isEqualTo(host1.getSocketAddress()); assertThat(e.getHost()).isEqualTo(host1.getAddress()); } }
@Test(groups = "unit") public void should_create_proper_read_timeout_exception() { ReadTimeoutException e = new ReadTimeoutException(address1, LOCAL_QUORUM, 2, 3, true); assertThat(e.getMessage()) .isEqualTo( "Cassandra timeout during read query at consistency LOCAL_QUORUM (3 responses were required but only 2 replica responded)"); assertThat(e.getConsistencyLevel()).isEqualTo(LOCAL_QUORUM); assertThat(e.getReceivedAcknowledgements()).isEqualTo(2); assertThat(e.getRequiredAcknowledgements()).isEqualTo(3); assertThat(e.wasDataRetrieved()).isTrue(); assertThat(e.getAddress()).isEqualTo(address1); assertThat(e.getHost()).isEqualTo(address1.getAddress()); e = e.copy(address2); assertThat(e.getMessage()) .isEqualTo( "Cassandra timeout during read query at consistency LOCAL_QUORUM (3 responses were required but only 2 replica responded)"); assertThat(e.getConsistencyLevel()).isEqualTo(LOCAL_QUORUM); assertThat(e.getReceivedAcknowledgements()).isEqualTo(2); assertThat(e.getRequiredAcknowledgements()).isEqualTo(3); assertThat(e.wasDataRetrieved()).isTrue(); assertThat(e.getAddress()).isEqualTo(address2); assertThat(e.getHost()).isEqualTo(address2.getAddress()); }
/** * Create a copy of this exception with a nicer stack trace, and including the coordinator * address that caused this exception to be raised. * <p/> * This method is mainly intended for internal use by the driver and exists mainly because: * <ol> * <li>the original exception was decoded from a response frame * and at that time, the coordinator address was not available; and</li> * <li>the newly-created exception will refer to the current thread in its stack trace, * which generally yields a more user-friendly stack trace that the original one.</li> * </ol> * * @param address The full address of the host that caused this exception to be thrown. * @return a copy/clone of this exception, but with the given host address instead of the original one. */ public ReadTimeoutException copy(InetSocketAddress address) { return new ReadTimeoutException( address, getMessage(), this, getConsistencyLevel(), getReceivedAcknowledgements(), getRequiredAcknowledgements(), wasDataRetrieved() ); }
/** * Create a copy of this exception with a nicer stack trace, and including the coordinator * address that caused this exception to be raised. * <p/> * This method is mainly intended for internal use by the driver and exists mainly because: * <ol> * <li>the original exception was decoded from a response frame * and at that time, the coordinator address was not available; and</li> * <li>the newly-created exception will refer to the current thread in its stack trace, * which generally yields a more user-friendly stack trace that the original one.</li> * </ol> * * @param address The full address of the host that caused this exception to be thrown. * @return a copy/clone of this exception, but with the given host address instead of the original one. */ public ReadTimeoutException copy(InetSocketAddress address) { return new ReadTimeoutException( address, getMessage(), this, getConsistencyLevel(), getReceivedAcknowledgements(), getRequiredAcknowledgements(), wasDataRetrieved() ); }
/** * Create a copy of this exception with a nicer stack trace, and including the coordinator * address that caused this exception to be raised. * <p/> * This method is mainly intended for internal use by the driver and exists mainly because: * <ol> * <li>the original exception was decoded from a response frame * and at that time, the coordinator address was not available; and</li> * <li>the newly-created exception will refer to the current thread in its stack trace, * which generally yields a more user-friendly stack trace that the original one.</li> * </ol> * * @param address The full address of the host that caused this exception to be thrown. * @return a copy/clone of this exception, but with the given host address instead of the original one. */ public ReadTimeoutException copy(InetSocketAddress address) { return new ReadTimeoutException( address, getMessage(), this, getConsistencyLevel(), getReceivedAcknowledgements(), getRequiredAcknowledgements(), wasDataRetrieved() ); }
/** * Ensures that when handling a read timeout with {@link DowngradingConsistencyRetryPolicy} that a * retry is reattempted with {@link ConsistencyLevel#ONE} if the consistency level on the * statement executed is {@link ConsistencyLevel#EACH_QUORUM}, even if the number of known alive * replicas was 0. * * @jira_ticket JAVA-1005 * @test_category retry_policy */ @Test(groups = "short") public void should_retry_once_on_same_host_from_each_quorum_to_one() { simulateError(1, read_request_timeout, new ReadTimeoutConfig(0, 3, false)); try { queryWithCL(ConsistencyLevel.EACH_QUORUM); } catch (ReadTimeoutException e) { assertThat(e.getConsistencyLevel()).isEqualTo(ConsistencyLevel.ONE); } assertOnReadTimeoutWasCalled(2); assertThat(errors.getRetries().getCount()).isEqualTo(1); assertThat(errors.getReadTimeouts().getCount()).isEqualTo(2); assertThat(errors.getRetriesOnReadTimeout().getCount()).isEqualTo(1); assertQueried(1, 2); assertQueried(2, 0); assertQueried(3, 0); }
/** * Ensures that when handling a read timeout with {@link DowngradingConsistencyRetryPolicy} that a * retry is reattempted with a {@link ConsistencyLevel} that matches min(received * acknowledgements, THREE) and is only retried once. * * @param received The number of received acknowledgements to use in read timeout. * @param expectedDowngradedCL The consistency level that is expected to be used on the retry. * @test_category retry_policy */ @Test(groups = "short", dataProvider = "consistencyLevels") public void should_retry_once_on_same_host_with_reduced_consistency_level_on_read_timeout( int received, ConsistencyLevel expectedDowngradedCL) { simulateError(1, read_request_timeout, new ReadTimeoutConfig(received, received + 1, true)); try { query(); fail("expected an ReadTimeoutException"); } catch (ReadTimeoutException e) { assertThat(e.getConsistencyLevel()).isEqualTo(expectedDowngradedCL); } assertOnReadTimeoutWasCalled(2); assertThat(errors.getRetries().getCount()).isEqualTo(1); assertThat(errors.getReadTimeouts().getCount()).isEqualTo(2); assertThat(errors.getRetriesOnReadTimeout().getCount()).isEqualTo(1); assertQueried(1, 2); assertQueried(2, 0); assertQueried(3, 0); }
ReadTimeoutException rte = (ReadTimeoutException) err.infos; retry = retryPolicy.onReadTimeout(statement, rte.getConsistencyLevel(), rte.getRequiredAcknowledgements(), rte.getReceivedAcknowledgements(),
rte.getConsistencyLevel(), rte.getRequiredAcknowledgements(), rte.getReceivedAcknowledgements(),