1010import org .elasticsearch .action .ActionListener ;
1111import org .elasticsearch .action .admin .indices .settings .put .UpdateSettingsRequest ;
1212import org .elasticsearch .action .admin .indices .settings .put .UpdateSettingsResponse ;
13- import org .elasticsearch .action .admin .indices .settings .put .UpdateSettingsTestHelper ;
1413import org .elasticsearch .client .AdminClient ;
1514import org .elasticsearch .client .Client ;
1615import org .elasticsearch .client .IndicesAdminClient ;
3938import org .mockito .invocation .InvocationOnMock ;
4039import org .mockito .stubbing .Answer ;
4140
41+ import java .io .IOException ;
4242import java .util .HashSet ;
4343import java .util .Set ;
44+ import java .util .stream .Collectors ;
45+
46+ import static org .hamcrest .Matchers .anyOf ;
47+ import static org .hamcrest .Matchers .equalTo ;
4448
4549public class SetSingleNodeAllocateStepTests extends AbstractStepTestCase <SetSingleNodeAllocateStep > {
4650
@@ -80,7 +84,18 @@ protected SetSingleNodeAllocateStep copyInstance(SetSingleNodeAllocateStep insta
8084 return new SetSingleNodeAllocateStep (instance .getKey (), instance .getNextStepKey (), client );
8185 }
8286
83- public void testPerformActionNoAttrs () {
87+ public static void assertSettingsRequestContainsValueFrom (UpdateSettingsRequest request , String settingsKey ,
88+ Set <String > acceptableValues , boolean assertOnlyKeyInSettings ,
89+ String ... expectedIndices ) {
90+ assertNotNull (request );
91+ assertArrayEquals (expectedIndices , request .indices ());
92+ assertThat (request .settings ().get (settingsKey ), anyOf (acceptableValues .stream ().map (e -> equalTo (e )).collect (Collectors .toList ())));
93+ if (assertOnlyKeyInSettings ) {
94+ assertEquals (1 , request .settings ().size ());
95+ }
96+ }
97+
98+ public void testPerformActionNoAttrs () throws IOException {
8499 IndexMetaData indexMetaData = IndexMetaData .builder (randomAlphaOfLength (10 )).settings (settings (Version .CURRENT ))
85100 .numberOfShards (randomIntBetween (1 , 5 )).numberOfReplicas (randomIntBetween (0 , 5 )).build ();
86101 Index index = indexMetaData .getIndex ();
@@ -101,7 +116,7 @@ public void testPerformActionNoAttrs() {
101116 assertNodeSelected (indexMetaData , index , validNodeNames , nodes );
102117 }
103118
104- public void testPerformActionAttrsAllNodesValid () {
119+ public void testPerformActionAttrsAllNodesValid () throws IOException {
105120 int numAttrs = randomIntBetween (1 , 10 );
106121 String [][] validAttrs = new String [numAttrs ][2 ];
107122 for (int i = 0 ; i < numAttrs ; i ++) {
@@ -132,7 +147,7 @@ public void testPerformActionAttrsAllNodesValid() {
132147 assertNodeSelected (indexMetaData , index , validNodeNames , nodes );
133148 }
134149
135- public void testPerformActionAttrsSomeNodesValid () {
150+ public void testPerformActionAttrsSomeNodesValid () throws IOException {
136151 String [] validAttr = new String [] { "box_type" , "valid" };
137152 String [] invalidAttr = new String [] { "box_type" , "not_valid" };
138153 Settings .Builder indexSettings = settings (Version .CURRENT );
@@ -237,7 +252,7 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
237252 UpdateSettingsRequest request = (UpdateSettingsRequest ) invocation .getArguments ()[0 ];
238253 @ SuppressWarnings ("unchecked" )
239254 ActionListener <UpdateSettingsResponse > listener = (ActionListener <UpdateSettingsResponse >) invocation .getArguments ()[1 ];
240- UpdateSettingsTestHelper . assertSettingsRequestContainsValueFrom (request ,
255+ assertSettingsRequestContainsValueFrom (request ,
241256 IndexMetaData .INDEX_ROUTING_REQUIRE_GROUP_SETTING .getKey () + "_name" , validNodeNames , true ,
242257 indexMetaData .getIndex ().getName ());
243258 listener .onFailure (exception );
@@ -325,7 +340,8 @@ public void onFailure(Exception e) {
325340 Mockito .verifyZeroInteractions (client );
326341 }
327342
328- private void assertNodeSelected (IndexMetaData indexMetaData , Index index , Set <String > validNodeNames , DiscoveryNodes .Builder nodes ) {
343+ private void assertNodeSelected (IndexMetaData indexMetaData , Index index ,
344+ Set <String > validNodeNames , DiscoveryNodes .Builder nodes ) throws IOException {
329345 ImmutableOpenMap .Builder <String , IndexMetaData > indices = ImmutableOpenMap .<String , IndexMetaData > builder ().fPut (index .getName (),
330346 indexMetaData );
331347 IndexRoutingTable .Builder indexRoutingTable = IndexRoutingTable .builder (index )
@@ -340,17 +356,18 @@ private void assertNodeSelected(IndexMetaData indexMetaData, Index index, Set<St
340356
341357 Mockito .when (client .admin ()).thenReturn (adminClient );
342358 Mockito .when (adminClient .indices ()).thenReturn (indicesClient );
359+
343360 Mockito .doAnswer (new Answer <Void >() {
344361
345362 @ Override
346363 public Void answer (InvocationOnMock invocation ) throws Throwable {
347364 UpdateSettingsRequest request = (UpdateSettingsRequest ) invocation .getArguments ()[0 ];
348365 @ SuppressWarnings ("unchecked" )
349366 ActionListener <UpdateSettingsResponse > listener = (ActionListener <UpdateSettingsResponse >) invocation .getArguments ()[1 ];
350- UpdateSettingsTestHelper . assertSettingsRequestContainsValueFrom (request ,
367+ assertSettingsRequestContainsValueFrom (request ,
351368 IndexMetaData .INDEX_ROUTING_REQUIRE_GROUP_SETTING .getKey () + "_name" , validNodeNames , true ,
352369 indexMetaData .getIndex ().getName ());
353- listener .onResponse (UpdateSettingsTestHelper . createMockResponse (true ));
370+ listener .onResponse (new UpdateSettingsResponse (true ));
354371 return null ;
355372 }
356373
0 commit comments