56
56
import static org .elasticsearch .xpack .TimeSeriesRestDriver .getStepKeyForIndex ;
57
57
import static org .elasticsearch .xpack .TimeSeriesRestDriver .indexDocument ;
58
58
import static org .elasticsearch .xpack .TimeSeriesRestDriver .rolloverMaxOneDocCondition ;
59
+ import static org .hamcrest .Matchers .containsString ;
59
60
import static org .hamcrest .Matchers .equalTo ;
60
61
import static org .hamcrest .Matchers .greaterThanOrEqualTo ;
61
62
import static org .hamcrest .Matchers .is ;
@@ -374,6 +375,7 @@ public void testIdenticalSearchableSnapshotActionIsNoop() throws Exception {
374
375
.put (LifecycleSettings .LIFECYCLE_NAME , policy )
375
376
.build ());
376
377
ensureGreen (index );
378
+ indexDocument (client (), index , true );
377
379
378
380
final String searchableSnapMountedIndexName = (storage == MountSearchableSnapshotRequest .Storage .FULL_COPY ?
379
381
SearchableSnapshotAction .FULL_RESTORED_INDEX_PREFIX : SearchableSnapshotAction .PARTIAL_RESTORED_INDEX_PREFIX ) + index ;
@@ -399,6 +401,10 @@ public void testIdenticalSearchableSnapshotActionIsNoop() throws Exception {
399
401
((List <Map <String , Object >>)
400
402
((Map <String , Object >)
401
403
((List <Object >) responseMap .get ("responses" )).get (0 )).get ("snapshots" )).size (), equalTo (1 ));
404
+
405
+ Request hitCount = new Request ("GET" , "/" + searchableSnapMountedIndexName + "/_count" );
406
+ Map <String , Object > count = entityAsMap (client ().performRequest (hitCount ));
407
+ assertThat ("expected a single document but got: " + count , (int ) count .get ("count" ), equalTo (1 ));
402
408
}
403
409
404
410
@ SuppressWarnings ("unchecked" )
@@ -419,7 +425,7 @@ public void testConvertingSearchableSnapshotFromFullToPartial() throws Exception
419
425
.put (LifecycleSettings .LIFECYCLE_NAME , policy )
420
426
.build ());
421
427
ensureGreen (index );
422
- indexDocument (client (), index );
428
+ indexDocument (client (), index , true );
423
429
424
430
final String searchableSnapMountedIndexName = SearchableSnapshotAction .PARTIAL_RESTORED_INDEX_PREFIX +
425
431
SearchableSnapshotAction .FULL_RESTORED_INDEX_PREFIX + index ;
@@ -445,6 +451,10 @@ public void testConvertingSearchableSnapshotFromFullToPartial() throws Exception
445
451
((List <Map <String , Object >>)
446
452
((Map <String , Object >)
447
453
((List <Object >) responseMap .get ("responses" )).get (0 )).get ("snapshots" )).size (), equalTo (1 ));
454
+
455
+ Request hitCount = new Request ("GET" , "/" + searchableSnapMountedIndexName + "/_count" );
456
+ Map <String , Object > count = entityAsMap (client ().performRequest (hitCount ));
457
+ assertThat ("expected a single document but got: " + count , (int ) count .get ("count" ), equalTo (1 ));
448
458
}
449
459
450
460
@ SuppressWarnings ("unchecked" )
@@ -465,7 +475,7 @@ public void testConvertingPartialSearchableSnapshotIntoFull() throws Exception {
465
475
.put (LifecycleSettings .LIFECYCLE_NAME , policy )
466
476
.build ());
467
477
ensureGreen (index );
468
- indexDocument (client (), index );
478
+ indexDocument (client (), index , true );
469
479
470
480
final String searchableSnapMountedIndexName = SearchableSnapshotAction .FULL_RESTORED_INDEX_PREFIX +
471
481
SearchableSnapshotAction .PARTIAL_RESTORED_INDEX_PREFIX + index ;
@@ -491,71 +501,28 @@ public void testConvertingPartialSearchableSnapshotIntoFull() throws Exception {
491
501
((List <Map <String , Object >>)
492
502
((Map <String , Object >)
493
503
((List <Object >) responseMap .get ("responses" )).get (0 )).get ("snapshots" )).size (), equalTo (1 ));
504
+
505
+ Request hitCount = new Request ("GET" , "/" + searchableSnapMountedIndexName + "/_count" );
506
+ Map <String , Object > count = entityAsMap (client ().performRequest (hitCount ));
507
+ assertThat ("expected a single document but got: " + count , (int ) count .get ("count" ), equalTo (1 ));
494
508
}
495
509
496
- @ SuppressWarnings ("unchecked" )
497
- @ AwaitsFix (bugUrl = "functionality not yet implemented" )
498
- public void testSecondSearchableSnapshotChangesRepo () throws Exception {
499
- String index = "myindex-" + randomAlphaOfLength (4 ).toLowerCase (Locale .ROOT );
510
+ public void testSecondSearchableSnapshotUsingDifferentRepoThrows () throws Exception {
500
511
String secondRepo = randomAlphaOfLengthBetween (10 , 20 );
501
512
createSnapshotRepo (client (), snapshotRepo , randomBoolean ());
502
513
createSnapshotRepo (client (), secondRepo , randomBoolean ());
503
- createPolicy (client (), policy , null , null ,
504
- new Phase ("cold" , TimeValue .ZERO ,
505
- singletonMap (SearchableSnapshotAction .NAME , new SearchableSnapshotAction (snapshotRepo , randomBoolean (),
506
- MountSearchableSnapshotRequest .Storage .FULL_COPY ))),
507
- new Phase ("frozen" , TimeValue .ZERO ,
508
- singletonMap (SearchableSnapshotAction .NAME , new SearchableSnapshotAction (secondRepo , randomBoolean (),
509
- MountSearchableSnapshotRequest .Storage .SHARED_CACHE ))),
510
- null
511
- );
512
-
513
- createIndex (index , Settings .builder ()
514
- .put (LifecycleSettings .LIFECYCLE_NAME , policy )
515
- .build ());
516
- ensureGreen (index );
517
- indexDocument (client (), index );
518
-
519
- final String searchableSnapMountedIndexName = SearchableSnapshotAction .PARTIAL_RESTORED_INDEX_PREFIX +
520
- SearchableSnapshotAction .FULL_RESTORED_INDEX_PREFIX + index ;
521
-
522
- assertBusy (() -> {
523
- logger .info ("--> waiting for [{}] to exist..." , searchableSnapMountedIndexName );
524
- assertTrue (indexExists (searchableSnapMountedIndexName ));
525
- }, 30 , TimeUnit .SECONDS );
526
-
527
- assertBusy (() -> {
528
- Step .StepKey stepKeyForIndex = getStepKeyForIndex (client (), searchableSnapMountedIndexName );
529
- assertThat (stepKeyForIndex .getPhase (), is ("frozen" ));
530
- assertThat (stepKeyForIndex .getName (), is (PhaseCompleteStep .NAME ));
531
- }, 30 , TimeUnit .SECONDS );
532
-
533
- // Check first repo has exactly 1 snapshot
534
- {
535
- Request getSnaps = new Request ("GET" , "/_snapshot/" + snapshotRepo + "/_all" );
536
- Response response = client ().performRequest (getSnaps );
537
- Map <String , Object > responseMap ;
538
- try (InputStream is = response .getEntity ().getContent ()) {
539
- responseMap = XContentHelper .convertToMap (XContentType .JSON .xContent (), is , true );
540
- }
541
- assertThat ("expected to have only one snapshot, but got: " + responseMap ,
542
- ((List <Map <String , Object >>)
543
- ((Map <String , Object >)
544
- ((List <Object >) responseMap .get ("responses" )).get (0 )).get ("snapshots" )).size (), equalTo (1 ));
545
- }
546
-
547
- // Check second repo has exactly 1 snapshot
548
- {
549
- Request getSnaps = new Request ("GET" , "/_snapshot/" + secondRepo + "/_all" );
550
- Response response = client ().performRequest (getSnaps );
551
- Map <String , Object > responseMap ;
552
- try (InputStream is = response .getEntity ().getContent ()) {
553
- responseMap = XContentHelper .convertToMap (XContentType .JSON .xContent (), is , true );
554
- }
555
- assertThat ("expected to have only one snapshot, but got: " + responseMap ,
556
- ((List <Map <String , Object >>)
557
- ((Map <String , Object >)
558
- ((List <Object >) responseMap .get ("responses" )).get (0 )).get ("snapshots" )).size (), equalTo (1 ));
559
- }
514
+ IllegalArgumentException e = expectThrows (IllegalArgumentException .class , () ->
515
+ createPolicy (client (), policy , null , null ,
516
+ new Phase ("cold" , TimeValue .ZERO ,
517
+ singletonMap (SearchableSnapshotAction .NAME , new SearchableSnapshotAction (snapshotRepo , randomBoolean (),
518
+ MountSearchableSnapshotRequest .Storage .FULL_COPY ))),
519
+ new Phase ("frozen" , TimeValue .ZERO ,
520
+ singletonMap (SearchableSnapshotAction .NAME , new SearchableSnapshotAction (secondRepo , randomBoolean (),
521
+ MountSearchableSnapshotRequest .Storage .SHARED_CACHE ))),
522
+ null
523
+ ));
524
+
525
+ assertThat (e .getMessage (),
526
+ containsString ("policy specifies [searchable_snapshot] action multiple times with differing repositories" ));
560
527
}
561
528
}
0 commit comments