adoroszlai commented on code in PR #10596: URL: https://github.com/apache/ozone/pull/10596#discussion_r3472148611
########## hadoop-ozone/freon/src/test/java/org/apache/hadoop/ozone/freon/TestRandomKeyGenerator.java: ########## @@ -0,0 +1,69 @@ +/* + * 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.ozone.freon; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.junit.jupiter.api.Test; +import picocli.CommandLine; + +/** + * Unit tests for RandomKeyGenerator command. + */ +public class TestRandomKeyGenerator { + + @Test + void rejectsNegativeNumOfVolumes() { + assertValidationFails( + new String[] {"--num-of-volumes", "-1", + "--num-of-buckets", "1", + "--num-of-keys", "1"}, + "numOfVolumes must be a positive integer"); + } + + @Test + void rejectsZeroNumOfBuckets() { + assertValidationFails( + new String[] {"--num-of-volumes", "1", + "--num-of-buckets", "0", + "--num-of-keys", "1"}, + "numOfBuckets must be a positive integer"); + } + + @Test + void rejectsNegativeNumOfKeys() { + assertValidationFails( + new String[] {"--num-of-volumes", "1", + "--num-of-buckets", "1", + "--num-of-keys", "-1"}, + "numOfKeys must be a positive integer"); + } + + private void assertValidationFails(String[] args, String expectedMessage) { Review Comment: Suggestion for minor improvement: change signature to `String expectedMessage, String... args`, then args can be passed without explicit `String[]` creation. ########## hadoop-ozone/freon/src/main/java/org/apache/hadoop/ozone/freon/RandomKeyGenerator.java: ########## @@ -290,11 +290,27 @@ public void init(OzoneConfiguration configuration) throws IOException { } } + private void validateCounts() { + if (numOfVolumes <= 0) { + throw new IllegalArgumentException( + "Invalid command, numOfVolumes must be a positive integer"); Review Comment: Please refer to option name (`--num-of-volumes`), not the internal variable name (`numOfVolumes`). (Same for other options.) -- 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]
