|
29 | 29 | import org.elasticsearch.common.settings.Settings.Builder;
|
30 | 30 | import org.elasticsearch.common.transport.TransportAddress;
|
31 | 31 | import org.elasticsearch.common.util.Maps;
|
| 32 | +import org.elasticsearch.env.BuildVersion; |
32 | 33 | import org.elasticsearch.index.Index;
|
33 | 34 | import org.elasticsearch.index.IndexNotFoundException;
|
34 | 35 | import org.elasticsearch.index.IndexVersion;
|
@@ -394,11 +395,7 @@ public void testPerformActionAttrsNoShard() {
|
394 | 395 | }
|
395 | 396 |
|
396 | 397 | public void testPerformActionSomeShardsOnlyOnNewNodes() throws Exception {
|
397 |
| - VersionInformation oldVersion = new VersionInformation( |
398 |
| - VersionUtils.randomCompatibleVersion(random(), VersionUtils.getPreviousVersion()), |
399 |
| - IndexVersions.MINIMUM_COMPATIBLE, |
400 |
| - IndexVersionUtils.randomCompatibleVersion(random()) |
401 |
| - ); |
| 398 | + final VersionInformation oldVersion = randomOldVersionInformation(); |
402 | 399 | final int numNodes = randomIntBetween(2, 20); // Need at least 2 nodes to have some nodes on a new version
|
403 | 400 | final int numNewNodes = randomIntBetween(1, numNodes - 1);
|
404 | 401 | final int numOldNodes = numNodes - numNewNodes;
|
@@ -459,11 +456,7 @@ public void testPerformActionSomeShardsOnlyOnNewNodes() throws Exception {
|
459 | 456 | }
|
460 | 457 |
|
461 | 458 | public void testPerformActionSomeShardsOnlyOnNewNodesButNewNodesInvalidAttrs() {
|
462 |
| - VersionInformation oldVersion = new VersionInformation( |
463 |
| - VersionUtils.randomCompatibleVersion(random(), VersionUtils.getPreviousVersion()), |
464 |
| - IndexVersions.MINIMUM_COMPATIBLE, |
465 |
| - IndexVersionUtils.randomCompatibleVersion(random()) |
466 |
| - ); |
| 459 | + final var oldVersion = randomOldVersionInformation(); |
467 | 460 | final int numNodes = randomIntBetween(2, 20); // Need at least 2 nodes to have some nodes on a new version
|
468 | 461 | final int numNewNodes = randomIntBetween(1, numNodes - 1);
|
469 | 462 | final int numOldNodes = numNodes - numNewNodes;
|
@@ -532,11 +525,7 @@ public void testPerformActionSomeShardsOnlyOnNewNodesButNewNodesInvalidAttrs() {
|
532 | 525 | }
|
533 | 526 |
|
534 | 527 | public void testPerformActionNewShardsExistButWithInvalidAttributes() throws Exception {
|
535 |
| - VersionInformation oldVersion = new VersionInformation( |
536 |
| - VersionUtils.randomCompatibleVersion(random(), VersionUtils.getPreviousVersion()), |
537 |
| - IndexVersions.MINIMUM_COMPATIBLE, |
538 |
| - IndexVersionUtils.randomCompatibleVersion(random()) |
539 |
| - ); |
| 528 | + final VersionInformation oldVersion = randomOldVersionInformation(); |
540 | 529 | final int numNodes = randomIntBetween(2, 20); // Need at least 2 nodes to have some nodes on a new version
|
541 | 530 | final int numNewNodes = randomIntBetween(1, numNodes - 1);
|
542 | 531 | final int numOldNodes = numNodes - numNewNodes;
|
@@ -604,6 +593,18 @@ public void testPerformActionNewShardsExistButWithInvalidAttributes() throws Exc
|
604 | 593 | assertNodeSelected(indexMetadata, indexMetadata.getIndex(), oldNodeIds, discoveryNodes, indexRoutingTable.build());
|
605 | 594 | }
|
606 | 595 |
|
| 596 | + private VersionInformation randomOldVersionInformation() { |
| 597 | + final var previousVersion = VersionUtils.getPreviousVersion(); |
| 598 | + final var version = VersionUtils.randomVersionBetween(random(), previousVersion.minimumCompatibilityVersion(), previousVersion); |
| 599 | + return new VersionInformation( |
| 600 | + BuildVersion.fromVersionId(version.id()), |
| 601 | + version, |
| 602 | + IndexVersions.MINIMUM_COMPATIBLE, |
| 603 | + IndexVersions.MINIMUM_COMPATIBLE, |
| 604 | + IndexVersionUtils.randomCompatibleVersion(random()) |
| 605 | + ); |
| 606 | + } |
| 607 | + |
607 | 608 | private Collection<Map.Entry<String, String>> generateRandomValidAttributes(int numAttrs) {
|
608 | 609 | return generateRandomValidAttributes(numAttrs, "");
|
609 | 610 | }
|
|
0 commit comments