hani-fouladgar commented on code in PR #11218: URL: https://github.com/apache/ozone/pull/11218#discussion_r4039751042
########## hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/scm/proxy/TestSCMFailoverProxyProviderChangeConfig.java: ########## @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hdds.scm.proxy; + +import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_ADDRESS_KEY; +import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_NODES_KEY; +import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_SERVICE_IDS_KEY; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.List; +import org.apache.hadoop.hdds.conf.ConfigurationException; +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.ozone.ha.ConfUtils; +import org.junit.jupiter.api.Test; + +/** + * Verifies that {@link SCMFailoverProxyProviderBase#changeConfig()} reloads the + * SCM node list from an updated configuration (the dynamic SCM reconfiguration + * scenario), adding and removing nodes and keeping the current proxy pointer + * valid, while leaving the previous state intact if the new configuration is + * incomplete. + */ +public class TestSCMFailoverProxyProviderChangeConfig { + + private static final String SERVICE_ID = "scmservice"; + + private static OzoneConfiguration haConf(String nodes) { + OzoneConfiguration conf = new OzoneConfiguration(); + conf.set(OZONE_SCM_SERVICE_IDS_KEY, SERVICE_ID); + conf.set(ConfUtils.addSuffix(OZONE_SCM_NODES_KEY, SERVICE_ID), nodes); + return conf; + } + + private static void setAddress(OzoneConfiguration conf, String nodeId, + String host) { + conf.set(ConfUtils.addKeySuffixes(OZONE_SCM_ADDRESS_KEY, SERVICE_ID, nodeId), + host); + } + + @Test + public void testChangeConfigAddsNode() { + OzoneConfiguration conf = haConf("scm1,scm2"); + setAddress(conf, "scm1", "host1"); + setAddress(conf, "scm2", "host2"); + + SCMBlockLocationFailoverProxyProvider provider = + new SCMBlockLocationFailoverProxyProvider(conf); + assertEquals(2, provider.getSCMNodeIds().size()); + + // Operator adds a third SCM: its address key first, then the node list. + setAddress(conf, "scm3", "host3"); + conf.set(ConfUtils.addSuffix(OZONE_SCM_NODES_KEY, SERVICE_ID), + "scm1,scm2,scm3"); + provider.changeConfig(); + + List<String> nodeIds = provider.getSCMNodeIds(); + assertEquals(3, nodeIds.size()); + assertTrue(nodeIds.contains("scm3")); + } + + @Test + public void testChangeConfigRemovesNode() { + OzoneConfiguration conf = haConf("scm1,scm2,scm3"); + setAddress(conf, "scm1", "host1"); + setAddress(conf, "scm2", "host2"); + setAddress(conf, "scm3", "host3"); + + SCMBlockLocationFailoverProxyProvider provider = + new SCMBlockLocationFailoverProxyProvider(conf); + // Point the current proxy at the node that is about to be removed. + provider.changeCurrentProxy("scm3"); Review Comment: Fixed. changeCurrentProxy advances to the next ring node, so I now target the node before scm3 and assertEquals("scm3", provider.getCurrentProxySCMNodeId()) before reload, so the removal path is actually exercised. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
