@Test void search() { when(searchAction.apply(any())).thenReturn(searchResponse); when(searchResponse.getHits()).thenReturn(searchHits); when(searchHits.getHits()).thenReturn(new SearchHit[] {searchHit}); ElasticsearchResponse searchResponse = request.search(searchAction, scrollAction); assertFalse(searchResponse.isEmpty()); searchResponse = request.search(searchAction, scrollAction); assertTrue(searchResponse.isEmpty()); verify(searchAction, times(1)).apply(any()); }
@Override public ElasticsearchResponse search(Function<SearchRequest, SearchResponse> searchAction, Function<SearchScrollRequest, SearchResponse> scrollAction) { if (searchDone) { return new ElasticsearchResponse(SearchHits.empty(), exprValueFactory); } else { searchDone = true; return new ElasticsearchResponse(searchAction.apply(searchRequest()), exprValueFactory); } }
ElasticsearchQueryRequest implements ElasticsearchRequest { @Override public ElasticsearchResponse search(Function<SearchRequest, SearchResponse> searchAction, Function<SearchScrollRequest, SearchResponse> scrollAction) { if (searchDone) { return new ElasticsearchResponse(SearchHits.empty(), exprValueFactory); } else { searchDone = true; return new ElasticsearchResponse(searchAction.apply(searchRequest()), exprValueFactory); } } }
ElasticsearchQueryRequest implements ElasticsearchRequest { @Override public ElasticsearchResponse search(Function<SearchRequest, SearchResponse> searchAction, Function<SearchScrollRequest, SearchResponse> scrollAction) { if (searchDone) { return new ElasticsearchResponse(SearchHits.empty(), exprValueFactory); } else { searchDone = true; return new ElasticsearchResponse(searchAction.apply(searchRequest()), exprValueFactory); } } ElasticsearchQueryRequest(String indexName, int size,
                                   ElasticsearchExprValueFactory factory); }
ElasticsearchQueryRequest implements ElasticsearchRequest { @Override public ElasticsearchResponse search(Function<SearchRequest, SearchResponse> searchAction, Function<SearchScrollRequest, SearchResponse> scrollAction) { if (searchDone) { return new ElasticsearchResponse(SearchHits.empty(), exprValueFactory); } else { searchDone = true; return new ElasticsearchResponse(searchAction.apply(searchRequest()), exprValueFactory); } } ElasticsearchQueryRequest(String indexName, int size,
                                   ElasticsearchExprValueFactory factory); @Override ElasticsearchResponse search(Function<SearchRequest, SearchResponse> searchAction,
                                      Function<SearchScrollRequest, SearchResponse> scrollAction); @Override void clean(Consumer<String> cleanAction); }
ElasticsearchQueryRequest implements ElasticsearchRequest { @Override public ElasticsearchResponse search(Function<SearchRequest, SearchResponse> searchAction, Function<SearchScrollRequest, SearchResponse> scrollAction) { if (searchDone) { return new ElasticsearchResponse(SearchHits.empty(), exprValueFactory); } else { searchDone = true; return new ElasticsearchResponse(searchAction.apply(searchRequest()), exprValueFactory); } } ElasticsearchQueryRequest(String indexName, int size,
                                   ElasticsearchExprValueFactory factory); @Override ElasticsearchResponse search(Function<SearchRequest, SearchResponse> searchAction,
                                      Function<SearchScrollRequest, SearchResponse> scrollAction); @Override void clean(Consumer<String> cleanAction); static final TimeValue DEFAULT_QUERY_TIMEOUT; }