static RuntimeException propagateCause(ExecutionException e) { Throwable cause = e.getCause(); if (cause instanceof Error) throw ((Error) cause); // We could just rethrow e.getCause(). However, the cause of the ExecutionException has likely been // created on the I/O thread receiving the response. Which means that the stacktrace associated // with said cause will make no mention of the current thread. This is painful for say, finding // out which execute() statement actually raised the exception. So instead, we re-create the // exception. if (cause instanceof DriverException) throw ((DriverException) cause).copy(); else throw new DriverInternalError("Unexpected exception thrown", cause); }
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 stopWithDriverInternalException() { final CassandraSink sink = new CassandraSink(); final Channel channel = mock(Channel.class); final Session session = mock(Session.class); final Cluster cluster = mock(Cluster.class); final Context ctx = new Context(); ctx.put("tables", "keyspace.table"); sink.configure(ctx); sink.setChannel(channel); sink.session = session; sink.cluster = cluster; doThrow(DriverInternalError.class).when(session).close(); doThrow(DriverInternalError.class).when(cluster).close(); sink.stop(); verify(session).isClosed(); verify(session).close(); verifyNoMoreInteractions(session); verify(cluster).isClosed(); verify(cluster).close(); verifyNoMoreInteractions(cluster); }
/** * @param statement te statement to execute in an async manner * @return the resultset future */ public ListenableFuture<ResultSet> executeAsync(Statement statement) { try { return getSession().executeAsync(statement); } catch (InvalidQueryException | DriverInternalError e) { cleanUp(); LOG.warn("could not execute statement", e); return Futures.immediateFailedFuture(e); } }
static Name fromProtocolId(int id) { Name name = nameToIds[id]; if (name == null) throw new DriverInternalError("Unknown data type protocol id: " + id); return name; }