3838import java .util .Arrays ;
3939import java .util .Collections ;
4040import java .util .HashMap ;
41+ import java .util .List ;
4142
4243import static org .elasticsearch .common .settings .ClusterSettings .createBuiltInClusterSettings ;
4344import static org .hamcrest .Matchers .equalTo ;
@@ -78,6 +79,12 @@ public class NodeShutdownAllocationDeciderTests extends ESAllocationTestCase {
7879 )
7980 .build ();
8081
82+ private static final List <SingleNodeShutdownMetadata .Type > REMOVE_SHUTDOWN_TYPES = List .of (
83+ SingleNodeShutdownMetadata .Type .REPLACE ,
84+ SingleNodeShutdownMetadata .Type .REMOVE ,
85+ SingleNodeShutdownMetadata .Type .SIGTERM
86+ );
87+
8188 public void testCanAllocateShardsToRestartingNode () {
8289 ClusterState state = prepareState (
8390 service .reroute (ClusterState .EMPTY_STATE , "initial state" , ActionListener .noop ()),
@@ -96,17 +103,16 @@ public void testCanAllocateShardsToRestartingNode() {
96103 }
97104
98105 public void testCannotAllocateShardsToRemovingNode () {
99- ClusterState state = prepareState (
100- service .reroute (ClusterState .EMPTY_STATE , "initial state" , ActionListener .noop ()),
101- randomFrom (SingleNodeShutdownMetadata .Type .REMOVE , SingleNodeShutdownMetadata .Type .REPLACE )
102- );
103- RoutingAllocation allocation = new RoutingAllocation (allocationDeciders , state , null , null , 0 );
104- RoutingNode routingNode = RoutingNodesHelper .routingNode (DATA_NODE .getId (), DATA_NODE , shard );
105- allocation .debugDecision (true );
106-
107- Decision decision = decider .canAllocate (shard , routingNode , allocation );
108- assertThat (decision .type (), equalTo (Decision .Type .NO ));
109- assertThat (decision .getExplanation (), equalTo ("node [" + DATA_NODE .getId () + "] is preparing to be removed from the cluster" ));
106+ for (SingleNodeShutdownMetadata .Type type : REMOVE_SHUTDOWN_TYPES ) {
107+ ClusterState state = prepareState (service .reroute (ClusterState .EMPTY_STATE , "initial state" , ActionListener .noop ()), type );
108+ RoutingAllocation allocation = new RoutingAllocation (allocationDeciders , state , null , null , 0 );
109+ RoutingNode routingNode = RoutingNodesHelper .routingNode (DATA_NODE .getId (), DATA_NODE , shard );
110+ allocation .debugDecision (true );
111+
112+ Decision decision = decider .canAllocate (shard , routingNode , allocation );
113+ assertThat (type .toString (), decision .type (), equalTo (Decision .Type .NO ));
114+ assertThat (decision .getExplanation (), equalTo ("node [" + DATA_NODE .getId () + "] is preparing to be removed from the cluster" ));
115+ }
110116 }
111117
112118 public void testShardsCanRemainOnRestartingNode () {
@@ -127,17 +133,20 @@ public void testShardsCanRemainOnRestartingNode() {
127133 }
128134
129135 public void testShardsCannotRemainOnRemovingNode () {
130- ClusterState state = prepareState (
131- service .reroute (ClusterState .EMPTY_STATE , "initial state" , ActionListener .noop ()),
132- randomFrom (SingleNodeShutdownMetadata .Type .REMOVE , SingleNodeShutdownMetadata .Type .REPLACE )
133- );
134- RoutingAllocation allocation = new RoutingAllocation (allocationDeciders , state , null , null , 0 );
135- RoutingNode routingNode = RoutingNodesHelper .routingNode (DATA_NODE .getId (), DATA_NODE , shard );
136- allocation .debugDecision (true );
137-
138- Decision decision = decider .canRemain (null , shard , routingNode , allocation );
139- assertThat (decision .type (), equalTo (Decision .Type .NO ));
140- assertThat (decision .getExplanation (), equalTo ("node [" + DATA_NODE .getId () + "] is preparing to be removed from the cluster" ));
136+ for (SingleNodeShutdownMetadata .Type type : REMOVE_SHUTDOWN_TYPES ) {
137+ ClusterState state = prepareState (service .reroute (ClusterState .EMPTY_STATE , "initial state" , ActionListener .noop ()), type );
138+ RoutingAllocation allocation = new RoutingAllocation (allocationDeciders , state , null , null , 0 );
139+ RoutingNode routingNode = RoutingNodesHelper .routingNode (DATA_NODE .getId (), DATA_NODE , shard );
140+ allocation .debugDecision (true );
141+
142+ Decision decision = decider .canRemain (null , shard , routingNode , allocation );
143+ assertThat (type .toString (), decision .type (), equalTo (Decision .Type .NO ));
144+ assertThat (
145+ type .toString (),
146+ decision .getExplanation (),
147+ equalTo ("node [" + DATA_NODE .getId () + "] is preparing to be removed from the cluster" )
148+ );
149+ }
141150 }
142151
143152 public void testCanAutoExpandToRestartingNode () {
@@ -168,31 +177,32 @@ public void testCanAutoExpandToNodeIfNoNodesShuttingDown() {
168177 }
169178
170179 public void testCanAutoExpandToNodeThatIsNotShuttingDown () {
171- ClusterState state = prepareState (
172- service .reroute (ClusterState .EMPTY_STATE , "initial state" , ActionListener .noop ()),
173- randomFrom (SingleNodeShutdownMetadata .Type .REMOVE , SingleNodeShutdownMetadata .Type .REPLACE ),
174- "other-node-id"
175- );
176-
177- RoutingAllocation allocation = new RoutingAllocation (allocationDeciders , state , null , null , 0 );
178- allocation .debugDecision (true );
179-
180- Decision decision = decider .shouldAutoExpandToNode (indexMetadata , DATA_NODE , allocation );
181- assertThat (decision .type (), equalTo (Decision .Type .YES ));
182- assertThat (decision .getExplanation (), equalTo ("this node is not shutting down" ));
180+ for (SingleNodeShutdownMetadata .Type type : REMOVE_SHUTDOWN_TYPES ) {
181+ ClusterState state = prepareState (
182+ service .reroute (ClusterState .EMPTY_STATE , "initial state" , ActionListener .noop ()),
183+ type ,
184+ "other-node-id"
185+ );
186+
187+ RoutingAllocation allocation = new RoutingAllocation (allocationDeciders , state , null , null , 0 );
188+ allocation .debugDecision (true );
189+
190+ Decision decision = decider .shouldAutoExpandToNode (indexMetadata , DATA_NODE , allocation );
191+ assertThat (type .toString (), decision .type (), equalTo (Decision .Type .YES ));
192+ assertThat (type .toString (), decision .getExplanation (), equalTo ("this node is not shutting down" ));
193+ }
183194 }
184195
185196 public void testCannotAutoExpandToRemovingNode () {
186- ClusterState state = prepareState (
187- service .reroute (ClusterState .EMPTY_STATE , "initial state" , ActionListener .noop ()),
188- randomFrom (SingleNodeShutdownMetadata .Type .REMOVE , SingleNodeShutdownMetadata .Type .REPLACE )
189- );
190- RoutingAllocation allocation = new RoutingAllocation (allocationDeciders , state , null , null , 0 );
191- allocation .debugDecision (true );
192-
193- Decision decision = decider .shouldAutoExpandToNode (indexMetadata , DATA_NODE , allocation );
194- assertThat (decision .type (), equalTo (Decision .Type .NO ));
195- assertThat (decision .getExplanation (), equalTo ("node [" + DATA_NODE .getId () + "] is preparing to be removed from the cluster" ));
197+ for (SingleNodeShutdownMetadata .Type type : REMOVE_SHUTDOWN_TYPES ) {
198+ ClusterState state = prepareState (service .reroute (ClusterState .EMPTY_STATE , "initial state" , ActionListener .noop ()), type );
199+ RoutingAllocation allocation = new RoutingAllocation (allocationDeciders , state , null , null , 0 );
200+ allocation .debugDecision (true );
201+
202+ Decision decision = decider .shouldAutoExpandToNode (indexMetadata , DATA_NODE , allocation );
203+ assertThat (decision .type (), equalTo (Decision .Type .NO ));
204+ assertThat (decision .getExplanation (), equalTo ("node [" + DATA_NODE .getId () + "] is preparing to be removed from the cluster" ));
205+ }
196206 }
197207
198208 private ClusterState prepareState (ClusterState initialState , SingleNodeShutdownMetadata .Type shutdownType ) {
0 commit comments