Krzysztof Szafrański
10 years ago
committed by
Jun Rao
15 changed files with 176 additions and 51 deletions
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
/** |
||||
* 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.kafka.common.utils; |
||||
|
||||
import org.apache.kafka.common.config.ConfigException; |
||||
import org.junit.Test; |
||||
|
||||
import java.util.Arrays; |
||||
|
||||
public class ClientUtilsTest { |
||||
|
||||
@Test |
||||
public void testParseAndValidateAddresses() { |
||||
check("127.0.0.1:8000"); |
||||
check("mydomain.com:8080"); |
||||
check("[::1]:8000"); |
||||
check("[2001:db8:85a3:8d3:1319:8a2e:370:7348]:1234", "mydomain.com:10000"); |
||||
} |
||||
|
||||
@Test(expected = ConfigException.class) |
||||
public void testNoPort() { |
||||
check("127.0.0.1"); |
||||
} |
||||
|
||||
private void check(String... url) { |
||||
ClientUtils.parseAndValidateAddresses(Arrays.asList(url)); |
||||
} |
||||
} |
@ -0,0 +1,51 @@
@@ -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.kafka.common.utils; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import static org.apache.kafka.common.utils.Utils.getHost; |
||||
import static org.apache.kafka.common.utils.Utils.getPort; |
||||
import static org.apache.kafka.common.utils.Utils.formatAddress; |
||||
import static org.junit.Assert.*; |
||||
|
||||
public class UtilsTest { |
||||
|
||||
@Test |
||||
public void testGetHost() { |
||||
assertEquals("127.0.0.1", getHost("127.0.0.1:8000")); |
||||
assertEquals("mydomain.com", getHost("mydomain.com:8080")); |
||||
assertEquals("::1", getHost("[::1]:1234")); |
||||
assertEquals("2001:db8:85a3:8d3:1319:8a2e:370:7348", getHost("[2001:db8:85a3:8d3:1319:8a2e:370:7348]:5678")); |
||||
} |
||||
|
||||
@Test |
||||
public void testGetPort() { |
||||
assertEquals(8000, getPort("127.0.0.1:8000").intValue()); |
||||
assertEquals(8080, getPort("mydomain.com:8080").intValue()); |
||||
assertEquals(1234, getPort("[::1]:1234").intValue()); |
||||
assertEquals(5678, getPort("[2001:db8:85a3:8d3:1319:8a2e:370:7348]:5678").intValue()); |
||||
} |
||||
|
||||
@Test |
||||
public void testFormatAddress() { |
||||
assertEquals("127.0.0.1:8000", formatAddress("127.0.0.1", 8000)); |
||||
assertEquals("mydomain.com:8080", formatAddress("mydomain.com", 8080)); |
||||
assertEquals("[::1]:1234", formatAddress("::1", 1234)); |
||||
assertEquals("[2001:db8:85a3:8d3:1319:8a2e:370:7348]:5678", formatAddress("2001:db8:85a3:8d3:1319:8a2e:370:7348", 5678)); |
||||
} |
||||
} |
Loading…
Reference in new issue