Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove duplicated unused method and move unit test #3446

Merged
merged 1 commit into from
Feb 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,8 @@ public List<URL> getBackupUrls() {
return urls;
}

private String appendDefaultPort(String address, int defaultPort) {
if (address != null && address.length() > 0
&& defaultPort > 0) {
static String appendDefaultPort(String address, int defaultPort) {
if (address != null && address.length() > 0 && defaultPort > 0) {
int i = address.indexOf(':');
if (i < 0) {
return address + ":" + defaultPort;
Expand Down
11 changes: 9 additions & 2 deletions dubbo-common/src/test/java/org/apache/dubbo/common/URLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.apache.dubbo.common.utils.CollectionUtils;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.File;
Expand Down Expand Up @@ -124,7 +125,7 @@ public void test_valueOf_noHost() throws Exception {
assertEquals("home/user1/router.js", url.getPath());
assertEquals(0, url.getParameters().size());

// Caution!!
// Caution!!
url = URL.valueOf("file://home/user1/router.js");
// ^^ only tow slash!
assertEquals("file", url.getProtocol());
Expand Down Expand Up @@ -680,4 +681,10 @@ public void testIpV6AddressWithScopeId(){
assertEquals("1.0.0", url.getParameter("version"));
assertEquals("morgan", url.getParameter("application"));
}
}

@Test
public void testDefaultPort() {
Assertions.assertEquals("10.20.153.10:2181", URL.appendDefaultPort("10.20.153.10:0", 2181));
Assertions.assertEquals("10.20.153.10:2181", URL.appendDefaultPort("10.20.153.10", 2181));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,6 @@ public ZookeeperRegistry(URL url, ZookeeperTransporter zookeeperTransporter) {
});
}

static String appendDefaultPort(String address) {
if (address != null && address.length() > 0) {
int i = address.indexOf(':');
if (i < 0) {
return address + ":" + DEFAULT_ZOOKEEPER_PORT;
} else if (Integer.parseInt(address.substring(i + 1)) == 0) {
return address.substring(0, i + 1) + DEFAULT_ZOOKEEPER_PORT;
}
}
return address;
}

@Override
public boolean isAvailable() {
return zkClient.isConnected();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
import java.util.Set;
import java.util.concurrent.CountDownLatch;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock;

Expand Down Expand Up @@ -65,12 +67,6 @@ public void tearDown() throws Exception {
zkServer.stop();
}

@Test
public void testDefaultPort() {
Assertions.assertEquals("10.20.153.10:2181", ZookeeperRegistry.appendDefaultPort("10.20.153.10:0"));
Assertions.assertEquals("10.20.153.10:2181", ZookeeperRegistry.appendDefaultPort("10.20.153.10"));
}

@Test
public void testAnyHost() {
Assertions.assertThrows(IllegalStateException.class, () -> {
Expand Down Expand Up @@ -153,13 +149,8 @@ public void testStatusChecker() {
public void testSubscribeAnyValue() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
zookeeperRegistry.register(serviceUrl);
zookeeperRegistry.subscribe(anyUrl, new NotifyListener() {
@Override
public void notify(List<URL> urls) {
latch.countDown();
}
});
zookeeperRegistry.subscribe(anyUrl, urls -> latch.countDown());
zookeeperRegistry.register(serviceUrl);
latch.await();
}
}
}