Skip to content

Commit df985e6

Browse files
Add includeDiskInfo to toString() (#131358)
Adds the `includeDiskInfo` parameter to the `cluster/allocation/explain` `toString()` method, and adds tests.
1 parent d06b0c8 commit df985e6

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

server/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainRequest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ public String toString() {
236236
}
237237
}
238238
sb.append(",").append(INCLUDE_YES_DECISIONS_PARAMETER_NAME).append("?=").append(includeYesDecisions);
239+
sb.append(",").append(INCLUDE_DISK_INFO_PARAMETER_NAME).append("?=").append(includeDiskInfo);
239240
return sb.toString();
240241
}
241242

server/src/test/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainRequestTests.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,66 @@ public void testSerialization() throws Exception {
3737
assertEquals(request.getCurrentNode(), actual.getCurrentNode());
3838
}
3939

40+
public void testToStringWithEmptyBody() {
41+
ClusterAllocationExplainRequest clusterAllocationExplainRequest = new ClusterAllocationExplainRequest(randomTimeValue());
42+
clusterAllocationExplainRequest.includeYesDecisions(true);
43+
clusterAllocationExplainRequest.includeDiskInfo(false);
44+
45+
String expected = "ClusterAllocationExplainRequest[useAnyUnassignedShard=true,"
46+
+ "include_yes_decisions?=true,include_disk_info?=false";
47+
assertEquals(expected, clusterAllocationExplainRequest.toString());
48+
}
49+
50+
public void testToStringWithValidBodyButCurrentNodeIsNull() {
51+
String index = "test-index";
52+
int shard = randomInt();
53+
boolean primary = randomBoolean();
54+
ClusterAllocationExplainRequest clusterAllocationExplainRequest = new ClusterAllocationExplainRequest(
55+
randomTimeValue(),
56+
index,
57+
shard,
58+
primary,
59+
null
60+
);
61+
clusterAllocationExplainRequest.includeYesDecisions(false);
62+
clusterAllocationExplainRequest.includeDiskInfo(true);
63+
64+
String expected = "ClusterAllocationExplainRequest[index="
65+
+ index
66+
+ ",shard="
67+
+ shard
68+
+ ",primary?="
69+
+ primary
70+
+ ",include_yes_decisions?=false"
71+
+ ",include_disk_info?=true";
72+
assertEquals(expected, clusterAllocationExplainRequest.toString());
73+
}
74+
75+
public void testToStringWithAllBodyParameters() {
76+
String index = "test-index";
77+
int shard = randomInt();
78+
boolean primary = randomBoolean();
79+
String currentNode = "current_node";
80+
ClusterAllocationExplainRequest clusterAllocationExplainRequest = new ClusterAllocationExplainRequest(
81+
randomTimeValue(),
82+
index,
83+
shard,
84+
primary,
85+
currentNode
86+
);
87+
clusterAllocationExplainRequest.includeYesDecisions(false);
88+
clusterAllocationExplainRequest.includeDiskInfo(true);
89+
90+
String expected = "ClusterAllocationExplainRequest[index="
91+
+ index
92+
+ ",shard="
93+
+ shard
94+
+ ",primary?="
95+
+ primary
96+
+ ",current_node="
97+
+ currentNode
98+
+ ",include_yes_decisions?=false"
99+
+ ",include_disk_info?=true";
100+
assertEquals(expected, clusterAllocationExplainRequest.toString());
101+
}
40102
}

0 commit comments

Comments
 (0)