@Test @SuppressWarnings("unchecked") void testBatchingSearchPageSizeLargerThanMax() { QueryImpl<Entity> query = mock(QueryImpl.class); when(query.getPageSize()).thenReturn(10001); when(query.getOffset()).thenReturn(5000); SearchHits searchHitsBatch = mock(SearchHits.class); when(searchHitsBatch.getHits()).thenReturn(asList(new SearchHit[10000])); SearchHits finalSearchHitsBatch = mock(SearchHits.class); when(finalSearchHitsBatch.getHits()).thenReturn(asList(new SearchHit[1])); when(clientFacade.search(any(), eq(5000), eq(MAX_BATCH_SIZE), any(), any())) .thenReturn(searchHitsBatch); when(clientFacade.search(any(), eq(15000), eq(1), any(), any())) .thenReturn(finalSearchHitsBatch); elasticsearchService.search(entityType, query); verify(clientFacade, times(1)).search(any(), eq(5000), eq(MAX_BATCH_SIZE), any(), any()); verify(clientFacade, times(1)).search(any(), eq(15000), eq(1), any(), any()); verifyNoMoreInteractions(clientFacade); }
@Override public Stream<Object> search(EntityType entityType, Query<Entity> q) { int from = q.getOffset(); return search(entityType, q, from, q.getPageSize()); }
ElasticsearchService implements SearchService, IndexService { @Override public Stream<Object> search(EntityType entityType, Query<Entity> q) { int from = q.getOffset(); return search(entityType, q, from, q.getPageSize()); } }
ElasticsearchService implements SearchService, IndexService { @Override public Stream<Object> search(EntityType entityType, Query<Entity> q) { int from = q.getOffset(); return search(entityType, q, from, q.getPageSize()); } ElasticsearchService(
      ClientFacade clientFacade, ContentGenerators contentGenerators, DataService dataService); }
ElasticsearchService implements SearchService, IndexService { @Override public Stream<Object> search(EntityType entityType, Query<Entity> q) { int from = q.getOffset(); return search(entityType, q, from, q.getPageSize()); } ElasticsearchService(
      ClientFacade clientFacade, ContentGenerators contentGenerators, DataService dataService); @Override void createIndex(EntityType entityType); @Override boolean hasIndex(EntityType entityType); @Override void deleteIndex(EntityType entityType); @Override void rebuildIndex(Repository<? extends Entity> repository); @Override void refreshIndex(); @Override long count(EntityType entityType); @Override long count(EntityType entityType, Query<Entity> q); @Override Stream<Object> search(EntityType entityType, Query<Entity> q); @Override Object searchOne(EntityType entityType, Query<Entity> q); @Override AggregateResult aggregate(final EntityType entityType, AggregateQuery aggregateQuery); Explanation explain(EntityType entityType, Object entityId, Query<Entity> q); @Override void index(EntityType entityType, Entity entity); @Override long index(EntityType entityType, Stream<? extends Entity> entities); @Override void delete(EntityType entityType, Entity entity); @Override void deleteById(EntityType entityType, Object entityId); @Override void deleteAll(EntityType entityType, Stream<Object> entityIds); @Override void delete(EntityType entityType, Stream<? extends Entity> entities); }
ElasticsearchService implements SearchService, IndexService { @Override public Stream<Object> search(EntityType entityType, Query<Entity> q) { int from = q.getOffset(); return search(entityType, q, from, q.getPageSize()); } ElasticsearchService(
      ClientFacade clientFacade, ContentGenerators contentGenerators, DataService dataService); @Override void createIndex(EntityType entityType); @Override boolean hasIndex(EntityType entityType); @Override void deleteIndex(EntityType entityType); @Override void rebuildIndex(Repository<? extends Entity> repository); @Override void refreshIndex(); @Override long count(EntityType entityType); @Override long count(EntityType entityType, Query<Entity> q); @Override Stream<Object> search(EntityType entityType, Query<Entity> q); @Override Object searchOne(EntityType entityType, Query<Entity> q); @Override AggregateResult aggregate(final EntityType entityType, AggregateQuery aggregateQuery); Explanation explain(EntityType entityType, Object entityId, Query<Entity> q); @Override void index(EntityType entityType, Entity entity); @Override long index(EntityType entityType, Stream<? extends Entity> entities); @Override void delete(EntityType entityType, Entity entity); @Override void deleteById(EntityType entityType, Object entityId); @Override void deleteAll(EntityType entityType, Stream<Object> entityIds); @Override void delete(EntityType entityType, Stream<? extends Entity> entities); static final int MAX_BATCH_SIZE; }