91
91
import static org .hamcrest .Matchers .containsString ;
92
92
import static org .hamcrest .Matchers .equalTo ;
93
93
import static org .hamcrest .Matchers .hasSize ;
94
+ import static org .hamcrest .Matchers .instanceOf ;
94
95
import static org .hamcrest .Matchers .is ;
96
+ import static org .hamcrest .Matchers .nullValue ;
95
97
import static org .mockito .Matchers .any ;
96
98
import static org .mockito .Matchers .eq ;
97
99
import static org .mockito .Mockito .doAnswer ;
@@ -225,7 +227,7 @@ public void testRolloverAliasActions() {
225
227
String targetIndex = randomAlphaOfLength (10 );
226
228
final RolloverRequest rolloverRequest = new RolloverRequest (sourceAlias , targetIndex );
227
229
228
- List <AliasAction > actions = TransportRolloverAction .rolloverAliasToNewIndex (sourceIndex , targetIndex , rolloverRequest , false );
230
+ List <AliasAction > actions = TransportRolloverAction .rolloverAliasToNewIndex (sourceIndex , targetIndex , rolloverRequest , false , null );
229
231
assertThat (actions , hasSize (2 ));
230
232
boolean foundAdd = false ;
231
233
boolean foundRemove = false ;
@@ -249,7 +251,7 @@ public void testRolloverAliasActionsWithExplicitWriteIndex() {
249
251
String sourceIndex = randomAlphaOfLength (10 );
250
252
String targetIndex = randomAlphaOfLength (10 );
251
253
final RolloverRequest rolloverRequest = new RolloverRequest (sourceAlias , targetIndex );
252
- List <AliasAction > actions = TransportRolloverAction .rolloverAliasToNewIndex (sourceIndex , targetIndex , rolloverRequest , true );
254
+ List <AliasAction > actions = TransportRolloverAction .rolloverAliasToNewIndex (sourceIndex , targetIndex , rolloverRequest , true , null );
253
255
254
256
assertThat (actions , hasSize (2 ));
255
257
boolean foundAddWrite = false ;
@@ -272,6 +274,68 @@ public void testRolloverAliasActionsWithExplicitWriteIndex() {
272
274
assertTrue (foundRemoveWrite );
273
275
}
274
276
277
+ public void testRolloverAliasActionsWithHiddenAliasAndExplicitWriteIndex () {
278
+ String sourceAlias = randomAlphaOfLength (10 );
279
+ String sourceIndex = randomAlphaOfLength (10 );
280
+ String targetIndex = randomAlphaOfLength (10 );
281
+ final RolloverRequest rolloverRequest = new RolloverRequest (sourceAlias , targetIndex );
282
+ List <AliasAction > actions = TransportRolloverAction .rolloverAliasToNewIndex (sourceIndex , targetIndex , rolloverRequest , true , true );
283
+
284
+ assertThat (actions , hasSize (2 ));
285
+ boolean foundAddWrite = false ;
286
+ boolean foundRemoveWrite = false ;
287
+ for (AliasAction action : actions ) {
288
+ assertThat (action , instanceOf (AliasAction .Add .class ));
289
+ AliasAction .Add addAction = (AliasAction .Add ) action ;
290
+ if (action .getIndex ().equals (targetIndex )) {
291
+ assertEquals (sourceAlias , addAction .getAlias ());
292
+ assertTrue (addAction .writeIndex ());
293
+ assertTrue (addAction .isHidden ());
294
+ foundAddWrite = true ;
295
+ } else if (action .getIndex ().equals (sourceIndex )) {
296
+ assertEquals (sourceAlias , addAction .getAlias ());
297
+ assertFalse (addAction .writeIndex ());
298
+ assertTrue (addAction .isHidden ());
299
+ foundRemoveWrite = true ;
300
+ } else {
301
+ throw new AssertionError ("Unknown index [" + action .getIndex () + "]" );
302
+ }
303
+ }
304
+ assertTrue (foundAddWrite );
305
+ assertTrue (foundRemoveWrite );
306
+ }
307
+
308
+ public void testRolloverAliasActionsWithHiddenAliasAndImplicitWriteIndex () {
309
+ String sourceAlias = randomAlphaOfLength (10 );
310
+ String sourceIndex = randomAlphaOfLength (10 );
311
+ String targetIndex = randomAlphaOfLength (10 );
312
+ final RolloverRequest rolloverRequest = new RolloverRequest (sourceAlias , targetIndex );
313
+ List <AliasAction > actions = TransportRolloverAction .rolloverAliasToNewIndex (sourceIndex , targetIndex , rolloverRequest , false , true );
314
+
315
+ assertThat (actions , hasSize (2 ));
316
+ boolean foundAddWrite = false ;
317
+ boolean foundRemoveWrite = false ;
318
+ for (AliasAction action : actions ) {
319
+ if (action .getIndex ().equals (targetIndex )) {
320
+ assertThat (action , instanceOf (AliasAction .Add .class ));
321
+ AliasAction .Add addAction = (AliasAction .Add ) action ;
322
+ assertEquals (sourceAlias , addAction .getAlias ());
323
+ assertThat (addAction .writeIndex (), nullValue ());
324
+ assertTrue (addAction .isHidden ());
325
+ foundAddWrite = true ;
326
+ } else if (action .getIndex ().equals (sourceIndex )) {
327
+ assertThat (action , instanceOf (AliasAction .Remove .class ));
328
+ AliasAction .Remove removeAction = (AliasAction .Remove ) action ;
329
+ assertEquals (sourceAlias , removeAction .getAlias ());
330
+ foundRemoveWrite = true ;
331
+ } else {
332
+ throw new AssertionError ("Unknown index [" + action .getIndex () + "]" );
333
+ }
334
+ }
335
+ assertTrue (foundAddWrite );
336
+ assertTrue (foundRemoveWrite );
337
+ }
338
+
275
339
public void testValidation () {
276
340
String index1 = randomAlphaOfLength (10 );
277
341
String aliasWithWriteIndex = randomAlphaOfLength (10 );
0 commit comments