adoroszlai commented on code in PR #8789:
URL: https://github.com/apache/ozone/pull/8789#discussion_r2221499921


##########
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/ContainerChecksumsTest.java:
##########
@@ -0,0 +1,55 @@
+/*
+ * 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.container;
+
+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;
+
+import org.junit.jupiter.api.Test;
+
+class ContainerChecksumsTest {

Review Comment:
   This is not run due to naming convention, should be `TestContainerChecksums`.



##########
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/TestContainerReportHandler.java:
##########
@@ -1205,7 +1205,7 @@ public void testWithNoContainerDataChecksum() throws 
Exception {
 
     // All replicas should start with an empty data checksum in SCM.
     boolean contOneDataChecksumsEmpty = 
containerManager.getContainerReplicas(contID).stream()
-        .allMatch(r -> r.getDataChecksum() == 0);
+        .allMatch(r -> r.getChecksums().getDataChecksum() == 0);

Review Comment:
   We could reduce change by keeping the `getDataChecksum()` method in 
`ContainerReplica` and delegate to `checksums`.



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerChecksums.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.container;
+
+import java.util.Objects;
+
+/**
+ * Wrapper for container checksums (data, metadata, etc.).
+ * Provides equality, hash, and hex string rendering.
+ */
+public class ContainerChecksums {

Review Comment:
   Could be `final`, and please annotate with `@Immutable`.



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerChecksums.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.container;
+
+import java.util.Objects;
+
+/**
+ * Wrapper for container checksums (data, metadata, etc.).
+ * Provides equality, hash, and hex string rendering.
+ */
+public class ContainerChecksums {
+  private final long dataChecksum;
+  private final Long metadataChecksum; // nullable for future use
+
+  public ContainerChecksums(long dataChecksum) {
+    this(dataChecksum, null);
+  }
+
+  public ContainerChecksums(long dataChecksum, Long metadataChecksum) {
+    this.dataChecksum = dataChecksum;
+    this.metadataChecksum = metadataChecksum;
+  }

Review Comment:
   We could add factory methods (and make constructor private) to reduce 
accidental mismatch of intended and actual source (data or metadata).
   
   Something like:
   
   ```java
   public static ContainerChecksums unknown(); // use constant value
   public static ContainerChecksums dataOnly(long dataChecksum);
   public static ContainerChecksums metadataOnly(long metadataChecksum);
   public static ContainerChecksums of(long dataChecksum, long 
metadataChecksum);
   ```



##########
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/ContainerChecksumsTest.java:
##########
@@ -0,0 +1,55 @@
+/*
+ * 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.container;
+
+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;
+
+import org.junit.jupiter.api.Test;
+
+class ContainerChecksumsTest {
+  @Test
+  void testEqualsAndHashCode() {
+    ContainerChecksums c1 = new ContainerChecksums(123L);
+    ContainerChecksums c2 = new ContainerChecksums(123L);
+    ContainerChecksums c3 = new ContainerChecksums(456L);
+    ContainerChecksums c4 = new ContainerChecksums(123L, 789L);
+    ContainerChecksums c5 = new ContainerChecksums(123L, 789L);
+    ContainerChecksums c6 = new ContainerChecksums(123L, 790L);
+
+    assertEquals(c1, c2);
+    assertEquals(c1.hashCode(), c2.hashCode());
+    assertNotEquals(c1, c3);
+    assertNotEquals(c1, c4);
+    assertEquals(c4, c5);
+    assertNotEquals(c4, c6);
+  }
+
+  @Test
+  void testToString() {
+    ContainerChecksums c1 = new ContainerChecksums(0x1234ABCDL);
+    assertTrue(c1.toString().contains("data=1234abcd"));
+    assertFalse(c1.toString().contains("metadata="));

Review Comment:
   nit: for better failure message prefer `assertThat(...).contains(...)` and 
`.doesNotContain(...)` (can be called in chain, too).



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