@@ -152,7 +152,7 @@ public void testMountIndexWithDeletionOfSnapshotFailsIfNotSingleIndexSnapshot()
152152 );
153153 }
154154
155- public void testMountIndexWithDeletionOfSnapshot () throws Exception {
155+ public void testMountIndexWithDifferentDeletionOfSnapshot () throws Exception {
156156 final String repository = "repository-" + getTestName ().toLowerCase (Locale .ROOT );
157157 createRepository (repository , FsRepository .TYPE , randomRepositorySettings ());
158158
@@ -165,53 +165,30 @@ public void testMountIndexWithDeletionOfSnapshot() throws Exception {
165165 createSnapshot (repository , snapshot , List .of (index ));
166166 assertAcked (client ().admin ().indices ().prepareDelete (index ));
167167
168- String mounted = "mounted-with-setting-enabled" ;
169- mountSnapshot (repository , snapshot , index , mounted , deleteSnapshotIndexSettings (true ), randomFrom (Storage .values ()));
170- assertIndexSetting (mounted , SEARCHABLE_SNAPSHOTS_DELETE_SNAPSHOT_ON_INDEX_DELETION , equalTo ("true" ));
168+ final boolean deleteSnapshot = randomBoolean ();
169+ final String mounted = "mounted-with-setting-" + deleteSnapshot ;
170+ mountSnapshot (repository , snapshot , index , mounted , deleteSnapshotIndexSettings (deleteSnapshot ), randomFrom (Storage .values ()));
171+ assertIndexSetting (mounted , SEARCHABLE_SNAPSHOTS_DELETE_SNAPSHOT_ON_INDEX_DELETION , equalTo (Boolean .toString (deleteSnapshot )));
171172 assertHitCount (client ().prepareSearch (mounted ).setTrackTotalHits (true ).get (), totalHits .value );
172173
173- // the snapshot is already mounted as an index with "index.store.snapshot.delete_searchable_snapshot: true",
174- // any attempt to mount the snapshot again should fail
175174 final String mountedAgain = randomValueOtherThan (mounted , () -> randomAlphaOfLength (10 ).toLowerCase (Locale .ROOT ));
176- SnapshotRestoreException exception = expectThrows (
177- SnapshotRestoreException .class ,
178- () -> mountSnapshot (repository , snapshot , index , mountedAgain , deleteSnapshotIndexSettings (randomBoolean ()))
179- );
180- assertThat (
181- exception .getMessage (),
182- allOf (
183- containsString ("cannot mount snapshot [" + repository + '/' ),
184- containsString (':' + snapshot + "] as index [" + mountedAgain + "]; another index [" + mounted + '/' ),
185- containsString ("] uses the snapshot with the deletion of snapshot on index removal enabled " ),
186- containsString ("[index.store.snapshot.delete_searchable_snapshot: true]." )
187- )
188- );
189-
190- assertAcked (client ().admin ().indices ().prepareDelete (mounted ));
191- mounted = "mounted-with-setting-disabled" ;
192- mountSnapshot (repository , snapshot , index , mounted , deleteSnapshotIndexSettings (false ), randomFrom (Storage .values ()));
193- assertIndexSetting (mounted , SEARCHABLE_SNAPSHOTS_DELETE_SNAPSHOT_ON_INDEX_DELETION , equalTo ("false" ));
194- assertHitCount (client ().prepareSearch (mounted ).setTrackTotalHits (true ).get (), totalHits .value );
195-
196- // the snapshot is now mounted as an index with "index.store.snapshot.delete_searchable_snapshot: false",
197- // any attempt to mount the snapshot again with "delete_searchable_snapshot: true" should fail
198- exception = expectThrows (
175+ final SnapshotRestoreException exception = expectThrows (
199176 SnapshotRestoreException .class ,
200- () -> mountSnapshot (repository , snapshot , index , mountedAgain , deleteSnapshotIndexSettings (true ))
177+ () -> mountSnapshot (repository , snapshot , index , mountedAgain , deleteSnapshotIndexSettings (deleteSnapshot == false ))
201178 );
202179 assertThat (
203180 exception .getMessage (),
204181 allOf (
205182 containsString ("cannot mount snapshot [" + repository + '/' ),
206- containsString (snapshot + "] as index [" + mountedAgain + "] with the deletion of snapshot on index removal enabled" ),
207- containsString ("[index.store.snapshot.delete_searchable_snapshot: true]; another index [" + mounted + '/' ),
208- containsString ("] uses the snapshot." )
183+ containsString (':' + snapshot + "] as index [" + mountedAgain + "] with " ),
184+ containsString ("[index.store.snapshot.delete_searchable_snapshot: " + (deleteSnapshot == false ) + "]; another " ),
185+ containsString ("index [" + mounted + '/' ),
186+ containsString ("is mounted with [index.store.snapshot.delete_searchable_snapshot: " + deleteSnapshot + "]." )
209187 )
210188 );
211189
212- // but we can continue to mount the snapshot, as long as it does not require the cascade deletion of the snapshot
213- mountSnapshot (repository , snapshot , index , mountedAgain , deleteSnapshotIndexSettings (false ));
214- assertIndexSetting (mountedAgain , SEARCHABLE_SNAPSHOTS_DELETE_SNAPSHOT_ON_INDEX_DELETION , equalTo ("false" ));
190+ mountSnapshot (repository , snapshot , index , mountedAgain , deleteSnapshotIndexSettings (deleteSnapshot ));
191+ assertIndexSetting (mountedAgain , SEARCHABLE_SNAPSHOTS_DELETE_SNAPSHOT_ON_INDEX_DELETION , equalTo (Boolean .toString (deleteSnapshot )));
215192 assertHitCount (client ().prepareSearch (mountedAgain ).setTrackTotalHits (true ).get (), totalHits .value );
216193
217194 assertAcked (client ().admin ().indices ().prepareDelete (mountedAgain ));
0 commit comments