public synchronized boolean sendHttpEvents(Collection<SplunkEvent> events) {

    LOG.info("Attempting to send {} events to {}.", events.size(), getHecEndpoint());

    // Construct base HEC request
    HttpPost httppost = new HttpPost(getHecEndpoint());
    httppost.addHeader("Authorization", "Splunk " + hecToken);

    // Loop over events and send one-by-one
    StringBuilder eventsData = new StringBuilder();
    events.forEach(
        event -> {
          String eventStr = splunkEventToJson(event);
          eventsData.append(eventStr);
          LOG.info("Sending HTTP event: {}", eventStr);
        });

    try (CloseableHttpClient httpClient = clientFactory.getHttpClient()) {
      // Set request data
      try {
        httppost.setEntity(new StringEntity(eventsData.toString()));
      } catch (UnsupportedEncodingException e) {
        throw new SplunkResourceManagerException(
            "Error setting HTTP message data to " + eventsData, e);
      }

      // Send request
      try (CloseableHttpResponse response = httpClient.execute(httppost)) {
        // Check error code
        int code = response.getStatusLine().getStatusCode();
        if (code != 200) {
          throw new SplunkResourceManagerException(
              "Received http error code " + code + " sending event.");
        }
      } catch (Exception e) {
        throw new SplunkResourceManagerException("Error sending event.", e);
      }
    } catch (IOException e) {
      throw new SplunkResourceManagerException("Error with HTTP client.", e);
    }

    LOG.info("Successfully sent {} events.", events.size());

    return true;
  }
@Test
  public void testSendHttpEventsShouldReturnTrueIfSplunkDoesNotThrowAnyError() throws IOException {
    SplunkEvent event = SplunkEvent.newBuilder().withEvent(EVENT).create();

    try (CloseableHttpResponse mockResponse =
        clientFactory.getHttpClient().execute(any(HttpPost.class))) {
      when(mockResponse.getStatusLine().getStatusCode()).thenReturn(200);
    }

    assertThat(testManager.sendHttpEvents(ImmutableList.of(event, event))).isTrue();
    verify(clientFactory.getHttpClient()).execute(any(HttpPost.class));
  }