10
10
import org .elasticsearch .action .ActionListener ;
11
11
import org .elasticsearch .action .admin .indices .settings .put .UpdateSettingsRequest ;
12
12
import org .elasticsearch .action .admin .indices .settings .put .UpdateSettingsResponse ;
13
- import org .elasticsearch .action .admin .indices .settings .put .UpdateSettingsTestHelper ;
14
13
import org .elasticsearch .client .AdminClient ;
15
14
import org .elasticsearch .client .Client ;
16
15
import org .elasticsearch .client .IndicesAdminClient ;
39
38
import org .mockito .invocation .InvocationOnMock ;
40
39
import org .mockito .stubbing .Answer ;
41
40
41
+ import java .io .IOException ;
42
42
import java .util .HashSet ;
43
43
import java .util .Set ;
44
+ import java .util .stream .Collectors ;
45
+
46
+ import static org .hamcrest .Matchers .anyOf ;
47
+ import static org .hamcrest .Matchers .equalTo ;
44
48
45
49
public class SetSingleNodeAllocateStepTests extends AbstractStepTestCase <SetSingleNodeAllocateStep > {
46
50
@@ -80,7 +84,18 @@ protected SetSingleNodeAllocateStep copyInstance(SetSingleNodeAllocateStep insta
80
84
return new SetSingleNodeAllocateStep (instance .getKey (), instance .getNextStepKey (), client );
81
85
}
82
86
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 {
84
99
IndexMetaData indexMetaData = IndexMetaData .builder (randomAlphaOfLength (10 )).settings (settings (Version .CURRENT ))
85
100
.numberOfShards (randomIntBetween (1 , 5 )).numberOfReplicas (randomIntBetween (0 , 5 )).build ();
86
101
Index index = indexMetaData .getIndex ();
@@ -101,7 +116,7 @@ public void testPerformActionNoAttrs() {
101
116
assertNodeSelected (indexMetaData , index , validNodeNames , nodes );
102
117
}
103
118
104
- public void testPerformActionAttrsAllNodesValid () {
119
+ public void testPerformActionAttrsAllNodesValid () throws IOException {
105
120
int numAttrs = randomIntBetween (1 , 10 );
106
121
String [][] validAttrs = new String [numAttrs ][2 ];
107
122
for (int i = 0 ; i < numAttrs ; i ++) {
@@ -132,7 +147,7 @@ public void testPerformActionAttrsAllNodesValid() {
132
147
assertNodeSelected (indexMetaData , index , validNodeNames , nodes );
133
148
}
134
149
135
- public void testPerformActionAttrsSomeNodesValid () {
150
+ public void testPerformActionAttrsSomeNodesValid () throws IOException {
136
151
String [] validAttr = new String [] { "box_type" , "valid" };
137
152
String [] invalidAttr = new String [] { "box_type" , "not_valid" };
138
153
Settings .Builder indexSettings = settings (Version .CURRENT );
@@ -237,7 +252,7 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
237
252
UpdateSettingsRequest request = (UpdateSettingsRequest ) invocation .getArguments ()[0 ];
238
253
@ SuppressWarnings ("unchecked" )
239
254
ActionListener <UpdateSettingsResponse > listener = (ActionListener <UpdateSettingsResponse >) invocation .getArguments ()[1 ];
240
- UpdateSettingsTestHelper . assertSettingsRequestContainsValueFrom (request ,
255
+ assertSettingsRequestContainsValueFrom (request ,
241
256
IndexMetaData .INDEX_ROUTING_REQUIRE_GROUP_SETTING .getKey () + "_name" , validNodeNames , true ,
242
257
indexMetaData .getIndex ().getName ());
243
258
listener .onFailure (exception );
@@ -325,7 +340,8 @@ public void onFailure(Exception e) {
325
340
Mockito .verifyZeroInteractions (client );
326
341
}
327
342
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 {
329
345
ImmutableOpenMap .Builder <String , IndexMetaData > indices = ImmutableOpenMap .<String , IndexMetaData > builder ().fPut (index .getName (),
330
346
indexMetaData );
331
347
IndexRoutingTable .Builder indexRoutingTable = IndexRoutingTable .builder (index )
@@ -340,17 +356,18 @@ private void assertNodeSelected(IndexMetaData indexMetaData, Index index, Set<St
340
356
341
357
Mockito .when (client .admin ()).thenReturn (adminClient );
342
358
Mockito .when (adminClient .indices ()).thenReturn (indicesClient );
359
+
343
360
Mockito .doAnswer (new Answer <Void >() {
344
361
345
362
@ Override
346
363
public Void answer (InvocationOnMock invocation ) throws Throwable {
347
364
UpdateSettingsRequest request = (UpdateSettingsRequest ) invocation .getArguments ()[0 ];
348
365
@ SuppressWarnings ("unchecked" )
349
366
ActionListener <UpdateSettingsResponse > listener = (ActionListener <UpdateSettingsResponse >) invocation .getArguments ()[1 ];
350
- UpdateSettingsTestHelper . assertSettingsRequestContainsValueFrom (request ,
367
+ assertSettingsRequestContainsValueFrom (request ,
351
368
IndexMetaData .INDEX_ROUTING_REQUIRE_GROUP_SETTING .getKey () + "_name" , validNodeNames , true ,
352
369
indexMetaData .getIndex ().getName ());
353
- listener .onResponse (UpdateSettingsTestHelper . createMockResponse (true ));
370
+ listener .onResponse (new UpdateSettingsResponse (true ));
354
371
return null ;
355
372
}
356
373
0 commit comments