@Test public void testContextIsClosedWhenNoHandlerIsAvailable() { SearchResultsConverterFactory resultsConverterFactory = mock(SearchResultsConverterFactory.class); NumberOfSearchResultsConverter searchResultsConverter = new NumberOfSearchResultsConverter("application/json"); when(resultsConverterFactory.getConverter(FrequentlyRelatedSearchResult[].class)).thenReturn(searchResultsConverter); SearchResponseContextHandlerLookup handlerLookup = mock(SearchResponseContextHandlerLookup.class); when(handlerLookup.getHandler(any(Class.class))).thenReturn(null); CountDownLatch latch = new CountDownLatch(1); eventHandler = createResponseEventHandler(configuration,handlerLookup,resultsConverterFactory,latch); SearchResponseContext<AsyncContext> context = mock(AsyncServletSearchResponseContext.class); when(context.getContextType()).thenReturn(AsyncContext.class); List<SearchResponseContext> holder = new ArrayList<SearchResponseContext>(1); holder.add(context); List<List<SearchResponseContext>> list= new ArrayList<List<SearchResponseContext>>(1); list.add(holder); eventHandler.handleResponseEvents(createSearchResultsEvent(new SearchResultsEvent[]{createStringResponse()}),list); try { boolean handled = latch.await(2000, TimeUnit.MILLISECONDS); if(handled==false) fail("Failed waiting for latch"); } catch(Exception e) { fail("Failed waiting for latch"); } assertEquals(0, searchResultsConverter.getNoOfExecutions()); verify(context, times(1)).close(); }
@Override public void handleResponseEvents(SearchResultEventWithSearchRequestKey[] searchResults,List<List<SearchResponseContext>> responseContexts) { for(int i=0;i<searchResults.length;i++) { log.debug("handling search result {}",i); handleResponseEvent(searchResults[i],responseContexts.get(i)); } }
ResponseContextTypeBasedResponseEventHandler implements ResponseEventHandler { @Override public void handleResponseEvents(SearchResultEventWithSearchRequestKey[] searchResults,List<List<SearchResponseContext>> responseContexts) { for(int i=0;i<searchResults.length;i++) { log.debug("handling search result {}",i); handleResponseEvent(searchResults[i],responseContexts.get(i)); } } }
ResponseContextTypeBasedResponseEventHandler implements ResponseEventHandler { @Override public void handleResponseEvents(SearchResultEventWithSearchRequestKey[] searchResults,List<List<SearchResponseContext>> responseContexts) { for(int i=0;i<searchResults.length;i++) { log.debug("handling search result {}",i); handleResponseEvent(searchResults[i],responseContexts.get(i)); } } ResponseContextTypeBasedResponseEventHandler(SearchResponseContextHandlerLookup responseContextHandler,
                                                        SearchResultsConverterFactory factory); }
ResponseContextTypeBasedResponseEventHandler implements ResponseEventHandler { @Override public void handleResponseEvents(SearchResultEventWithSearchRequestKey[] searchResults,List<List<SearchResponseContext>> responseContexts) { for(int i=0;i<searchResults.length;i++) { log.debug("handling search result {}",i); handleResponseEvent(searchResults[i],responseContexts.get(i)); } } ResponseContextTypeBasedResponseEventHandler(SearchResponseContextHandlerLookup responseContextHandler,
                                                        SearchResultsConverterFactory factory); @Override void handleResponseEvents(SearchResultEventWithSearchRequestKey[] searchResults,List<List<SearchResponseContext>> responseContexts); @Override void shutdown(); void handleResponseEvent(SearchResultEventWithSearchRequestKey results,List<SearchResponseContext> awaitingResponses); }
ResponseContextTypeBasedResponseEventHandler implements ResponseEventHandler { @Override public void handleResponseEvents(SearchResultEventWithSearchRequestKey[] searchResults,List<List<SearchResponseContext>> responseContexts) { for(int i=0;i<searchResults.length;i++) { log.debug("handling search result {}",i); handleResponseEvent(searchResults[i],responseContexts.get(i)); } } ResponseContextTypeBasedResponseEventHandler(SearchResponseContextHandlerLookup responseContextHandler,
                                                        SearchResultsConverterFactory factory); @Override void handleResponseEvents(SearchResultEventWithSearchRequestKey[] searchResults,List<List<SearchResponseContext>> responseContexts); @Override void shutdown(); void handleResponseEvent(SearchResultEventWithSearchRequestKey results,List<SearchResponseContext> awaitingResponses); static final String ERROR_RESPONSE; static final String ERROR_MEDIA_TYPE; }