From ab0cbea6f67617f78b3e278c3f499c533340031e Mon Sep 17 00:00:00 2001 From: Mohit Godwani Date: Tue, 3 Sep 2024 11:29:35 +0530 Subject: [PATCH] Add remote state test for context field in metadata Signed-off-by: Mohit Godwani --- .../gateway/remote/RemoteStatePublicationIT.java | 15 +++++++++++---- .../remotestore/RemoteStoreBaseIntegTestCase.java | 13 ++++++++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/server/src/internalClusterTest/java/org/opensearch/gateway/remote/RemoteStatePublicationIT.java b/server/src/internalClusterTest/java/org/opensearch/gateway/remote/RemoteStatePublicationIT.java index eac4f39da48e3..c692f1cc3925b 100644 --- a/server/src/internalClusterTest/java/org/opensearch/gateway/remote/RemoteStatePublicationIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/gateway/remote/RemoteStatePublicationIT.java @@ -99,7 +99,7 @@ protected Settings nodeSettings(int nodeOrdinal) { public void testPublication() throws Exception { // create cluster with multi node (3 master + 2 data) - prepareCluster(3, 2, INDEX_NAME, 1, 2); + prepareClusterWithDefaultContext(3, 2, INDEX_NAME, 1, 2); ensureStableCluster(5); ensureGreen(INDEX_NAME); // update settings on a random node @@ -141,15 +141,22 @@ public void testPublication() throws Exception { Settings settings = clusterService().getSettings(); logger.info("settings : {}", settings); for (Client client : clients()) { - ClusterStateResponse response = client.admin().cluster().prepareState().clear().setMetadata(true).get(); + ClusterStateResponse response = client.admin().cluster().prepareState().clear() + .setMetadata(true) + .setLocal(true) + .get(); + String refreshSetting = response.getState() .metadata() .settings() .get(RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey()); - assertEquals(new Context("testcontext"), response.getState() - .metadata().indices().get(INDEX_NAME).context()); assertEquals("10mb", refreshSetting); + + + // Verify context is present in metadata + assertEquals(new Context(CONTEXT_NAME), response.getState() + .metadata().indices().get(INDEX_NAME).context()); } } diff --git a/server/src/internalClusterTest/java/org/opensearch/remotestore/RemoteStoreBaseIntegTestCase.java b/server/src/internalClusterTest/java/org/opensearch/remotestore/RemoteStoreBaseIntegTestCase.java index 045ffce4d94f7..690b249897886 100644 --- a/server/src/internalClusterTest/java/org/opensearch/remotestore/RemoteStoreBaseIntegTestCase.java +++ b/server/src/internalClusterTest/java/org/opensearch/remotestore/RemoteStoreBaseIntegTestCase.java @@ -362,11 +362,22 @@ protected void restore(boolean restoreAllShards, String... indices) { protected void prepareCluster(int numClusterManagerNodes, int numDataOnlyNodes, String indices, int replicaCount, int shardCount) { internalCluster().startClusterManagerOnlyNodes(numClusterManagerNodes); + internalCluster().startDataOnlyNodes(numDataOnlyNodes); + for (String index : indices.split(",")) { + createIndex(index, remoteStoreIndexSettings(replicaCount, shardCount)); + ensureYellowAndNoInitializingShards(index); + ensureGreen(index); + } + } - // Adding context template to the cluster + protected void prepareClusterWithDefaultContext(int numClusterManagerNodes, int numDataOnlyNodes, String indices, int replicaCount, int shardCount) { + internalCluster().startClusterManagerOnlyNodes(numClusterManagerNodes); + // Adding context template to the cluster addTemplateForContext(CONTEXT_NAME); + internalCluster().startDataOnlyNodes(numDataOnlyNodes); + for (String index : indices.split(",")) { // Ensure index is created with additional metadata field. assertAcked(prepareCreate(index)