Skip to content

Commit f96251f

Browse files
author
Kishore Kumaar Natarajan
committed
Updated the Check Content
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
1 parent 6837408 commit f96251f

File tree

3 files changed

+48
-33
lines changed

3 files changed

+48
-33
lines changed

src/test/java/org/opensearch/plugin/insights/QueryInsightsRestTestCase.java

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
import java.time.Instant;
1414
import java.time.ZoneOffset;
1515
import java.time.format.DateTimeFormatter;
16-
import java.util.*;
16+
import java.util.Collections;
17+
import java.util.List;
18+
import java.util.Locale;
19+
import java.util.Map;
20+
import java.util.Optional;
1721
import java.util.function.Supplier;
1822
import java.util.logging.Logger;
1923
import java.util.regex.Matcher;
@@ -36,7 +40,11 @@
3640
import org.junit.After;
3741
import org.junit.Assert;
3842
import org.junit.Before;
39-
import org.opensearch.client.*;
43+
import org.opensearch.client.Request;
44+
import org.opensearch.client.Response;
45+
import org.opensearch.client.ResponseException;
46+
import org.opensearch.client.RestClient;
47+
import org.opensearch.client.RestClientBuilder;
4048
import org.opensearch.common.settings.Settings;
4149
import org.opensearch.common.unit.TimeValue;
4250
import org.opensearch.common.util.concurrent.ThreadContext;
@@ -47,7 +55,6 @@
4755
import org.opensearch.core.xcontent.XContentParser;
4856
import org.opensearch.plugin.insights.settings.QueryInsightsSettings;
4957
import org.opensearch.test.rest.OpenSearchRestTestCase;
50-
import org.opensearch.client.Response;
5158

5259
public abstract class QueryInsightsRestTestCase extends OpenSearchRestTestCase {
5360
protected static final String QUERY_INSIGHTS_INDICES_PREFIX = "top_queries";
@@ -390,7 +397,7 @@ protected void createDocument() throws IOException {
390397
assertEquals(201, response.getStatusLine().getStatusCode());
391398
}
392399

393-
protected void performSearch() throws IOException , InterruptedException {
400+
protected void performSearch() throws IOException, InterruptedException {
394401
Thread.sleep(3000);
395402

396403
String searchJson = "{ \"query\": { \"match\": { \"title\": \"Test Document\" } } }";
@@ -411,9 +418,11 @@ protected void setLatencyWindowSize(String size) throws IOException {
411418

412419
protected void defaultExporterSettings() throws IOException {
413420
Request request = new Request("PUT", "/_cluster/settings");
414-
request.setJsonEntity("{ \"persistent\": { " +
415-
"\"search.insights.top_queries.exporter.type\": \"local_index\", " +
416-
"\"search.insights.top_queries.latency.enabled\": \"true\" } }");
421+
request.setJsonEntity(
422+
"{ \"persistent\": { "
423+
+ "\"search.insights.top_queries.exporter.type\": \"local_index\", "
424+
+ "\"search.insights.top_queries.latency.enabled\": \"true\" } }"
425+
);
417426
Response response = client().performRequest(request);
418427
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
419428
}
@@ -432,9 +441,9 @@ protected void cleanup() throws IOException, InterruptedException {
432441
logger.warning("Cleanup: Failed to delete /my-index-0: " + e.getMessage());
433442
}
434443

435-
String resetSettings = "{ \"persistent\": { " +
436-
"\"search.insights.top_queries.exporter.type\": \"none\", " +
437-
"\"search.insights.top_queries.latency.enabled\": \"false\" } }";
444+
String resetSettings = "{ \"persistent\": { "
445+
+ "\"search.insights.top_queries.exporter.type\": \"none\", "
446+
+ "\"search.insights.top_queries.latency.enabled\": \"false\" } }";
438447
Request resetReq = new Request("PUT", "/_cluster/settings");
439448
resetReq.setJsonEntity(resetSettings);
440449
client().performRequest(resetReq);
@@ -449,6 +458,7 @@ protected void cleanupIndextemplate() throws IOException, InterruptedException {
449458
logger.warning("Failed to delete /_index_template: " + e.getMessage());
450459
}
451460
}
461+
452462
protected void checkLocalIndices() throws IOException {
453463
Request indicesRequest = new Request("GET", "/_cat/indices?v");
454464
Response response = client().performRequest(indicesRequest);
@@ -476,9 +486,13 @@ protected void checkLocalIndices() throws IOException {
476486

477487
byte[] bytes = fetchResponse.getEntity().getContent().readAllBytes();
478488

479-
try (XContentParser parser = JsonXContent.jsonXContent.createParser(
480-
NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytes
481-
)) {
489+
try (
490+
XContentParser parser = JsonXContent.jsonXContent.createParser(
491+
NamedXContentRegistry.EMPTY,
492+
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
493+
bytes
494+
)
495+
) {
482496
Map<String, Object> responseMap = parser.map();
483497

484498
Map<String, Object> hitsWrapper = (Map<String, Object>) responseMap.get("hits");
@@ -507,8 +521,7 @@ protected void checkLocalIndices() throws IOException {
507521
assertTrue(measurements.containsKey("latency"));
508522
assertTrue(measurements.containsKey("memory"));
509523

510-
List<Map<String, Object>> taskResourceUsages =
511-
(List<Map<String, Object>>) source.get("task_resource_usages");
524+
List<Map<String, Object>> taskResourceUsages = (List<Map<String, Object>>) source.get("task_resource_usages");
512525
assertTrue("Expected non-empty task_resource_usages", taskResourceUsages.size() > 0);
513526
}
514527
}
@@ -518,9 +531,13 @@ protected void checkQueryInsightsIndexTemplate() throws IOException {
518531
Response response = client().performRequest(request);
519532
byte[] bytes = response.getEntity().getContent().readAllBytes();
520533

521-
try (XContentParser parser = JsonXContent.jsonXContent.createParser(
522-
NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytes
523-
)) {
534+
try (
535+
XContentParser parser = JsonXContent.jsonXContent.createParser(
536+
NamedXContentRegistry.EMPTY,
537+
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
538+
bytes
539+
)
540+
) {
524541
Map<String, Object> parsed = parser.map();
525542

526543
List<Map<String, Object>> templates = (List<Map<String, Object>>) parsed.get("index_templates");
@@ -561,8 +578,6 @@ protected void setLocalIndexToDebug() throws IOException {
561578
client().performRequest(debugExporterRequest);
562579
}
563580

564-
565-
566581
protected void disableLocalIndexExporter() throws IOException {
567582
String disableExporterJson = "{ \"persistent\": { \"search.insights.top_queries.exporter.type\": \"none\" } }";
568583
Request disableExporterRequest = new Request("PUT", "/_cluster/settings");
@@ -573,8 +588,7 @@ protected void disableLocalIndexExporter() throws IOException {
573588
protected String[] invalidExporterSettings() {
574589
return new String[] {
575590
"{ \"persistent\" : { \"search.insights.top_queries.exporter.type\" : invalid_type } }",
576-
"{ \"persistent\" : { \"search.insights.top_queries.exporter.type\" : local_index, \"search.insights.top_queries.exporter.config.index\" : \"1a2b\" } }"
577-
};
591+
"{ \"persistent\" : { \"search.insights.top_queries.exporter.type\" : local_index, \"search.insights.top_queries.exporter.config.index\" : \"1a2b\" } }" };
578592
}
579593

580594
protected void fetchHistoricalTopQueries() throws IOException {
@@ -588,11 +602,13 @@ protected void fetchHistoricalTopQueries() throws IOException {
588602
assertEquals(200, fetchResponse.getStatusLine().getStatusCode());
589603
byte[] content = fetchResponse.getEntity().getContent().readAllBytes();
590604

591-
try (XContentParser parser = JsonXContent.jsonXContent.createParser(
592-
NamedXContentRegistry.EMPTY,
593-
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
594-
content
595-
)) {
605+
try (
606+
XContentParser parser = JsonXContent.jsonXContent.createParser(
607+
NamedXContentRegistry.EMPTY,
608+
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
609+
content
610+
)
611+
) {
596612
Map<String, Object> root = parser.map();
597613
List<Map<String, Object>> topQueries = (List<Map<String, Object>>) root.get("top_queries");
598614
assertNotNull("Expected 'top_queries' field", topQueries);
@@ -634,5 +650,4 @@ protected void fetchHistoricalTopQueries() throws IOException {
634650
}
635651
}
636652

637-
638653
}

src/test/java/org/opensearch/plugin/insights/core/exporter/QueryInsightsExporterIT.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
*/
88

99
package org.opensearch.plugin.insights.core.exporter;
10-
import org.opensearch.plugin.insights.QueryInsightsRestTestCase;
11-
import org.opensearch.client.ResponseException;
10+
1211
import org.opensearch.client.Request;
12+
import org.opensearch.client.ResponseException;
13+
import org.opensearch.plugin.insights.QueryInsightsRestTestCase;
1314

1415
/** Rest Action tests for query */
1516
public class QueryInsightsExporterIT extends QueryInsightsRestTestCase {
@@ -34,8 +35,8 @@ public void testQueryInsightsExporterSettings() throws Exception {
3435
checkQueryInsightsIndexTemplate();
3536
cleanupIndextemplate();
3637
disableLocalIndexExporter();
37-
defaultExporterSettings();//Re-enabling the Local Index
38-
setLocalIndexToDebug();//Ensuring it is able to toggle Local to Debug
38+
defaultExporterSettings();// Re-enabling the Local Index
39+
setLocalIndexToDebug();// Ensuring it is able to toggle Local to Debug
3940
cleanup();
4041
}
4142
}

src/test/java/org/opensearch/plugin/insights/core/reader/QueryInsightsReaderIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.io.IOException;
1111
import org.opensearch.plugin.insights.QueryInsightsRestTestCase;
1212

13-
1413
public class QueryInsightsReaderIT extends QueryInsightsRestTestCase {
1514

1615
public void testQueryInsightsHistoricalTopQueriesRead() throws IOException, InterruptedException {

0 commit comments

Comments
 (0)