Skip to content

Commit 494847b

Browse files
authored
Remove unnecessary reroute from tests (#96435)
NodeReplacement and NodeShutdown test perform reroute on empty cluster state. This does nothing (on empty state) and could be safely removed.
1 parent 66a951e commit 494847b

File tree

2 files changed

+11
-70
lines changed

2 files changed

+11
-70
lines changed

server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/NodeReplacementAllocationDeciderTests.java

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@
99
package org.elasticsearch.cluster.routing.allocation.decider;
1010

1111
import org.elasticsearch.Version;
12-
import org.elasticsearch.action.ActionListener;
1312
import org.elasticsearch.cluster.ClusterState;
1413
import org.elasticsearch.cluster.ESAllocationTestCase;
15-
import org.elasticsearch.cluster.EmptyClusterInfoService;
16-
import org.elasticsearch.cluster.TestShardRoutingRoleStrategies;
1714
import org.elasticsearch.cluster.metadata.IndexMetadata;
1815
import org.elasticsearch.cluster.metadata.Metadata;
1916
import org.elasticsearch.cluster.metadata.NodesShutdownMetadata;
@@ -26,14 +23,9 @@
2623
import org.elasticsearch.cluster.routing.RoutingNodesHelper;
2724
import org.elasticsearch.cluster.routing.ShardRouting;
2825
import org.elasticsearch.cluster.routing.UnassignedInfo;
29-
import org.elasticsearch.cluster.routing.allocation.AllocationService;
3026
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
31-
import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator;
3227
import org.elasticsearch.common.settings.ClusterSettings;
33-
import org.elasticsearch.common.settings.Settings;
3428
import org.elasticsearch.index.shard.ShardId;
35-
import org.elasticsearch.snapshots.EmptySnapshotsInfoService;
36-
import org.elasticsearch.test.gateway.TestGatewayAllocator;
3729

3830
import java.util.Arrays;
3931
import java.util.Collections;
@@ -63,14 +55,6 @@ public class NodeReplacementAllocationDeciderTests extends ESAllocationTestCase
6355
new NodeShutdownAllocationDecider()
6456
)
6557
);
66-
private final AllocationService service = new AllocationService(
67-
allocationDeciders,
68-
new TestGatewayAllocator(),
69-
new BalancedShardsAllocator(Settings.EMPTY),
70-
EmptyClusterInfoService.INSTANCE,
71-
EmptySnapshotsInfoService.INSTANCE,
72-
TestShardRoutingRoleStrategies.DEFAULT_ROLE_ONLY
73-
);
7458

7559
private final String idxName = "test-idx";
7660
private final String idxUuid = "test-idx-uuid";
@@ -98,11 +82,7 @@ public void testNoReplacements() {
9882
}
9983

10084
public void testCanForceAllocate() {
101-
ClusterState state = prepareState(
102-
service.reroute(ClusterState.EMPTY_STATE, "initial state", ActionListener.noop()),
103-
NODE_A.getId(),
104-
NODE_B.getName()
105-
);
85+
ClusterState state = prepareState(ClusterState.EMPTY_STATE, NODE_A.getId(), NODE_B.getName());
10686
RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state, null, null, 0);
10787
RoutingNode routingNode = RoutingNodesHelper.routingNode(NODE_A.getId(), NODE_A, shard);
10888
allocation.debugDecision(true);
@@ -146,11 +126,7 @@ public void testCanForceAllocate() {
146126
}
147127

148128
public void testCannotRemainOnReplacedNode() {
149-
ClusterState state = prepareState(
150-
service.reroute(ClusterState.EMPTY_STATE, "initial state", ActionListener.noop()),
151-
NODE_A.getId(),
152-
NODE_B.getName()
153-
);
129+
ClusterState state = prepareState(ClusterState.EMPTY_STATE, NODE_A.getId(), NODE_B.getName());
154130
RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state, null, null, 0);
155131
RoutingNode routingNode = RoutingNodesHelper.routingNode(NODE_A.getId(), NODE_A, shard);
156132
allocation.debugDecision(true);
@@ -176,11 +152,7 @@ public void testCannotRemainOnReplacedNode() {
176152
}
177153

178154
public void testCanAllocateToNeitherSourceNorTarget() {
179-
ClusterState state = prepareState(
180-
service.reroute(ClusterState.EMPTY_STATE, "initial state", ActionListener.noop()),
181-
NODE_A.getId(),
182-
NODE_B.getName()
183-
);
155+
ClusterState state = prepareState(ClusterState.EMPTY_STATE, NODE_A.getId(), NODE_B.getName());
184156
RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state, null, null, 0);
185157
RoutingNode routingNode = RoutingNodesHelper.routingNode(NODE_A.getId(), NODE_A, shard);
186158
allocation.debugDecision(true);

server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/NodeShutdownAllocationDeciderTests.java

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@
99
package org.elasticsearch.cluster.routing.allocation.decider;
1010

1111
import org.elasticsearch.Version;
12-
import org.elasticsearch.action.ActionListener;
1312
import org.elasticsearch.cluster.ClusterState;
1413
import org.elasticsearch.cluster.ESAllocationTestCase;
15-
import org.elasticsearch.cluster.EmptyClusterInfoService;
16-
import org.elasticsearch.cluster.TestShardRoutingRoleStrategies;
1714
import org.elasticsearch.cluster.metadata.IndexMetadata;
1815
import org.elasticsearch.cluster.metadata.Metadata;
1916
import org.elasticsearch.cluster.metadata.NodesShutdownMetadata;
@@ -26,15 +23,10 @@
2623
import org.elasticsearch.cluster.routing.RoutingNodesHelper;
2724
import org.elasticsearch.cluster.routing.ShardRouting;
2825
import org.elasticsearch.cluster.routing.UnassignedInfo;
29-
import org.elasticsearch.cluster.routing.allocation.AllocationService;
3026
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
31-
import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator;
3227
import org.elasticsearch.common.settings.ClusterSettings;
33-
import org.elasticsearch.common.settings.Settings;
3428
import org.elasticsearch.core.TimeValue;
3529
import org.elasticsearch.index.shard.ShardId;
36-
import org.elasticsearch.snapshots.EmptySnapshotsInfoService;
37-
import org.elasticsearch.test.gateway.TestGatewayAllocator;
3830

3931
import java.util.Arrays;
4032
import java.util.Collections;
@@ -58,14 +50,6 @@ public class NodeShutdownAllocationDeciderTests extends ESAllocationTestCase {
5850
private final AllocationDeciders allocationDeciders = new AllocationDeciders(
5951
Arrays.asList(decider, new SameShardAllocationDecider(clusterSettings), new ReplicaAfterPrimaryActiveAllocationDecider())
6052
);
61-
private final AllocationService service = new AllocationService(
62-
allocationDeciders,
63-
new TestGatewayAllocator(),
64-
new BalancedShardsAllocator(Settings.EMPTY),
65-
EmptyClusterInfoService.INSTANCE,
66-
EmptySnapshotsInfoService.INSTANCE,
67-
TestShardRoutingRoleStrategies.DEFAULT_ROLE_ONLY
68-
);
6953

7054
private final String idxName = "test-idx";
7155
private final String idxUuid = "test-idx-uuid";
@@ -80,10 +64,7 @@ public class NodeShutdownAllocationDeciderTests extends ESAllocationTestCase {
8064
);
8165

8266
public void testCanAllocateShardsToRestartingNode() {
83-
ClusterState state = prepareState(
84-
service.reroute(ClusterState.EMPTY_STATE, "initial state", ActionListener.noop()),
85-
SingleNodeShutdownMetadata.Type.RESTART
86-
);
67+
ClusterState state = prepareState(ClusterState.EMPTY_STATE, SingleNodeShutdownMetadata.Type.RESTART);
8768
RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state, null, null, 0);
8869
RoutingNode routingNode = RoutingNodesHelper.routingNode(DATA_NODE.getId(), DATA_NODE, shard);
8970
allocation.debugDecision(true);
@@ -98,7 +79,7 @@ public void testCanAllocateShardsToRestartingNode() {
9879

9980
public void testCannotAllocateShardsToRemovingNode() {
10081
for (SingleNodeShutdownMetadata.Type type : REMOVE_SHUTDOWN_TYPES) {
101-
ClusterState state = prepareState(service.reroute(ClusterState.EMPTY_STATE, "initial state", ActionListener.noop()), type);
82+
ClusterState state = prepareState(ClusterState.EMPTY_STATE, type);
10283
RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state, null, null, 0);
10384
RoutingNode routingNode = RoutingNodesHelper.routingNode(DATA_NODE.getId(), DATA_NODE, shard);
10485
allocation.debugDecision(true);
@@ -110,10 +91,7 @@ public void testCannotAllocateShardsToRemovingNode() {
11091
}
11192

11293
public void testShardsCanRemainOnRestartingNode() {
113-
ClusterState state = prepareState(
114-
service.reroute(ClusterState.EMPTY_STATE, "initial state", ActionListener.noop()),
115-
SingleNodeShutdownMetadata.Type.RESTART
116-
);
94+
ClusterState state = prepareState(ClusterState.EMPTY_STATE, SingleNodeShutdownMetadata.Type.RESTART);
11795
RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state, null, null, 0);
11896
RoutingNode routingNode = RoutingNodesHelper.routingNode(DATA_NODE.getId(), DATA_NODE, shard);
11997
allocation.debugDecision(true);
@@ -128,7 +106,7 @@ public void testShardsCanRemainOnRestartingNode() {
128106

129107
public void testShardsCannotRemainOnRemovingNode() {
130108
for (SingleNodeShutdownMetadata.Type type : REMOVE_SHUTDOWN_TYPES) {
131-
ClusterState state = prepareState(service.reroute(ClusterState.EMPTY_STATE, "initial state", ActionListener.noop()), type);
109+
ClusterState state = prepareState(ClusterState.EMPTY_STATE, type);
132110
RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state, null, null, 0);
133111
RoutingNode routingNode = RoutingNodesHelper.routingNode(DATA_NODE.getId(), DATA_NODE, shard);
134112
allocation.debugDecision(true);
@@ -144,10 +122,7 @@ public void testShardsCannotRemainOnRemovingNode() {
144122
}
145123

146124
public void testCanAutoExpandToRestartingNode() {
147-
ClusterState state = prepareState(
148-
service.reroute(ClusterState.EMPTY_STATE, "initial state", ActionListener.noop()),
149-
SingleNodeShutdownMetadata.Type.RESTART
150-
);
125+
ClusterState state = prepareState(ClusterState.EMPTY_STATE, SingleNodeShutdownMetadata.Type.RESTART);
151126
RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state, null, null, 0);
152127
allocation.debugDecision(true);
153128

@@ -160,9 +135,7 @@ public void testCanAutoExpandToRestartingNode() {
160135
}
161136

162137
public void testCanAutoExpandToNodeIfNoNodesShuttingDown() {
163-
ClusterState state = service.reroute(ClusterState.EMPTY_STATE, "initial state", ActionListener.noop());
164-
165-
RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state, null, null, 0);
138+
RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, ClusterState.EMPTY_STATE, null, null, 0);
166139
allocation.debugDecision(true);
167140

168141
Decision decision = decider.shouldAutoExpandToNode(indexMetadata, DATA_NODE, allocation);
@@ -172,11 +145,7 @@ public void testCanAutoExpandToNodeIfNoNodesShuttingDown() {
172145

173146
public void testCanAutoExpandToNodeThatIsNotShuttingDown() {
174147
for (SingleNodeShutdownMetadata.Type type : REMOVE_SHUTDOWN_TYPES) {
175-
ClusterState state = prepareState(
176-
service.reroute(ClusterState.EMPTY_STATE, "initial state", ActionListener.noop()),
177-
type,
178-
"other-node-id"
179-
);
148+
ClusterState state = prepareState(ClusterState.EMPTY_STATE, type, "other-node-id");
180149

181150
RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state, null, null, 0);
182151
allocation.debugDecision(true);
@@ -189,7 +158,7 @@ public void testCanAutoExpandToNodeThatIsNotShuttingDown() {
189158

190159
public void testCannotAutoExpandToRemovingNode() {
191160
for (SingleNodeShutdownMetadata.Type type : REMOVE_SHUTDOWN_TYPES) {
192-
ClusterState state = prepareState(service.reroute(ClusterState.EMPTY_STATE, "initial state", ActionListener.noop()), type);
161+
ClusterState state = prepareState(ClusterState.EMPTY_STATE, type);
193162
RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state, null, null, 0);
194163
allocation.debugDecision(true);
195164

0 commit comments

Comments
 (0)