|
9 | 9 |
|
10 | 10 | import org.apache.http.entity.ContentType;
|
11 | 11 | import org.apache.http.entity.StringEntity;
|
12 |
| -import org.apache.http.util.EntityUtils; |
13 |
| -import org.elasticsearch.client.Client; |
14 | 12 | import org.elasticsearch.client.Request;
|
15 | 13 | import org.elasticsearch.client.Response;
|
16 | 14 | import org.elasticsearch.cluster.metadata.DataStream;
|
|
22 | 20 | import org.elasticsearch.common.xcontent.XContentBuilder;
|
23 | 21 | import org.elasticsearch.common.xcontent.XContentHelper;
|
24 | 22 | import org.elasticsearch.common.xcontent.XContentType;
|
25 |
| -import org.elasticsearch.test.client.NoOpClient; |
26 | 23 | import org.elasticsearch.test.rest.ESRestTestCase;
|
27 | 24 | import org.elasticsearch.xpack.core.ilm.DeleteAction;
|
28 | 25 | import org.elasticsearch.xpack.core.ilm.ForceMergeAction;
|
29 | 26 | import org.elasticsearch.xpack.core.ilm.FreezeAction;
|
30 | 27 | import org.elasticsearch.xpack.core.ilm.LifecycleAction;
|
31 | 28 | import org.elasticsearch.xpack.core.ilm.LifecyclePolicy;
|
32 | 29 | import org.elasticsearch.xpack.core.ilm.LifecycleSettings;
|
33 |
| -import org.elasticsearch.xpack.core.ilm.MountSnapshotStep; |
34 | 30 | import org.elasticsearch.xpack.core.ilm.Phase;
|
35 | 31 | import org.elasticsearch.xpack.core.ilm.PhaseCompleteStep;
|
36 | 32 | import org.elasticsearch.xpack.core.ilm.RolloverAction;
|
37 | 33 | import org.elasticsearch.xpack.core.ilm.SearchableSnapshotAction;
|
38 | 34 | import org.elasticsearch.xpack.core.ilm.SetPriorityAction;
|
39 | 35 | import org.elasticsearch.xpack.core.ilm.ShrinkAction;
|
40 | 36 | import org.elasticsearch.xpack.core.ilm.Step;
|
41 |
| -import org.elasticsearch.xpack.core.ilm.StepKeyTests; |
42 | 37 | import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotRequest;
|
43 | 38 | import org.junit.Before;
|
44 | 39 |
|
@@ -163,8 +158,8 @@ public void testSearchableSnapshotForceMergesIndexToOneSegment() throws Exceptio
|
163 | 158 | TimeUnit.SECONDS);
|
164 | 159 | }
|
165 | 160 |
|
166 |
| - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/pull/54433") |
167 |
| - public void testDeleteActionDeletesSearchableSnapshot() throws Exception { |
| 161 | + @SuppressWarnings("unchecked") |
| 162 | + public void testDeleteActionDeletesSearchableSnapshot() throws Exception { |
168 | 163 | createSnapshotRepo(client(), snapshotRepo, randomBoolean());
|
169 | 164 |
|
170 | 165 | // create policy with cold and delete phases
|
@@ -192,32 +187,29 @@ public void testDeleteActionDeletesSearchableSnapshot() throws Exception {
|
192 | 187 | // rolling over the data stream so we can apply the searchable snapshot policy to a backing index that's not the write index
|
193 | 188 | rolloverMaxOneDocCondition(client(), dataStream);
|
194 | 189 |
|
195 |
| - String[] snapshotName = new String[1]; |
196 | 190 | String backingIndexName = DataStream.getDefaultBackingIndexName(dataStream, 1L);
|
197 | 191 | String restoredIndexName = SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + backingIndexName;
|
198 |
| - assertTrue(waitUntil(() -> { |
199 |
| - try { |
200 |
| - Map<String, Object> explainIndex = explainIndex(client(), backingIndexName); |
201 |
| - if (explainIndex == null) { |
202 |
| - // in case we missed the original index and it was deleted |
203 |
| - explainIndex = explainIndex(client(), restoredIndexName); |
204 |
| - } |
205 |
| - snapshotName[0] = (String) explainIndex.get("snapshot_name"); |
206 |
| - return snapshotName[0] != null; |
207 |
| - } catch (IOException e) { |
208 |
| - return false; |
209 |
| - } |
210 |
| - }, 30, TimeUnit.SECONDS)); |
211 |
| - assertBusy(() -> assertFalse(indexExists(restoredIndexName))); |
| 192 | + |
| 193 | + // let's wait for ILM to finish |
| 194 | + assertBusy(() -> assertFalse(indexExists(backingIndexName)), 60, TimeUnit.SECONDS); |
| 195 | + assertBusy(() -> assertFalse(indexExists(restoredIndexName)), 60, TimeUnit.SECONDS); |
212 | 196 |
|
213 | 197 | assertTrue("the snapshot we generate in the cold phase should be deleted by the delete phase", waitUntil(() -> {
|
214 |
| - try { |
215 |
| - Request getSnapshotsRequest = new Request("GET", "_snapshot/" + snapshotRepo + "/" + snapshotName[0]); |
216 |
| - Response getSnapshotsResponse = client().performRequest(getSnapshotsRequest); |
217 |
| - return EntityUtils.toString(getSnapshotsResponse.getEntity()).contains("snapshot_missing_exception"); |
218 |
| - } catch (IOException e) { |
219 |
| - return false; |
220 |
| - } |
| 198 | + try { |
| 199 | + Request getSnapshotsRequest = new Request("GET", "_snapshot/" + snapshotRepo + "/_all"); |
| 200 | + Response getSnapshotsResponse = client().performRequest(getSnapshotsRequest); |
| 201 | + |
| 202 | + Map<String, Object> responseMap; |
| 203 | + try (InputStream is = getSnapshotsResponse.getEntity().getContent()) { |
| 204 | + responseMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true); |
| 205 | + } |
| 206 | + List<Object> responses = (List<Object>) responseMap.get("responses"); |
| 207 | + Object snapshots = ((Map<String, Object>) responses.get(0)).get("snapshots"); |
| 208 | + return ((List<Map<String, Object>>) snapshots).size() == 0; |
| 209 | + } catch (Exception e) { |
| 210 | + logger.error(e.getMessage(), e); |
| 211 | + return false; |
| 212 | + } |
221 | 213 | }, 30, TimeUnit.SECONDS));
|
222 | 214 | }
|
223 | 215 |
|
|
0 commit comments