siddhantsangwan commented on code in PR #5758: URL: https://github.com/apache/ozone/pull/5758#discussion_r1520907465
########## hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/balancer/TestContainerBalancerDatanodeNodeLimit.java: ########## @@ -0,0 +1,161 @@ +/* + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.container.balancer; + +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.ozone.OzoneConsts; +import org.apache.ozone.test.GenericTestUtils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.slf4j.event.Level; + +import javax.annotation.Nonnull; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Tests for {@link ContainerBalancerTask} moved from {@link TestContainerBalancerTask} to run them on clusters + * with different datanode count. + */ +public class TestContainerBalancerDatanodeNodeLimit { + @BeforeAll + public static void setup() { + GenericTestUtils.setLogLevel(ContainerBalancerTask.LOG, Level.DEBUG); + } + + private static Stream<Arguments> createMockedSCMs() { + return Stream.of( + Arguments.of(MockedSCM.getMockedSCM(4)), + Arguments.of(MockedSCM.getMockedSCM(5)), + Arguments.of(MockedSCM.getMockedSCM(6)), + Arguments.of(MockedSCM.getMockedSCM(7)), + Arguments.of(MockedSCM.getMockedSCM(8)), + Arguments.of(MockedSCM.getMockedSCM(9)), + Arguments.of(MockedSCM.getMockedSCM(10)), + Arguments.of(MockedSCM.getMockedSCM(11)), + Arguments.of(MockedSCM.getMockedSCM(12)), + Arguments.of(MockedSCM.getMockedSCM(13)), + Arguments.of(MockedSCM.getMockedSCM(14)), + Arguments.of(MockedSCM.getMockedSCM(15)), + Arguments.of(MockedSCM.getMockedSCM(17)), + Arguments.of(MockedSCM.getMockedSCM(19)), + Arguments.of(MockedSCM.getMockedSCM(20)), + Arguments.of(MockedSCM.getMockedSCM(30))); + } + + @ParameterizedTest(name = "MockedSCM #{index}: {0}") + @MethodSource("createMockedSCMs") + public void containerBalancerShouldObeyMaxDatanodesToInvolveLimit(@Nonnull MockedSCM mockedSCM) { + ContainerBalancerConfiguration config = mockedSCM.getBalancerConfig(); + config.setMaxSizeToMovePerIteration(100 * MockedSCM.STORAGE_UNIT); + config.setThreshold(1); + config.setIterations(1); + + ContainerBalancerTask task = mockedSCM.startBalancerTask(config); + ContainerBalancerMetrics metrics = task.getMetrics(); + + int maxDatanodePercentage = 40; + int nodeCount = mockedSCM.getCluster().getNodeCount(); + int number = mockedSCM.getCluster().isSmall() ? nodeCount : maxDatanodePercentage * nodeCount / 100; Review Comment: Right now, the code to configure the max percentage of datanodes to involve is hidden in the setup code: ``` if (cluster.isSmall()) { balancerCfg.setMaxDatanodesPercentageToInvolvePerIteration(100); } ``` Instead of using the `isSmall` logic, can we bring this code to the test so that it's more obvious what is happening? Right now if I'm only reading the test case it's not clear how the configuration is configured and what our expectation in this test is. -- 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]
