@Test(expected = RuntimeException.class) public void searchDetectorFail() throws IOException { Mockito.when(legacyElasticSearchClient.search(any(SearchRequest.class), any(RequestOptions.class))).thenThrow(new IOException()); repoUnderTest.findByUuid("aeb4d849-847a-45c0-8312-dc0fcf22b639"); }
@Override public DetectorDocument findByUuid(String uuid) { MDC.put("DetectorUuid", uuid); val queryBuilder = QueryBuilders.termQuery("uuid", uuid); val searchSourceBuilder = elasticsearchUtil.getSourceBuilder(queryBuilder).size(DEFAULT_ES_RESULTS_SIZE); val searchRequest = elasticsearchUtil.getSearchRequest(searchSourceBuilder, DETECTOR_INDEX, DETECTOR_DOC_TYPE); val detectors = getDetectorsFromElasticSearch(searchRequest); MDC.remove("DetectorUuid"); return detectors.isEmpty() ? null : detectors.get(0); }
LegacyDetectorRepositoryImpl implements LegacyDetectorRepository { @Override public DetectorDocument findByUuid(String uuid) { MDC.put("DetectorUuid", uuid); val queryBuilder = QueryBuilders.termQuery("uuid", uuid); val searchSourceBuilder = elasticsearchUtil.getSourceBuilder(queryBuilder).size(DEFAULT_ES_RESULTS_SIZE); val searchRequest = elasticsearchUtil.getSearchRequest(searchSourceBuilder, DETECTOR_INDEX, DETECTOR_DOC_TYPE); val detectors = getDetectorsFromElasticSearch(searchRequest); MDC.remove("DetectorUuid"); return detectors.isEmpty() ? null : detectors.get(0); } }
LegacyDetectorRepositoryImpl implements LegacyDetectorRepository { @Override public DetectorDocument findByUuid(String uuid) { MDC.put("DetectorUuid", uuid); val queryBuilder = QueryBuilders.termQuery("uuid", uuid); val searchSourceBuilder = elasticsearchUtil.getSourceBuilder(queryBuilder).size(DEFAULT_ES_RESULTS_SIZE); val searchRequest = elasticsearchUtil.getSearchRequest(searchSourceBuilder, DETECTOR_INDEX, DETECTOR_DOC_TYPE); val detectors = getDetectorsFromElasticSearch(searchRequest); MDC.remove("DetectorUuid"); return detectors.isEmpty() ? null : detectors.get(0); }  }
LegacyDetectorRepositoryImpl implements LegacyDetectorRepository { @Override public DetectorDocument findByUuid(String uuid) { MDC.put("DetectorUuid", uuid); val queryBuilder = QueryBuilders.termQuery("uuid", uuid); val searchSourceBuilder = elasticsearchUtil.getSourceBuilder(queryBuilder).size(DEFAULT_ES_RESULTS_SIZE); val searchRequest = elasticsearchUtil.getSearchRequest(searchSourceBuilder, DETECTOR_INDEX, DETECTOR_DOC_TYPE); val detectors = getDetectorsFromElasticSearch(searchRequest); MDC.remove("DetectorUuid"); return detectors.isEmpty() ? null : detectors.get(0); }  @Override UUID createDetector(DetectorDocument document); @Override void deleteDetector(String uuid); @Override void updateDetector(String uuid, DetectorDocument document); @Override DetectorDocument findByUuid(String uuid); @Override List<DetectorDocument> findByCreatedBy(String user); @Override void toggleDetector(String uuid, Boolean enabled); @Override void trustDetector(String uuid, Boolean trusted); @Override List<DetectorDocument> getLastUpdatedDetectors(long interval); @Override List<DetectorDocument> getLastUpdatedDetectors(String fromDate, String toDate); }
LegacyDetectorRepositoryImpl implements LegacyDetectorRepository { @Override public DetectorDocument findByUuid(String uuid) { MDC.put("DetectorUuid", uuid); val queryBuilder = QueryBuilders.termQuery("uuid", uuid); val searchSourceBuilder = elasticsearchUtil.getSourceBuilder(queryBuilder).size(DEFAULT_ES_RESULTS_SIZE); val searchRequest = elasticsearchUtil.getSearchRequest(searchSourceBuilder, DETECTOR_INDEX, DETECTOR_DOC_TYPE); val detectors = getDetectorsFromElasticSearch(searchRequest); MDC.remove("DetectorUuid"); return detectors.isEmpty() ? null : detectors.get(0); }  @Override UUID createDetector(DetectorDocument document); @Override void deleteDetector(String uuid); @Override void updateDetector(String uuid, DetectorDocument document); @Override DetectorDocument findByUuid(String uuid); @Override List<DetectorDocument> findByCreatedBy(String user); @Override void toggleDetector(String uuid, Boolean enabled); @Override void trustDetector(String uuid, Boolean trusted); @Override List<DetectorDocument> getLastUpdatedDetectors(long interval); @Override List<DetectorDocument> getLastUpdatedDetectors(String fromDate, String toDate);  }