REST hl client: adjust wait_for_active_shards param in cluster health (#31266)
The default wait_for_active_shards is NONE for cluster health, which differs from all the other API in master, hence we need to make sure to set the parameter whenever it differs from NONE (0). The test around this also had a bug, which is why this was not originally uncovered. Relates to #29331
This commit is contained in:
parent
92eb324776
commit
bd51b6b96a
|
@ -721,7 +721,7 @@ final class RequestConverters {
|
||||||
.withWaitForStatus(healthRequest.waitForStatus())
|
.withWaitForStatus(healthRequest.waitForStatus())
|
||||||
.withWaitForNoRelocatingShards(healthRequest.waitForNoRelocatingShards())
|
.withWaitForNoRelocatingShards(healthRequest.waitForNoRelocatingShards())
|
||||||
.withWaitForNoInitializingShards(healthRequest.waitForNoInitializingShards())
|
.withWaitForNoInitializingShards(healthRequest.waitForNoInitializingShards())
|
||||||
.withWaitForActiveShards(healthRequest.waitForActiveShards())
|
.withWaitForActiveShards(healthRequest.waitForActiveShards(), ActiveShardCount.NONE)
|
||||||
.withWaitForNodes(healthRequest.waitForNodes())
|
.withWaitForNodes(healthRequest.waitForNodes())
|
||||||
.withWaitForEvents(healthRequest.waitForEvents())
|
.withWaitForEvents(healthRequest.waitForEvents())
|
||||||
.withTimeout(healthRequest.timeout())
|
.withTimeout(healthRequest.timeout())
|
||||||
|
@ -1047,7 +1047,11 @@ final class RequestConverters {
|
||||||
}
|
}
|
||||||
|
|
||||||
Params withWaitForActiveShards(ActiveShardCount activeShardCount) {
|
Params withWaitForActiveShards(ActiveShardCount activeShardCount) {
|
||||||
if (activeShardCount != null && activeShardCount != ActiveShardCount.DEFAULT) {
|
return withWaitForActiveShards(activeShardCount, ActiveShardCount.DEFAULT);
|
||||||
|
}
|
||||||
|
|
||||||
|
Params withWaitForActiveShards(ActiveShardCount activeShardCount, ActiveShardCount defaultActiveShardCount) {
|
||||||
|
if (activeShardCount != null && activeShardCount != defaultActiveShardCount) {
|
||||||
return putParam("wait_for_active_shards", activeShardCount.toString().toLowerCase(Locale.ROOT));
|
return putParam("wait_for_active_shards", activeShardCount.toString().toLowerCase(Locale.ROOT));
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -1562,7 +1562,7 @@ public class RequestConvertersTests extends ESTestCase {
|
||||||
default:
|
default:
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
setRandomWaitForActiveShards(healthRequest::waitForActiveShards, expectedParams, "0");
|
setRandomWaitForActiveShards(healthRequest::waitForActiveShards, ActiveShardCount.NONE, expectedParams);
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
ClusterHealthRequest.Level level = randomFrom(ClusterHealthRequest.Level.values());
|
ClusterHealthRequest.Level level = randomFrom(ClusterHealthRequest.Level.values());
|
||||||
healthRequest.level(level);
|
healthRequest.level(level);
|
||||||
|
@ -2187,23 +2187,24 @@ public class RequestConvertersTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setRandomWaitForActiveShards(Consumer<ActiveShardCount> setter, Map<String, String> expectedParams) {
|
private static void setRandomWaitForActiveShards(Consumer<ActiveShardCount> setter, Map<String, String> expectedParams) {
|
||||||
setRandomWaitForActiveShards(setter, expectedParams, null);
|
setRandomWaitForActiveShards(setter, ActiveShardCount.DEFAULT, expectedParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setRandomWaitForActiveShards(Consumer<ActiveShardCount> setter,Map<String, String> expectedParams,
|
private static void setRandomWaitForActiveShards(Consumer<ActiveShardCount> setter, ActiveShardCount defaultActiveShardCount,
|
||||||
String defaultValue) {
|
Map<String, String> expectedParams) {
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
|
int waitForActiveShardsInt = randomIntBetween(-1, 5);
|
||||||
String waitForActiveShardsString;
|
String waitForActiveShardsString;
|
||||||
int waitForActiveShards = randomIntBetween(-1, 5);
|
if (waitForActiveShardsInt == -1) {
|
||||||
if (waitForActiveShards == -1) {
|
|
||||||
waitForActiveShardsString = "all";
|
waitForActiveShardsString = "all";
|
||||||
} else {
|
} else {
|
||||||
waitForActiveShardsString = String.valueOf(waitForActiveShards);
|
waitForActiveShardsString = String.valueOf(waitForActiveShardsInt);
|
||||||
|
}
|
||||||
|
ActiveShardCount activeShardCount = ActiveShardCount.parseString(waitForActiveShardsString);
|
||||||
|
setter.accept(activeShardCount);
|
||||||
|
if (defaultActiveShardCount.equals(activeShardCount) == false) {
|
||||||
|
expectedParams.put("wait_for_active_shards", waitForActiveShardsString);
|
||||||
}
|
}
|
||||||
setter.accept(ActiveShardCount.parseString(waitForActiveShardsString));
|
|
||||||
expectedParams.put("wait_for_active_shards", waitForActiveShardsString);
|
|
||||||
} else if (defaultValue != null) {
|
|
||||||
expectedParams.put("wait_for_active_shards", defaultValue);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue