Skip to content

Commit 84817db

Browse files
David Turner revision 1 comments fixed
1 parent a8042af commit 84817db

File tree

4 files changed

+36
-19
lines changed

4 files changed

+36
-19
lines changed

rest-api-spec/src/main/resources/rest-api-spec/api/cluster.allocation_explain.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@
2424
"params":{
2525
"index": {
2626
"type": "string",
27-
"description": "Specifies the index within which we would like to describe the shard"
27+
"description": "Index containing the shard to be explained"
2828
},
2929
"shard": {
3030
"type": "number",
31-
"description": "Specifies the ID of the shard that you would like an explanation for"
31+
"description": "Shard ID to be explained"
3232
},
3333
"primary": {
3434
"type":"boolean",
3535
"description":"If true, returns explanation for the primary shard for the given shard ID"
3636
},
3737
"current_node": {
3838
"type": "string",
39-
"description": "Specifies the node ID or the name of the node to only explain a shard that is currently located on the specified node"
39+
"description": "Node ID or the name of the node to only explain a shard that is currently located on the specified node"
4040
},
4141
"master_timeout":{
4242
"type":"time",

server/src/main/java/org/elasticsearch/rest/RestRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ public int paramAsInt(String key, int defaultValue) {
478478
}
479479
}
480480

481-
public Integer paramAsInt(String key, Integer defaultValue) {
481+
public Integer paramAsInteger(String key, Integer defaultValue) {
482482
String sValue = param(key);
483483
if (sValue == null) {
484484
return defaultValue;

server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterAllocationExplainAction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
7777
);
7878

7979
clusterAllocationExplainRequest.setShard(
80-
request.paramAsInt(ClusterAllocationExplainRequest.SHARD_PARAMETER_NAME, clusterAllocationExplainRequest.getShard())
80+
request.paramAsInteger(ClusterAllocationExplainRequest.SHARD_PARAMETER_NAME, clusterAllocationExplainRequest.getShard())
8181
);
8282

8383
clusterAllocationExplainRequest.setPrimary(
@@ -89,7 +89,6 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
8989
);
9090
}
9191

92-
// This checks for optionally provided query parameters
9392
clusterAllocationExplainRequest.includeYesDecisions(
9493
request.paramAsBoolean(ClusterAllocationExplainRequest.INCLUDE_YES_DECISIONS_PARAMETER_NAME, false)
9594
);

server/src/test/java/org/elasticsearch/rest/RestRequestTests.java

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,38 +120,56 @@ public void testApplyContentParser() throws IOException {
120120
assertEquals(emptyMap(), source.get());
121121
}
122122

123-
public void testParseAsIntWithNoParameters() {
123+
public void testParamAsIntWithNoParameters() {
124124
RestRequest restRequest = contentRestRequest("", emptyMap());
125-
int defaultValue = -1;
125+
int defaultValue = randomInt();
126126
String parameterKey = randomIdentifier();
127127

128128
int value = restRequest.paramAsInt(parameterKey, defaultValue);
129129
assertEquals(defaultValue, value);
130-
131-
Integer value2 = restRequest.paramAsInt(parameterKey, Integer.valueOf(defaultValue));
132-
assertEquals(defaultValue, value2.intValue());
133130
}
134131

135-
public void testParseAsIntWithIntegerParameter() {
132+
public void testParamAsIntWithIntegerParameter() {
136133
String parameterKey = randomIdentifier();
137134
RestRequest restRequest = contentRestRequest("", singletonMap(parameterKey, "123"));
138-
int defaultValue = -1;
135+
int defaultValue = randomInt();
139136

140137
int value = restRequest.paramAsInt(parameterKey, defaultValue);
141138
assertEquals(123, value);
142-
143-
Integer value2 = restRequest.paramAsInt(parameterKey, Integer.valueOf(defaultValue));
144-
assertEquals(123, value2.intValue());
145139
}
146140

147-
public void testParseAsIntWithoutIntegerParameter() {
141+
public void testParamAsIntWithoutIntegerParameter() {
148142
String parameterKey = randomIdentifier();
149143
RestRequest restRequest = contentRestRequest("", singletonMap(parameterKey, "123T"));
150-
int defaultValue = -1;
144+
int defaultValue = randomInt();
151145

152146
assertThrows(IllegalArgumentException.class, () -> { restRequest.paramAsInt(parameterKey, defaultValue); });
147+
}
148+
149+
public void testParamAsIntegerWithNoParameters() {
150+
RestRequest restRequest = contentRestRequest("", emptyMap());
151+
int defaultValue = randomInt();
152+
String parameterKey = randomIdentifier();
153+
154+
Integer value2 = restRequest.paramAsInteger(parameterKey, defaultValue);
155+
assertEquals(defaultValue, value2.intValue());
156+
}
157+
158+
public void testParamAsIntegerWithIntegerParameter() {
159+
String parameterKey = randomIdentifier();
160+
RestRequest restRequest = contentRestRequest("", singletonMap(parameterKey, "123"));
161+
int defaultValue = randomInt();
162+
163+
Integer value2 = restRequest.paramAsInteger(parameterKey, defaultValue);
164+
assertEquals(123, value2.intValue());
165+
}
166+
167+
public void testParamAsIntegerWithoutIntegerParameter() {
168+
String parameterKey = randomIdentifier();
169+
RestRequest restRequest = contentRestRequest("", singletonMap(parameterKey, "123T"));
170+
int defaultValue = randomInt();
153171

154-
assertThrows(IllegalArgumentException.class, () -> { restRequest.paramAsInt(parameterKey, Integer.valueOf(defaultValue)); });
172+
assertThrows(IllegalArgumentException.class, () -> { restRequest.paramAsInteger(parameterKey, defaultValue); });
155173
}
156174

157175
public void testContentOrSourceParam() throws IOException {

0 commit comments

Comments
 (0)