AnalyticsIndexerService { public int index( Experiment experiment, Map<String, Map<BioentityPropertyName, Set<String>>> bioentityIdToProperties, int batchSize) { List<SolrInputDocument> toLoad = new ArrayList<>(batchSize); int addedIntoThisBatch = 0; int addedInTotal = 0; try (SolrInputDocumentInputStream solrInputDocumentInputStream = new SolrInputDocumentInputStream( experimentDataPointStreamFactory.stream(experiment), bioentityIdToProperties)) { Iterator<SolrInputDocument> it = new IterableObjectInputStream<>(solrInputDocumentInputStream).iterator(); while (it.hasNext()) { while (addedIntoThisBatch < batchSize && it.hasNext()) { SolrInputDocument analyticsInputDocument = it.next(); toLoad.add(analyticsInputDocument); addedIntoThisBatch++; } if (addedIntoThisBatch > 0) { UpdateResponse r = solrClient.add(toLoad); LOGGER.info( "Sent {} documents for {}, qTime:{}", addedIntoThisBatch, experiment.getAccession(), r.getQTime()); addedInTotal += addedIntoThisBatch; addedIntoThisBatch = 0; toLoad.clear(); } } } catch (Exception e) { LOGGER.error(e.getMessage(), e); throw new RuntimeException(e); } LOGGER.info("Finished: " + experiment.getAccession()); return addedInTotal; } AnalyticsIndexerService(SolrClient solrClientAnalytics,
                                   ExperimentDataPointStreamFactory experimentDataPointStreamFactory); int index(
            Experiment experiment,
            Map<String, Map<BioentityPropertyName, Set<String>>> bioentityIdToProperties, int batchSize); synchronized void deleteExperimentFromIndex(String accession); synchronized void deleteAll(); synchronized void commitAfterAdd(); synchronized void optimize();  }
@Test public void successfulRunForNoData() throws Exception { BaselineExperimentDataPoint[] nullArray = {null}; mockExperimentDataPointStreamFactory(experimentDataPointStreamFactory, experiment, nullArray); Map<String, Map<BioentityPropertyName, Set<String>>> bioentityIdToIdentifierSearch = new HashMap<>(); int batchSize = Integer.parseInt(DEFAULT_SOLR_BATCH_SIZE); int response = subject.index(experiment, bioentityIdToIdentifierSearch, batchSize); Mockito.verify(solrClient, times(0)).add(anyCollection()); assertThat(response, is(0)); }
@Test(expected = RuntimeException.class) public void exceptionsFromIteratorArePropagated() throws Exception { final ExperimentDataPoint experimentDataPoint = Mockito.mock(ExperimentDataPoint.class); Mockito.doAnswer(invocationOnMock -> ImmutableList.of(experimentDataPoint)) .when(experimentDataPointStreamFactory).stream(experiment); Map<String, Map<BioentityPropertyName, Set<String>>> bioentityIdToIdentifierSearch = new HashMap<>(); int batchSize = 1; subject.index(experiment, bioentityIdToIdentifierSearch, batchSize); }
@Test(expected = RuntimeException.class) public void exceptionsFromSolrAreWrappedAndThrown() throws Exception { final BaselineExperimentDataPoint baselineExperimentDataPointMock = Mockito.mock(BaselineExperimentDataPoint.class); when(baselineExperimentDataPointMock.getRelevantBioentityPropertyNames()).thenReturn(ImmutableList.of()); mockExperimentDataPointStreamFactory( experimentDataPointStreamFactory, experiment, baselineExperimentDataPointMock, null); Map<String, Map<BioentityPropertyName, Set<String>>> bioentityIdToIdentifierSearch = new HashMap<>(); int batchSize = 1; subject.index(experiment, bioentityIdToIdentifierSearch, batchSize); }
@Test(expected = RuntimeException.class) public void exceptionsFromFilesAreWrappedAndThrown() throws Exception { when(experimentDataPointStreamFactory.stream(experiment)) .thenThrow(new NoSuchFileException(String.format("%s-tpms.tsv not found", experiment.getAccession()))); Map<String, Map<BioentityPropertyName, Set<String>>> bioentityIdToIdentifierSearch = new HashMap<>(); int batchSize = 1; subject.index(experiment, bioentityIdToIdentifierSearch, batchSize); }