Skip to content

Commit

Permalink
remove duplicated unused method and move unit test (#3446)
Browse files Browse the repository at this point in the history
  • Loading branch information
kezhenxu94 authored and beiwei30 committed Feb 11, 2019
1 parent bccac78 commit ba282a8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 31 deletions.
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();
}
}
}

0 comments on commit ba282a8

Please sign in to comment.