1515import org .opensearch .action .admin .cluster .shards .routing .weighted .put .ClusterPutWeightedRoutingResponse ;
1616import org .opensearch .action .admin .cluster .state .ClusterStateRequest ;
1717import org .opensearch .action .search .SearchResponse ;
18- import org .opensearch .cluster .health .ClusterHealthStatus ;
1918import org .opensearch .common .settings .Settings ;
2019import org .opensearch .core .rest .RestStatus ;
2120import org .opensearch .discovery .ClusterManagerNotDiscoveredException ;
21+ import org .opensearch .index .IndexNotFoundException ;
2222import org .opensearch .plugins .Plugin ;
2323import org .opensearch .snapshots .mockstore .MockRepository ;
2424import org .opensearch .test .InternalTestCluster ;
4040
4141import static org .opensearch .index .query .QueryBuilders .matchAllQuery ;
4242import static org .opensearch .test .hamcrest .OpenSearchAssertions .assertAcked ;
43+ import static org .hamcrest .Matchers .containsString ;
4344import 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