ElasticsearchNodeClient implements ElasticsearchClient { @Override public void cleanup(ElasticsearchRequest request) { request.clean(scrollId -> client.prepareClearScroll().addScrollId(scrollId).get()); }  @Override Map<String, IndexMapping> getIndexMappings(String indexExpression); @Override ElasticsearchResponse search(ElasticsearchRequest request); @Override void cleanup(ElasticsearchRequest request); @Override void schedule(Runnable task); static final String[] ALL_TYPES; static final Function<String, Predicate<String>> ALL_FIELDS; }
@Test void cleanup() { ClearScrollRequestBuilder requestBuilder = mock(ClearScrollRequestBuilder.class); when(nodeClient.prepareClearScroll()).thenReturn(requestBuilder); when(requestBuilder.addScrollId(any())).thenReturn(requestBuilder); when(requestBuilder.get()).thenReturn(null); ElasticsearchNodeClient client = new ElasticsearchNodeClient(mock(ClusterService.class), nodeClient); ElasticsearchScrollRequest request = new ElasticsearchScrollRequest("test", factory); request.setScrollId("scroll123"); client.cleanup(request); assertFalse(request.isScrollStarted()); InOrder inOrder = Mockito.inOrder(nodeClient, requestBuilder); inOrder.verify(nodeClient).prepareClearScroll(); inOrder.verify(requestBuilder).addScrollId("scroll123"); inOrder.verify(requestBuilder).get(); }
@Test void cleanupWithoutScrollId() { ElasticsearchNodeClient client = new ElasticsearchNodeClient(mock(ClusterService.class), nodeClient); ElasticsearchScrollRequest request = new ElasticsearchScrollRequest("test", factory); client.cleanup(request); verify(nodeClient, never()).prepareClearScroll(); }