JobCallbackRequestMaker { public void makeHttpRequest(final String jobId, final Logger logger, final List<HttpRequestBase> httpRequestList) { if (httpRequestList == null || httpRequestList.isEmpty()) { logger.info("No HTTP requests to make for: " + jobId); return; } for (final HttpRequestBase httpRequest : httpRequestList) { logger.debug("Job callback http request for " + jobId + ": " + httpRequest.toString()); logger.debug("headers ["); for (final Header header : httpRequest.getAllHeaders()) { logger.debug(String.format(" %s : %s", header.getName(), header.getValue())); } logger.debug("]"); final HttpRequestFutureTask<Integer> task = this.futureRequestExecutionService.execute(httpRequest, HttpClientContext.create(), new LoggingResponseHandler(logger)); try { final Integer statusCode = task.get(this.responseWaitTimeoutMS, TimeUnit.MILLISECONDS); logger.info("http callback status code for " + jobId + ": " + statusCode); } catch (final TimeoutException timeOutEx) { logger .warn("Job callback target took longer " + (this.responseWaitTimeoutMS / 1000) + " seconds to respond for: " + jobId, timeOutEx); } catch (final ExecutionException ee) { if (ee.getCause() instanceof SocketTimeoutException) { logger.warn("Job callback target took longer " + (this.responseWaitTimeoutMS / 1000) + " seconds to respond", ee); } else { logger.warn( "Failed to execute job callback for: " + jobId, ee); } } catch (final Throwable e) { logger.warn( "Failed to execute job callback for: " + jobId, e); } } } private  JobCallbackRequestMaker(final Props props); static void initialize(final Props props); static boolean isInitialized(); static JobCallbackRequestMaker getInstance(); FutureRequestExecutionMetrics getJobcallbackMetrics(); void makeHttpRequest(final String jobId, final Logger logger,
      final List<HttpRequestBase> httpRequestList);  }
@Test(timeout = 4000) public void basicGetTest() { final Props props = new Props(); final String url = buildUrlForDelay(1); props.put("job.notification." + JobCallbackStatusEnum.STARTED.name().toLowerCase() + ".1.url", url); final List<HttpRequestBase> httpRequestList = JobCallbackUtil.parseJobCallbackProperties(props, JobCallbackStatusEnum.STARTED, contextInfo, 3); jobCBMaker.makeHttpRequest(JOB_NANE, logger, httpRequestList); }
@Test(timeout = 4000) public void simulateNotOKStatusCodeTest() { final Props props = new Props(); final String url = buildUrlForStatusCode(404); props.put("job.notification." + JobCallbackStatusEnum.STARTED.name().toLowerCase() + ".1.url", url); final List<HttpRequestBase> httpRequestList = JobCallbackUtil.parseJobCallbackProperties(props, JobCallbackStatusEnum.STARTED, contextInfo, 3); jobCBMaker.makeHttpRequest(JOB_NANE, logger, httpRequestList); }
@Test(timeout = 4000) public void unResponsiveGetTest() { final Props props = new Props(); final String url = buildUrlForDelay(10); props.put("job.notification." + JobCallbackStatusEnum.STARTED.name().toLowerCase() + ".1.url", url); final List<HttpRequestBase> httpRequestList = JobCallbackUtil.parseJobCallbackProperties(props, JobCallbackStatusEnum.STARTED, contextInfo, 3); jobCBMaker.makeHttpRequest(JOB_NANE, logger, httpRequestList); }
@Test(timeout = 4000) public void basicPostTest() { final Props props = new Props(); final String url = buildUrlForDelay(1); props.put("job.notification." + JobCallbackStatusEnum.STARTED.name().toLowerCase() + ".1.url", url); props.put("job.notification." + JobCallbackStatusEnum.STARTED.name().toLowerCase() + ".1.method", JobCallbackConstants.HTTP_POST); props.put("job.notification." + JobCallbackStatusEnum.STARTED.name().toLowerCase() + ".1.body", "This is it"); final List<HttpRequestBase> httpRequestList = JobCallbackUtil.parseJobCallbackProperties(props, JobCallbackStatusEnum.STARTED, contextInfo, 3); jobCBMaker.makeHttpRequest(JOB_NANE, logger, httpRequestList); }