|
14 | 14 | import org.elasticsearch.cluster.node.DiscoveryNodes;
|
15 | 15 | import org.elasticsearch.cluster.routing.IndexRoutingTable;
|
16 | 16 | import org.elasticsearch.cluster.routing.RoutingTable;
|
| 17 | +import org.elasticsearch.cluster.routing.ShardRouting; |
17 | 18 | import org.elasticsearch.cluster.routing.ShardRoutingState;
|
18 | 19 | import org.elasticsearch.cluster.routing.TestShardRouting;
|
19 | 20 | import org.elasticsearch.cluster.routing.UnassignedInfo;
|
@@ -132,6 +133,35 @@ public void testConditionMetOnlyOneCopyAllocated() {
|
132 | 133 | new ClusterStateWaitStep.Result(false, new AllocationRoutedStep.Info(0, 1, true)));
|
133 | 134 | }
|
134 | 135 |
|
| 136 | + public void testConditionNotMetDueToRelocation() { |
| 137 | + Index index = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20)); |
| 138 | + Map<String, String> requires = AllocateActionTests.randomMap(1, 5); |
| 139 | + Settings.Builder existingSettings = Settings.builder() |
| 140 | + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT.id) |
| 141 | + .put(IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_PREFIX + "._id", "node1") |
| 142 | + .put(IndexMetaData.SETTING_INDEX_UUID, index.getUUID()); |
| 143 | + Settings.Builder expectedSettings = Settings.builder(); |
| 144 | + Settings.Builder node1Settings = Settings.builder(); |
| 145 | + Settings.Builder node2Settings = Settings.builder(); |
| 146 | + requires.forEach((k, v) -> { |
| 147 | + existingSettings.put(IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + k, v); |
| 148 | + expectedSettings.put(IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + k, v); |
| 149 | + node1Settings.put(Node.NODE_ATTRIBUTES.getKey() + k, v); |
| 150 | + }); |
| 151 | + boolean primaryOnNode1 = randomBoolean(); |
| 152 | + ShardRouting shardOnNode1 = TestShardRouting.newShardRouting(new ShardId(index, 0), |
| 153 | + "node1", primaryOnNode1, ShardRoutingState.STARTED); |
| 154 | + shardOnNode1 = shardOnNode1.relocate("node3", 230); |
| 155 | + IndexRoutingTable.Builder indexRoutingTable = IndexRoutingTable.builder(index) |
| 156 | + .addShard(shardOnNode1) |
| 157 | + .addShard(TestShardRouting.newShardRouting(new ShardId(index, 0), "node2", primaryOnNode1 == false, |
| 158 | + ShardRoutingState.STARTED)); |
| 159 | + |
| 160 | + AllocationRoutedStep step = new AllocationRoutedStep(randomStepKey(), randomStepKey()); |
| 161 | + assertAllocateStatus(index, 1, 0, step, existingSettings, node1Settings, node2Settings, indexRoutingTable, |
| 162 | + new ClusterStateWaitStep.Result(false, new AllocationRoutedStep.Info(0, 2, true))); |
| 163 | + } |
| 164 | + |
135 | 165 | public void testExecuteAllocateNotComplete() throws Exception {
|
136 | 166 | Index index = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20));
|
137 | 167 | Map<String, String> includes = AllocateActionTests.randomMap(1, 5);
|
|
0 commit comments