@Test
void scrollWithIOException() throws IOException {

  // Mock first scroll request
  SearchResponse searchResponse = mock(SearchResponse.class);
  when(restClient.search(any(), any())).thenReturn(searchResponse);
  when(searchResponse.getScrollId()).thenReturn("scroll123");
  when(searchResponse.getHits())
      .thenReturn(
          new SearchHits(
              new SearchHit[] {new SearchHit(1)},
              new TotalHits(1L, TotalHits.Relation.EQUAL_TO),
              1.0F));
  // Mock second scroll request followed
  when(restClient.scroll(any(), any())).thenThrow(new IOException());
  // First request run successfully
  ElasticsearchScrollRequest scrollRequest = new ElasticsearchScrollRequest("test", factory);
  client.search(scrollRequest);
  assertThrows(
      IllegalStateException.class, () -> client.search(scrollRequest));
}