This is an automated email from the ASF dual-hosted git repository.
adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new ae533de983c HDDS-15653. RandomKeyGenerator should reject negative
inputs (#10596)
ae533de983c is described below
commit ae533de983c6ce524282c0c24460f7e49092c1d4
Author: sravani <[email protected]>
AuthorDate: Thu Jun 25 13:39:23 2026 +0530
HDDS-15653. RandomKeyGenerator should reject negative inputs (#10596)
---
.../hadoop/ozone/freon/RandomKeyGenerator.java | 24 ++++++
.../hadoop/ozone/freon/TestRandomKeyGenerator.java | 90 ++++++++++++++++++++++
2 files changed, 114 insertions(+)
diff --git
a/hadoop-ozone/freon/src/main/java/org/apache/hadoop/ozone/freon/RandomKeyGenerator.java
b/hadoop-ozone/freon/src/main/java/org/apache/hadoop/ozone/freon/RandomKeyGenerator.java
index 5b8205e2c33..6f3baa69689 100644
---
a/hadoop-ozone/freon/src/main/java/org/apache/hadoop/ozone/freon/RandomKeyGenerator.java
+++
b/hadoop-ozone/freon/src/main/java/org/apache/hadoop/ozone/freon/RandomKeyGenerator.java
@@ -282,6 +282,29 @@ public void init(OzoneConfiguration configuration) throws
IOException {
}
}
+ private void validateCounts() {
+ if (numOfVolumes <= 0) {
+ throw new IllegalArgumentException(
+ "Invalid command, --num-of-volumes must be a positive integer");
+ }
+ if (numOfBuckets <= 0) {
+ throw new IllegalArgumentException(
+ "Invalid command, --num-of-buckets must be a positive integer");
+ }
+ if (numOfKeys <= 0) {
+ throw new IllegalArgumentException(
+ "Invalid command, --num-of-keys must be a positive integer");
+ }
+ if (numOfThreads <= 0) {
+ throw new IllegalArgumentException(
+ "Invalid command, --num-of-threads must be a positive integer");
+ }
+ if (validateWrites && numOfValidateThreads <= 0) {
+ throw new IllegalArgumentException(
+ "Invalid command, --num-of-validate-threads must be a positive
integer");
+ }
+ }
+
@Override
public Void call() throws Exception {
if (ozoneConfiguration == null) {
@@ -294,6 +317,7 @@ public Void call() throws Exception {
+ HddsConfigKeys.HDDS_CONTAINER_PERSISTDATA + " is set to false.");
validateWrites = false;
}
+ validateCounts();
init(ozoneConfiguration);
replicationConfig = replication.fromParamsOrConfig(ozoneConfiguration);
diff --git
a/hadoop-ozone/freon/src/test/java/org/apache/hadoop/ozone/freon/TestRandomKeyGenerator.java
b/hadoop-ozone/freon/src/test/java/org/apache/hadoop/ozone/freon/TestRandomKeyGenerator.java
new file mode 100644
index 00000000000..3a3c8dc2b09
--- /dev/null
+++
b/hadoop-ozone/freon/src/test/java/org/apache/hadoop/ozone/freon/TestRandomKeyGenerator.java
@@ -0,0 +1,90 @@
+/*
+ * 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(
+ "--num-of-volumes must be a positive integer",
+ "--num-of-volumes", "-1",
+ "--num-of-buckets", "1",
+ "--num-of-keys", "1");
+ }
+
+ @Test
+ void rejectsZeroNumOfBuckets() {
+ assertValidationFails(
+ "--num-of-buckets must be a positive integer",
+ "--num-of-volumes", "1",
+ "--num-of-buckets", "0",
+ "--num-of-keys", "1");
+ }
+
+ @Test
+ void rejectsNegativeNumOfKeys() {
+ assertValidationFails(
+ "--num-of-keys must be a positive integer",
+ "--num-of-volumes", "1",
+ "--num-of-buckets", "1",
+ "--num-of-keys", "-1");
+ }
+
+ @Test
+ void rejectsNegativeNumOfThreads() {
+ assertValidationFails(
+ "--num-of-threads must be a positive integer",
+ "--num-of-volumes", "1",
+ "--num-of-buckets", "1",
+ "--num-of-keys", "1",
+ "--num-of-threads", "-1");
+ }
+
+ @Test
+ void rejectsNegativeNumOfValidateThreadsWhenValidateWritesEnabled() {
+ assertValidationFails(
+ "--num-of-validate-threads must be a positive integer",
+ "--num-of-volumes", "1",
+ "--num-of-buckets", "1",
+ "--num-of-keys", "1",
+ "--validate-writes",
+ "--num-of-validate-threads", "-1");
+ }
+
+ private void assertValidationFails(String expectedMessage, String... args) {
+ RandomKeyGenerator generator = new RandomKeyGenerator(new
OzoneConfiguration());
+ CommandLine cmd = new CommandLine(generator);
+ cmd.parseArgs(args);
+
+ IllegalArgumentException ex = assertThrows(
+ IllegalArgumentException.class, generator::call);
+
+ assertThat(ex.getMessage()).contains(expectedMessage);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]