Skip to content

Commit 56d0b76

Browse files
Fix flaky tests in org.opensearch.cluster.routing.remote.RemoteRoutingTableServiceTests (#14264) (#14401)
(cherry picked from commit 5ec2abe) Signed-off-by: Gao Binlong <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent bd4bd67 commit 56d0b76

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

server/src/test/java/org/opensearch/cluster/routing/remote/RemoteRoutingTableServiceTests.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,11 @@ public void testGetIndicesRoutingMapDiffIndexAdded() {
227227
.put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT)
228228
.put(IndexMetadata.SETTING_INDEX_UUID, "uuid")
229229
.build()
230-
).numberOfShards(randomInt(1000)).numberOfReplicas(randomInt(10)).build();
230+
).numberOfShards(between(1, 1000)).numberOfReplicas(randomInt(10)).build();
231231
RoutingTable routingTable = RoutingTable.builder().addAsNew(indexMetadata).build();
232232

233233
String indexName2 = randomAlphaOfLength(randomIntBetween(1, 50));
234-
int noOfShards = randomInt(1000);
234+
int noOfShards = between(1, 1000);
235235
int noOfReplicas = randomInt(10);
236236
final IndexMetadata indexMetadata2 = new IndexMetadata.Builder(indexName2).settings(
237237
Settings.builder()
@@ -252,8 +252,7 @@ public void testGetIndicesRoutingMapDiffIndexAdded() {
252252

253253
public void testGetIndicesRoutingMapDiffShardChanged() {
254254
String indexName = randomAlphaOfLength(randomIntBetween(1, 50));
255-
final Index index = new Index(indexName, "uuid");
256-
int noOfShards = randomInt(1000);
255+
int noOfShards = between(1, 1000);
257256
int noOfReplicas = randomInt(10);
258257
final IndexMetadata indexMetadata = new IndexMetadata.Builder(indexName).settings(
259258
Settings.builder()
@@ -299,8 +298,7 @@ public void testGetIndicesRoutingMapDiffShardChanged() {
299298

300299
public void testGetIndicesRoutingMapDiffShardDetailChanged() {
301300
String indexName = randomAlphaOfLength(randomIntBetween(1, 50));
302-
final Index index = new Index(indexName, "uuid");
303-
int noOfShards = randomInt(1000);
301+
int noOfShards = between(1, 1000);
304302
int noOfReplicas = randomInt(10);
305303
final IndexMetadata indexMetadata = new IndexMetadata.Builder(indexName).settings(
306304
Settings.builder()
@@ -328,7 +326,7 @@ public void testGetIndicesRoutingMapDiffIndexDeleted() {
328326
.put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT)
329327
.put(IndexMetadata.SETTING_INDEX_UUID, "uuid")
330328
.build()
331-
).numberOfShards(randomInt(1000)).numberOfReplicas(randomInt(10)).build();
329+
).numberOfShards(between(1, 1000)).numberOfReplicas(randomInt(10)).build();
332330
RoutingTable routingTable = RoutingTable.builder().addAsNew(indexMetadata).build();
333331

334332
String indexName2 = randomAlphaOfLength(randomIntBetween(1, 50));
@@ -337,7 +335,7 @@ public void testGetIndicesRoutingMapDiffIndexDeleted() {
337335
.put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT)
338336
.put(IndexMetadata.SETTING_INDEX_UUID, "uuid2")
339337
.build()
340-
).numberOfShards(randomInt(1000)).numberOfReplicas(randomInt(10)).build();
338+
).numberOfShards(between(1, 1000)).numberOfReplicas(randomInt(10)).build();
341339
RoutingTable routingTable2 = RoutingTable.builder().addAsNew(indexMetadata2).build();
342340

343341
DiffableUtils.MapDiff<String, IndexRoutingTable, Map<String, IndexRoutingTable>> diff = remoteRoutingTableService
@@ -732,7 +730,6 @@ private ClusterState createIndices(int numberOfIndices) {
732730
RoutingTable.Builder routingTableBuilder = RoutingTable.builder();
733731
for (int i = 0; i < numberOfIndices; i++) {
734732
String indexName = randomAlphaOfLength(randomIntBetween(1, 50));
735-
final Index index = new Index(indexName, "uuid");
736733
final IndexMetadata indexMetadata = new IndexMetadata.Builder(indexName).settings(
737734
Settings.builder()
738735
.put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT)
@@ -751,7 +748,7 @@ private ClusterState createClusterState(String indexName) {
751748
.put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT)
752749
.put(IndexMetadata.SETTING_INDEX_UUID, "uuid")
753750
.build()
754-
).numberOfShards(randomInt(1000)).numberOfReplicas(randomInt(10)).build();
751+
).numberOfShards(between(1, 1000)).numberOfReplicas(randomInt(10)).build();
755752
RoutingTable routingTable = RoutingTable.builder().addAsNew(indexMetadata).build();
756753
return ClusterState.builder(ClusterName.DEFAULT)
757754
.routingTable(routingTable)

0 commit comments

Comments
 (0)