5757import static org .elasticsearch .xpack .TimeSeriesRestDriver .getStepKeyForIndex ;
5858import static org .elasticsearch .xpack .TimeSeriesRestDriver .indexDocument ;
5959import static org .elasticsearch .xpack .TimeSeriesRestDriver .rolloverMaxOneDocCondition ;
60+ import static org .hamcrest .Matchers .containsString ;
6061import static org .hamcrest .Matchers .equalTo ;
6162import static org .hamcrest .Matchers .greaterThan ;
6263import static org .hamcrest .Matchers .is ;
@@ -378,6 +379,7 @@ public void testIdenticalSearchableSnapshotActionIsNoop() throws Exception {
378379 .put (LifecycleSettings .LIFECYCLE_NAME , policy )
379380 .build ());
380381 ensureGreen (index );
382+ indexDocument (client (), index , true );
381383
382384 final String searchableSnapMountedIndexName = (storage == MountSearchableSnapshotRequest .Storage .FULL_COPY ?
383385 SearchableSnapshotAction .FULL_RESTORED_INDEX_PREFIX : SearchableSnapshotAction .PARTIAL_RESTORED_INDEX_PREFIX ) + index ;
@@ -401,6 +403,10 @@ public void testIdenticalSearchableSnapshotActionIsNoop() throws Exception {
401403 }
402404 assertThat ("expected to have only one snapshot, but got: " + responseMap ,
403405 ((List <Object >) responseMap .get ("snapshots" )).size (), equalTo (1 ));
406+
407+ Request hitCount = new Request ("GET" , "/" + searchableSnapMountedIndexName + "/_count" );
408+ Map <String , Object > count = entityAsMap (client ().performRequest (hitCount ));
409+ assertThat ("expected a single document but got: " + count , (int ) count .get ("count" ), equalTo (1 ));
404410 }
405411
406412 @ SuppressWarnings ("unchecked" )
@@ -421,7 +427,7 @@ public void testConvertingSearchableSnapshotFromFullToPartial() throws Exception
421427 .put (LifecycleSettings .LIFECYCLE_NAME , policy )
422428 .build ());
423429 ensureGreen (index );
424- indexDocument (client (), index );
430+ indexDocument (client (), index , true );
425431
426432 final String searchableSnapMountedIndexName = SearchableSnapshotAction .PARTIAL_RESTORED_INDEX_PREFIX +
427433 SearchableSnapshotAction .FULL_RESTORED_INDEX_PREFIX + index ;
@@ -445,6 +451,10 @@ public void testConvertingSearchableSnapshotFromFullToPartial() throws Exception
445451 }
446452 assertThat ("expected to have only one snapshot, but got: " + responseMap ,
447453 ((List <Object >) responseMap .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 ));
448458 }
449459
450460 @ SuppressWarnings ("unchecked" )
@@ -465,7 +475,7 @@ public void testConvertingPartialSearchableSnapshotIntoFull() throws Exception {
465475 .put (LifecycleSettings .LIFECYCLE_NAME , policy )
466476 .build ());
467477 ensureGreen (index );
468- indexDocument (client (), index );
478+ indexDocument (client (), index , true );
469479
470480 final String searchableSnapMountedIndexName = SearchableSnapshotAction .FULL_RESTORED_INDEX_PREFIX +
471481 SearchableSnapshotAction .PARTIAL_RESTORED_INDEX_PREFIX + index ;
@@ -489,71 +499,28 @@ public void testConvertingPartialSearchableSnapshotIntoFull() throws Exception {
489499 }
490500 assertThat ("expected to have only one snapshot, but got: " + responseMap ,
491501 ((List <Object >) responseMap .get ("snapshots" )).size (), equalTo (1 ));
502+
503+ Request hitCount = new Request ("GET" , "/" + searchableSnapMountedIndexName + "/_count" );
504+ Map <String , Object > count = entityAsMap (client ().performRequest (hitCount ));
505+ assertThat ("expected a single document but got: " + count , (int ) count .get ("count" ), equalTo (1 ));
492506 }
493507
494- @ SuppressWarnings ("unchecked" )
495- @ AwaitsFix (bugUrl = "functionality not yet implemented" )
496- public void testSecondSearchableSnapshotChangesRepo () throws Exception {
497- String index = "myindex-" + randomAlphaOfLength (4 ).toLowerCase (Locale .ROOT );
508+ public void testSecondSearchableSnapshotUsingDifferentRepoThrows () throws Exception {
498509 String secondRepo = randomAlphaOfLengthBetween (10 , 20 );
499510 createSnapshotRepo (client (), snapshotRepo , randomBoolean ());
500511 createSnapshotRepo (client (), secondRepo , randomBoolean ());
501- createPolicy (client (), policy , null , null ,
502- new Phase ("cold" , TimeValue .ZERO ,
503- singletonMap (SearchableSnapshotAction .NAME , new SearchableSnapshotAction (snapshotRepo , randomBoolean (),
504- MountSearchableSnapshotRequest .Storage .FULL_COPY ))),
505- new Phase ("frozen" , TimeValue .ZERO ,
506- singletonMap (SearchableSnapshotAction .NAME , new SearchableSnapshotAction (secondRepo , randomBoolean (),
507- MountSearchableSnapshotRequest .Storage .SHARED_CACHE ))),
508- null
509- );
510-
511- createIndex (index , Settings .builder ()
512- .put (LifecycleSettings .LIFECYCLE_NAME , policy )
513- .build ());
514- ensureGreen (index );
515- indexDocument (client (), index );
516-
517- final String searchableSnapMountedIndexName = SearchableSnapshotAction .PARTIAL_RESTORED_INDEX_PREFIX +
518- SearchableSnapshotAction .FULL_RESTORED_INDEX_PREFIX + index ;
519-
520- assertBusy (() -> {
521- logger .info ("--> waiting for [{}] to exist..." , searchableSnapMountedIndexName );
522- assertTrue (indexExists (searchableSnapMountedIndexName ));
523- }, 30 , TimeUnit .SECONDS );
524-
525- assertBusy (() -> {
526- Step .StepKey stepKeyForIndex = getStepKeyForIndex (client (), searchableSnapMountedIndexName );
527- assertThat (stepKeyForIndex .getPhase (), is ("frozen" ));
528- assertThat (stepKeyForIndex .getName (), is (PhaseCompleteStep .NAME ));
529- }, 30 , TimeUnit .SECONDS );
530-
531- // Check first repo has exactly 1 snapshot
532- {
533- Request getSnaps = new Request ("GET" , "/_snapshot/" + snapshotRepo + "/_all" );
534- Response response = client ().performRequest (getSnaps );
535- Map <String , Object > responseMap ;
536- try (InputStream is = response .getEntity ().getContent ()) {
537- responseMap = XContentHelper .convertToMap (XContentType .JSON .xContent (), is , true );
538- }
539- assertThat ("expected to have only one snapshot, but got: " + responseMap ,
540- ((List <Map <String , Object >>)
541- ((Map <String , Object >)
542- ((List <Object >) responseMap .get ("responses" )).get (0 )).get ("snapshots" )).size (), equalTo (1 ));
543- }
544-
545- // Check second repo has exactly 1 snapshot
546- {
547- Request getSnaps = new Request ("GET" , "/_snapshot/" + secondRepo + "/_all" );
548- Response response = client ().performRequest (getSnaps );
549- Map <String , Object > responseMap ;
550- try (InputStream is = response .getEntity ().getContent ()) {
551- responseMap = XContentHelper .convertToMap (XContentType .JSON .xContent (), is , true );
552- }
553- assertThat ("expected to have only one snapshot, but got: " + responseMap ,
554- ((List <Map <String , Object >>)
555- ((Map <String , Object >)
556- ((List <Object >) responseMap .get ("responses" )).get (0 )).get ("snapshots" )).size (), equalTo (1 ));
557- }
512+ IllegalArgumentException e = expectThrows (IllegalArgumentException .class , () ->
513+ createPolicy (client (), policy , null , null ,
514+ new Phase ("cold" , TimeValue .ZERO ,
515+ singletonMap (SearchableSnapshotAction .NAME , new SearchableSnapshotAction (snapshotRepo , randomBoolean (),
516+ MountSearchableSnapshotRequest .Storage .FULL_COPY ))),
517+ new Phase ("frozen" , TimeValue .ZERO ,
518+ singletonMap (SearchableSnapshotAction .NAME , new SearchableSnapshotAction (secondRepo , randomBoolean (),
519+ MountSearchableSnapshotRequest .Storage .SHARED_CACHE ))),
520+ null
521+ ));
522+
523+ assertThat (e .getMessage (),
524+ containsString ("policy specifies [searchable_snapshot] action multiple times with differing repositories" ));
558525 }
559526}
0 commit comments