@Test public void testTimeoutResultsAreReturned() { server.createIndex(configuration.getStorageIndexNamePrefix()); System.setProperty(ConfigurationConstants.PROPNAME_FREQUENTLY_RELATED_SEARCH_TIMEOUT_IN_MILLIS, "0"); try { Configuration config = new SystemPropertiesConfiguration(); ElasticSearchRelatedItemSearchRepository repository = new ElasticSearchRelatedItemSearchRepository(factory,new ElasticSearchFrequentlyRelatedItemSearchProcessor(config,new FrequentRelatedSearchRequestBuilder(config),RelatedItemNoopGetRepository.INSTANCE)); SearchResultEventWithSearchRequestKey[] results = repository.findRelatedItems(configuration, createSearch()); assertEquals(2,results.length); System.out.println("testTimeoutResultsAreReturned, Results 0 outcometype: " + results[0].getResponse().getOutcomeType()); System.out.println("testTimeoutResultsAreReturned, Results 1 outcometype: " + results[1].getResponse().getOutcomeType()); assertSame(SearchResultsEvent.EMPTY_TIMED_OUT_FREQUENTLY_RELATED_SEARCH_RESULTS, results[0].getResponse()); assertSame(SearchResultsEvent.EMPTY_TIMED_OUT_FREQUENTLY_RELATED_SEARCH_RESULTS, results[1].getResponse()); } finally { System.clearProperty(ConfigurationConstants.PROPNAME_FREQUENTLY_RELATED_SEARCH_TIMEOUT_IN_MILLIS); } }
@Override public SearchResultEventWithSearchRequestKey[] findRelatedItems(Configuration configuration, RelatedItemSearch[] searches) { log.debug("request to execute {} searches",searches.length); SearchResultEventWithSearchRequestKey[] results; MultiSearchResponse sr; long startNanos = System.nanoTime(); try { sr = frequentlyRelatedWithSearchBuilder.executeSearch(elasticClient,searches); log.debug("Processing results for search {} request(s)",searches.length); results = frequentlyRelatedWithSearchBuilder.processMultiSearchResponse(searches,sr); log.debug("Search Completed, returning processed results."); } catch(ElasticsearchTimeoutException timeoutException) { long time = (System.nanoTime()-startNanos)/1000000; log.warn("Timeout exception executing search request: ",timeoutException); int size = searches.length; results = new SearchResultEventWithSearchRequestKey[size]; for(int i=0;i<size;i++) { SearchRequestLookupKey key = searches[i].getLookupKey(); results[i] = new SearchResultEventWithSearchRequestKey(SearchResultsEvent.EMPTY_TIMED_OUT_FREQUENTLY_RELATED_SEARCH_RESULTS,key,time,searches[i].getStartOfRequestNanos()); } } catch(Exception searchException) { long time = (System.nanoTime()-startNanos)/1000000; log.warn("Exception executing search request: ",searchException); int size = searches.length; results = new SearchResultEventWithSearchRequestKey[size]; for(int i=0;i<size;i++) { SearchRequestLookupKey key = searches[i].getLookupKey(); results[i] = new SearchResultEventWithSearchRequestKey(SearchResultsEvent.EMPTY_FAILED_FREQUENTLY_RELATED_SEARCH_RESULTS,key,time,searches[i].getStartOfRequestNanos()); } } return results; }
ElasticSearchRelatedItemSearchRepository implements RelatedItemSearchRepository<FrequentlyRelatedSearchResult[]> { @Override public SearchResultEventWithSearchRequestKey[] findRelatedItems(Configuration configuration, RelatedItemSearch[] searches) { log.debug("request to execute {} searches",searches.length); SearchResultEventWithSearchRequestKey[] results; MultiSearchResponse sr; long startNanos = System.nanoTime(); try { sr = frequentlyRelatedWithSearchBuilder.executeSearch(elasticClient,searches); log.debug("Processing results for search {} request(s)",searches.length); results = frequentlyRelatedWithSearchBuilder.processMultiSearchResponse(searches,sr); log.debug("Search Completed, returning processed results."); } catch(ElasticsearchTimeoutException timeoutException) { long time = (System.nanoTime()-startNanos)/1000000; log.warn("Timeout exception executing search request: ",timeoutException); int size = searches.length; results = new SearchResultEventWithSearchRequestKey[size]; for(int i=0;i<size;i++) { SearchRequestLookupKey key = searches[i].getLookupKey(); results[i] = new SearchResultEventWithSearchRequestKey(SearchResultsEvent.EMPTY_TIMED_OUT_FREQUENTLY_RELATED_SEARCH_RESULTS,key,time,searches[i].getStartOfRequestNanos()); } } catch(Exception searchException) { long time = (System.nanoTime()-startNanos)/1000000; log.warn("Exception executing search request: ",searchException); int size = searches.length; results = new SearchResultEventWithSearchRequestKey[size]; for(int i=0;i<size;i++) { SearchRequestLookupKey key = searches[i].getLookupKey(); results[i] = new SearchResultEventWithSearchRequestKey(SearchResultsEvent.EMPTY_FAILED_FREQUENTLY_RELATED_SEARCH_RESULTS,key,time,searches[i].getStartOfRequestNanos()); } } return results; } }
ElasticSearchRelatedItemSearchRepository implements RelatedItemSearchRepository<FrequentlyRelatedSearchResult[]> { @Override public SearchResultEventWithSearchRequestKey[] findRelatedItems(Configuration configuration, RelatedItemSearch[] searches) { log.debug("request to execute {} searches",searches.length); SearchResultEventWithSearchRequestKey[] results; MultiSearchResponse sr; long startNanos = System.nanoTime(); try { sr = frequentlyRelatedWithSearchBuilder.executeSearch(elasticClient,searches); log.debug("Processing results for search {} request(s)",searches.length); results = frequentlyRelatedWithSearchBuilder.processMultiSearchResponse(searches,sr); log.debug("Search Completed, returning processed results."); } catch(ElasticsearchTimeoutException timeoutException) { long time = (System.nanoTime()-startNanos)/1000000; log.warn("Timeout exception executing search request: ",timeoutException); int size = searches.length; results = new SearchResultEventWithSearchRequestKey[size]; for(int i=0;i<size;i++) { SearchRequestLookupKey key = searches[i].getLookupKey(); results[i] = new SearchResultEventWithSearchRequestKey(SearchResultsEvent.EMPTY_TIMED_OUT_FREQUENTLY_RELATED_SEARCH_RESULTS,key,time,searches[i].getStartOfRequestNanos()); } } catch(Exception searchException) { long time = (System.nanoTime()-startNanos)/1000000; log.warn("Exception executing search request: ",searchException); int size = searches.length; results = new SearchResultEventWithSearchRequestKey[size]; for(int i=0;i<size;i++) { SearchRequestLookupKey key = searches[i].getLookupKey(); results[i] = new SearchResultEventWithSearchRequestKey(SearchResultsEvent.EMPTY_FAILED_FREQUENTLY_RELATED_SEARCH_RESULTS,key,time,searches[i].getStartOfRequestNanos()); } } return results; } ElasticSearchRelatedItemSearchRepository(ElasticSearchClientFactory searchClientFactory,
                                                    ElasticSearchFrequentlyRelatedItemSearchProcessor builder); }
ElasticSearchRelatedItemSearchRepository implements RelatedItemSearchRepository<FrequentlyRelatedSearchResult[]> { @Override public SearchResultEventWithSearchRequestKey[] findRelatedItems(Configuration configuration, RelatedItemSearch[] searches) { log.debug("request to execute {} searches",searches.length); SearchResultEventWithSearchRequestKey[] results; MultiSearchResponse sr; long startNanos = System.nanoTime(); try { sr = frequentlyRelatedWithSearchBuilder.executeSearch(elasticClient,searches); log.debug("Processing results for search {} request(s)",searches.length); results = frequentlyRelatedWithSearchBuilder.processMultiSearchResponse(searches,sr); log.debug("Search Completed, returning processed results."); } catch(ElasticsearchTimeoutException timeoutException) { long time = (System.nanoTime()-startNanos)/1000000; log.warn("Timeout exception executing search request: ",timeoutException); int size = searches.length; results = new SearchResultEventWithSearchRequestKey[size]; for(int i=0;i<size;i++) { SearchRequestLookupKey key = searches[i].getLookupKey(); results[i] = new SearchResultEventWithSearchRequestKey(SearchResultsEvent.EMPTY_TIMED_OUT_FREQUENTLY_RELATED_SEARCH_RESULTS,key,time,searches[i].getStartOfRequestNanos()); } } catch(Exception searchException) { long time = (System.nanoTime()-startNanos)/1000000; log.warn("Exception executing search request: ",searchException); int size = searches.length; results = new SearchResultEventWithSearchRequestKey[size]; for(int i=0;i<size;i++) { SearchRequestLookupKey key = searches[i].getLookupKey(); results[i] = new SearchResultEventWithSearchRequestKey(SearchResultsEvent.EMPTY_FAILED_FREQUENTLY_RELATED_SEARCH_RESULTS,key,time,searches[i].getStartOfRequestNanos()); } } return results; } ElasticSearchRelatedItemSearchRepository(ElasticSearchClientFactory searchClientFactory,
                                                    ElasticSearchFrequentlyRelatedItemSearchProcessor builder); @Override SearchResultEventWithSearchRequestKey[] findRelatedItems(Configuration configuration,
                                                                    RelatedItemSearch[] searches); @Override void shutdown(); }
ElasticSearchRelatedItemSearchRepository implements RelatedItemSearchRepository<FrequentlyRelatedSearchResult[]> { @Override public SearchResultEventWithSearchRequestKey[] findRelatedItems(Configuration configuration, RelatedItemSearch[] searches) { log.debug("request to execute {} searches",searches.length); SearchResultEventWithSearchRequestKey[] results; MultiSearchResponse sr; long startNanos = System.nanoTime(); try { sr = frequentlyRelatedWithSearchBuilder.executeSearch(elasticClient,searches); log.debug("Processing results for search {} request(s)",searches.length); results = frequentlyRelatedWithSearchBuilder.processMultiSearchResponse(searches,sr); log.debug("Search Completed, returning processed results."); } catch(ElasticsearchTimeoutException timeoutException) { long time = (System.nanoTime()-startNanos)/1000000; log.warn("Timeout exception executing search request: ",timeoutException); int size = searches.length; results = new SearchResultEventWithSearchRequestKey[size]; for(int i=0;i<size;i++) { SearchRequestLookupKey key = searches[i].getLookupKey(); results[i] = new SearchResultEventWithSearchRequestKey(SearchResultsEvent.EMPTY_TIMED_OUT_FREQUENTLY_RELATED_SEARCH_RESULTS,key,time,searches[i].getStartOfRequestNanos()); } } catch(Exception searchException) { long time = (System.nanoTime()-startNanos)/1000000; log.warn("Exception executing search request: ",searchException); int size = searches.length; results = new SearchResultEventWithSearchRequestKey[size]; for(int i=0;i<size;i++) { SearchRequestLookupKey key = searches[i].getLookupKey(); results[i] = new SearchResultEventWithSearchRequestKey(SearchResultsEvent.EMPTY_FAILED_FREQUENTLY_RELATED_SEARCH_RESULTS,key,time,searches[i].getStartOfRequestNanos()); } } return results; } ElasticSearchRelatedItemSearchRepository(ElasticSearchClientFactory searchClientFactory,
                                                    ElasticSearchFrequentlyRelatedItemSearchProcessor builder); @Override SearchResultEventWithSearchRequestKey[] findRelatedItems(Configuration configuration,
                                                                    RelatedItemSearch[] searches); @Override void shutdown();  }