@Test public void deleteFromIndexWithoutCorrespondingJudgmentInDb_WITH_DIFFERENCE() throws SolrServerException, IOException { List<Long> indexIds = Lists.newArrayList(1L, 2L, 3L, 4L); List<Long> databaseIds = Lists.newArrayList(1L, 7L); when(solrJudgmentsServer.query(any())).then(buildSolrResponseAnswer(indexIds)); when(judgmentRepository.filterIdsToExisting(any())).then(new Answer<List<Long>>() { @SuppressWarnings("unchecked") @Override public List<Long> answer(InvocationOnMock invocation) throws Throwable { List<Long> arg = (List<Long>)invocation.getArguments()[0]; return arg.stream().filter(id -> databaseIds.contains(id)).collect(Collectors.toList()); } }); judgmentIndexDeleter.deleteFromIndexWithoutCorrespondingJudgmentInDb(); verify(solrJudgmentsServer, times(2)).deleteById(deleteJudgmentIdsCaptor.capture()); verify(solrJudgmentsServer, times(3)).query(solrParamsCaptor.capture()); verify(judgmentRepository, times(2)).filterIdsToExisting(filterExistingIdsCaptor.capture()); assertThat(deleteJudgmentIdsCaptor.getAllValues().get(0), contains("2")); assertThat(deleteJudgmentIdsCaptor.getAllValues().get(1), contains("3", "4")); assertSolrParams(solrParamsCaptor.getAllValues().get(0), 0, 2); assertSolrParams(solrParamsCaptor.getAllValues().get(1), 2, 2); assertSolrParams(solrParamsCaptor.getAllValues().get(2), 4, 2); assertThat(filterExistingIdsCaptor.getAllValues().get(0), contains(1L, 2L)); assertThat(filterExistingIdsCaptor.getAllValues().get(1), contains(3L, 4L)); verifyNoMoreInteractions(solrJudgmentsServer, judgmentRepository); }
public void deleteFromIndexWithoutCorrespondingJudgmentInDb() throws SolrServerException, IOException { int pageNumber = 0; while (true) { SolrQuery query = createIndexIteratingQuery(pageNumber); QueryResponse response = solrJudgmentsServer.query(query); if (response.getResults().size() == 0) { break; } List<Long> indexJudgmentIds = extractIdsFromResult(response); List<Long> existingJudgmentIds = judgmentRepository.filterIdsToExisting(indexJudgmentIds); List<Long> judgmentIdsToDelete = Lists.newArrayList(indexJudgmentIds); judgmentIdsToDelete.removeAll(existingJudgmentIds); if (judgmentIdsToDelete.size() > 0) { log.info("Removing judgments from index which don't have corresponding entry in database: {}", judgmentIdsToDelete); solrJudgmentsServer.deleteById(judgmentIdsToDelete.stream().map(x -> String.valueOf(x)).collect(Collectors.toList())); } ++pageNumber; } }
JudgmentIndexDeleter { public void deleteFromIndexWithoutCorrespondingJudgmentInDb() throws SolrServerException, IOException { int pageNumber = 0; while (true) { SolrQuery query = createIndexIteratingQuery(pageNumber); QueryResponse response = solrJudgmentsServer.query(query); if (response.getResults().size() == 0) { break; } List<Long> indexJudgmentIds = extractIdsFromResult(response); List<Long> existingJudgmentIds = judgmentRepository.filterIdsToExisting(indexJudgmentIds); List<Long> judgmentIdsToDelete = Lists.newArrayList(indexJudgmentIds); judgmentIdsToDelete.removeAll(existingJudgmentIds); if (judgmentIdsToDelete.size() > 0) { log.info("Removing judgments from index which don't have corresponding entry in database: {}", judgmentIdsToDelete); solrJudgmentsServer.deleteById(judgmentIdsToDelete.stream().map(x -> String.valueOf(x)).collect(Collectors.toList())); } ++pageNumber; } } }
JudgmentIndexDeleter { public void deleteFromIndexWithoutCorrespondingJudgmentInDb() throws SolrServerException, IOException { int pageNumber = 0; while (true) { SolrQuery query = createIndexIteratingQuery(pageNumber); QueryResponse response = solrJudgmentsServer.query(query); if (response.getResults().size() == 0) { break; } List<Long> indexJudgmentIds = extractIdsFromResult(response); List<Long> existingJudgmentIds = judgmentRepository.filterIdsToExisting(indexJudgmentIds); List<Long> judgmentIdsToDelete = Lists.newArrayList(indexJudgmentIds); judgmentIdsToDelete.removeAll(existingJudgmentIds); if (judgmentIdsToDelete.size() > 0) { log.info("Removing judgments from index which don't have corresponding entry in database: {}", judgmentIdsToDelete); solrJudgmentsServer.deleteById(judgmentIdsToDelete.stream().map(x -> String.valueOf(x)).collect(Collectors.toList())); } ++pageNumber; } }  }
JudgmentIndexDeleter { public void deleteFromIndexWithoutCorrespondingJudgmentInDb() throws SolrServerException, IOException { int pageNumber = 0; while (true) { SolrQuery query = createIndexIteratingQuery(pageNumber); QueryResponse response = solrJudgmentsServer.query(query); if (response.getResults().size() == 0) { break; } List<Long> indexJudgmentIds = extractIdsFromResult(response); List<Long> existingJudgmentIds = judgmentRepository.filterIdsToExisting(indexJudgmentIds); List<Long> judgmentIdsToDelete = Lists.newArrayList(indexJudgmentIds); judgmentIdsToDelete.removeAll(existingJudgmentIds); if (judgmentIdsToDelete.size() > 0) { log.info("Removing judgments from index which don't have corresponding entry in database: {}", judgmentIdsToDelete); solrJudgmentsServer.deleteById(judgmentIdsToDelete.stream().map(x -> String.valueOf(x)).collect(Collectors.toList())); } ++pageNumber; } }  void deleteFromIndexWithoutCorrespondingJudgmentInDb(); @Autowired void setJudgmentRepository(JudgmentRepository judgmentRepository); @Autowired @Qualifier("solrJudgmentsServer") void setSolrJudgmentsServer(SolrServer solrJudgmentsServer); void setIndexIteratingPageSize(int indexIteratingPageSize); }
JudgmentIndexDeleter { public void deleteFromIndexWithoutCorrespondingJudgmentInDb() throws SolrServerException, IOException { int pageNumber = 0; while (true) { SolrQuery query = createIndexIteratingQuery(pageNumber); QueryResponse response = solrJudgmentsServer.query(query); if (response.getResults().size() == 0) { break; } List<Long> indexJudgmentIds = extractIdsFromResult(response); List<Long> existingJudgmentIds = judgmentRepository.filterIdsToExisting(indexJudgmentIds); List<Long> judgmentIdsToDelete = Lists.newArrayList(indexJudgmentIds); judgmentIdsToDelete.removeAll(existingJudgmentIds); if (judgmentIdsToDelete.size() > 0) { log.info("Removing judgments from index which don't have corresponding entry in database: {}", judgmentIdsToDelete); solrJudgmentsServer.deleteById(judgmentIdsToDelete.stream().map(x -> String.valueOf(x)).collect(Collectors.toList())); } ++pageNumber; } }  void deleteFromIndexWithoutCorrespondingJudgmentInDb(); @Autowired void setJudgmentRepository(JudgmentRepository judgmentRepository); @Autowired @Qualifier("solrJudgmentsServer") void setSolrJudgmentsServer(SolrServer solrJudgmentsServer); void setIndexIteratingPageSize(int indexIteratingPageSize);  }