Closed
@olavloite

Description

The following test case shows that the callback will continue to be called after the callback has returned PAUSE and the result set has been cancelled. This will only happen if the callback method does not call resultSet.tryNext().

@Test
public void testCallbackIsNotCalledWhilePausedAndCanceled() throws InterruptedException, ExecutionException {
  Executor executor = Executors.newSingleThreadExecutor();
  ResultSet delegate = mock(ResultSet.class);

  final AtomicInteger callbackCounter = new AtomicInteger();

  try (AsyncResultSetImpl rs =
      new AsyncResultSetImpl(simpleProvider, delegate, AsyncResultSetImpl.DEFAULT_BUFFER_SIZE)) {
        rs.setCallback(executor,
            resultSet -> {
              callbackCounter.getAndIncrement();
              return CallbackResponse.PAUSE;
            });

    rs.cancel();

    while (callbackCounter.get() < 100) {
      Thread.yield();
    }

   assertThat(callbackCounter.get()).isGreaterThan(99);
  }
}