瀏覽代碼

Add Cluster Allocation Explain API Tests (#130381)

Add Cluster Allocation Explain API Tests

Adds tests for the `cluster/allocation/explain` API for when non-integer values are passed as the integer expected shard parameter. This change does not modify the `cluster/allocation/explain` API itself.
Joshua Adams 3 月之前
父節點
當前提交
5c8c001c58

+ 85 - 13
rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.allocation_explain/10_basic.yml

@@ -5,7 +5,28 @@
       cluster.allocation_explain: {}
 
 ---
-"cluster shard allocation explanation test":
+"cluster shard allocation explanation test with empty request":
+  - do:
+      indices.create:
+        index: test
+        body: { "settings": { "index.number_of_shards": 1, "index.number_of_replicas": 9 } }
+
+  - do:
+      cluster.allocation_explain:
+        include_disk_info: true
+
+  - match: { current_state: "unassigned" }
+  - match: { unassigned_info.reason: "INDEX_CREATED" }
+  - is_true: unassigned_info.at
+  - match: { index: "test" }
+  - match: { shard: 0 }
+  - match: { primary: false }
+  - is_true: cluster_info
+  - is_true: can_allocate
+
+---
+# This test has a valid integer input, but it's above the shard limit, so the index cannot be located
+"cluster shard allocation explanation test with max integer shard value":
   - do:
       indices.create:
         index: test
@@ -13,13 +34,40 @@
   - match: { acknowledged: true }
 
   - do:
+      catch: /shard_not_found_exception/
       cluster.allocation_explain:
-        body: { "index": "test", "shard": 0, "primary": true }
+        body: { "index": "test", "shard": 2147483647, "primary": true }
+
+---
+"cluster shard allocation explanation test with long shard value":
+  - do:
+      indices.create:
+        index: test
+
+  - match: { acknowledged: true }
+
+  - do:
+      catch: /x_content_parse_exception/
+      cluster.allocation_explain:
+        body: { "index": "test", "shard": 214748364777, "primary": true }
+
+---
+"cluster shard allocation explanation test with float shard value":
+  - do:
+      indices.create:
+        index: test
+        body: { "settings": { "index.number_of_shards": 2, "index.number_of_replicas": 0 } }
+
+  - match: { acknowledged: true }
+
+  - do:
+      cluster.allocation_explain:
+        body: { "index": "test", "shard": 1.0, "primary": true }
 
   - match: { current_state: "started" }
   - is_true: current_node.id
   - match: { index: "test" }
-  - match: { shard: 0 }
+  - match: { shard: 1 }
   - match: { primary: true }
   - is_true: can_remain_on_current_node
   - is_true: can_rebalance_cluster
@@ -27,25 +75,49 @@
   - is_true: rebalance_explanation
 
 ---
-"cluster shard allocation explanation test with empty request":
+"cluster shard allocation explanation test with double shard value":
   - do:
       indices.create:
         index: test
-        body: { "settings": { "index.number_of_shards": 1, "index.number_of_replicas": 9 } }
+        body: { "settings": { "index.number_of_shards": 2, "index.number_of_replicas": 0 } }
+
+  - match: { acknowledged: true }
 
   - do:
       cluster.allocation_explain:
-        include_disk_info: true
+        body: { "index": "test", "shard": 1.1234567891234567, "primary": true }
 
-  - match: { current_state: "unassigned" }
-  - match: { unassigned_info.reason: "INDEX_CREATED" }
-  - is_true: unassigned_info.at
+  - match: { current_state: "started" }
+  - is_true: current_node.id
   - match: { index: "test" }
-  - match: { shard: 0 }
-  - match: { primary: false }
-  - is_true: cluster_info
-  - is_true: can_allocate
+  - match: { shard: 1 }
+  - match: { primary: true }
+  - is_true: can_remain_on_current_node
+  - is_true: can_rebalance_cluster
+  - is_true: can_rebalance_to_other_node
+  - is_true: rebalance_explanation
 
+---
+"cluster shard allocation explanation test with three valid body parameters":
+  - do:
+      indices.create:
+        index: test
+
+  - match: { acknowledged: true }
+
+  - do:
+      cluster.allocation_explain:
+        body: { "index": "test", "shard": 0, "primary": true }
+
+  - match: { current_state: "started" }
+  - is_true: current_node.id
+  - match: { index: "test" }
+  - match: { shard: 0 }
+  - match: { primary: true }
+  - is_true: can_remain_on_current_node
+  - is_true: can_rebalance_cluster
+  - is_true: can_rebalance_to_other_node
+  - is_true: rebalance_explanation
 
 ---
 "Cluster shard allocation explanation test with a closed index":