RoutingTable.Builder routingTableBuilder = routingTable();
for (int i = 0; i < numberOfIndices; i++) {
routingTableBuilder.add(indexRoutingTable("test" + i).initializeEmpty(metaData.index("test" + i)));
}
RoutingTable routingTable = routingTableBuilder.build();
ClusterState clusterState = newClusterStateBuilder().metaData(metaData).routingTable(routingTable).build();
assertThat(routingTable.indicesRouting().size(), equalTo(numberOfIndices));
for (int i = 0; i < numberOfIndices; i++) {
assertThat(routingTable.index("test" + i).shards().size(), equalTo(1));
assertThat(routingTable.index("test" + i).shard(0).size(), equalTo(1));
assertThat(routingTable.index("test" + i).shard(0).shards().size(), equalTo(1));
assertThat(routingTable.index("test" + i).shard(0).shards().get(0).state(), equalTo(UNASSIGNED));
assertThat(routingTable.index("test" + i).shard(0).shards().get(0).currentNodeId(), nullValue());
}
logger.info("Adding " + (numberOfIndices / 2) + " nodes");
DiscoveryNodes.Builder nodesBuilder = newNodesBuilder();
List<DiscoveryNode> nodes = newArrayList();
for (int i = 0; i < (numberOfIndices / 2); i++) {
nodesBuilder.put(newNode("node" + i));
}
RoutingTable prevRoutingTable = routingTable;
clusterState = newClusterStateBuilder().state(clusterState).nodes(nodesBuilder).build();
routingTable = strategy.reroute(clusterState).routingTable();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).build();
assertThat(prevRoutingTable != routingTable, equalTo(true));