NhinTaskExecutor { @SuppressWarnings("static-access") public void executeTask() throws InterruptedException, ExecutionException { LOG.debug("NhinTaskExecutor::executeTask begin"); try { CompletionService<IndividualResponse> executorCompletionService = new ExecutorCompletionService<>(executor); for (NhinCallableRequest<IndividualResponse> c : callableList) { executorCompletionService.submit(c); } int count = 0; for (NhinCallableRequest<IndividualResponse> c : callableList) { Future<IndividualResponse> future = executorCompletionService.take(); count++; LOG.debug("NhinTaskExecutor::executeTask::take received response count=" + count); if (future != null) { try { IndividualResponse r = future.get(); if (r != null) { Optional<OutboundResponseProcessor> optionalProcessor = r.getResponseProcessor(); if (!optionalProcessor.isPresent()) { throw new IllegalArgumentException( "IndividualResponse.getResponseProcessor returned null"); } OutboundResponseProcessor processor = optionalProcessor.get(); cumulativeResponse = (CumulativeResponse) processor.processNhinResponse(r, cumulativeResponse); } else { LOG.error( "NhinTaskExecutor::executeTask (count=" + count + ") received null response!!!!!"); } } catch (Exception e) { LOG.error("NhinTaskExecutor processResponse EXCEPTION!!!"); ExecutorServiceHelper.getInstance().outputCompleteException(e); } } else { LOG.error("NhinTaskExecutor::executeTask received null future from queue (i.e. take)!!!!!"); } } LOG.debug("NhinTaskExecutor::executeTask done"); } catch (Exception e) { LOG.error("NhinTaskExecutor EXCEPTION!!!"); ExecutorServiceHelper.getInstance().outputCompleteException(e); } } NhinTaskExecutor(Executor e, List<NhinCallableRequest<IndividualResponse>> list, String id); CumulativeResponse getFinalResponse(); @SuppressWarnings("static-access") void executeTask();  }
@Test public void testExecuteTask() throws Exception { System.out.println("executeTask"); String transactionId = UUID.randomUUID().toString(); List<NhinCallableRequest<TestOutboundOrchestratableMessage>> callableList = new ArrayList<>(); for (UrlInfo urlInfo : getUrlList()) { TestOutboundOrchestratableMessage message = new TestOutboundOrchestratableMessage(); callableList.add(new NhinCallableRequest<TestOutboundOrchestratableMessage>(message)); } NhinTaskExecutor<TestOutboundOrchestratableMessage, TestOutboundOrchestratableMessage> instance = new NhinTaskExecutor<>( Executors.newFixedThreadPool(1), callableList, transactionId); instance.executeTask(); Object result = instance.getFinalResponse(); assertNotNull(result); }