|
85 | 85 | import java.util.concurrent.atomic.AtomicBoolean; |
86 | 86 | import java.util.function.Consumer; |
87 | 87 | import java.util.function.Function; |
| 88 | +import java.util.function.Predicate; |
88 | 89 | import java.util.stream.IntStream; |
89 | 90 |
|
90 | 91 | import static org.elasticsearch.action.support.ActionTestUtils.wrapAsRestResponseListener; |
@@ -598,11 +599,14 @@ public void testNoActiveCopy() throws Exception { |
598 | 599 | } |
599 | 600 | } |
600 | 601 |
|
601 | | - private void moveOrCloseShardsOnNodes(String nodeName) throws Exception { |
| 602 | + private void moveOrCloseShardsOnNodes(String nodeName, Predicate<String> indexName) throws Exception { |
602 | 603 | final IndicesService indicesService = internalCluster().getInstance(IndicesService.class, nodeName); |
603 | 604 | final ClusterState clusterState = clusterService().state(); |
604 | 605 | for (IndexService indexService : indicesService) { |
605 | 606 | for (IndexShard indexShard : indexService) { |
| 607 | + if (indexName.test(indexShard.shardId().getIndexName()) == false) { |
| 608 | + continue; |
| 609 | + } |
606 | 610 | if (randomBoolean()) { |
607 | 611 | closeShardNoCheck(indexShard, randomBoolean()); |
608 | 612 | } else if (randomBoolean()) { |
@@ -644,13 +648,21 @@ private void moveOrCloseShardsOnNodes(String nodeName) throws Exception { |
644 | 648 |
|
645 | 649 | public void testRelocation() throws Exception { |
646 | 650 | populateTimeRangeIndices(); |
| 651 | + assertAcked( |
| 652 | + client().admin() |
| 653 | + .indices() |
| 654 | + .prepareUpdateSettings("log-index-*") |
| 655 | + .setSettings(Settings.builder().put("index.routing.rebalance.enable", "none").build()) |
| 656 | + .get() |
| 657 | + ); |
| 658 | + ensureGreen("log-index-*"); |
647 | 659 | try { |
648 | 660 | final AtomicBoolean relocated = new AtomicBoolean(); |
649 | 661 | for (String node : internalCluster().getNodeNames()) { |
650 | 662 | MockTransportService.getInstance(node) |
651 | 663 | .addRequestHandlingBehavior(TransportFieldCapabilitiesAction.ACTION_NODE_NAME, (handler, request, channel, task) -> { |
652 | 664 | if (relocated.compareAndSet(false, true)) { |
653 | | - moveOrCloseShardsOnNodes(node); |
| 665 | + moveOrCloseShardsOnNodes(node, indexName -> indexName.startsWith("log-index-")); |
654 | 666 | } |
655 | 667 | handler.messageReceived(request, channel, task); |
656 | 668 | }); |
|
0 commit comments