@Test(groups = "unit") public void should_create_proper_unavailable_exception() { UnavailableException e = new UnavailableException(address1, LOCAL_QUORUM, 3, 2); assertThat(e.getMessage()) .isEqualTo( "Not enough replicas available for query at consistency LOCAL_QUORUM (3 required but only 2 alive)"); assertThat(e.getConsistencyLevel()).isEqualTo(LOCAL_QUORUM); assertThat(e.getAliveReplicas()).isEqualTo(2); assertThat(e.getRequiredReplicas()).isEqualTo(3); assertThat(e.getAddress()).isEqualTo(address1); assertThat(e.getHost()).isEqualTo(address1.getAddress()); e = e.copy(address2); assertThat(e.getMessage()) .isEqualTo( "Not enough replicas available for query at consistency LOCAL_QUORUM (3 required but only 2 alive)"); assertThat(e.getConsistencyLevel()).isEqualTo(LOCAL_QUORUM); assertThat(e.getAliveReplicas()).isEqualTo(2); assertThat(e.getRequiredReplicas()).isEqualTo(3); assertThat(e.getAddress()).isEqualTo(address2); assertThat(e.getHost()).isEqualTo(address2.getAddress()); }
@Override public UnavailableException copy() { return new UnavailableException(getAddress(), getMessage(), this, consistency, required, alive); }
/** * 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 UnavailableException copy(InetSocketAddress address) { return new UnavailableException(address, getMessage(), this, consistency, required, alive); } }
@Test(groups = "short") public void should_throw_proper_unavailable_exception() { simulateError(1, unavailable); try { query(); fail("expected an UnavailableException"); } catch (UnavailableException e) { assertThat(e.getMessage()) .isEqualTo( "Not enough replicas available for query at consistency LOCAL_ONE (1 required but only 0 alive)"); assertThat(e.getConsistencyLevel()).isEqualTo(LOCAL_ONE); assertThat(e.getAliveReplicas()).isEqualTo(0); assertThat(e.getRequiredReplicas()).isEqualTo(1); assertThat(e.getAddress()).isEqualTo(host1.getSocketAddress()); assertThat(e.getHost()).isEqualTo(host1.getAddress()); } }
retryPolicy.onUnavailable( statement, ue.getConsistencyLevel(), ue.getRequiredReplicas(), ue.getAliveReplicas(), retriesByPolicy); if (metricsEnabled()) {
return new CassandraInsufficientReplicasAvailableException(ux.getRequiredReplicas(), ux.getAliveReplicas(), exception.getMessage(), exception);
@Test(groups = "short") public void should_rethrow_on_unavailable_if_CAS() { simulateError(1, unavailable, new UnavailableConfig(1, 0, SERIAL)); simulateError(2, unavailable, new UnavailableConfig(1, 0, SERIAL)); try { query(); fail("expected an UnavailableException"); } catch (UnavailableException e) { assertThat(e.getConsistencyLevel()).isEqualTo(ConsistencyLevel.SERIAL); } assertOnUnavailableWasCalled(2); assertThat(errors.getRetries().getCount()).isEqualTo(1); assertThat(errors.getUnavailables().getCount()).isEqualTo(2); assertThat(errors.getRetriesOnUnavailable().getCount()).isEqualTo(1); assertQueried(1, 1); assertQueried(2, 1); assertQueried(3, 0); }
return new AuthenticationException(host, message); case UNAVAILABLE: return ((UnavailableException) infos).copy(host); // We copy to have a nice stack trace case OVERLOADED: return new OverloadedException(host, message);
logger.error(ue.getMessage()); throw ue;
new UnavailableException(ConsistencyLevel.ANY, 0, 0), new OverloadedException(null, "Overloaded"), new BootstrappingException(null, "Bootstrapping"),
@Test(groups = "short") public void should_throw_proper_unavailable_exception() { simulateError(1, unavailable); try { query(); fail("expected an UnavailableException"); } catch (UnavailableException e) { assertThat(e.getMessage()) .isEqualTo( "Not enough replicas available for query at consistency LOCAL_ONE (1 required but only 0 alive)"); assertThat(e.getConsistencyLevel()).isEqualTo(LOCAL_ONE); assertThat(e.getAliveReplicas()).isEqualTo(0); assertThat(e.getRequiredReplicas()).isEqualTo(1); assertThat(e.getAddress()).isEqualTo(host1.getSocketAddress()); assertThat(e.getHost()).isEqualTo(host1.getAddress()); } }
UnavailableException ue = (UnavailableException) err.infos; retry = retryPolicy.onUnavailable(statement, ue.getConsistencyLevel(), ue.getRequiredReplicas(), ue.getAliveReplicas(), retriesByPolicy); if (metricsEnabled()) {
@Override public UnavailableException copy() { return new UnavailableException(getAddress(), getMessage(), this, consistency, required, alive); }
@Override public DriverException copy() { return new UnavailableException(getMessage(), this, consistency, required, alive); } }
return new CassandraInsufficientReplicasAvailableException(ux.getRequiredReplicas(), ux.getAliveReplicas(), message, exception);
@Test(groups = "short") public void should_rethrow_on_unavailable_if_CAS() { simulateError(1, unavailable, new UnavailableConfig(1, 0, LOCAL_SERIAL)); simulateError(2, unavailable, new UnavailableConfig(1, 0, LOCAL_SERIAL)); try { query(); Assert.fail("expected an UnavailableException"); } catch (UnavailableException e) { assertThat(e.getConsistencyLevel()).isEqualTo(ConsistencyLevel.LOCAL_SERIAL); } assertOnUnavailableWasCalled(2); assertThat(errors.getRetries().getCount()).isEqualTo(1); assertThat(errors.getUnavailables().getCount()).isEqualTo(2); assertThat(errors.getRetriesOnUnavailable().getCount()).isEqualTo(1); assertQueried(1, 1); assertQueried(2, 1); assertQueried(3, 0); } }
public DriverException asException(InetSocketAddress host) { switch (code) { case SERVER_ERROR: return new DriverInternalError(String.format("An unexpected error occurred server side on %s: %s", host, message)); case PROTOCOL_ERROR: return new DriverInternalError("An unexpected protocol error occurred. This is a bug in this library, please report: " + message); case BAD_CREDENTIALS: return new AuthenticationException(host, message); case UNAVAILABLE: return ((UnavailableException)infos).copy(); // We copy to have a nice stack trace case OVERLOADED: return new DriverInternalError(String.format("Queried host (%s) was overloaded; this shouldn't happen, another node should have been tried", host)); case IS_BOOTSTRAPPING: return new DriverInternalError(String.format("Queried host (%s) was bootstrapping; this shouldn't happen, another node should have been tried", host)); case TRUNCATE_ERROR: return new TruncateException(message); case WRITE_TIMEOUT: return ((WriteTimeoutException)infos).copy(); case READ_TIMEOUT: return ((ReadTimeoutException)infos).copy(); case SYNTAX_ERROR: return new SyntaxError(message); case UNAUTHORIZED: return new UnauthorizedException(message); case INVALID: return new InvalidQueryException(message); case CONFIG_ERROR: return new InvalidConfigurationInQueryException(message); case ALREADY_EXISTS: return ((AlreadyExistsException)infos).copy(); case UNPREPARED: return new DriverInternalError(String.format("A prepared query was submitted on %s but was not known of that node; this shouldn't happen, the query should have been re-prepared", host)); default: return new DriverInternalError(String.format("Unknown protocol error code %s returned by %s. The error message was: %s", code, host, message)); } }
new UnavailableException(ConsistencyLevel.ANY, 0, 0), new OverloadedException(null, "Overloaded"), new BootstrappingException(null, "Bootstrapping"),
@Test(groups = "unit") public void should_create_proper_unavailable_exception() { UnavailableException e = new UnavailableException(address1, LOCAL_QUORUM, 3, 2); assertThat(e.getMessage()) .isEqualTo( "Not enough replicas available for query at consistency LOCAL_QUORUM (3 required but only 2 alive)"); assertThat(e.getConsistencyLevel()).isEqualTo(LOCAL_QUORUM); assertThat(e.getAliveReplicas()).isEqualTo(2); assertThat(e.getRequiredReplicas()).isEqualTo(3); assertThat(e.getAddress()).isEqualTo(address1); assertThat(e.getHost()).isEqualTo(address1.getAddress()); e = e.copy(address2); assertThat(e.getMessage()) .isEqualTo( "Not enough replicas available for query at consistency LOCAL_QUORUM (3 required but only 2 alive)"); assertThat(e.getConsistencyLevel()).isEqualTo(LOCAL_QUORUM); assertThat(e.getAliveReplicas()).isEqualTo(2); assertThat(e.getRequiredReplicas()).isEqualTo(3); assertThat(e.getAddress()).isEqualTo(address2); assertThat(e.getHost()).isEqualTo(address2.getAddress()); }
UnavailableException ue = (UnavailableException) err.infos; retry = retryPolicy.onUnavailable(statement, ue.getConsistencyLevel(), ue.getRequiredReplicas(), ue.getAliveReplicas(), retriesByPolicy); if (metricsEnabled()) {