Skip to content

Commit 7fb4ca2

Browse files
committed
Apply Spotless formatting
Signed-off-by: Prakash Bhardwaj <bhardwajprakash653@gmail.com>
1 parent ff4cc79 commit 7fb4ca2

3 files changed

Lines changed: 59 additions & 46 deletions

File tree

client/rest-high-level/src/test/java/org/opensearch/client/ClusterClientIT.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,18 @@ public void testClusterHealthNotFoundIndex() throws IOException {
339339
createIndex("index", Settings.EMPTY);
340340
ClusterHealthRequest request = new ClusterHealthRequest("notexisted-index");
341341
request.timeout("5s");
342-
ClusterHealthResponse response = execute(request, highLevelClient().cluster()::health, highLevelClient().cluster()::healthAsync);
343342

344-
assertThat(response, notNullValue());
345-
assertThat(response.isTimedOut(), equalTo(true));
346-
assertThat(response.status(), equalTo(RestStatus.REQUEST_TIMEOUT));
347-
assertThat(response.getStatus(), equalTo(ClusterHealthStatus.RED));
348-
assertNoIndices(response);
343+
// After the fix, querying non-existent index should return 404 instead of timeout
344+
OpenSearchException exception = expectThrows(
345+
OpenSearchException.class,
346+
() -> execute(request, highLevelClient().cluster()::health, highLevelClient().cluster()::healthAsync)
347+
);
348+
349+
assertThat(exception.status(), equalTo(RestStatus.NOT_FOUND));
350+
assertThat(
351+
exception.getMessage(),
352+
equalTo("OpenSearch exception [type=index_not_found_exception, reason=no such index [notexisted-index]]")
353+
);
349354
}
350355

351356
public void testRemoteInfo() throws Exception {

server/src/internalClusterTest/java/org/opensearch/cluster/ClusterHealthIT.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,18 @@ public void testHealth() {
8686
logger.info("--> running cluster health on an index that does not exists");
8787
IndexNotFoundException exception = expectThrows(
8888
IndexNotFoundException.class,
89-
() -> client().admin()
90-
.cluster()
91-
.prepareHealth("test1")
92-
.setWaitForYellowStatus()
93-
.setTimeout("1s")
94-
.execute()
95-
.actionGet()
89+
() -> client().admin().cluster().prepareHealth("test1").setWaitForYellowStatus().setTimeout("1s").execute().actionGet()
9690
);
9791
assertThat(exception.getMessage(), equalTo("no such index [test1]"));
9892

9993
logger.info("--> running cluster wide health");
100-
ClusterHealthResponse healthResponse = client().admin().cluster().prepareHealth().setWaitForGreenStatus().setTimeout("10s").execute().actionGet();
94+
ClusterHealthResponse healthResponse = client().admin()
95+
.cluster()
96+
.prepareHealth()
97+
.setWaitForGreenStatus()
98+
.setTimeout("10s")
99+
.execute()
100+
.actionGet();
101101
assertThat(healthResponse.isTimedOut(), equalTo(false));
102102
assertThat(healthResponse.getStatus(), equalTo(ClusterHealthStatus.GREEN));
103103
assertThat(healthResponse.getIndices().isEmpty(), equalTo(true));
@@ -114,13 +114,7 @@ public void testHealth() {
114114
logger.info("--> running cluster health on an index that does exists and an index that doesn't exists");
115115
IndexNotFoundException exception2 = expectThrows(
116116
IndexNotFoundException.class,
117-
() -> client().admin()
118-
.cluster()
119-
.prepareHealth("test1", "test2")
120-
.setWaitForYellowStatus()
121-
.setTimeout("1s")
122-
.execute()
123-
.actionGet()
117+
() -> client().admin().cluster().prepareHealth("test1", "test2").setWaitForYellowStatus().setTimeout("1s").execute().actionGet()
124118
);
125119
assertThat(exception2.getMessage(), equalTo("no such index [test2]"));
126120
}

server/src/internalClusterTest/java/org/opensearch/cluster/routing/WeightedRoutingIT.java

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
import org.opensearch.action.admin.cluster.shards.routing.weighted.put.ClusterPutWeightedRoutingResponse;
1616
import org.opensearch.action.admin.cluster.state.ClusterStateRequest;
1717
import org.opensearch.action.search.SearchResponse;
18-
import org.opensearch.cluster.health.ClusterHealthStatus;
1918
import org.opensearch.common.settings.Settings;
2019
import org.opensearch.core.rest.RestStatus;
2120
import org.opensearch.discovery.ClusterManagerNotDiscoveredException;
21+
import org.opensearch.index.IndexNotFoundException;
2222
import org.opensearch.plugins.Plugin;
2323
import org.opensearch.snapshots.mockstore.MockRepository;
2424
import org.opensearch.test.InternalTestCluster;
@@ -40,6 +40,7 @@
4040

4141
import static org.opensearch.index.query.QueryBuilders.matchAllQuery;
4242
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
43+
import static org.hamcrest.Matchers.containsString;
4344
import static org.hamcrest.Matchers.equalTo;
4445

4546
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0, minNumDataNodes = 3)
@@ -646,7 +647,8 @@ public void testClusterHealthResponseWithEnsureNodeWeighedInParam() throws Excep
646647
assertTrue(response.isAcknowledged());
647648
assertNotNull(internalCluster().clusterService().state().metadata().weightedRoutingMetadata());
648649

649-
// Check cluster health for weighed in node, health check should return a response with 200 status code
650+
// Check cluster health for weighed in node, health check should return a
651+
// response with 200 status code
650652
ClusterHealthResponse nodeLocalHealth = client(nodes_in_zone_a.get(0)).admin()
651653
.cluster()
652654
.prepareHealth()
@@ -655,25 +657,29 @@ public void testClusterHealthResponseWithEnsureNodeWeighedInParam() throws Excep
655657
.get();
656658
assertFalse(nodeLocalHealth.isTimedOut());
657659

658-
// Check cluster health for weighed away node, health check should respond with an exception
660+
// Check cluster health for weighed away node, health check should respond with
661+
// an exception
659662
NodeWeighedAwayException ex = expectThrows(
660663
NodeWeighedAwayException.class,
661664
() -> client(nodes_in_zone_c.get(0)).admin().cluster().prepareHealth().setLocal(true).setEnsureNodeWeighedIn(true).get()
662665
);
663666
assertTrue(ex.getMessage().contains("local node is weighed away"));
664667

665668
logger.info("--> running cluster health on an index that does not exists");
666-
ClusterHealthResponse healthResponse = client(nodes_in_zone_c.get(0)).admin()
667-
.cluster()
668-
.prepareHealth("test1")
669-
.setLocal(true)
670-
.setEnsureNodeWeighedIn(true)
671-
.setTimeout("1s")
672-
.execute()
673-
.actionGet();
674-
assertThat(healthResponse.isTimedOut(), equalTo(true));
675-
assertThat(healthResponse.getStatus(), equalTo(ClusterHealthStatus.RED));
676-
assertThat(healthResponse.getIndices().isEmpty(), equalTo(true));
669+
// After the fix, querying non-existent index should return 404 instead of
670+
// timeout
671+
IndexNotFoundException exception = expectThrows(
672+
IndexNotFoundException.class,
673+
() -> client(nodes_in_zone_c.get(0)).admin()
674+
.cluster()
675+
.prepareHealth("test1")
676+
.setLocal(true)
677+
.setEnsureNodeWeighedIn(true)
678+
.setTimeout("1s")
679+
.execute()
680+
.actionGet()
681+
);
682+
assertThat(exception.getMessage(), containsString("no such index [test1]"));
677683

678684
Set<String> nodesInOneSide = Stream.of(nodes_in_zone_a.get(0), nodes_in_zone_b.get(0), nodes_in_zone_c.get(0))
679685
.collect(Collectors.toCollection(HashSet::new));
@@ -689,14 +695,16 @@ public void testClusterHealthResponseWithEnsureNodeWeighedInParam() throws Excep
689695
networkDisruption.startDisrupting();
690696

691697
assertBusy(() -> {
692-
// Check cluster health for weighed in node when cluster manager is not discovered, health check should
698+
// Check cluster health for weighed in node when cluster manager is not
699+
// discovered, health check should
693700
// return a response with 503 status code
694701
assertThrows(
695702
ClusterManagerNotDiscoveredException.class,
696703
() -> client(nodes_in_zone_a.get(0)).admin().cluster().prepareHealth().setLocal(true).setEnsureNodeWeighedIn(true).get()
697704
);
698705

699-
// Check cluster health for weighed away node when cluster manager is not discovered, health check should
706+
// Check cluster health for weighed away node when cluster manager is not
707+
// discovered, health check should
700708
// return a response with 503 status code
701709
assertThrows(
702710
ClusterManagerNotDiscoveredException.class,
@@ -779,7 +787,8 @@ public void testReadWriteWeightedRoutingMetadataOnNodeRestart() throws Exception
779787
ClusterDeleteWeightedRoutingResponse deleteResponse = client().admin().cluster().prepareDeleteWeightedRouting().setVersion(0).get();
780788
assertTrue(deleteResponse.isAcknowledged());
781789

782-
// check weighted routing metadata after node restart, ensure node comes healthy after restart
790+
// check weighted routing metadata after node restart, ensure node comes healthy
791+
// after restart
783792
internalCluster().restartNode(nodes_in_zone_a.get(0), new InternalTestCluster.RestartCallback());
784793
ensureGreen();
785794
assertNotNull(internalCluster().clusterService().state().metadata().weightedRoutingMetadata());
@@ -878,8 +887,10 @@ public void testReadWriteWeightedRoutingMetadataOnNodeRestart() throws Exception
878887

879888
/**
880889
* https://github.com/opensearch-project/OpenSearch/issues/18817
881-
* For regression in custom string query preference with awareness attributes enabled.
882-
* We expect preference will consistently route to the same shard replica. However, when awareness attributes
890+
* For regression in custom string query preference with awareness attributes
891+
* enabled.
892+
* We expect preference will consistently route to the same shard replica.
893+
* However, when awareness attributes
883894
* are configured this does not hold.
884895
*/
885896
public void testCustomPreferenceShardIdCombination() {
@@ -915,10 +926,12 @@ public void testCustomPreferenceShardIdCombination() {
915926
refreshAndWaitForReplication("test_index");
916927

917928
/*
918-
Execute the same match all query with custom string preference.
919-
For each search and each shard in the response we record the node on which the shard was located.
920-
Given the custom string preference, we expect each shard or each search should report the exact same node id.
921-
Otherwise, the custom string pref is not producing consistent shard routing.
929+
* Execute the same match all query with custom string preference.
930+
* For each search and each shard in the response we record the node on which
931+
* the shard was located.
932+
* Given the custom string preference, we expect each shard or each search
933+
* should report the exact same node id.
934+
* Otherwise, the custom string pref is not producing consistent shard routing.
922935
*/
923936
Map<String, Set<String>> shardToNodes = new HashMap<>();
924937
for (int i = 0; i < 20; i++) {
@@ -935,8 +948,9 @@ public void testCustomPreferenceShardIdCombination() {
935948
}
936949

937950
/*
938-
If more than one node was responsible for serving a request for a given shard,
939-
then there was a regression in the custom preference string.
951+
* If more than one node was responsible for serving a request for a given
952+
* shard,
953+
* then there was a regression in the custom preference string.
940954
*/
941955
logger.info("--> shard to node mappings: {}", shardToNodes);
942956
for (Map.Entry<String, Set<String>> entry : shardToNodes.entrySet()) {

0 commit comments

Comments
 (0)