|
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 | 12 | import org.elasticsearch.client.Request; |
14 | 13 | import org.elasticsearch.client.Response; |
15 | 14 | import org.elasticsearch.cluster.metadata.DataStream; |
@@ -153,8 +152,8 @@ public void testSearchableSnapshotForceMergesIndexToOneSegment() throws Exceptio |
153 | 152 | TimeUnit.SECONDS); |
154 | 153 | } |
155 | 154 |
|
156 | | - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/pull/54433") |
157 | | - public void testDeleteActionDeletesSearchableSnapshot() throws Exception { |
| 155 | + @SuppressWarnings("unchecked") |
| 156 | + public void testDeleteActionDeletesSearchableSnapshot() throws Exception { |
158 | 157 | createSnapshotRepo(client(), snapshotRepo, randomBoolean()); |
159 | 158 |
|
160 | 159 | // create policy with cold and delete phases |
@@ -182,32 +181,28 @@ public void testDeleteActionDeletesSearchableSnapshot() throws Exception { |
182 | 181 | // rolling over the data stream so we can apply the searchable snapshot policy to a backing index that's not the write index |
183 | 182 | rolloverMaxOneDocCondition(client(), dataStream); |
184 | 183 |
|
185 | | - String[] snapshotName = new String[1]; |
186 | 184 | String backingIndexName = DataStream.getDefaultBackingIndexName(dataStream, 1L); |
187 | 185 | String restoredIndexName = SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + backingIndexName; |
188 | | - assertTrue(waitUntil(() -> { |
189 | | - try { |
190 | | - Map<String, Object> explainIndex = explainIndex(client(), backingIndexName); |
191 | | - if (explainIndex == null) { |
192 | | - // in case we missed the original index and it was deleted |
193 | | - explainIndex = explainIndex(client(), restoredIndexName); |
194 | | - } |
195 | | - snapshotName[0] = (String) explainIndex.get("snapshot_name"); |
196 | | - return snapshotName[0] != null; |
197 | | - } catch (IOException e) { |
198 | | - return false; |
199 | | - } |
200 | | - }, 30, TimeUnit.SECONDS)); |
201 | | - assertBusy(() -> assertFalse(indexExists(restoredIndexName))); |
| 186 | + |
| 187 | + // let's wait for ILM to finish |
| 188 | + assertBusy(() -> assertFalse(indexExists(backingIndexName)), 60, TimeUnit.SECONDS); |
| 189 | + assertBusy(() -> assertFalse(indexExists(restoredIndexName)), 60, TimeUnit.SECONDS); |
202 | 190 |
|
203 | 191 | assertTrue("the snapshot we generate in the cold phase should be deleted by the delete phase", waitUntil(() -> { |
204 | | - try { |
205 | | - Request getSnapshotsRequest = new Request("GET", "_snapshot/" + snapshotRepo + "/" + snapshotName[0]); |
206 | | - Response getSnapshotsResponse = client().performRequest(getSnapshotsRequest); |
207 | | - return EntityUtils.toString(getSnapshotsResponse.getEntity()).contains("snapshot_missing_exception"); |
208 | | - } catch (IOException e) { |
209 | | - return false; |
210 | | - } |
| 192 | + try { |
| 193 | + Request getSnapshotsRequest = new Request("GET", "_snapshot/" + snapshotRepo + "/_all"); |
| 194 | + Response getSnapshotsResponse = client().performRequest(getSnapshotsRequest); |
| 195 | + |
| 196 | + Map<String, Object> responseMap; |
| 197 | + try (InputStream is = getSnapshotsResponse.getEntity().getContent()) { |
| 198 | + responseMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true); |
| 199 | + } |
| 200 | + List<Map<String, Object>> snapshots = (List<Map<String, Object>>) responseMap.get("snapshots"); |
| 201 | + return snapshots.size() == 0; |
| 202 | + } catch (Exception e) { |
| 203 | + logger.error(e.getMessage(), e); |
| 204 | + return false; |
| 205 | + } |
211 | 206 | }, 30, TimeUnit.SECONDS)); |
212 | 207 | } |
213 | 208 |
|
|
0 commit comments