@Test
public void doNotReleasePermissionIfRateLimitFutureFailed() throws InterruptedException {

    when(rateLimiter.acquireAsync()).thenReturn(Futures.immediateFailedFuture(new BufferLimitException()));
    resultSetFuture = new RateLimitedResultSetFuture(session, rateLimiter, statement);
    Thread.sleep(1000L);
    verify(rateLimiter).acquireAsync();
    try {
        assertTrue(resultSetFuture.isDone());
        fail();
    } catch (Exception e) {
        assertTrue(e instanceof IllegalStateException);
        Throwable actualCause = e.getCause();
        assertTrue(actualCause instanceof ExecutionException);
    }
    verifyNoMoreInteractions(session, rateLimiter, statement);
}