RateLimitedResultSetFuture implements ResultSetFuture { @Override public ResultSet get() throws InterruptedException, ExecutionException { return safeGet().get(); } RateLimitedResultSetFuture(Session session, AsyncRateLimiter rateLimiter, Statement statement); @Override ResultSet getUninterruptibly(); @Override ResultSet getUninterruptibly(long timeout, TimeUnit unit); @Override boolean cancel(boolean mayInterruptIfRunning); @Override boolean isCancelled(); @Override boolean isDone(); @Override ResultSet get(); @Override ResultSet get(long timeout, TimeUnit unit); @Override void addListener(Runnable listener, Executor executor);  }
@Test public void immidiateCassandraExceptionReturnsPermit() throws InterruptedException, ExecutionException { when(rateLimiter.acquireAsync()).thenReturn(Futures.immediateFuture(null)); when(session.executeAsync(statement)).thenThrow(new UnsupportedFeatureException(ProtocolVersion.V3, "hjg")); resultSetFuture = new RateLimitedResultSetFuture(session, rateLimiter, statement); ListenableFuture<Row> transform = Futures.transform(resultSetFuture, ResultSet::one); try { transform.get(); fail(); } catch (Exception e) { assertTrue(e instanceof ExecutionException); } verify(rateLimiter, times(1)).acquireAsync(); verify(rateLimiter, times(1)).release(); }