Browse Source

Fixes tests so allocation ids in IndexMetaData is in sync with
what is in the RoutingTable

Ali Beyad 9 years ago
parent
commit
cf32f8de34

+ 3 - 2
core/src/test/java/org/elasticsearch/cluster/routing/RoutingTableTests.java

@@ -332,11 +332,12 @@ public class RoutingTableTests extends ESAllocationTestCase {
         expectThrows(IllegalStateException.class, () -> indexRoutingTable.validate(metaData4));
     }
 
-    private IndexMetaData updateActiveAllocations(IndexRoutingTable indexRoutingTable, IndexMetaData indexMetaData) {
+    public static IndexMetaData updateActiveAllocations(IndexRoutingTable indexRoutingTable, IndexMetaData indexMetaData) {
         IndexMetaData.Builder imdBuilder = IndexMetaData.builder(indexMetaData);
         for (IndexShardRoutingTable shardTable : indexRoutingTable) {
             for (ShardRouting shardRouting : shardTable) {
-                Set<String> activeAllocations = shardTable.activeShards().stream().map(shr -> shr.allocationId().getId()).collect(Collectors.toSet());
+                Set<String> activeAllocations = shardTable.activeShards().stream().map(
+                    shr -> shr.allocationId().getId()).collect(Collectors.toSet());
                 imdBuilder.putActiveAllocationIds(shardRouting.id(), activeAllocations);
             }
         }

+ 5 - 2
core/src/test/java/org/elasticsearch/discovery/zen/NodeJoinControllerTests.java

@@ -80,6 +80,7 @@ import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_CREATION_
 import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
 import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS;
 import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_VERSION_CREATED;
+import static org.elasticsearch.cluster.routing.RoutingTableTests.updateActiveAllocations;
 import static org.elasticsearch.test.ClusterServiceUtils.createClusterService;
 import static org.elasticsearch.test.ClusterServiceUtils.setState;
 import static org.elasticsearch.cluster.ESAllocationTestCase.createAllocationService;
@@ -596,7 +597,6 @@ public class NodeJoinControllerTests extends ESTestCase {
                 .put(SETTING_VERSION_CREATED, Version.CURRENT)
                 .put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 1)
                 .put(SETTING_CREATION_DATE, System.currentTimeMillis())).build();
-            stateBuilder.metaData(MetaData.builder().put(indexMetaData, false).generateClusterUuidIfNeeded());
             IndexRoutingTable.Builder indexRoutingTableBuilder = IndexRoutingTable.builder(indexMetaData.getIndex());
             RoutingTable.Builder routing = new RoutingTable.Builder();
             routing.addAsNew(indexMetaData);
@@ -619,7 +619,10 @@ public class NodeJoinControllerTests extends ESTestCase {
                     ShardRoutingState.UNASSIGNED, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "life sucks")));
             }
             indexRoutingTableBuilder.addIndexShard(indexShardRoutingBuilder.build());
-            stateBuilder.routingTable(RoutingTable.builder().add(indexRoutingTableBuilder.build()).build());
+            IndexRoutingTable indexRoutingTable = indexRoutingTableBuilder.build();
+            IndexMetaData updatedIndexMetaData = updateActiveAllocations(indexRoutingTable, indexMetaData);
+            stateBuilder.metaData(MetaData.builder().put(updatedIndexMetaData, false).generateClusterUuidIfNeeded())
+                        .routingTable(RoutingTable.builder().add(indexRoutingTable).build());
         }
 
         setState(clusterService, stateBuilder.build());