ScanIndexTask extends DefaultTask<Long> implements UserTask { @Override public Long call() throws Exception { logger.info("scanning index {} with scroll size {} and {} slices", projectName, scrollSize, scrollSlices); Optional<Long> nb = IntStream.range(0, scrollSlices).parallel().mapToObj(this::slicedScroll).reduce(Long::sum); logger.info("imported {} paths into {}", nb.get(), reportMap); reportMap.close(); return nb.get(); } @Inject  ScanIndexTask(DocumentCollectionFactory factory, final Indexer indexer, final PropertiesProvider propertiesProvider,
                         @Assisted User user, @Assisted String reportName); @Override Long call(); @Override User getUser();  }
@Test public void test_empty_index() throws Exception { assertThat(new ScanIndexTask(documentCollectionFactory, indexer, propertiesProvider, User.nullUser(), "test:report").call()).isEqualTo(0); }
@Test public void test_transfer_indexed_paths_to_filter_set() throws Exception { indexer.add(TEST_INDEX, DocumentBuilder.createDoc("id1").build()); indexer.add(TEST_INDEX, DocumentBuilder.createDoc("id2").build()); assertThat(new ScanIndexTask(documentCollectionFactory, indexer, propertiesProvider, User.nullUser(), "test:report").call()).isEqualTo(2); ReportMap actualReportMap = documentCollectionFactory.createMap(propertiesProvider, "test:report"); assertThat(actualReportMap).includes( entry(Paths.get("file:/path/to/id1"), new Report(ExtractionStatus.SUCCESS)), entry(Paths.get("file:/path/to/id2"), new Report(ExtractionStatus.SUCCESS)) ); }