Skip to content

Commit

Permalink
Add IT that tries to rename a DS backing index (#59006)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreidan authored Jul 3, 2020
1 parent c3aaf33 commit 91db0db
Showing 1 changed file with 77 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@
import java.util.Map;
import java.util.concurrent.ExecutionException;

import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.is;

import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;

public class DataStreamsSnapshotsIT extends AbstractSnapshotIntegTestCase {

private static final String DS_BACKING_INDEX_NAME = DataStream.getDefaultBackingIndexName("ds", 1);
Expand Down Expand Up @@ -194,6 +193,82 @@ public void testRename() throws Exception {
assertEquals(DOCUMENT_SOURCE, client.prepareGet(DS2_BACKING_INDEX_NAME, id).get().getSourceAsMap());
}

public void testBackingIndexIsNotRenamedWhenRestoringDataStream() {
CreateSnapshotResponse createSnapshotResponse = client.admin().cluster()
.prepareCreateSnapshot(REPO, SNAPSHOT)
.setWaitForCompletion(true)
.setIndices("ds")
.setIncludeGlobalState(false)
.get();

RestStatus status = createSnapshotResponse.getSnapshotInfo().status();
assertEquals(RestStatus.OK, status);

expectThrows(SnapshotRestoreException.class, () -> client.admin().cluster()
.prepareRestoreSnapshot(REPO, SNAPSHOT)
.setWaitForCompletion(true)
.setIndices("ds")
.get());

// delete data stream
client.admin().indices().deleteDataStream(new DeleteDataStreamAction.Request("ds")).actionGet();

// restore data stream attempting to rename the backing index
RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster()
.prepareRestoreSnapshot(REPO, SNAPSHOT)
.setWaitForCompletion(true)
.setIndices("ds")
.setRenamePattern(DS_BACKING_INDEX_NAME)
.setRenameReplacement("new_index_name")
.get();

assertThat(restoreSnapshotResponse.status(), is(RestStatus.OK));

GetDataStreamAction.Request getDSRequest = new GetDataStreamAction.Request("ds");
GetDataStreamAction.Response response = client.admin().indices().getDataStreams(getDSRequest).actionGet();
assertThat(response.getDataStreams().get(0).getIndices().get(0).getName(), is(DS_BACKING_INDEX_NAME));
}

public void testDataStreamAndBackingIndidcesAreRenamedUsingRegex() {
CreateSnapshotResponse createSnapshotResponse = client.admin().cluster()
.prepareCreateSnapshot(REPO, SNAPSHOT)
.setWaitForCompletion(true)
.setIndices("ds")
.setIncludeGlobalState(false)
.get();

RestStatus status = createSnapshotResponse.getSnapshotInfo().status();
assertEquals(RestStatus.OK, status);

expectThrows(SnapshotRestoreException.class, () -> client.admin().cluster()
.prepareRestoreSnapshot(REPO, SNAPSHOT)
.setWaitForCompletion(true)
.setIndices("ds")
.get());

// restore data stream attempting to rename the backing index
RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster()
.prepareRestoreSnapshot(REPO, SNAPSHOT)
.setWaitForCompletion(true)
.setIndices("ds")
.setRenamePattern("(.+)")
.setRenameReplacement("test-$1")
.get();

assertThat(restoreSnapshotResponse.status(), is(RestStatus.OK));

// assert "ds" was restored as "test-ds" and the backing index has a valid name
GetDataStreamAction.Request getRenamedDS = new GetDataStreamAction.Request("test-ds");
GetDataStreamAction.Response response = client.admin().indices().getDataStreams(getRenamedDS).actionGet();
assertThat(response.getDataStreams().get(0).getIndices().get(0).getName(),
is(DataStream.getDefaultBackingIndexName("test-ds", 1L)));

// data stream "ds" should still exist in the system
GetDataStreamAction.Request getDSRequest = new GetDataStreamAction.Request("ds");
response = client.admin().indices().getDataStreams(getDSRequest).actionGet();
assertThat(response.getDataStreams().get(0).getIndices().get(0).getName(), is(DS_BACKING_INDEX_NAME));
}

public void testWildcards() throws Exception {
CreateSnapshotResponse createSnapshotResponse = client.admin().cluster()
.prepareCreateSnapshot(REPO, "snap2")
Expand Down

0 comments on commit 91db0db

Please sign in to comment.