@@ -110,7 +110,7 @@ public void testDeleteWithParamDeletesAutoCreatedDestinationIndex() throws Excep
110110
111111 deleteTransform (transformId , false , true );
112112 assertFalse (indexExists (transformDest ));
113- assertFalse (aliasExists (transformDest ));
113+ assertFalse (aliasExists (transformDestAlias ));
114114 }
115115
116116 public void testDeleteWithParamDeletesManuallyCreatedDestinationIndex () throws Exception {
@@ -139,7 +139,7 @@ public void testDeleteWithParamDeletesManuallyCreatedDestinationIndex() throws E
139139 assertFalse (aliasExists (transformDestAlias ));
140140 }
141141
142- public void testDeleteWithParamDoesNotDeleteManuallySetUpAlias () throws Exception {
142+ public void testDeleteWithManuallyCreatedIndexAndManuallyCreatedAlias () throws Exception {
143143 String transformId = "transform-4" ;
144144 String transformDest = transformId + "_idx" ;
145145 String transformDestAlias = transformId + "_alias" ;
@@ -158,31 +158,106 @@ public void testDeleteWithParamDoesNotDeleteManuallySetUpAlias() throws Exceptio
158158 assertTrue (indexExists (transformDest ));
159159 assertTrue (aliasExists (transformDestAlias ));
160160
161+ deleteTransform (transformId , false , true );
162+ assertFalse (indexExists (transformDest ));
163+ assertFalse (aliasExists (transformDestAlias ));
164+ }
165+
166+ public void testDeleteDestinationIndexIsNoOpWhenNoDestinationIndexExists () throws Exception {
167+ String transformId = "transform-5" ;
168+ String transformDest = transformId + "_idx" ;
169+ String transformDestAlias = transformId + "_alias" ;
170+ setupDataAccessRole (DATA_ACCESS_ROLE , REVIEWS_INDEX_NAME , transformDest , transformDestAlias );
171+
172+ createTransform (transformId , transformDest , transformDestAlias );
173+ assertFalse (indexExists (transformDest ));
174+ assertFalse (aliasExists (transformDestAlias ));
175+
176+ deleteTransform (transformId , false , true );
177+ assertFalse (indexExists (transformDest ));
178+ assertFalse (aliasExists (transformDestAlias ));
179+ }
180+
181+ public void testDeleteWithAliasPointingToManyIndices () throws Exception {
182+ var transformId = "transform-6" ;
183+ var transformDest = transformId + "_idx" ;
184+ var otherIndex = "some-other-index-6" ;
185+ String transformDestAlias = transformId + "_alias" ;
186+ setupDataAccessRole (DATA_ACCESS_ROLE , REVIEWS_INDEX_NAME , transformDest , otherIndex , transformDestAlias );
187+
188+ createIndex (transformDest , null , null , "\" " + transformDestAlias + "\" : { \" is_write_index\" : true }" );
189+ createIndex (otherIndex , null , null , "\" " + transformDestAlias + "\" : {}" );
190+
191+ assertTrue (indexExists (transformDest ));
192+ assertTrue (indexExists (otherIndex ));
193+ assertTrue (aliasExists (transformDestAlias ));
194+
195+ createTransform (transformId , transformDestAlias , null );
196+
197+ startTransform (transformId );
198+ waitForTransformCheckpoint (transformId , 1 );
199+
200+ stopTransform (transformId , false );
201+
202+ assertTrue (indexExists (transformDest ));
203+ assertTrue (indexExists (otherIndex ));
204+ assertTrue (aliasExists (transformDestAlias ));
205+
206+ deleteTransform (transformId , false , true );
207+
208+ assertFalse (indexExists (transformDest ));
209+ assertTrue (indexExists (otherIndex ));
210+ assertTrue (aliasExists (transformDestAlias ));
211+ }
212+
213+ public void testDeleteWithNoWriteIndexThrowsException () throws Exception {
214+ var transformId = "transform-7" ;
215+ var transformDest = transformId + "_idx" ;
216+ var otherIndex = "some-other-index-7" ;
217+ String transformDestAlias = transformId + "_alias" ;
218+ setupDataAccessRole (DATA_ACCESS_ROLE , REVIEWS_INDEX_NAME , transformDest , otherIndex , transformDestAlias );
219+
220+ createIndex (transformDest , null , null , "\" " + transformDestAlias + "\" : {}" );
221+
222+ assertTrue (indexExists (transformDest ));
223+ assertTrue (aliasExists (transformDestAlias ));
224+
225+ createTransform (transformId , transformDestAlias , null );
226+
227+ createIndex (otherIndex , null , null , "\" " + transformDestAlias + "\" : {}" );
228+ assertTrue (indexExists (otherIndex ));
229+
161230 ResponseException e = expectThrows (ResponseException .class , () -> deleteTransform (transformId , false , true ));
162231 assertThat (
163232 e .getMessage (),
164233 containsString (
165234 Strings .format (
166- "The provided expression [%s] matches an alias, specify the corresponding concrete indices instead." ,
235+ "Cannot disambiguate destination index alias [%s]. Alias points to many indices with no clear write alias."
236+ + " Retry with delete_dest_index=false and manually clean up destination index." ,
167237 transformDestAlias
168238 )
169239 )
170240 );
171241 }
172242
173- public void testDeleteDestinationIndexIsNoOpWhenNoDestinationIndexExists () throws Exception {
174- String transformId = "transform-5" ;
175- String transformDest = transformId + "_idx" ;
176- String transformDestAlias = transformId + "_alias" ;
177- setupDataAccessRole (DATA_ACCESS_ROLE , REVIEWS_INDEX_NAME , transformDest , transformDestAlias );
243+ public void testDeleteWithAlreadyDeletedIndex () throws Exception {
244+ var transformId = "transform-8" ;
245+ var transformDest = transformId + "_idx" ;
246+ setupDataAccessRole (DATA_ACCESS_ROLE , REVIEWS_INDEX_NAME , transformDest );
247+
248+ createIndex (transformDest );
249+
250+ assertTrue (indexExists (transformDest ));
251+
252+ createTransform (transformId , transformDest , null );
253+
254+ deleteIndex (transformDest );
178255
179- createTransform (transformId , transformDest , transformDestAlias );
180256 assertFalse (indexExists (transformDest ));
181- assertFalse (aliasExists (transformDestAlias ));
182257
183258 deleteTransform (transformId , false , true );
259+
184260 assertFalse (indexExists (transformDest ));
185- assertFalse (aliasExists (transformDestAlias ));
186261 }
187262
188263 private void createTransform (String transformId , String destIndex , String destAlias ) throws IOException {
0 commit comments