|
26 | 26 | import org.elasticsearch.common.settings.Settings.Builder; |
27 | 27 | import org.elasticsearch.common.transport.TransportAddress; |
28 | 28 | import org.elasticsearch.common.util.Maps; |
| 29 | +import org.elasticsearch.env.BuildVersion; |
29 | 30 | import org.elasticsearch.index.Index; |
30 | 31 | import org.elasticsearch.index.IndexNotFoundException; |
31 | 32 | import org.elasticsearch.index.IndexVersion; |
@@ -386,11 +387,7 @@ public void testPerformActionAttrsNoShard() { |
386 | 387 | } |
387 | 388 |
|
388 | 389 | public void testPerformActionSomeShardsOnlyOnNewNodes() throws Exception { |
389 | | - VersionInformation oldVersion = new VersionInformation( |
390 | | - VersionUtils.randomCompatibleVersion(random(), VersionUtils.getPreviousVersion()), |
391 | | - IndexVersions.MINIMUM_COMPATIBLE, |
392 | | - IndexVersionUtils.randomCompatibleVersion(random()) |
393 | | - ); |
| 390 | + final VersionInformation oldVersion = randomOldVersionInformation(); |
394 | 391 | final int numNodes = randomIntBetween(2, 20); // Need at least 2 nodes to have some nodes on a new version |
395 | 392 | final int numNewNodes = randomIntBetween(1, numNodes - 1); |
396 | 393 | final int numOldNodes = numNodes - numNewNodes; |
@@ -451,11 +448,7 @@ public void testPerformActionSomeShardsOnlyOnNewNodes() throws Exception { |
451 | 448 | } |
452 | 449 |
|
453 | 450 | public void testPerformActionSomeShardsOnlyOnNewNodesButNewNodesInvalidAttrs() { |
454 | | - VersionInformation oldVersion = new VersionInformation( |
455 | | - VersionUtils.randomCompatibleVersion(random(), VersionUtils.getPreviousVersion()), |
456 | | - IndexVersions.MINIMUM_COMPATIBLE, |
457 | | - IndexVersionUtils.randomCompatibleVersion(random()) |
458 | | - ); |
| 451 | + final var oldVersion = randomOldVersionInformation(); |
459 | 452 | final int numNodes = randomIntBetween(2, 20); // Need at least 2 nodes to have some nodes on a new version |
460 | 453 | final int numNewNodes = randomIntBetween(1, numNodes - 1); |
461 | 454 | final int numOldNodes = numNodes - numNewNodes; |
@@ -524,11 +517,7 @@ public void testPerformActionSomeShardsOnlyOnNewNodesButNewNodesInvalidAttrs() { |
524 | 517 | } |
525 | 518 |
|
526 | 519 | public void testPerformActionNewShardsExistButWithInvalidAttributes() throws Exception { |
527 | | - VersionInformation oldVersion = new VersionInformation( |
528 | | - VersionUtils.randomCompatibleVersion(random(), VersionUtils.getPreviousVersion()), |
529 | | - IndexVersions.MINIMUM_COMPATIBLE, |
530 | | - IndexVersionUtils.randomCompatibleVersion(random()) |
531 | | - ); |
| 520 | + final VersionInformation oldVersion = randomOldVersionInformation(); |
532 | 521 | final int numNodes = randomIntBetween(2, 20); // Need at least 2 nodes to have some nodes on a new version |
533 | 522 | final int numNewNodes = randomIntBetween(1, numNodes - 1); |
534 | 523 | final int numOldNodes = numNodes - numNewNodes; |
@@ -596,6 +585,18 @@ public void testPerformActionNewShardsExistButWithInvalidAttributes() throws Exc |
596 | 585 | assertNodeSelected(indexMetadata, indexMetadata.getIndex(), oldNodeIds, discoveryNodes, indexRoutingTable.build()); |
597 | 586 | } |
598 | 587 |
|
| 588 | + private VersionInformation randomOldVersionInformation() { |
| 589 | + final var previousVersion = VersionUtils.getPreviousVersion(); |
| 590 | + final var version = VersionUtils.randomVersionBetween(random(), previousVersion.minimumCompatibilityVersion(), previousVersion); |
| 591 | + return new VersionInformation( |
| 592 | + BuildVersion.fromVersionId(version.id()), |
| 593 | + version, |
| 594 | + IndexVersions.MINIMUM_COMPATIBLE, |
| 595 | + IndexVersions.MINIMUM_COMPATIBLE, |
| 596 | + IndexVersionUtils.randomCompatibleVersion(random()) |
| 597 | + ); |
| 598 | + } |
| 599 | + |
599 | 600 | private Collection<Map.Entry<String, String>> generateRandomValidAttributes(int numAttrs) { |
600 | 601 | return generateRandomValidAttributes(numAttrs, ""); |
601 | 602 | } |
|
0 commit comments