From 99c2142297072e734def595743b8daa0bc3938c4 Mon Sep 17 00:00:00 2001 From: Shailendra Singh Date: Wed, 3 Jul 2024 10:26:40 +0530 Subject: [PATCH] Add integration tests for RemoteRoutingTable. Signed-off-by: Shailendra Singh --- .../remote/RemoteRoutingTableServiceIT.java | 61 ++++++++++++++++--- 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/server/src/internalClusterTest/java/org/opensearch/gateway/remote/RemoteRoutingTableServiceIT.java b/server/src/internalClusterTest/java/org/opensearch/gateway/remote/RemoteRoutingTableServiceIT.java index 642f0274f653c..0f3d253d9a6b7 100644 --- a/server/src/internalClusterTest/java/org/opensearch/gateway/remote/RemoteRoutingTableServiceIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/gateway/remote/RemoteRoutingTableServiceIT.java @@ -10,7 +10,7 @@ import org.junit.Before; import org.opensearch.action.admin.cluster.state.ClusterStateRequest; -import org.opensearch.action.admin.cluster.state.ClusterStateResponse; +import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.cluster.routing.IndexRoutingTable; import org.opensearch.cluster.routing.RoutingTable; import org.opensearch.common.blobstore.BlobPath; @@ -28,7 +28,10 @@ import org.opensearch.test.OpenSearchIntegTestCase; import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.ArrayList; +import java.util.Base64; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; import static org.opensearch.gateway.remote.RemoteClusterStateService.REMOTE_CLUSTER_STATE_ENABLED_SETTING; @@ -53,10 +56,9 @@ protected Settings nodeSettings(int nodeOrdinal) { private RemoteStoreEnums.PathType pathType = RemoteStoreEnums.PathType.HASHED_PREFIX; - public void testRemoteRoutingTableCreateIndex() throws Exception { + public void testRemoteRoutingTableIndexLifecycle() throws Exception { prepareCluster(1, 3, INDEX_NAME, 1, 1); ensureGreen(INDEX_NAME); - createIndex("index-2", remoteStoreIndexSettings(2, 5)); RepositoriesService repositoriesService = internalCluster().getClusterManagerNodeInstance(RepositoriesService.class); BlobStoreRepository repository = (BlobStoreRepository) repositoriesService.repository(REPOSITORY_NAME); @@ -77,16 +79,17 @@ public void testRemoteRoutingTableCreateIndex() throws Exception { RemoteStorePathStrategy.PathInput.builder().basePath(indexRoutingPath).indexUUID(indexRoutingTable.get(0).getIndex().getUUID()).build(), pathHashAlgo ); + AtomicInteger indexRoutingFiles = new AtomicInteger(); assertBusy(() -> { - int indexRoutingFiles = repository.blobStore().blobContainer(path).listBlobs().size(); - assertTrue(indexRoutingFiles>0); + indexRoutingFiles.set(repository.blobStore().blobContainer(path).listBlobs().size()); + assertTrue(indexRoutingFiles.get() >0); logger.info("number of index routing files {}", indexRoutingFiles); }); String[] allNodes = internalCluster().getNodeNames(); List routingTableVersions = new ArrayList<>(); - // get cluster state from all the nodes + // Retrieve cluster state from all nodes for (String node : allNodes) { RoutingTable routingTable = internalCluster().client(node) .admin() @@ -96,6 +99,50 @@ public void testRemoteRoutingTableCreateIndex() throws Exception { routingTableVersions.add(routingTable.version()); } assertTrue(areRoutingTableVersionsSame(routingTableVersions)); + + // Update index settings + client().admin() + .indices() + .prepareUpdateSettings(INDEX_NAME) + .setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 2)) + .execute() + .actionGet(); + assertBusy(() -> { + int indexRoutingFilesAfterUpdate = repository.blobStore().blobContainer(path).listBlobs().size(); + assertTrue(indexRoutingFilesAfterUpdate > indexRoutingFiles.get()); + logger.info("number of index routing files {} {}", indexRoutingFiles, indexRoutingFilesAfterUpdate); + }); + + allNodes = internalCluster().getNodeNames(); + routingTableVersions = new ArrayList<>(); + // Retrieve updated cluster state from all nodes again + for (String node : allNodes) { + RoutingTable routingTable = internalCluster().client(node) + .admin() + .cluster() + .state(new ClusterStateRequest().local(true)) + .get().getState().routingTable(); + routingTableVersions.add(routingTable.version()); + } + assertTrue(areRoutingTableVersionsSame(routingTableVersions)); + + // Delete the index and assert its deletion + client().admin().indices().prepareDelete(INDEX_NAME).execute().actionGet(); + assertFalse(client().admin().indices().prepareExists(INDEX_NAME).get().isExists()); + + allNodes = internalCluster().getNodeNames(); + routingTableVersions = new ArrayList<>(); + // Retrieve updated cluster state from all nodes again + for (String node : allNodes) { + RoutingTable routingTable = internalCluster().client(node) + .admin() + .cluster() + .state(new ClusterStateRequest().local(true)) + .get().getState().routingTable(); + routingTableVersions.add(routingTable.version()); + } + assertTrue(areRoutingTableVersionsSame(routingTableVersions)); + } private boolean areRoutingTableVersionsSame(List routingTableVersions) {