protected void checkCassandraException(Exception e) { _mexceptions.incr(); if (e instanceof AlreadyExistsException || e instanceof AuthenticationException || e instanceof DriverException || e instanceof DriverInternalError || e instanceof InvalidConfigurationInQueryException || e instanceof InvalidQueryException || e instanceof InvalidTypeException || e instanceof QueryExecutionException || e instanceof QueryTimeoutException || e instanceof QueryValidationException || e instanceof ReadTimeoutException || e instanceof SyntaxError || e instanceof TraceRetrievalException || e instanceof TruncateException || e instanceof UnauthorizedException || e instanceof UnavailableException || e instanceof ReadTimeoutException || e instanceof WriteTimeoutException) { throw new ReportedFailedException(e); } else { throw new RuntimeException(e); } }
@Test public void testShouldReturnReadTimeout() throws Exception { server.prime(when(query).then(readTimeout(ConsistencyLevel.TWO, 1, 2, false))); thrown.expect(ReadTimeoutException.class); thrown.expect( match( (ReadTimeoutException rte) -> rte.getRequiredAcknowledgements() == 2 && rte.getReceivedAcknowledgements() == 1 && !rte.wasDataRetrieved() && rte.getConsistencyLevel() == com.datastax.driver.core.ConsistencyLevel.TWO)); query(); }
/** * Checks if Cassandra host availability error occur, thus host became unavailable. * * @param e Exception to check. * @return {@code true} in case of host not available error. */ public static boolean isHostsAvailabilityError(Throwable e) { while (e != null) { if (e instanceof NoHostAvailableException || e instanceof ReadTimeoutException) return true; e = e.getCause(); } return false; }
@Override public List<Person> retrievePeople() { ResultSet result; try { Statement statement = new SimpleStatement("select * from person"); statement.setConsistencyLevel(ConsistencyLevel.QUORUM); result = session.execute(statement); } catch (ReadTimeoutException e) { throw new UnableToRetrievePeopleException(); } return result.all().stream().map( row -> new Person(row.getString("first_name"), row.getString("last_name"), row.getInt("age"), row.getSet("interesting_dates", Date.class)) ).collect(Collectors.toList()); }