rakeshadr commented on code in PR #9886:
URL: https://github.com/apache/ozone/pull/9886#discussion_r3050727446


##########
hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/helpers/TestOmMultipartPartKey.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.om.helpers;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.stream.IntStream;
+import org.apache.hadoop.hdds.utils.db.Codec;
+import org.apache.hadoop.hdds.utils.db.CodecBuffer;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * Unit tests for {@link OmMultipartPartKey}.
+ */
+public class TestOmMultipartPartKey {
+
+  private final Codec<OmMultipartPartKey> codec = 
OmMultipartPartKey.getCodec();
+
+  /**
+   * Generate a stream of part numbers with low byte separator as 2F,
+   * in the supported MPU range [1, 10000], values with low byte 0x2f.
+   * AND operation with 0xFF gives the low byte of the part number.
+   * @return IntStream of part numbers with low byte separator as 2F.
+   */
+  private static IntStream partNumbersWithLowByteSeparator() {
+    return IntStream.rangeClosed(1, 10000)
+        .filter(partNumber -> (partNumber & 0xFF) == 0x2F);
+  }
+
+  @Test
+  public void testRoundTripFullKey() throws Exception {

Review Comment:
   Can you add a few more test cases.
   1) Sort order correctness — big-endian int32 must sort numerically so 
iteration returns parts  1 -> 1000 in order:
   ```
     @Test
     public void testSortOrderIsNumericalNotLexicographic() throws Exception {
       // "9" sorts after "10" lexicographically, but 9 < 10 numerically.
       // Big-endian int32 encoding must produce the numerical order.
       byte[] raw9  = codec.toPersistedFormat(OmMultipartPartKey.of("uid", 9));
       byte[] raw10 = codec.toPersistedFormat(OmMultipartPartKey.of("uid", 10));
   
       // Arrays.compare is unsigned byte-by-byte — same as RocksDB's default 
comparator.
       assertTrue(Arrays.compare(raw9, raw10) < 0,
           "part 9 must sort before part 10 in byte order (big-endian 
encoding)");
     }
   ```
   2) 
   ```
   @Test
   public void testUploadIdContainingSlashRoundTrips() throws Exception {
       // uploadId itself contains '/' — the codec separator character.
       // A naive "find first slash" parser would split at the wrong position.
       OmMultipartPartKey key = OmMultipartPartKey.of("upload/with/slashes", 5);
       byte[] raw = codec.toPersistedFormat(key);
       OmMultipartPartKey decoded = codec.fromPersistedFormat(raw);
       assertEquals("upload/with/slashes", decoded.getUploadId());
       assertEquals(5, decoded.getPartNumber().intValue());
   }
   ```
   



-- 
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]

Reply via email to