Skip to content

Commit f8f6806

Browse files
committed
Add integ tests
Signed-off-by: Ashish Singh <ssashish@amazon.com>
1 parent 08cb85c commit f8f6806

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

server/src/internalClusterTest/java/org/opensearch/snapshots/RestoreSnapshotIT.java

+57
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.opensearch.action.admin.indices.template.get.GetIndexTemplatesResponse;
4040
import org.opensearch.action.index.IndexRequestBuilder;
4141
import org.opensearch.client.Client;
42+
import org.opensearch.cluster.ClusterState;
4243
import org.opensearch.cluster.block.ClusterBlocks;
4344
import org.opensearch.cluster.metadata.IndexMetadata;
4445
import org.opensearch.cluster.metadata.MappingMetadata;
@@ -151,6 +152,62 @@ public void testParallelRestoreOperations() {
151152
assertThat(client.prepareGet(restoredIndexName2, docId2).get().isExists(), equalTo(true));
152153
}
153154

155+
/**
156+
* In this test, we test that an index created does not have any remote_store custom data in index metadata at the
157+
* time of index creation and after snapshot restore.
158+
*/
159+
public void testNoRemoteStoreCustomDataOnIndexCreationAndRestore() {
160+
String indexName1 = "testindex1";
161+
String repoName = "test-restore-snapshot-repo";
162+
String snapshotName1 = "test-restore-snapshot1";
163+
Path absolutePath = randomRepoPath().toAbsolutePath();
164+
logger.info("Path [{}]", absolutePath);
165+
String restoredIndexName1 = indexName1 + "-restored";
166+
String expectedValue = "expected";
167+
168+
Client client = client();
169+
// Write a document
170+
String docId = Integer.toString(randomInt());
171+
index(indexName1, "_doc", docId, "value", expectedValue);
172+
173+
createRepository(repoName, "fs", absolutePath);
174+
175+
logger.info("--> snapshot");
176+
CreateSnapshotResponse createSnapshotResponse = client.admin()
177+
.cluster()
178+
.prepareCreateSnapshot(repoName, snapshotName1)
179+
.setWaitForCompletion(true)
180+
.setIndices(indexName1)
181+
.get();
182+
assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
183+
assertThat(
184+
createSnapshotResponse.getSnapshotInfo().successfulShards(),
185+
equalTo(createSnapshotResponse.getSnapshotInfo().totalShards())
186+
);
187+
assertThat(createSnapshotResponse.getSnapshotInfo().state(), equalTo(SnapshotState.SUCCESS));
188+
189+
ClusterState state = client().admin().cluster().prepareState().execute().actionGet().getState();
190+
191+
// Validate that the remote_store custom data is not present in index metadata for the created index.
192+
assertNull(state.metadata().index(indexName1).getCustomData(IndexMetadata.REMOTE_STORE_CUSTOM_KEY));
193+
194+
RestoreSnapshotResponse restoreSnapshotResponse1 = client.admin()
195+
.cluster()
196+
.prepareRestoreSnapshot(repoName, snapshotName1)
197+
.setWaitForCompletion(false)
198+
.setRenamePattern(indexName1)
199+
.setRenameReplacement(restoredIndexName1)
200+
.get();
201+
assertThat(restoreSnapshotResponse1.status(), equalTo(RestStatus.ACCEPTED));
202+
ensureGreen(restoredIndexName1);
203+
assertThat(client.prepareGet(restoredIndexName1, docId).get().isExists(), equalTo(true));
204+
205+
state = client().admin().cluster().prepareState().execute().actionGet().getState();
206+
207+
// Validate that the remote_store custom data is not present in index metadata for the restored index.
208+
assertNull(state.metadata().index(restoredIndexName1).getCustomData(IndexMetadata.REMOTE_STORE_CUSTOM_KEY));
209+
}
210+
154211
public void testParallelRestoreOperationsFromSingleSnapshot() throws Exception {
155212
String indexName1 = "testindex1";
156213
String indexName2 = "testindex2";

0 commit comments

Comments
 (0)