Caideyipi commented on code in PR #11457: URL: https://github.com/apache/iotdb/pull/11457#discussion_r1385899469
########## iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/UrlUtils.java: ########## @@ -0,0 +1,51 @@ +/* + * 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.iotdb.rpc; + +import org.apache.iotdb.common.rpc.thrift.TEndPoint; + +/** The UrlUtils */ +public class UrlUtils { + private static final String POINT_COLON = ":"; + private static final String ABB_COLON = "["; + + private UrlUtils() {} + + /** + * Parse TEndPoint from a given TEndPointUrl example:D80:0000:0000:0000:ABAA:0000:00C2:0002:22227 Review Comment: How about the []? ########## iotdb-client/service-rpc/src/test/java/org/apache/iotdb/rpc/UrlUtilsTest.java: ########## @@ -0,0 +1,61 @@ +/* + * 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.iotdb.rpc; + +import org.apache.iotdb.common.rpc.thrift.TEndPoint; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class UrlUtilsTest { + + @Test + public void testParseIPV6URL() { + String hostAndPoint = "D80:0000:0000:0000:ABAA:00BB:EEAA:BBRR:22227"; + TEndPoint endPoint = UrlUtils.parseTEndPointIpv4AndIpv6Url(hostAndPoint); + assertEquals(endPoint.getIp(), "D80:0000:0000:0000:ABAA:00BB:EEAA:BBRR"); Review Comment: The hexademical string may not contain the word "R" ########## iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/utils/NodeUrlUtilsTest.java: ########## @@ -59,4 +59,37 @@ public void parseAndConvertTConfigNodeUrlsTest() throws BadNodeUrlException { Assert.assertEquals(configNodeUrls, NodeUrlUtils.convertTConfigNodeUrls(configNodeLocations)); Assert.assertEquals(configNodeLocations, NodeUrlUtils.parseTConfigNodeUrls(configNodeUrls)); } + + @Test + public void parseAndConvertTEndPointUrlsIPV4AndIPV6Test() throws BadNodeUrlException { + final List<TEndPoint> endPoints = + Arrays.asList( + new TEndPoint("AD80:E32B:CR25:B3WE:DG4G:DWTF:CGDE:2345", 6667), + new TEndPoint("0:0:0:0:0:FFFF:129.144.52.38", 6668), + new TEndPoint("::13.1.68.3", 6669)); + final String endPointUrls = + "AD80:E32B:CR25:B3WE:DG4G:DWTF:CGDE:2345:6667,[0:0:0:0:0:FFFF:129.144.52.38]:6668,[::13.1.68.3]:6669"; + Assert.assertEquals(endPoints, NodeUrlUtils.parseTEndPointUrls(endPointUrls)); + } + + @Test + public void parseAndConvertTConfigNodeUrlsIPV4AndIPV6Test() throws BadNodeUrlException { + final List<TConfigNodeLocation> configNodeLocations = + Arrays.asList( + new TConfigNodeLocation( + 0, + new TEndPoint("AD80:E32B:CR25:B3WE:DG4G:DWTF:CGDE:ABFD", 22277), + new TEndPoint("AD80:E32B:CR25:B3WE:DG4G:DWTF:CGDE:ABFD", 22278)), + new TConfigNodeLocation( + 1, + new TEndPoint("AD80:E32B:CR25:B3WE:DG4G:DWTF:CGDE:ABFD", 22279), + new TEndPoint("AD80:E32B:CR25:B3WE:DG4G:DWTF:CGDE:ABFD", 22280)), + new TConfigNodeLocation( + 2, + new TEndPoint("AD80:E32B:CR25:B3WE:DG4G:DWTF:CGDE:ABFD", 22281), + new TEndPoint("AD80:E32B:CR25:B3WE:DG4G:DWTF:CGDE:ABFD", 22282))); + final String configNodeUrls = + "0,AD80:E32B:CR25:B3WE:DG4G:DWTF:CGDE:ABFD:22277,[AD80:E32B:CR25:B3WE:DG4G:DWTF:CGDE:ABFD]:22278;1,AD80:E32B:CR25:B3WE:DG4G:DWTF:CGDE:ABFD:22279,AD80:E32B:CR25:B3WE:DG4G:DWTF:CGDE:ABFD:22280;2,AD80:E32B:CR25:B3WE:DG4G:DWTF:CGDE:ABFD:22281,AD80:E32B:CR25:B3WE:DG4G:DWTF:CGDE:ABFD:22282"; Review Comment: [], and A-F ########## iotdb-client/service-rpc/src/test/java/org/apache/iotdb/rpc/UrlUtilsTest.java: ########## @@ -0,0 +1,61 @@ +/* + * 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.iotdb.rpc; + +import org.apache.iotdb.common.rpc.thrift.TEndPoint; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class UrlUtilsTest { + + @Test + public void testParseIPV6URL() { + String hostAndPoint = "D80:0000:0000:0000:ABAA:00BB:EEAA:BBRR:22227"; + TEndPoint endPoint = UrlUtils.parseTEndPointIpv4AndIpv6Url(hostAndPoint); + assertEquals(endPoint.getIp(), "D80:0000:0000:0000:ABAA:00BB:EEAA:BBRR"); + assertEquals(endPoint.getPort(), 22227); + } + + @Test + public void testParseIPV6PercentURL() { + String hostAndPoint = "D80:0000:GETW:SSEE:0000:0000:ABAA:0000%14:22227"; + TEndPoint endPoint = UrlUtils.parseTEndPointIpv4AndIpv6Url(hostAndPoint); + assertEquals(endPoint.getIp(), "D80:0000:GETW:SSEE:0000:0000:ABAA:0000%14"); Review Comment: Trim it to A-F ########## iotdb-client/service-rpc/src/test/java/org/apache/iotdb/rpc/UrlUtilsTest.java: ########## @@ -0,0 +1,61 @@ +/* + * 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.iotdb.rpc; + +import org.apache.iotdb.common.rpc.thrift.TEndPoint; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class UrlUtilsTest { + + @Test + public void testParseIPV6URL() { + String hostAndPoint = "D80:0000:0000:0000:ABAA:00BB:EEAA:BBRR:22227"; Review Comment: [] ########## iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/UtilsTest.java: ########## @@ -65,6 +65,31 @@ public void testParseURL() throws IoTDBURLException { assertEquals(params.getPassword(), userPwd); } + @Test + public void testParseIPV6URL() throws IoTDBURLException { + String userName = "test"; + String userPwd = "test"; + String host1 = + "AD80:E32B:CR25:B3WE:DG4G:DWTF,AD80:E32B:CR25:B3WE:DG4G:DWTF:CGDE,AD80:E32B:CR25:B3WE:DG4G:DWTF"; Review Comment: This can be expanded to 8 segments ########## iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/utils/NodeUrlUtilsTest.java: ########## @@ -59,4 +59,37 @@ public void parseAndConvertTConfigNodeUrlsTest() throws BadNodeUrlException { Assert.assertEquals(configNodeUrls, NodeUrlUtils.convertTConfigNodeUrls(configNodeLocations)); Assert.assertEquals(configNodeLocations, NodeUrlUtils.parseTConfigNodeUrls(configNodeUrls)); } + + @Test + public void parseAndConvertTEndPointUrlsIPV4AndIPV6Test() throws BadNodeUrlException { + final List<TEndPoint> endPoints = + Arrays.asList( + new TEndPoint("AD80:E32B:CR25:B3WE:DG4G:DWTF:CGDE:2345", 6667), Review Comment: Limit the words to A-F ########## iotdb-client/service-rpc/src/test/java/org/apache/iotdb/rpc/UrlUtilsTest.java: ########## @@ -0,0 +1,61 @@ +/* + * 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.iotdb.rpc; + +import org.apache.iotdb.common.rpc.thrift.TEndPoint; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class UrlUtilsTest { + + @Test + public void testParseIPV6URL() { + String hostAndPoint = "D80:0000:0000:0000:ABAA:00BB:EEAA:BBRR:22227"; + TEndPoint endPoint = UrlUtils.parseTEndPointIpv4AndIpv6Url(hostAndPoint); + assertEquals(endPoint.getIp(), "D80:0000:0000:0000:ABAA:00BB:EEAA:BBRR"); + assertEquals(endPoint.getPort(), 22227); + } + + @Test + public void testParseIPV6PercentURL() { + String hostAndPoint = "D80:0000:GETW:SSEE:0000:0000:ABAA:0000%14:22227"; Review Comment: [] ########## iotdb-client/service-rpc/src/test/java/org/apache/iotdb/rpc/UrlUtilsTest.java: ########## @@ -0,0 +1,61 @@ +/* + * 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.iotdb.rpc; + +import org.apache.iotdb.common.rpc.thrift.TEndPoint; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class UrlUtilsTest { + + @Test + public void testParseIPV6URL() { + String hostAndPoint = "D80:0000:0000:0000:ABAA:00BB:EEAA:BBRR:22227"; + TEndPoint endPoint = UrlUtils.parseTEndPointIpv4AndIpv6Url(hostAndPoint); + assertEquals(endPoint.getIp(), "D80:0000:0000:0000:ABAA:00BB:EEAA:BBRR"); + assertEquals(endPoint.getPort(), 22227); + } + + @Test + public void testParseIPV6PercentURL() { + String hostAndPoint = "D80:0000:GETW:SSEE:0000:0000:ABAA:0000%14:22227"; + TEndPoint endPoint = UrlUtils.parseTEndPointIpv4AndIpv6Url(hostAndPoint); + assertEquals(endPoint.getIp(), "D80:0000:GETW:SSEE:0000:0000:ABAA:0000%14"); + assertEquals(endPoint.getPort(), 22227); + } + + @Test + public void testParseIPV6AbbURL() { + String hostAndPoint = "[D80:ABAA:0]:22227"; Review Comment: Maybe D80::ABAA:0? -- 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]
