From ccf75afd7baa2114601bcb50984b03e3d48c3293 Mon Sep 17 00:00:00 2001 From: Vihas Splunk Date: Wed, 20 Sep 2023 18:27:25 +0530 Subject: [PATCH 1/5] fix: sonar bugs --- sonar-project.properties | 1 + src/main/java/com/splunk/hecclient/DoubleSerializer.java | 3 ++- src/main/java/com/splunk/hecclient/Hec.java | 2 +- src/main/java/com/splunk/hecclient/HecAckPoller.java | 2 +- src/main/java/com/splunk/hecclient/Indexer.java | 5 ++--- src/main/java/com/splunk/kafka/connect/SplunkSinkTask.java | 6 +++--- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/sonar-project.properties b/sonar-project.properties index 0e4f196a..9f1c6f8d 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -2,3 +2,4 @@ sonar.projectKey=github-mirrors.kafka-connect-splunk sonar.sources=src/main/java/ sonar.language=java sonar.java.binaries=. +sonar.exclusions=src/java/test/**,**/examples/** \ No newline at end of file diff --git a/src/main/java/com/splunk/hecclient/DoubleSerializer.java b/src/main/java/com/splunk/hecclient/DoubleSerializer.java index 8eb13327..aedf341a 100644 --- a/src/main/java/com/splunk/hecclient/DoubleSerializer.java +++ b/src/main/java/com/splunk/hecclient/DoubleSerializer.java @@ -7,6 +7,7 @@ import java.io.IOException; import java.math.BigDecimal; +import java.math.RoundingMode; /* * Copyright 2017 Splunk, Inc.. @@ -26,7 +27,7 @@ public class DoubleSerializer extends JsonSerializer { @Override public void serialize(Double value, JsonGenerator jgen, SerializerProvider provider) throws IOException { - String d = new BigDecimal(value).setScale(6, BigDecimal.ROUND_HALF_UP).toPlainString(); + String d = BigDecimal.valueOf(value).setScale(6, RoundingMode.HALF_UP).toPlainString(); jgen.writeNumber(d); } } diff --git a/src/main/java/com/splunk/hecclient/Hec.java b/src/main/java/com/splunk/hecclient/Hec.java index 1a965bd3..cdb5f133 100644 --- a/src/main/java/com/splunk/hecclient/Hec.java +++ b/src/main/java/com/splunk/hecclient/Hec.java @@ -351,7 +351,7 @@ public static SSLContext loadTrustManagerFactory(KeyStore keyStore) { TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); tmf.init(keyStore); - SSLContext sslContext = SSLContext.getInstance("SSL"); + SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, tmf.getTrustManagers(), new SecureRandom()); return sslContext; diff --git a/src/main/java/com/splunk/hecclient/HecAckPoller.java b/src/main/java/com/splunk/hecclient/HecAckPoller.java index a0931bc3..3f05bfd0 100644 --- a/src/main/java/com/splunk/hecclient/HecAckPoller.java +++ b/src/main/java/com/splunk/hecclient/HecAckPoller.java @@ -131,7 +131,7 @@ public void add(HecChannel channel, EventBatch batch, String response) { return; } - if (resp.getText() == "Invalid data format") { + if (resp.getText().equals("Invalid data format")) { log.warn("Invalid Splunk HEC data format. Ignoring events. channel={} index={} events={}", channel, channel.getIndexer(), batch.toString()); batch.commit(); List committedBatches = new ArrayList<>(); diff --git a/src/main/java/com/splunk/hecclient/Indexer.java b/src/main/java/com/splunk/hecclient/Indexer.java index 4bebc453..0cdf68c0 100644 --- a/src/main/java/com/splunk/hecclient/Indexer.java +++ b/src/main/java/com/splunk/hecclient/Indexer.java @@ -62,13 +62,12 @@ final class Indexer implements IndexerInf { private Poller poller; private long backPressure; private long lastBackPressure; - private long backPressureThreshold = 60 * 1000; // 1 min + private long backPressureThreshold = Long.valueOf(60) * 1000; // 1 min // Indexer doesn't own client, ack poller public Indexer(String baseUrl,CloseableHttpClient client,Poller poller,HecConfig config) { this.httpClient = client; this.baseUrl = baseUrl; - this.hecToken = hecToken; this.hecConfig = config; this.hecToken = config.getToken(); this.poller = poller; @@ -242,7 +241,7 @@ private String readAndCloseResponse(CloseableHttpResponse resp) { try { resp.close(); } catch (IOException ex) { - throw new HecException("failed to close http response", ex); + new HecException("failed to close http response", ex); } } diff --git a/src/main/java/com/splunk/kafka/connect/SplunkSinkTask.java b/src/main/java/com/splunk/kafka/connect/SplunkSinkTask.java index bc268e27..c85d2efc 100644 --- a/src/main/java/com/splunk/kafka/connect/SplunkSinkTask.java +++ b/src/main/java/com/splunk/kafka/connect/SplunkSinkTask.java @@ -42,7 +42,7 @@ public final class SplunkSinkTask extends SinkTask implements PollerCallback { private static final Logger log = LoggerFactory.getLogger(SplunkSinkTask.class); - private static long flushWindow = 30 * 1000; // 30 seconds + private static long flushWindow = Long.valueOf(30) * 1000; // 30 seconds private static final String HEADERTOKEN = "$$$"; private HecInf hec; @@ -571,8 +571,8 @@ private void timestampExtraction(Event event) { try { double epoch; epoch = ((Double.parseDouble(timestamp))); - long long_epoch = (new Double(epoch)).longValue(); - event.setTime(epoch / (Math.pow(10, Long.toString(long_epoch).length()-10))); + long long_epoch = Double.valueOf(epoch).longValue(); + event.setTime(epoch / (Math.pow(10, Long.toString(long_epoch).length()-10.00))); } catch (Exception e) { log.warn("Could not set the time", e); From 19c95892ecfa3f86df6a45e64bff3d04a7deb834 Mon Sep 17 00:00:00 2001 From: Vihas Splunk Date: Wed, 20 Sep 2023 18:41:36 +0530 Subject: [PATCH 2/5] fix: sonar --- src/main/java/com/splunk/hecclient/ConcurrentHec.java | 1 - src/main/java/com/splunk/hecclient/Indexer.java | 2 +- src/main/java/com/splunk/hecclient/JsonEventBatch.java | 2 +- src/main/java/com/splunk/kafka/connect/SplunkSinkTask.java | 5 ++--- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/splunk/hecclient/ConcurrentHec.java b/src/main/java/com/splunk/hecclient/ConcurrentHec.java index 7a57b8ed..2ebe008a 100644 --- a/src/main/java/com/splunk/hecclient/ConcurrentHec.java +++ b/src/main/java/com/splunk/hecclient/ConcurrentHec.java @@ -74,7 +74,6 @@ public final void close() { } stopped = true; - // executorService.shutdownNow(); executorService.shutdown(); } diff --git a/src/main/java/com/splunk/hecclient/Indexer.java b/src/main/java/com/splunk/hecclient/Indexer.java index 0cdf68c0..eb2207b0 100644 --- a/src/main/java/com/splunk/hecclient/Indexer.java +++ b/src/main/java/com/splunk/hecclient/Indexer.java @@ -272,7 +272,7 @@ private String readAndCloseResponse(CloseableHttpResponse resp) { String respText = (jsonNode.has("text")) ? jsonNode.get("text").asText() : null; - if (respText == "Invalid data format") { + if (respText.equals("Invalid data format")) { ObjectNode objNode = jsonMapper.createObjectNode(); objNode.put("text", "Invalid data format"); objNode.put("code", 0); // Mark it as success diff --git a/src/main/java/com/splunk/hecclient/JsonEventBatch.java b/src/main/java/com/splunk/hecclient/JsonEventBatch.java index ed74c78d..324d90d6 100644 --- a/src/main/java/com/splunk/hecclient/JsonEventBatch.java +++ b/src/main/java/com/splunk/hecclient/JsonEventBatch.java @@ -57,7 +57,7 @@ public int hashCode() { public boolean equals(Object obj) { if (obj instanceof JsonEventBatch) { final JsonEventBatch other = (JsonEventBatch) obj; - return endpoint.equals(endpoint); + return obj.equals(other); } return false; } diff --git a/src/main/java/com/splunk/kafka/connect/SplunkSinkTask.java b/src/main/java/com/splunk/kafka/connect/SplunkSinkTask.java index c85d2efc..53a3c421 100644 --- a/src/main/java/com/splunk/kafka/connect/SplunkSinkTask.java +++ b/src/main/java/com/splunk/kafka/connect/SplunkSinkTask.java @@ -71,7 +71,7 @@ public void start(Map taskConfig) { tracker = new KafkaRecordTracker(); bufferedRecords = new ArrayList<>(); if(connectorConfig.flushWindow > 0) { - flushWindow = connectorConfig.flushWindow * 1000; // Flush window set to user configured value (Multiply by 1000 as all the calculations are done in milliseconds) + flushWindow = connectorConfig.flushWindow * Long.valueOf(1000); // Flush window set to user configured value (Multiply by 1000 as all the calculations are done in milliseconds) } log.info("kafka-connect-splunk task starts with config={}", connectorConfig); @@ -569,8 +569,7 @@ private void timestampExtraction(Event event) { if (connectorConfig.timestampFormat.equalsIgnoreCase("epoch")) { try { - double epoch; - epoch = ((Double.parseDouble(timestamp))); + double epoch = (Double.parseDouble(timestamp)); long long_epoch = Double.valueOf(epoch).longValue(); event.setTime(epoch / (Math.pow(10, Long.toString(long_epoch).length()-10.00))); From 6aec3c076d3312473624448b56c4aa274d4e66d4 Mon Sep 17 00:00:00 2001 From: Vihas Splunk Date: Wed, 20 Sep 2023 18:48:39 +0530 Subject: [PATCH 3/5] fix: rename variables --- .../com/splunk/hecclient/JsonEventBatch.java | 8 +++--- .../com/splunk/hecclient/RawEventBatch.java | 8 +++--- .../hecclient/CloseableHttpClientMock.java | 28 +++++++++---------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/splunk/hecclient/JsonEventBatch.java b/src/main/java/com/splunk/hecclient/JsonEventBatch.java index 324d90d6..68caa728 100644 --- a/src/main/java/com/splunk/hecclient/JsonEventBatch.java +++ b/src/main/java/com/splunk/hecclient/JsonEventBatch.java @@ -18,8 +18,8 @@ import org.apache.commons.lang3.builder.HashCodeBuilder; public final class JsonEventBatch extends EventBatch { - public static final String endpoint = "/services/collector/event"; - public static final String contentType = "application/json; profile=urn:splunk:event:1.0; charset=utf-8"; + public static final String ENDPOINT = "/services/collector/event"; + public static final String CONTENT_TYPE = "application/json; profile=urn:splunk:event:1.0; charset=utf-8"; @Override public void add(Event event) { @@ -33,12 +33,12 @@ public void add(Event event) { @Override public final String getRestEndpoint() { - return endpoint; + return ENDPOINT; } @Override public String getContentType() { - return contentType; + return CONTENT_TYPE; } @Override diff --git a/src/main/java/com/splunk/hecclient/RawEventBatch.java b/src/main/java/com/splunk/hecclient/RawEventBatch.java index 860d0090..49b36396 100644 --- a/src/main/java/com/splunk/hecclient/RawEventBatch.java +++ b/src/main/java/com/splunk/hecclient/RawEventBatch.java @@ -20,8 +20,8 @@ import org.apache.http.client.utils.URIBuilder; public final class RawEventBatch extends EventBatch { - public static final String endpoint = "/services/collector/raw"; - public static final String contentType = "text/plain; profile=urn:splunk:event:1.0; charset=utf-8"; + public static final String ENDPOINT = "/services/collector/raw"; + public static final String CONTENT_TYPE = "text/plain; profile=urn:splunk:event:1.0; charset=utf-8"; private String index; private String source; @@ -111,12 +111,12 @@ public void add(Event event) throws HecException { @Override public final String getRestEndpoint() { - return endpoint + getMetadataParams(); + return ENDPOINT + getMetadataParams(); } @Override public String getContentType() { - return contentType; + return CONTENT_TYPE; } @Override diff --git a/src/test/java/com/splunk/hecclient/CloseableHttpClientMock.java b/src/test/java/com/splunk/hecclient/CloseableHttpClientMock.java index d573abc7..3f2347cd 100644 --- a/src/test/java/com/splunk/hecclient/CloseableHttpClientMock.java +++ b/src/test/java/com/splunk/hecclient/CloseableHttpClientMock.java @@ -27,13 +27,13 @@ @SuppressWarnings( "deprecation") public class CloseableHttpClientMock extends CloseableHttpClient { - public static final String success = "{\"text\":\"Success\",\"code\":0,\"ackId\":2}"; - public static final String serverBusy = "{\"text\":\"Server busy\",\"code\":1}"; - public static final String noDataError = "{\"text\":\"No data\",\"code\":5}"; - public static final String invalidDataFormat = "{\"text\":\"Invalid data format\",\"code\":6}"; - public static final String inValidToken = "{\"text\":\"Invalid token\",\"code\":4}"; - public static final String inValidIndex = "{\"text\":\"Incorrect index\",\"code\":4,\"invalid-event-number\":1}"; - public static final String exception = "excpetion"; + public static final String SUCCESS = "{\"text\":\"Success\",\"code\":0,\"ackId\":2}"; + public static final String SERVER_BUSY = "{\"text\":\"Server busy\",\"code\":1}"; + public static final String NO_DATA_ERROR = "{\"text\":\"No data\",\"code\":5}"; + public static final String INVALID_DATA_FORMAT = "{\"text\":\"Invalid data format\",\"code\":6}"; + public static final String INVALID_TOKEN = "{\"text\":\"Invalid token\",\"code\":4}"; + public static final String INVALID_INDEX = "{\"text\":\"Incorrect index\",\"code\":4,\"invalid-event-number\":1}"; + public static final String EXCEPTION = "excpetion"; private String resp = ""; private boolean throwOnClose = false; @@ -41,22 +41,22 @@ public class CloseableHttpClientMock extends CloseableHttpClient { protected CloseableHttpResponse doExecute(HttpHost target, HttpRequest request, HttpContext context) throws IOException { - if (resp == exception) { + if (resp == EXCEPTION) { throw new IOException("mocked up"); } - if (resp.equals(success)) { + if (resp.equals(SUCCESS)) { return createResponse(resp, 200); - } else if (resp.equals(serverBusy)) { + } else if (resp.equals(SERVER_BUSY)) { return createResponse(resp, 503); - } else if (resp.equals(noDataError)) { + } else if (resp.equals(NO_DATA_ERROR)) { return createResponse(resp, 400); - }else if (resp.equals(inValidToken)) { + }else if (resp.equals(INVALID_TOKEN)) { return createResponse(resp, 400); - }else if (resp.equals(inValidIndex)) { + }else if (resp.equals(INVALID_INDEX)) { return createResponse(resp, 400); } else { - return createResponse(success, 201); + return createResponse(SUCCESS, 201); } } From be62f5efad1a70e56d43aa76c2cedf7844024148 Mon Sep 17 00:00:00 2001 From: Vihas Splunk Date: Thu, 21 Sep 2023 01:33:03 +0530 Subject: [PATCH 4/5] update pom --- pom.xml | 12 ++++++++++++ sonar-project.properties | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6c1954b7..28f39a67 100644 --- a/pom.xml +++ b/pom.xml @@ -21,6 +21,7 @@ 2.14.2 3.4.0 2.0.7 + ${project.build.directory}/coverage-reports/jacoco-ut/jacoco.xml @@ -194,6 +195,11 @@ jar compile + + org.jacoco + jacoco-maven-plugin + 0.8.9 + @@ -321,6 +327,12 @@ + + org.sonarsource.scanner.maven + sonar-maven-plugin + 3.10.0.2594 + + maven-surefire-plugin 3.0.0 diff --git a/sonar-project.properties b/sonar-project.properties index 9f1c6f8d..7ab534c6 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -2,4 +2,5 @@ sonar.projectKey=github-mirrors.kafka-connect-splunk sonar.sources=src/main/java/ sonar.language=java sonar.java.binaries=. -sonar.exclusions=src/java/test/**,**/examples/** \ No newline at end of file +sonar.exclusions=src/java/test/**,**/examples/** +sonar.java.coveragePlugin=jacoco From 109acd0171e1284ecb4fee578a40b9030c364bc2 Mon Sep 17 00:00:00 2001 From: VihasMakwana <121151420+VihasMakwana@users.noreply.github.com> Date: Thu, 21 Sep 2023 21:44:12 +0530 Subject: [PATCH 5/5] Update src/main/java/com/splunk/hecclient/Hec.java Co-authored-by: semgrep-app[bot] <63493438+semgrep-app[bot]@users.noreply.github.com> --- src/main/java/com/splunk/hecclient/Hec.java | 2 +- .../java/com/splunk/hecclient/Indexer.java | 2 +- .../com/splunk/hecclient/JsonEventBatch.java | 2 +- .../com/splunk/hecclient/IndexerTest.java | 26 +++++++++---------- .../splunk/hecclient/JsonEvenBatchTest.java | 4 +-- .../splunk/hecclient/LoadBalancerTest.java | 16 ++++++------ .../splunk/hecclient/RawEventBatchTest.java | 4 +-- .../connect/SplunkSinkConnecterTest.java | 16 ++++++------ 8 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/splunk/hecclient/Hec.java b/src/main/java/com/splunk/hecclient/Hec.java index cdb5f133..629be36d 100644 --- a/src/main/java/com/splunk/hecclient/Hec.java +++ b/src/main/java/com/splunk/hecclient/Hec.java @@ -351,7 +351,7 @@ public static SSLContext loadTrustManagerFactory(KeyStore keyStore) { TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); tmf.init(keyStore); - SSLContext sslContext = SSLContext.getInstance("TLS"); + SSLContext sslContext = SSLContext.getInstance("TLSv1.2"); sslContext.init(null, tmf.getTrustManagers(), new SecureRandom()); return sslContext; diff --git a/src/main/java/com/splunk/hecclient/Indexer.java b/src/main/java/com/splunk/hecclient/Indexer.java index eb2207b0..0c33fa6d 100644 --- a/src/main/java/com/splunk/hecclient/Indexer.java +++ b/src/main/java/com/splunk/hecclient/Indexer.java @@ -241,7 +241,7 @@ private String readAndCloseResponse(CloseableHttpResponse resp) { try { resp.close(); } catch (IOException ex) { - new HecException("failed to close http response", ex); + throw new HecException("failed to close http response", ex); } } diff --git a/src/main/java/com/splunk/hecclient/JsonEventBatch.java b/src/main/java/com/splunk/hecclient/JsonEventBatch.java index 68caa728..afa9be3a 100644 --- a/src/main/java/com/splunk/hecclient/JsonEventBatch.java +++ b/src/main/java/com/splunk/hecclient/JsonEventBatch.java @@ -49,7 +49,7 @@ public EventBatch createFromThis() { @Override public int hashCode() { return new HashCodeBuilder() - .append(endpoint) + .append(ENDPOINT) .toHashCode(); } diff --git a/src/test/java/com/splunk/hecclient/IndexerTest.java b/src/test/java/com/splunk/hecclient/IndexerTest.java index afa2ebf5..73c7398d 100644 --- a/src/test/java/com/splunk/hecclient/IndexerTest.java +++ b/src/test/java/com/splunk/hecclient/IndexerTest.java @@ -100,7 +100,7 @@ public void sendWithSuccess() { for (int i = 0; i < 2; i++) { CloseableHttpClientMock client = new CloseableHttpClientMock(); if (i == 0) { - client.setResponse(CloseableHttpClientMock.success); + client.setResponse(CloseableHttpClientMock.SUCCESS); } PollerMock poller = new PollerMock(); @@ -112,14 +112,14 @@ public void sendWithSuccess() { Assert.assertNull(poller.getFailedBatch()); Assert.assertNull(poller.getException()); Assert.assertEquals(indexer.getChannel(), poller.getChannel()); - Assert.assertEquals(CloseableHttpClientMock.success, poller.getResponse()); + Assert.assertEquals(CloseableHttpClientMock.SUCCESS, poller.getResponse()); } } @Test public void sendWithInvalidData() { CloseableHttpClientMock client = new CloseableHttpClientMock(); - client.setResponse(CloseableHttpClientMock.invalidDataFormat); + client.setResponse(CloseableHttpClientMock.INVALID_DATA_FORMAT); PollerMock poller = new PollerMock(); Indexer indexer = new Indexer(baseUrl, client, poller, hecConfig); @@ -130,14 +130,14 @@ public void sendWithInvalidData() { Assert.assertNull(poller.getFailedBatch()); Assert.assertNull(poller.getException()); Assert.assertEquals(indexer.getChannel(), poller.getChannel()); - Assert.assertEquals(CloseableHttpClientMock.success, poller.getResponse()); + Assert.assertEquals(CloseableHttpClientMock.SUCCESS, poller.getResponse()); } @Test public void sendWithServerBusy() { CloseableHttpClientMock client = new CloseableHttpClientMock(); - client.setResponse(CloseableHttpClientMock.serverBusy); + client.setResponse(CloseableHttpClientMock.SERVER_BUSY); Indexer indexer = assertFailure(client); Assert.assertTrue(indexer.hasBackPressure()); @@ -151,7 +151,7 @@ public void sendWithServerBusy() { @Test public void ConfirmShortBackPressureConfig() { CloseableHttpClientMock client = new CloseableHttpClientMock(); - client.setResponse(CloseableHttpClientMock.serverBusy); + client.setResponse(CloseableHttpClientMock.SERVER_BUSY); Indexer indexer = assertFailure(client); Assert.assertTrue(indexer.hasBackPressure()); @@ -165,14 +165,14 @@ public void ConfirmShortBackPressureConfig() { @Test public void sendWithIOError() { CloseableHttpClientMock client = new CloseableHttpClientMock(); - client.setResponse(CloseableHttpClientMock.exception); + client.setResponse(CloseableHttpClientMock.EXCEPTION); assertFailure(client); } @Test public void sendWithCloseError() { CloseableHttpClientMock client = new CloseableHttpClientMock(); - client.setResponse(CloseableHttpClientMock.success); + client.setResponse(CloseableHttpClientMock.SUCCESS); client.setThrowOnClose(true); assertFailure(client); } @@ -180,7 +180,7 @@ public void sendWithCloseError() { @Test public void sendWithReadError() { CloseableHttpClientMock client = new CloseableHttpClientMock(); - client.setResponse(CloseableHttpClientMock.success); + client.setResponse(CloseableHttpClientMock.SUCCESS); client.setThrowOnGetContent(true); assertFailure(client); } @@ -204,7 +204,7 @@ public void sendCompressedBatchWithSuccess() { for (int i = 0; i < 2; i++) { CloseableHttpClientMock client = new CloseableHttpClientMock(); if (i == 0) { - client.setResponse(CloseableHttpClientMock.success); + client.setResponse(CloseableHttpClientMock.SUCCESS); } PollerMock poller = new PollerMock(); @@ -217,7 +217,7 @@ public void sendCompressedBatchWithSuccess() { Assert.assertNull(poller.getFailedBatch()); Assert.assertNull(poller.getException()); Assert.assertEquals(indexer.getChannel(), poller.getChannel()); - Assert.assertEquals(CloseableHttpClientMock.success, poller.getResponse()); + Assert.assertEquals(CloseableHttpClientMock.SUCCESS, poller.getResponse()); } } @@ -226,7 +226,7 @@ public void sendCompressedRawBatchWithSuccess() { for (int i = 0; i < 2; i++) { CloseableHttpClientMock client = new CloseableHttpClientMock(); if (i == 0) { - client.setResponse(CloseableHttpClientMock.success); + client.setResponse(CloseableHttpClientMock.SUCCESS); } PollerMock poller = new PollerMock(); @@ -239,7 +239,7 @@ public void sendCompressedRawBatchWithSuccess() { Assert.assertNull(poller.getFailedBatch()); Assert.assertNull(poller.getException()); Assert.assertEquals(indexer.getChannel(), poller.getChannel()); - Assert.assertEquals(CloseableHttpClientMock.success, poller.getResponse()); + Assert.assertEquals(CloseableHttpClientMock.SUCCESS, poller.getResponse()); } } } diff --git a/src/test/java/com/splunk/hecclient/JsonEvenBatchTest.java b/src/test/java/com/splunk/hecclient/JsonEvenBatchTest.java index bffe5c29..29fefbf1 100644 --- a/src/test/java/com/splunk/hecclient/JsonEvenBatchTest.java +++ b/src/test/java/com/splunk/hecclient/JsonEvenBatchTest.java @@ -51,13 +51,13 @@ public void addWithFailure() { @Test public void getRestEndpoint() { EventBatch batch = new JsonEventBatch(); - Assert.assertEquals(batch.getRestEndpoint(), JsonEventBatch.endpoint); + Assert.assertEquals(batch.getRestEndpoint(), JsonEventBatch.ENDPOINT); } @Test public void getContentType() { EventBatch batch = new JsonEventBatch(); - Assert.assertEquals(batch.getContentType(), JsonEventBatch.contentType); + Assert.assertEquals(batch.getContentType(), JsonEventBatch.CONTENT_TYPE); } @Test diff --git a/src/test/java/com/splunk/hecclient/LoadBalancerTest.java b/src/test/java/com/splunk/hecclient/LoadBalancerTest.java index 40dd6d5b..781c5f57 100644 --- a/src/test/java/com/splunk/hecclient/LoadBalancerTest.java +++ b/src/test/java/com/splunk/hecclient/LoadBalancerTest.java @@ -29,7 +29,7 @@ public void add() { String token = "mytoken"; HecConfig config = new HecConfig(Arrays.asList(uri), token); CloseableHttpClientMock client = new CloseableHttpClientMock(); - client.setResponse(CloseableHttpClientMock.success); + client.setResponse(CloseableHttpClientMock.SUCCESS); LoadBalancer lb = new LoadBalancer(config, client); int numberOfChannels = 3; @@ -48,7 +48,7 @@ public void send() { String token = "mytoken"; HecConfig config = new HecConfig(Arrays.asList(uri), token); CloseableHttpClientMock client = new CloseableHttpClientMock(); - client.setResponse(CloseableHttpClientMock.success); + client.setResponse(CloseableHttpClientMock.SUCCESS); LoadBalancer lb = new LoadBalancer(config, client); List indexers = new ArrayList<>(); int numberOfChannels = 3; @@ -76,7 +76,7 @@ public void sendWithAllBackPressure() { String token = "mytoken"; HecConfig config = new HecConfig(Arrays.asList(uri), token); CloseableHttpClientMock client = new CloseableHttpClientMock(); - client.setResponse(CloseableHttpClientMock.success); + client.setResponse(CloseableHttpClientMock.SUCCESS); LoadBalancer lb = new LoadBalancer(config, client); List indexers = new ArrayList<>(); @@ -98,7 +98,7 @@ public void sendWithOneBackPressure() { String token = "mytoken"; HecConfig config = new HecConfig(Arrays.asList(uri), token); CloseableHttpClientMock client = new CloseableHttpClientMock(); - client.setResponse(CloseableHttpClientMock.success); + client.setResponse(CloseableHttpClientMock.SUCCESS); LoadBalancer lb = new LoadBalancer(config, client); List indexers = new ArrayList<>(); @@ -127,7 +127,7 @@ public void sendWithOneNotAvailable() { String token = "mytoken"; HecConfig config = new HecConfig(Arrays.asList(uri), token); CloseableHttpClientMock client = new CloseableHttpClientMock(); - client.setResponse(CloseableHttpClientMock.success); + client.setResponse(CloseableHttpClientMock.SUCCESS); LoadBalancer lb = new LoadBalancer(config, client); List indexers = new ArrayList<>(); @@ -158,7 +158,7 @@ public void sendWithoutChannels() { String token = "mytoken"; HecConfig config = new HecConfig(Arrays.asList(uri), token); CloseableHttpClientMock client = new CloseableHttpClientMock(); - client.setResponse(CloseableHttpClientMock.success); + client.setResponse(CloseableHttpClientMock.SUCCESS); LoadBalancer lb = new LoadBalancer(config, client); lb.send(UnitUtil.createBatch()); } @@ -169,7 +169,7 @@ public void remove() { String token = "mytoken"; HecConfig config = new HecConfig(Arrays.asList(uri), token); CloseableHttpClientMock client = new CloseableHttpClientMock(); - client.setResponse(CloseableHttpClientMock.success); + client.setResponse(CloseableHttpClientMock.SUCCESS); LoadBalancer lb = new LoadBalancer(config, client); List channels = new ArrayList<>(); @@ -194,7 +194,7 @@ public void size() { String token = "mytoken"; HecConfig config = new HecConfig(Arrays.asList(uri), token); CloseableHttpClientMock client = new CloseableHttpClientMock(); - client.setResponse(CloseableHttpClientMock.success); + client.setResponse(CloseableHttpClientMock.SUCCESS); LoadBalancer lb = new LoadBalancer(config, client); Assert.assertEquals(0, lb.size()); } diff --git a/src/test/java/com/splunk/hecclient/RawEventBatchTest.java b/src/test/java/com/splunk/hecclient/RawEventBatchTest.java index dfd528a4..6277559b 100644 --- a/src/test/java/com/splunk/hecclient/RawEventBatchTest.java +++ b/src/test/java/com/splunk/hecclient/RawEventBatchTest.java @@ -49,7 +49,7 @@ public void addWithFailure() { public void getRestEndpoint() { // Without metadata EventBatch batch = RawEventBatch.factory().build(); - Assert.assertEquals(batch.getRestEndpoint(), RawEventBatch.endpoint); + Assert.assertEquals(batch.getRestEndpoint(), RawEventBatch.ENDPOINT); // With all metadata EventBatch rawBatch = RawEventBatch.factory() @@ -83,7 +83,7 @@ public void getRestEndpoint() { @Test public void getContentType() { EventBatch batch = RawEventBatch.factory().build(); - Assert.assertEquals(batch.getContentType(), RawEventBatch.contentType); + Assert.assertEquals(batch.getContentType(), RawEventBatch.CONTENT_TYPE); } @Test diff --git a/src/test/java/com/splunk/kafka/connect/SplunkSinkConnecterTest.java b/src/test/java/com/splunk/kafka/connect/SplunkSinkConnecterTest.java index 652ff6a4..ba330fe4 100644 --- a/src/test/java/com/splunk/kafka/connect/SplunkSinkConnecterTest.java +++ b/src/test/java/com/splunk/kafka/connect/SplunkSinkConnecterTest.java @@ -177,7 +177,7 @@ public void testInvalidToken() { configs.put("topics", "b"); configs.put("splunk.indexes", "b"); MockHecClientWrapper clientInstance = new MockHecClientWrapper(); - clientInstance.client.setResponse(CloseableHttpClientMock.inValidToken); + clientInstance.client.setResponse(CloseableHttpClientMock.INVALID_TOKEN); ((SplunkSinkConnector) connector).setHecInstance(clientInstance); Assertions.assertThrows(ConfigException.class, ()->connector.validate(configs)); } @@ -202,7 +202,7 @@ public void testInvalidIndex() { configs.put("topics", "b"); configs.put("splunk.indexes", "b"); MockHecClientWrapper clientInstance = new MockHecClientWrapper(); - clientInstance.client.setResponse(CloseableHttpClientMock.inValidIndex); + clientInstance.client.setResponse(CloseableHttpClientMock.INVALID_INDEX); ((SplunkSinkConnector) connector).setHecInstance(clientInstance); Assertions.assertThrows(ConfigException.class, ()->connector.validate(configs)); } @@ -217,7 +217,7 @@ public void testValidMultipleURIs() { configs.put("splunk.hec.uri", "https://localhost:8088,https://localhost:8089"); configs.put("splunk.hec.ssl.validate.certs", "false"); MockHecClientWrapper clientInstance = new MockHecClientWrapper(); - clientInstance.client.setResponse(CloseableHttpClientMock.success); + clientInstance.client.setResponse(CloseableHttpClientMock.SUCCESS); ((SplunkSinkConnector) connector).setHecInstance(clientInstance); Assertions.assertDoesNotThrow(()->connector.validate(configs)); } @@ -230,7 +230,7 @@ public void testValidSplunkConfigurations() { configs.put("topics", "b"); configs.put("splunk.indexes", "b"); MockHecClientWrapper clientInstance = new MockHecClientWrapper(); - clientInstance.client.setResponse(CloseableHttpClientMock.success); + clientInstance.client.setResponse(CloseableHttpClientMock.SUCCESS); ((SplunkSinkConnector) connector).setHecInstance(clientInstance); Assertions.assertDoesNotThrow(()->connector.validate(configs)); } @@ -243,7 +243,7 @@ public void testInvalidSplunkConfigurationsWithValidationDisabled() { configs.put("splunk.validation.disable", "true"); configs.put("topics", "b"); MockHecClientWrapper clientInstance = new MockHecClientWrapper(); - clientInstance.client.setResponse(CloseableHttpClientMock.exception); + clientInstance.client.setResponse(CloseableHttpClientMock.EXCEPTION); ((SplunkSinkConnector) connector).setHecInstance(clientInstance); Assertions.assertDoesNotThrow(()->connector.validate(configs)); } @@ -256,7 +256,7 @@ public void testInvalidSplunkConfigurationsWithValidationEnabled() { configs.put("splunk.validation.disable", "false"); configs.put("topics", "b"); MockHecClientWrapper clientInstance = new MockHecClientWrapper(); - clientInstance.client.setResponse(CloseableHttpClientMock.exception); + clientInstance.client.setResponse(CloseableHttpClientMock.EXCEPTION); ((SplunkSinkConnector) connector).setHecInstance(clientInstance); Assertions.assertThrows(ConfigException.class, ()->connector.validate(configs)); } @@ -270,7 +270,7 @@ public void testValidQueueCapacity() { configs.put("topics", "b"); configs.put("splunk.indexes", "b"); MockHecClientWrapper clientInstance = new MockHecClientWrapper(); - clientInstance.client.setResponse(CloseableHttpClientMock.success); + clientInstance.client.setResponse(CloseableHttpClientMock.SUCCESS); ((SplunkSinkConnector) connector).setHecInstance(clientInstance); Assertions.assertDoesNotThrow(()->connector.validate(configs)); } @@ -284,7 +284,7 @@ public void testInvalidQueueCapacity() { configs.put("topics", "b"); configs.put("splunk.indexes", "b"); MockHecClientWrapper clientInstance = new MockHecClientWrapper(); - clientInstance.client.setResponse(CloseableHttpClientMock.success); + clientInstance.client.setResponse(CloseableHttpClientMock.SUCCESS); ((SplunkSinkConnector) connector).setHecInstance(clientInstance); Assertions.assertThrows(ConfigException.class, ()->connector.validate(configs)); }