Skip to content

Commit b9dc835

Browse files
committed
split assertion
1 parent 88a0bbe commit b9dc835

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceComputer.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.elasticsearch.index.shard.ShardId;
3737

3838
import java.util.ArrayList;
39-
import java.util.Arrays;
4039
import java.util.HashMap;
4140
import java.util.HashSet;
4241
import java.util.LinkedList;
@@ -293,21 +292,23 @@ public DesiredBalance compute(
293292
for (MoveAllocationCommand command : commands) {
294293
try {
295294
final var rerouteExplanation = command.execute(routingAllocation, false);
296-
assert rerouteExplanation.decisions().type() != Decision.Type.NO;
295+
assert rerouteExplanation.decisions().type() != Decision.Type.NO : "should have thrown for NO decision";
297296
if (rerouteExplanation.decisions().type() != Decision.Type.NO) {
298297
final ShardRouting[] initializingShards = routingNodes.node(
299298
routingAllocation.nodes().resolveNode(command.toNode()).getId()
300299
).initializing();
301300
assert initializingShards.length == 1
302-
&& routingAllocation.nodes()
303-
.resolveNode(command.fromNode())
304-
.getId()
305-
.equals(initializingShards[0].relocatingNodeId())
306-
: "expect one relocating shard, but got : " + List.of(initializingShards);
307-
Arrays.stream(initializingShards).forEach(shard -> {
308-
clusterInfoSimulator.simulateShardStarted(shard);
309-
routingNodes.startShard(shard, changes, 0L);
310-
});
301+
: "expect exactly one relocating shard, but got: " + List.of(initializingShards);
302+
final var initializingShard = initializingShards[0];
303+
assert routingAllocation.nodes()
304+
.resolveNode(command.fromNode())
305+
.getId()
306+
.equals(initializingShard.relocatingNodeId())
307+
: initializingShard
308+
+ " has unexpected relocation source node, expect node "
309+
+ routingAllocation.nodes().resolveNode(command.fromNode());
310+
clusterInfoSimulator.simulateShardStarted(initializingShard);
311+
routingNodes.startShard(initializingShard, changes, 0L);
311312
}
312313
} catch (RuntimeException e) {
313314
logger.debug(

0 commit comments

Comments
 (0)