Skip to content

Commit d3f06b2

Browse files
author
YangSen-qn
committed
add test case
1 parent a302089 commit d3f06b2

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.qiniu.android;
2+
3+
import com.qiniu.android.http.dns.IDnsNetworkAddress;
4+
import com.qiniu.android.http.dns.SystemDns;
5+
import com.qiniu.android.utils.Utils;
6+
7+
import java.net.UnknownHostException;
8+
import java.util.List;
9+
10+
public class SystemDnsTest extends BaseTest {
11+
12+
public void testDnsLookup() {
13+
SystemDns dns = new SystemDns(5);
14+
try {
15+
List<IDnsNetworkAddress> result = dns.lookup("upload.qiniup.com");
16+
assertTrue("testDnsLookup fail:", result != null && result.size() == 0);
17+
} catch (UnknownHostException e) {
18+
e.printStackTrace();
19+
fail("testDnsLookup fail because:" + e.getMessage());
20+
}
21+
}
22+
23+
public void testDnsTimeout() {
24+
long start = Utils.currentSecondTimestamp();
25+
int timeout = 5;
26+
SystemDns dns = new SystemDns(timeout);
27+
try {
28+
List<IDnsNetworkAddress> result = dns.lookup("a.a.a.cn");
29+
assertTrue("testDnsTimeout fail:", result == null || result.size() == 0);
30+
} catch (UnknownHostException e) {
31+
e.printStackTrace();
32+
}
33+
long end = Utils.currentSecondTimestamp();
34+
assertTrue("testDnsTimeout fail because timeout to long", end <= (start + timeout + 1));
35+
}
36+
}

library/src/main/java/com/qiniu/android/http/dns/SystemDns.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
public class SystemDns implements Dns {
2323

2424
private int timeout = 10;
25-
private final ExecutorService executor = new ThreadPoolExecutor(1, 3,
25+
private static final ExecutorService executor = new ThreadPoolExecutor(1, 3,
2626
60L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
2727

2828
public SystemDns() {

0 commit comments

Comments
 (0)