File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed
androidTest/java/com/qiniu/android
main/java/com/qiniu/android/http/dns Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 2222public 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 () {
You can’t perform that action at this time.
0 commit comments