echonesis commented on code in PR #11108:
URL: https://github.com/apache/ozone/pull/11108#discussion_r3864779086


##########
hadoop-ozone/ozonefs-common/src/test/java/org/apache/hadoop/fs/ozone/TestBasicOzoneFileSystems.java:
##########
@@ -178,6 +184,98 @@ public void testRootedAuthorityParsing(String uri, String 
expectedHost,
     assertEquals(new URI(uri).getAuthority(), ofs.getUri().getAuthority());
   }
 
+  @Test
+  public void testRootedIpv6UriConstructionAndRoundTrip() throws Exception {
+    URI uri = new URI("ofs", null, "2001:db8::10", 9862, "/", null, null);
+    assertEquals("ofs://[2001:db8::10]:9862/", uri.toString());
+
+    BasicRootedOzoneFileSystem ofs = spy(new BasicRootedOzoneFileSystem());
+    BasicRootedOzoneClientAdapterImpl adapter = 
mock(BasicRootedOzoneClientAdapterImpl.class);
+    doReturn(adapter).when(ofs).createAdapter(any(), anyString(), anyInt());
+    ofs.initialize(uri, new OzoneConfiguration());
+
+    Path qualified = ofs.makeQualified(new Path("/volume/bucket/key"));
+    assertEquals("ofs://[2001:db8::10]:9862/volume/bucket/key", 
qualified.toString());
+    assertEquals(qualified, new Path(qualified.toUri()));
+  }
+
+  @ParameterizedTest
+  @CsvSource({
+      "ofs://2001:db8::10/",
+      "ofs://2001:db8::10:9862/"
+  })
+  public void testRootedAuthorityRejectsUnbracketedIpv6(String uri) throws 
Exception {
+    BasicRootedOzoneFileSystem ofs = new BasicRootedOzoneFileSystem();
+    IllegalArgumentException exception = 
assertThrows(IllegalArgumentException.class,
+        () -> ofs.initialize(new URI(uri), new OzoneConfiguration()));
+    assertTrue(exception.getMessage().contains("must be enclosed in 
brackets"));
+  }
+
+  @ParameterizedTest
+  @CsvSource(value = {
+      "o3fs://bucket.volume/, NULL, -1",
+      "o3fs://bucket.volume.omservice1/, omservice1, -1",
+      "o3fs://bucket.volume.om.example.com:9862/, om.example.com, 9862",
+      "o3fs://bucket.volume.192.0.2.1:9862/, 192.0.2.1, 9862"
+  }, nullValues = "NULL")
+  public void testO3fsAuthorityParsing(String uri, String expectedHost, int 
expectedPort) throws Exception {
+    BasicOzoneFileSystem o3fs = spy(new BasicOzoneFileSystem());
+    BasicOzoneClientAdapterImpl adapter = 
mock(BasicOzoneClientAdapterImpl.class);
+    doReturn(adapter).when(o3fs).createAdapter(any(), anyString(), 
anyString(), nullable(String.class), anyInt());
+
+    o3fs.initialize(new URI(uri), new OzoneConfiguration());
+
+    ArgumentCaptor<String> hostCaptor = ArgumentCaptor.forClass(String.class);
+    ArgumentCaptor<Integer> portCaptor = 
ArgumentCaptor.forClass(Integer.class);
+    verify(o3fs).createAdapter(any(), anyString(), anyString(), 
hostCaptor.capture(), portCaptor.capture());
+    assertEquals(expectedHost, hostCaptor.getValue());
+    assertEquals(expectedPort, portCaptor.getValue().intValue());
+    assertEquals(new URI(uri).getAuthority(), o3fs.getUri().getAuthority());
+  }
+
+  @Test
+  public void testO3fsConfiguredIpv6Endpoint() throws Exception {
+    OzoneConfiguration conf = new OzoneConfiguration();
+    conf.set(OMConfigKeys.OZONE_OM_ADDRESS_KEY,
+        "[2001:db8::10]:9862");

Review Comment:
   Agreed. I kept the affected statements on one line since they fit within the 
120-character limit and match the surrounding tests.



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