|
44 | 44 | import java.util.Map;
|
45 | 45 | import java.util.concurrent.ExecutionException;
|
46 | 46 |
|
| 47 | +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; |
47 | 48 | import static org.hamcrest.Matchers.empty;
|
48 | 49 | import static org.hamcrest.Matchers.is;
|
49 | 50 |
|
50 |
| -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; |
51 |
| - |
52 | 51 | public class DataStreamsSnapshotsIT extends AbstractSnapshotIntegTestCase {
|
53 | 52 |
|
54 | 53 | private static final String DS_BACKING_INDEX_NAME = DataStream.getDefaultBackingIndexName("ds", 1);
|
@@ -194,6 +193,82 @@ public void testRename() throws Exception {
|
194 | 193 | assertEquals(DOCUMENT_SOURCE, client.prepareGet(DS2_BACKING_INDEX_NAME, id).get().getSourceAsMap());
|
195 | 194 | }
|
196 | 195 |
|
| 196 | + public void testBackingIndexIsNotRenamedWhenRestoringDataStream() { |
| 197 | + CreateSnapshotResponse createSnapshotResponse = client.admin().cluster() |
| 198 | + .prepareCreateSnapshot(REPO, SNAPSHOT) |
| 199 | + .setWaitForCompletion(true) |
| 200 | + .setIndices("ds") |
| 201 | + .setIncludeGlobalState(false) |
| 202 | + .get(); |
| 203 | + |
| 204 | + RestStatus status = createSnapshotResponse.getSnapshotInfo().status(); |
| 205 | + assertEquals(RestStatus.OK, status); |
| 206 | + |
| 207 | + expectThrows(SnapshotRestoreException.class, () -> client.admin().cluster() |
| 208 | + .prepareRestoreSnapshot(REPO, SNAPSHOT) |
| 209 | + .setWaitForCompletion(true) |
| 210 | + .setIndices("ds") |
| 211 | + .get()); |
| 212 | + |
| 213 | + // delete data stream |
| 214 | + client.admin().indices().deleteDataStream(new DeleteDataStreamAction.Request("ds")).actionGet(); |
| 215 | + |
| 216 | + // restore data stream attempting to rename the backing index |
| 217 | + RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster() |
| 218 | + .prepareRestoreSnapshot(REPO, SNAPSHOT) |
| 219 | + .setWaitForCompletion(true) |
| 220 | + .setIndices("ds") |
| 221 | + .setRenamePattern(DS_BACKING_INDEX_NAME) |
| 222 | + .setRenameReplacement("new_index_name") |
| 223 | + .get(); |
| 224 | + |
| 225 | + assertThat(restoreSnapshotResponse.status(), is(RestStatus.OK)); |
| 226 | + |
| 227 | + GetDataStreamAction.Request getDSRequest = new GetDataStreamAction.Request("ds"); |
| 228 | + GetDataStreamAction.Response response = client.admin().indices().getDataStreams(getDSRequest).actionGet(); |
| 229 | + assertThat(response.getDataStreams().get(0).getIndices().get(0).getName(), is(DS_BACKING_INDEX_NAME)); |
| 230 | + } |
| 231 | + |
| 232 | + public void testDataStreamAndBackingIndidcesAreRenamedUsingRegex() { |
| 233 | + CreateSnapshotResponse createSnapshotResponse = client.admin().cluster() |
| 234 | + .prepareCreateSnapshot(REPO, SNAPSHOT) |
| 235 | + .setWaitForCompletion(true) |
| 236 | + .setIndices("ds") |
| 237 | + .setIncludeGlobalState(false) |
| 238 | + .get(); |
| 239 | + |
| 240 | + RestStatus status = createSnapshotResponse.getSnapshotInfo().status(); |
| 241 | + assertEquals(RestStatus.OK, status); |
| 242 | + |
| 243 | + expectThrows(SnapshotRestoreException.class, () -> client.admin().cluster() |
| 244 | + .prepareRestoreSnapshot(REPO, SNAPSHOT) |
| 245 | + .setWaitForCompletion(true) |
| 246 | + .setIndices("ds") |
| 247 | + .get()); |
| 248 | + |
| 249 | + // restore data stream attempting to rename the backing index |
| 250 | + RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster() |
| 251 | + .prepareRestoreSnapshot(REPO, SNAPSHOT) |
| 252 | + .setWaitForCompletion(true) |
| 253 | + .setIndices("ds") |
| 254 | + .setRenamePattern("(.+)") |
| 255 | + .setRenameReplacement("test-$1") |
| 256 | + .get(); |
| 257 | + |
| 258 | + assertThat(restoreSnapshotResponse.status(), is(RestStatus.OK)); |
| 259 | + |
| 260 | + // assert "ds" was restored as "test-ds" and the backing index has a valid name |
| 261 | + GetDataStreamAction.Request getRenamedDS = new GetDataStreamAction.Request("test-ds"); |
| 262 | + GetDataStreamAction.Response response = client.admin().indices().getDataStreams(getRenamedDS).actionGet(); |
| 263 | + assertThat(response.getDataStreams().get(0).getIndices().get(0).getName(), |
| 264 | + is(DataStream.getDefaultBackingIndexName("test-ds", 1L))); |
| 265 | + |
| 266 | + // data stream "ds" should still exist in the system |
| 267 | + GetDataStreamAction.Request getDSRequest = new GetDataStreamAction.Request("ds"); |
| 268 | + response = client.admin().indices().getDataStreams(getDSRequest).actionGet(); |
| 269 | + assertThat(response.getDataStreams().get(0).getIndices().get(0).getName(), is(DS_BACKING_INDEX_NAME)); |
| 270 | + } |
| 271 | + |
197 | 272 | public void testWildcards() throws Exception {
|
198 | 273 | CreateSnapshotResponse createSnapshotResponse = client.admin().cluster()
|
199 | 274 | .prepareCreateSnapshot(REPO, "snap2")
|
|
0 commit comments