Skip to content

Commit d30f745

Browse files
joshua-adams-1mridula-s109
authored andcommitted
Add Cluster Allocation Explain API Tests (elastic#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.
1 parent 317af7a commit d30f745

File tree

1 file changed

+85
-13
lines changed
  • rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.allocation_explain

1 file changed

+85
-13
lines changed

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

Lines changed: 85 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,119 @@
55
cluster.allocation_explain: {}
66

77
---
8-
"cluster shard allocation explanation test":
8+
"cluster shard allocation explanation test with empty request":
9+
- do:
10+
indices.create:
11+
index: test
12+
body: { "settings": { "index.number_of_shards": 1, "index.number_of_replicas": 9 } }
13+
14+
- do:
15+
cluster.allocation_explain:
16+
include_disk_info: true
17+
18+
- match: { current_state: "unassigned" }
19+
- match: { unassigned_info.reason: "INDEX_CREATED" }
20+
- is_true: unassigned_info.at
21+
- match: { index: "test" }
22+
- match: { shard: 0 }
23+
- match: { primary: false }
24+
- is_true: cluster_info
25+
- is_true: can_allocate
26+
27+
---
28+
# This test has a valid integer input, but it's above the shard limit, so the index cannot be located
29+
"cluster shard allocation explanation test with max integer shard value":
930
- do:
1031
indices.create:
1132
index: test
1233

1334
- match: { acknowledged: true }
1435

1536
- do:
37+
catch: /shard_not_found_exception/
1638
cluster.allocation_explain:
17-
body: { "index": "test", "shard": 0, "primary": true }
39+
body: { "index": "test", "shard": 2147483647, "primary": true }
40+
41+
---
42+
"cluster shard allocation explanation test with long shard value":
43+
- do:
44+
indices.create:
45+
index: test
46+
47+
- match: { acknowledged: true }
48+
49+
- do:
50+
catch: /x_content_parse_exception/
51+
cluster.allocation_explain:
52+
body: { "index": "test", "shard": 214748364777, "primary": true }
53+
54+
---
55+
"cluster shard allocation explanation test with float shard value":
56+
- do:
57+
indices.create:
58+
index: test
59+
body: { "settings": { "index.number_of_shards": 2, "index.number_of_replicas": 0 } }
60+
61+
- match: { acknowledged: true }
62+
63+
- do:
64+
cluster.allocation_explain:
65+
body: { "index": "test", "shard": 1.0, "primary": true }
1866

1967
- match: { current_state: "started" }
2068
- is_true: current_node.id
2169
- match: { index: "test" }
22-
- match: { shard: 0 }
70+
- match: { shard: 1 }
2371
- match: { primary: true }
2472
- is_true: can_remain_on_current_node
2573
- is_true: can_rebalance_cluster
2674
- is_true: can_rebalance_to_other_node
2775
- is_true: rebalance_explanation
2876

2977
---
30-
"cluster shard allocation explanation test with empty request":
78+
"cluster shard allocation explanation test with double shard value":
3179
- do:
3280
indices.create:
3381
index: test
34-
body: { "settings": { "index.number_of_shards": 1, "index.number_of_replicas": 9 } }
82+
body: { "settings": { "index.number_of_shards": 2, "index.number_of_replicas": 0 } }
83+
84+
- match: { acknowledged: true }
3585

3686
- do:
3787
cluster.allocation_explain:
38-
include_disk_info: true
88+
body: { "index": "test", "shard": 1.1234567891234567, "primary": true }
3989

40-
- match: { current_state: "unassigned" }
41-
- match: { unassigned_info.reason: "INDEX_CREATED" }
42-
- is_true: unassigned_info.at
90+
- match: { current_state: "started" }
91+
- is_true: current_node.id
4392
- match: { index: "test" }
44-
- match: { shard: 0 }
45-
- match: { primary: false }
46-
- is_true: cluster_info
47-
- is_true: can_allocate
93+
- match: { shard: 1 }
94+
- match: { primary: true }
95+
- is_true: can_remain_on_current_node
96+
- is_true: can_rebalance_cluster
97+
- is_true: can_rebalance_to_other_node
98+
- is_true: rebalance_explanation
4899

100+
---
101+
"cluster shard allocation explanation test with three valid body parameters":
102+
- do:
103+
indices.create:
104+
index: test
105+
106+
- match: { acknowledged: true }
107+
108+
- do:
109+
cluster.allocation_explain:
110+
body: { "index": "test", "shard": 0, "primary": true }
111+
112+
- match: { current_state: "started" }
113+
- is_true: current_node.id
114+
- match: { index: "test" }
115+
- match: { shard: 0 }
116+
- match: { primary: true }
117+
- is_true: can_remain_on_current_node
118+
- is_true: can_rebalance_cluster
119+
- is_true: can_rebalance_to_other_node
120+
- is_true: rebalance_explanation
49121

50122
---
51123
"Cluster shard allocation explanation test with a closed index":

0 commit comments

Comments
 (0)