Skip to content

Commit

Permalink
Fix AllocateRoutedStepTests reusing keys for random values (#53958)
Browse files Browse the repository at this point in the history
In these tests there was a very small chance that keys could collide,
which causes test failures.

Backport of #51016

Co-authored-by: Lee Hinman <dakrone@users.noreply.github.com>
  • Loading branch information
droberts195 and dakrone committed Mar 23, 2020
1 parent 866282c commit 3fac7ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static Map<String, String> randomMap(int minEntries, int maxEntries) {
Map<String, String> map = new HashMap<>();
int numIncludes = randomIntBetween(minEntries, maxEntries);
for (int i = 0; i < numIncludes; i++) {
map.put(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20));
map.put(randomAlphaOfLengthBetween(2, 20), randomAlphaOfLengthBetween(2, 20));
}
return map;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,11 @@ public void testConditionNotMetDueToRelocation() {
public void testExecuteAllocateNotComplete() throws Exception {
Index index = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20));
Map<String, String> includes = AllocateActionTests.randomMap(1, 5);
Map<String, String> excludes = AllocateActionTests.randomMap(1, 5);
Map<String, String> requires = AllocateActionTests.randomMap(1, 5);
Map<String, String> excludes = randomValueOtherThanMany(map -> map.keySet().stream().anyMatch(includes::containsKey),
() -> AllocateActionTests.randomMap(1, 5));
Map<String, String> requires = randomValueOtherThanMany(map -> map.keySet().stream().anyMatch(includes::containsKey) ||
map.keySet().stream().anyMatch(excludes::containsKey),
() -> AllocateActionTests.randomMap(1, 5));
Settings.Builder existingSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT.id)
.put(IndexMetaData.SETTING_INDEX_UUID, index.getUUID());
Settings.Builder expectedSettings = Settings.builder();
Expand Down Expand Up @@ -230,8 +233,11 @@ public void testExecuteAllocateNotComplete() throws Exception {
public void testExecuteAllocateNotCompleteOnlyOneCopyAllocated() throws Exception {
Index index = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20));
Map<String, String> includes = AllocateActionTests.randomMap(1, 5);
Map<String, String> excludes = AllocateActionTests.randomMap(1, 5);
Map<String, String> requires = AllocateActionTests.randomMap(1, 5);
Map<String, String> excludes = randomValueOtherThanMany(map -> map.keySet().stream().anyMatch(includes::containsKey),
() -> AllocateActionTests.randomMap(1, 5));
Map<String, String> requires = randomValueOtherThanMany(map -> map.keySet().stream().anyMatch(includes::containsKey) ||
map.keySet().stream().anyMatch(excludes::containsKey),
() -> AllocateActionTests.randomMap(1, 5));
Settings.Builder existingSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT.id)
.put(IndexMetaData.SETTING_INDEX_UUID, index.getUUID());
Settings.Builder expectedSettings = Settings.builder();
Expand Down Expand Up @@ -266,8 +272,11 @@ public void testExecuteAllocateNotCompleteOnlyOneCopyAllocated() throws Exceptio
public void testExecuteAllocateUnassigned() throws Exception {
Index index = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20));
Map<String, String> includes = AllocateActionTests.randomMap(1, 5);
Map<String, String> excludes = AllocateActionTests.randomMap(1, 5);
Map<String, String> requires = AllocateActionTests.randomMap(1, 5);
Map<String, String> excludes = randomValueOtherThanMany(map -> map.keySet().stream().anyMatch(includes::containsKey),
() -> AllocateActionTests.randomMap(1, 5));
Map<String, String> requires = randomValueOtherThanMany(map -> map.keySet().stream().anyMatch(includes::containsKey) ||
map.keySet().stream().anyMatch(excludes::containsKey),
() -> AllocateActionTests.randomMap(1, 5));
Settings.Builder existingSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT.id)
.put(IndexMetaData.SETTING_INDEX_UUID, index.getUUID());
Settings.Builder expectedSettings = Settings.builder();
Expand Down

0 comments on commit 3fac7ac

Please sign in to comment.