From 80cc40d8bd82167fc8aab6ff36de6a8563f8918f Mon Sep 17 00:00:00 2001 From: bansvaru Date: Thu, 7 Sep 2023 14:21:42 +0530 Subject: [PATCH] fix UTs Signed-off-by: bansvaru --- .../coordination/CoordinationStateTests.java | 1 + .../node/RemoteStoreNodeAttributeTests.java | 83 ++++++++++++------- 2 files changed, 55 insertions(+), 29 deletions(-) diff --git a/server/src/test/java/org/opensearch/cluster/coordination/CoordinationStateTests.java b/server/src/test/java/org/opensearch/cluster/coordination/CoordinationStateTests.java index 514640a2fd691..ef56d70d6153c 100644 --- a/server/src/test/java/org/opensearch/cluster/coordination/CoordinationStateTests.java +++ b/server/src/test/java/org/opensearch/cluster/coordination/CoordinationStateTests.java @@ -959,6 +959,7 @@ public void testHandlePrePublishAndCommitWhenRemoteStateEnabled() throws IOExcep .put("node.attr." + REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY, randomRepoName) .put(stateRepoTypeAttributeKey, FsRepository.TYPE) .put(stateRepoSettingsAttributeKeyPrefix + "location", "randomRepoPath") + .put(RemoteClusterStateService.REMOTE_CLUSTER_STATE_ENABLED_SETTING.getKey(), true) .build(); final CoordinationState coordinationState = createCoordinationState(persistedStateRegistry, node1, settings); diff --git a/server/src/test/java/org/opensearch/node/RemoteStoreNodeAttributeTests.java b/server/src/test/java/org/opensearch/node/RemoteStoreNodeAttributeTests.java index 5206064273334..c4ba271d27ae9 100644 --- a/server/src/test/java/org/opensearch/node/RemoteStoreNodeAttributeTests.java +++ b/server/src/test/java/org/opensearch/node/RemoteStoreNodeAttributeTests.java @@ -19,9 +19,17 @@ import java.net.InetAddress; import java.net.UnknownHostException; +import java.util.Locale; import java.util.Map; import static java.util.Collections.emptySet; +import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY; +import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_REPOSITORY_CRYPTO_ATTRIBUTE_KEY_FORMAT; +import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_REPOSITORY_CRYPTO_SETTINGS_PREFIX; +import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_REPOSITORY_SETTINGS_ATTRIBUTE_KEY_PREFIX; +import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT; +import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY; +import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY; public class RemoteStoreNodeAttributeTests extends OpenSearchTestCase { @@ -29,24 +37,31 @@ public class RemoteStoreNodeAttributeTests extends OpenSearchTestCase { static private final String REGION = "us-east-1"; public void testCryptoMetadata() throws UnknownHostException { + String repoName = "remote-store-A"; + String repoTypeSettingKey = String.format(Locale.ROOT, REMOTE_STORE_REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT, repoName); + String repoSettingsKey = String.format(Locale.ROOT, REMOTE_STORE_REPOSITORY_SETTINGS_ATTRIBUTE_KEY_PREFIX, repoName); + String repoCryptoMetadataKey = String.format(Locale.ROOT, REMOTE_STORE_REPOSITORY_CRYPTO_ATTRIBUTE_KEY_FORMAT, repoName); + String repoCryptoMetadataSettingsKey = String.format(Locale.ROOT, REMOTE_STORE_REPOSITORY_CRYPTO_SETTINGS_PREFIX, repoName); Map attr = Map.of( - "remote_store.segment.repository", - "remote-store-A", - "remote_store.translog.repository", - "remote-store-A", - "remote_store.repository.remote-store-A.type", + REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY, + repoName, + REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY, + repoName, + REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY, + repoName, + repoTypeSettingKey, "s3", - "remote_store.repository.remote-store-A.settings.bucket", + repoSettingsKey, "abc", - "remote_store.repository.remote-store-A.settings.base_path", + repoSettingsKey + "base_path", "xyz", - "remote_store.repository.remote-store-A.crypto_metadata.key_provider_name", + repoCryptoMetadataKey + ".key_provider_name", "store-test", - "remote_store.repository.remote-store-A.crypto_metadata.key_provider_type", + repoCryptoMetadataKey + ".key_provider_type", "aws-kms", - "remote_store.repository.remote-store-A.crypto_metadata.settings.region", + repoCryptoMetadataSettingsKey + ".region", REGION, - "remote_store.repository.remote-store-A.crypto_metadata.settings.key_arn", + repoCryptoMetadataSettingsKey + ".key_arn", KEY_ARN ); DiscoveryNode node = new DiscoveryNode( @@ -68,22 +83,27 @@ public void testCryptoMetadata() throws UnknownHostException { } public void testInvalidCryptoMetadata() throws UnknownHostException { + String repoName = "remote-store-A"; + String repoTypeSettingKey = String.format(Locale.ROOT, REMOTE_STORE_REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT, repoName); + String repoSettingsKey = String.format(Locale.ROOT, REMOTE_STORE_REPOSITORY_SETTINGS_ATTRIBUTE_KEY_PREFIX, repoName); + String repoCryptoMetadataKey = String.format(Locale.ROOT, REMOTE_STORE_REPOSITORY_CRYPTO_ATTRIBUTE_KEY_FORMAT, repoName); + String repoCryptoMetadataSettingsKey = String.format(Locale.ROOT, REMOTE_STORE_REPOSITORY_CRYPTO_SETTINGS_PREFIX, repoName); Map attr = Map.of( - "remote_store.segment.repository", - "remote-store-A", - "remote_store.translog.repository", - "remote-store-A", - "remote_store.repository.remote-store-A.type", + REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY, + repoName, + REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY, + repoName, + REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY, + repoName, + repoTypeSettingKey, "s3", - "remote_store.repository.remote-store-A.settings.bucket", + repoSettingsKey, "abc", - "remote_store.repository.remote-store-A.settings.base_path", + repoSettingsKey + "base_path", "xyz", - "remote_store.repository.remote-store-A.crypto_metadata.key_provider_name", - "store-test", - "remote_store.repository.remote-store-A.crypto_metadata.settings.region", + repoCryptoMetadataSettingsKey + ".region", REGION, - "remote_store.repository.remote-store-A.crypto_metadata.settings.key_arn", + repoCryptoMetadataSettingsKey + ".key_arn", KEY_ARN ); DiscoveryNode node = new DiscoveryNode( @@ -98,16 +118,21 @@ public void testInvalidCryptoMetadata() throws UnknownHostException { } public void testNoCryptoMetadata() throws UnknownHostException { + String repoName = "remote-store-A"; + String repoTypeSettingKey = String.format(Locale.ROOT, REMOTE_STORE_REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT, repoName); + String repoSettingsKey = String.format(Locale.ROOT, REMOTE_STORE_REPOSITORY_SETTINGS_ATTRIBUTE_KEY_PREFIX, repoName); Map attr = Map.of( - "remote_store.segment.repository", - "remote-store-A", - "remote_store.translog.repository", - "remote-store-A", - "remote_store.repository.remote-store-A.type", + REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY, + repoName, + REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY, + repoName, + REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY, + repoName, + repoTypeSettingKey, "s3", - "remote_store.repository.remote-store-A.settings.bucket", + repoSettingsKey, "abc", - "remote_store.repository.remote-store-A.settings.base_path", + repoSettingsKey + "base_path", "xyz" ); DiscoveryNode node = new DiscoveryNode(