2929import org .elasticsearch .common .Strings ;
3030import org .elasticsearch .common .xcontent .ChunkedToXContent ;
3131import org .elasticsearch .common .xcontent .XContentHelper ;
32+ import org .elasticsearch .index .Index ;
3233import org .elasticsearch .test .ESTestCase ;
3334import org .elasticsearch .test .gateway .TestGatewayAllocator ;
3435import org .elasticsearch .xcontent .ToXContent ;
@@ -55,7 +56,7 @@ public class ClusterAllocationExplainActionTests extends ESTestCase {
5556
5657 public void testInitializingOrRelocatingShardExplanation () throws Exception {
5758 ShardRoutingState shardRoutingState = randomFrom (ShardRoutingState .INITIALIZING , ShardRoutingState .RELOCATING );
58- ClusterState clusterState = ClusterStateCreationUtils .state ("idx" , randomBoolean (), shardRoutingState );
59+ ClusterState clusterState = ClusterStateCreationUtils .state (new Index ( "idx" , randomUUID ()) , randomBoolean (), shardRoutingState );
5960
6061 assertThat (clusterState .metadata ().projects (), aMapWithSize (1 ));
6162 final ProjectId projectId = clusterState .metadata ().projects ().keySet ().iterator ().next ();
@@ -140,20 +141,25 @@ public ShardAllocationDecision decideShardAllocation(ShardRouting shard, Routing
140141
141142 public void testFindAnyUnassignedShardToExplain () {
142143 // find unassigned primary
143- ClusterState clusterState = ClusterStateCreationUtils .state ("idx" , randomBoolean (), ShardRoutingState .UNASSIGNED );
144+ Index index = new Index ("idx" , randomUUID ());
145+ ClusterState clusterState = ClusterStateCreationUtils .state (index , randomBoolean (), ShardRoutingState .UNASSIGNED );
144146 ClusterAllocationExplainRequest request = new ClusterAllocationExplainRequest (TEST_REQUEST_TIMEOUT );
145147 Set <ProjectId > projectIds = clusterState .metadata ().projects ().keySet ();
146148 ShardRouting shard = findShardToExplain (request , routingAllocation (clusterState ), projectIds );
147- assertEquals (clusterState .getRoutingTable ().index ("idx" ).shard (0 ).primaryShard (), shard );
149+ assertEquals (clusterState .getRoutingTable ().index (index ).shard (0 ).primaryShard (), shard );
148150
149151 // find unassigned replica
150- clusterState = ClusterStateCreationUtils .state ("idx" , randomBoolean (), ShardRoutingState .STARTED , ShardRoutingState .UNASSIGNED );
152+ clusterState = ClusterStateCreationUtils .state (index , randomBoolean (), ShardRoutingState .STARTED , ShardRoutingState .UNASSIGNED );
151153 request = new ClusterAllocationExplainRequest (TEST_REQUEST_TIMEOUT );
152154 shard = findShardToExplain (request , routingAllocation (clusterState ), projectIds );
153- assertEquals (clusterState .getRoutingTable ().index ("idx" ).shard (0 ).replicaShards ().get (0 ), shard );
155+ assertEquals (clusterState .getRoutingTable ().index (index ).shard (0 ).replicaShards ().get (0 ), shard );
154156
155157 // prefer unassigned primary to replica
156- clusterState = ClusterStateCreationUtils .stateWithAssignedPrimariesAndReplicas (new String [] { "idx1" , "idx2" }, 1 , 1 );
158+ clusterState = ClusterStateCreationUtils .stateWithAssignedPrimariesAndReplicas (
159+ new Index [] { new Index ("idx1" , randomUUID ()), new Index ("idx2" , randomUUID ()) },
160+ 1 ,
161+ 1
162+ );
157163 final String redIndex = randomBoolean () ? "idx1" : "idx2" ;
158164 final RoutingTable .Builder routingTableBuilder = RoutingTable .builder (clusterState .routingTable ());
159165 for (final IndexRoutingTable indexRoutingTable : clusterState .routingTable ()) {
@@ -183,7 +189,7 @@ public void testFindAnyUnassignedShardToExplain() {
183189
184190 // no unassigned shard to explain
185191 final ClusterState allStartedClusterState = ClusterStateCreationUtils .state (
186- "idx" ,
192+ index ,
187193 randomBoolean (),
188194 ShardRoutingState .STARTED ,
189195 ShardRoutingState .STARTED
@@ -204,28 +210,36 @@ public void testFindAnyUnassignedShardToExplain() {
204210 }
205211
206212 public void testFindPrimaryShardToExplain () {
207- ClusterState clusterState = ClusterStateCreationUtils .state ("idx" , randomBoolean (), randomFrom (ShardRoutingState .values ()));
213+ Index index = new Index ("idx" , randomUUID ());
214+ ClusterState clusterState = ClusterStateCreationUtils .state (index , randomBoolean (), randomFrom (ShardRoutingState .values ()));
208215 Set <ProjectId > projectIds = clusterState .metadata ().projects ().keySet ();
209- ClusterAllocationExplainRequest request = new ClusterAllocationExplainRequest (TEST_REQUEST_TIMEOUT , "idx" , 0 , true , null );
216+ ClusterAllocationExplainRequest request = new ClusterAllocationExplainRequest (TEST_REQUEST_TIMEOUT , index . getName () , 0 , true , null );
210217 ShardRouting shard = findShardToExplain (request , routingAllocation (clusterState ), projectIds );
211- assertEquals (clusterState .getRoutingTable ().index ("idx" ).shard (0 ).primaryShard (), shard );
218+ assertEquals (clusterState .getRoutingTable ().index (index ).shard (0 ).primaryShard (), shard );
212219 }
213220
214221 public void testFindAnyReplicaToExplain () {
222+ Index index = new Index ("idx" , randomUUID ());
215223 // prefer unassigned replicas to started replicas
216224 ClusterState clusterState = ClusterStateCreationUtils .state (
217- "idx" ,
225+ index ,
218226 randomBoolean (),
219227 ShardRoutingState .STARTED ,
220228 ShardRoutingState .STARTED ,
221229 ShardRoutingState .UNASSIGNED
222230 );
223231 Set <ProjectId > projectIds = clusterState .metadata ().projects ().keySet ();
224- ClusterAllocationExplainRequest request = new ClusterAllocationExplainRequest (TEST_REQUEST_TIMEOUT , "idx" , 0 , false , null );
232+ ClusterAllocationExplainRequest request = new ClusterAllocationExplainRequest (
233+ TEST_REQUEST_TIMEOUT ,
234+ index .getName (),
235+ 0 ,
236+ false ,
237+ null
238+ );
225239 ShardRouting shard = findShardToExplain (request , routingAllocation (clusterState ), projectIds );
226240 assertEquals (
227241 clusterState .getRoutingTable ()
228- .index ("idx" )
242+ .index (index )
229243 .shard (0 )
230244 .replicaShards ()
231245 .stream ()
@@ -237,7 +251,7 @@ public void testFindAnyReplicaToExplain() {
237251
238252 // prefer started replicas to initializing/relocating replicas
239253 clusterState = ClusterStateCreationUtils .state (
240- "idx" ,
254+ index ,
241255 randomBoolean (),
242256 ShardRoutingState .STARTED ,
243257 randomFrom (ShardRoutingState .RELOCATING , ShardRoutingState .INITIALIZING ),
@@ -246,7 +260,7 @@ public void testFindAnyReplicaToExplain() {
246260 request = new ClusterAllocationExplainRequest (TEST_REQUEST_TIMEOUT , "idx" , 0 , false , null );
247261 shard = findShardToExplain (request , routingAllocation (clusterState ), projectIds );
248262 assertEquals (
249- clusterState .getRoutingTable ().index ("idx" ).shard (0 ).replicaShards ().stream ().filter (ShardRouting ::started ).findFirst ().get (),
263+ clusterState .getRoutingTable ().index (index ).shard (0 ).replicaShards ().stream ().filter (ShardRouting ::started ).findFirst ().get (),
250264 shard
251265 );
252266 }
@@ -258,15 +272,16 @@ public void testFindShardAssignedToNode() {
258272 if (primary == false ) {
259273 replicaStates = new ShardRoutingState [] { ShardRoutingState .STARTED };
260274 }
261- ClusterState clusterState = ClusterStateCreationUtils .state ("idx" , randomBoolean (), ShardRoutingState .STARTED , replicaStates );
275+ Index index = new Index ("idx" , randomUUID ());
276+ ClusterState clusterState = ClusterStateCreationUtils .state (index , randomBoolean (), ShardRoutingState .STARTED , replicaStates );
262277 assertThat (clusterState .metadata ().projects (), aMapWithSize (1 ));
263278 final ProjectId projectId = clusterState .metadata ().projects ().keySet ().iterator ().next ();
264279 ShardRouting shardToExplain = primary
265- ? clusterState .routingTable (projectId ).index ("idx" ).shard (0 ).primaryShard ()
266- : clusterState .routingTable (projectId ).index ("idx" ).shard (0 ).replicaShards ().get (0 );
280+ ? clusterState .routingTable (projectId ).index (index ).shard (0 ).primaryShard ()
281+ : clusterState .routingTable (projectId ).index (index ).shard (0 ).replicaShards ().get (0 );
267282 ClusterAllocationExplainRequest request = new ClusterAllocationExplainRequest (
268283 TEST_REQUEST_TIMEOUT ,
269- "idx" ,
284+ index . getName () ,
270285 0 ,
271286 primary ,
272287 shardToExplain .currentNodeId ()
@@ -285,7 +300,7 @@ public void testFindShardAssignedToNode() {
285300 }
286301 final ClusterAllocationExplainRequest failingRequest = new ClusterAllocationExplainRequest (
287302 TEST_REQUEST_TIMEOUT ,
288- "idx" ,
303+ index . getName () ,
289304 0 ,
290305 primary ,
291306 explainNode
0 commit comments