ayushtkn commented on code in PR #10611:
URL: https://github.com/apache/ozone/pull/10611#discussion_r3503530847


##########
hadoop-ozone/client/src/test/java/org/apache/hadoop/ozone/client/rpc/TestRpcClient.java:
##########
@@ -215,4 +247,65 @@ public void 
testUnknownVersionShouldNotBeAnExpectedVersion() {
         IllegalArgumentException.class,
         () -> validateOmVersion(OzoneManagerVersion.UNKNOWN_VERSION, null));
   }
+
+  @Test
+  public void testValidateOmVersionFailsWhenNoOmPresent() {
+    // At least one OM must be present. An empty list should fail validation.
+    assertFalse(validateOmVersion(OzoneManagerVersion.SOFTWARE_VERSION, 
Collections.emptyList()));
+  }
+
+  @Test
+  public void testGetOmVersionWithNoOmDefaultsToSoftwareVersion() {
+    // Default software version should be returned if OM list is empty.
+    assertEquals(OzoneManagerVersion.SOFTWARE_VERSION, 
getOmVersion(serviceInfoEx()));
+  }
+
+  @Test
+  public void testGetOmVersionReturnsSingleOmVersion() {
+    assertEquals(OzoneManagerVersion.HBASE_SUPPORT, 
getOmVersion(serviceInfoEx(om(OzoneManagerVersion.HBASE_SUPPORT))));
+  }
+
+  @Test
+  public void testGetOmVersionReturnsMinimumAcrossOms() {
+    // The lowest version among all OMs is returned, regardless of ordering.
+    assertEquals(OzoneManagerVersion.HBASE_SUPPORT, // version 7
+        getOmVersion(serviceInfoEx(
+            om(OzoneManagerVersion.LIGHTWEIGHT_LIST_STATUS), // version 8
+            om(OzoneManagerVersion.HBASE_SUPPORT)))); // version 7
+    assertEquals(OzoneManagerVersion.DEFAULT_VERSION, // version 0
+        getOmVersion(serviceInfoEx(
+            om(OzoneManagerVersion.DEFAULT_VERSION), // version 0
+            om(OzoneManagerVersion.SOFTWARE_VERSION)))); // largest concrete 
version.
+  }
+
+  @Test
+  public void testGetOmVersionWithFutureOM() {
+    // A future (unknown) OM version must never be returned as the version to 
use, even if it is the only one present.
+    // The client's latest known OM version should be used in this case, which 
should still be less than the future
+    // versions.
+    assertEquals(OzoneManagerVersion.SOFTWARE_VERSION,
+        getOmVersion(serviceInfoEx(
+            om(OzoneManagerVersion.UNKNOWN_VERSION),
+            om(OzoneManagerVersion.SOFTWARE_VERSION))));
+    assertEquals(OzoneManagerVersion.SOFTWARE_VERSION,
+        getOmVersion(serviceInfoEx(
+            om(OzoneManagerVersion.UNKNOWN_VERSION),
+            om(OzoneManagerVersion.UNKNOWN_VERSION))));
+  }
+
+  private static ServiceInfo om(OzoneManagerVersion version) {
+    return node(HddsProtos.NodeType.OM, version);
+  }
+
+  private static ServiceInfo node(HddsProtos.NodeType nodeType, 
OzoneManagerVersion version) {

Review Comment:
   this method is called only by 
   ```
    private static ServiceInfo om(OzoneManagerVersion version) {
   ```
   
   maybe we could have implemented there itself rather than having two methods



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