Skip to content

Commit 1ae4c87

Browse files
author
YangSen-qn
committed
change connect check test case
1 parent 80978f3 commit 1ae4c87

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

library/src/androidTest/java/com/qiniu/android/ConnectCheckTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.qiniu.android;
22

33
import com.qiniu.android.http.connectCheck.ConnectChecker;
4+
import com.qiniu.android.storage.GlobalConfiguration;
45

56
public class ConnectCheckTest extends BaseTest {
67

@@ -16,4 +17,30 @@ public void testCheck() {
1617

1718
assertEquals("maxCount:" + maxCount + " successCount:" + successCount, maxCount, successCount);
1819
}
20+
21+
public void testCustomCheckHosts() {
22+
GlobalConfiguration.getInstance().connectCheckURLStrings = new String[]{"https://www.baidu.com"};
23+
int maxCount = 1000;
24+
int successCount = 0;
25+
for (int i = 0; i < maxCount; i++) {
26+
if (ConnectChecker.check()) {
27+
successCount += 1;
28+
}
29+
}
30+
31+
assertEquals("maxCount:" + maxCount + " successCount:" + successCount, maxCount, successCount);
32+
}
33+
34+
public void testNotConnected() {
35+
GlobalConfiguration.getInstance().connectCheckURLStrings = new String[]{"https://www.test1.com", "https://www.test2.com"};
36+
int maxCount = 1000;
37+
int successCount = 0;
38+
for (int i = 0; i < maxCount; i++) {
39+
if (ConnectChecker.check()) {
40+
successCount += 1;
41+
}
42+
}
43+
44+
assertEquals("maxCount:" + maxCount + " successCount:" + successCount, 0, successCount);
45+
}
1946
}

library/src/main/java/com/qiniu/android/http/connectCheck/ConnectChecker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ private static void checkHost(final String host, final CheckCompleteHandler comp
101101
@Override
102102
public void complete(ResponseInfo responseInfo, UploadSingleRequestMetrics metrics, JSONObject response) {
103103
if (responseInfo.statusCode > 99) {
104-
LogUtil.i("== checkHost:" + host + "result: true");
104+
LogUtil.i("== checkHost:" + host + " result: true");
105105
completeHandler.complete(true);
106106
} else {
107-
LogUtil.i("== checkHost:" + host + "result: false");
107+
LogUtil.i("== checkHost:" + host + " result: false");
108108
completeHandler.complete(false);
109109
}
110110
}

0 commit comments

Comments
 (0)