Skip to content
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
3 changes: 3 additions & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ int code = versionNameToCode(version)
android {
compileSdkVersion 29
buildToolsVersion '29.0.2'
aaptOptions.cruncherEnabled = false
aaptOptions.useNewCruncher = false
defaultConfig {
//applicationId "com.qiniu.android"
minSdkVersion 18
Expand All @@ -40,6 +42,7 @@ android {

}


lintOptions {
warning 'InvalidPackage'
}
Expand Down
2 changes: 1 addition & 1 deletion library/library.iml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res;file://$MODULE_DIR$/build/generated/res/resValues/debug" />
<option name="TEST_RES_FOLDERS_RELATIVE_PATH" value="" />
<option name="TEST_RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" />
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
<option name="PROJECT_TYPE" value="1" />
</configuration>
Expand Down
100 changes: 20 additions & 80 deletions library/src/androidTest/java/com/qiniu/android/DnsApiTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.qiniu.android;


import android.test.AndroidTestCase;
import android.test.InstrumentationTestCase;
import android.util.Log;

Expand Down Expand Up @@ -32,15 +33,21 @@
* Created by jemy on 2019/8/20.
*/

public class DnsApiTest extends InstrumentationTestCase {
public class DnsApiTest extends AndroidTestCase {
private Configuration configuration = null;

@Override
protected void setUp() throws Exception {
configuration = new Configuration.Builder().build();
}

public void testDns() throws Throwable {
List<InetAddress> inetAddresses = null;
DnsPrefetcher dnsPrefetcher;
// try {
// inetAddresses = DnsPrefetcher.getDnsBySystem().lookup("upload.qiniup.com");
// } catch (UnknownHostException e) {
// e.printStackTrace();
// }
try {
inetAddresses = okhttp3.Dns.SYSTEM.lookup("upload.qiniup.com");
} catch (UnknownHostException e) {
e.printStackTrace();
}
Log.e("qiniutest", "InetAddress: " + inetAddresses.size());
//超耗时过程
// for (int i = 0; i < inetAddresses.size(); i++) {
Expand All @@ -58,7 +65,7 @@ public void testQueryDomain() {

DnsPrefetcher dnsPrefetcher = DnsPrefetcher.getDnsPrefetcher();
try {
info = dnsPrefetcher.init(TestConfig.uptoken_prefetch).getPreQueryZone();
info = dnsPrefetcher.init(TestConfig.uptoken_prefetch, configuration).getPreQueryZone();
} catch (UnknownHostException e) {
e.printStackTrace();
}
Expand All @@ -74,7 +81,7 @@ public void testLocalDomain() {
List<ZoneInfo> info = null;
DnsPrefetcher dnsPrefetcher = DnsPrefetcher.getDnsPrefetcher();
try {
info = dnsPrefetcher.init(TestConfig.uptoken_prefetch).getLocalZone();
info = dnsPrefetcher.init(TestConfig.uptoken_prefetch, configuration).getLocalZone();
} catch (UnknownHostException e) {
e.printStackTrace();
}
Expand All @@ -93,31 +100,6 @@ public void testLocalIp() {
Log.e("qiniutest", s);
}

public void testDnsPreAndcache() {
Configuration config = new Configuration.Builder().build();
boolean needPrefetch = DnsPrefetcher.checkRePrefetchDns(TestConfig.uptoken_prefetch, config);
Log.e("qiniutest", "check:" + needPrefetch);
if (needPrefetch) {
DnsPrefetcher.startPrefetchDns(TestConfig.uptoken_prefetch, config);
} else {
testRecoverCache();
return;
}
//预取或者recover success
List<String> list = DnsPrefetcher.getDnsPrefetcher().getHosts();
ConcurrentHashMap<String, List<InetAddress>> map = DnsPrefetcher.getDnsPrefetcher().getConcurrentHashMap();
Log.e("qiniutest: ", "list size: " + list.size());
for (String s : list) {
Log.e("qiniutest: ", "uphost: " + s);
List<InetAddress> list1 = map.get(s);
for (InetAddress inetAddress :
list1) {
Log.e("qiniutest: ", "ip: " + inetAddress.getHostAddress());
}
}

}

//test recover
public void testRecoverCache() {

Expand All @@ -126,6 +108,7 @@ public void testRecoverCache() {
recorder = new DnsCacheFile(Config.dnscacheDir);
} catch (IOException e) {
e.printStackTrace();
return;
}
String fileName = recorder.getFileName();
if (fileName == null) {
Expand All @@ -141,9 +124,9 @@ public void testRecoverCache() {


ConcurrentHashMap<String, List<InetAddress>> map1 = DnsPrefetcher.getDnsPrefetcher().getConcurrentHashMap();
List<String> list = DnsPrefetcher.getDnsPrefetcher().getHosts();
Log.e("qiniutest: ", "size for cache: " + list.size());
for (String s : list) {
if (map1.size() <= 0)
return;
for (String s : map1.keySet()) {
Log.e("qiniutest: ", "uphost for cache: " + s);
List<InetAddress> list1 = map1.get(s);
for (InetAddress inetAddress :
Expand All @@ -156,49 +139,6 @@ public void testRecoverCache() {
int time = 0;
final Object lock = new Object();

public void testAtomic() {
final int size = 6 * 1024;
for (int i = 0; i < 3; i++) {
new Thread(new Runnable() {
@Override
public void run() {
try {
Configuration config = new Configuration.Builder().build();
final UploadManager uploadManager = new UploadManager(config, 3);
final String expectKey = "r=" + size + "k";
final File f;
f = TempFile.createFile(size);
final UploadOptions uploadoption = new UploadOptions(null, null, false, new UpProgressHandler() {
public void progress(String key, double percent) {
Log.e("qiniutest", percent + "");
}
}, null);

uploadManager.put(f, expectKey, TestConfig.token_z0, new UpCompletionHandler() {
public void complete(String k, ResponseInfo rinfo, JSONObject response) {
Log.e("qiniutest", k + rinfo);
time += 1;
if (time == 3) {
lock.notify();
}
}
}, uploadoption);


} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
synchronized (lock) {
try {
lock.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

public void testSerializable() {
DnsCacheKey key = new DnsCacheKey("12321", "127.0.0.1", "akscope");
Expand Down
44 changes: 10 additions & 34 deletions library/src/androidTest/java/com/qiniu/android/FormUploadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void setUp() throws Exception {
this.bucketZoneMap = new HashMap<>();
//this.bucketZoneMap.put(TestConfig.bucket_z0, FixedZone.zone0);
this.bucketZoneMap.put(TestConfig.bucket_z1, FixedZone.zone1);
//this.bucketZoneMap.put(TestConfig.bucket_z2, FixedZone.zone2);
this.bucketZoneMap.put(TestConfig.bucket_z2, FixedZone.zone2);
//this.bucketZoneMap.put(TestConfig.bucket_na0, FixedZone.zoneNa0);


Expand All @@ -60,13 +60,9 @@ public void setUp() throws Exception {
*/
@SmallTest
public void testPutBytesWithAutoZone() throws Throwable {
//params
Map<String, String> params = new HashMap<String, String>();
params.put("x:foo", "foo");
params.put("x:bar", "bar");
//mime type
final String mimeType = "text/plain";
final UploadOptions options = new UploadOptions(params, mimeType, true, null, null);
final UploadOptions options = new UploadOptions(null, mimeType, true, null, null);
byte[] putData = "hello qiniu cloud storage".getBytes();

for (Map.Entry<String, String> bucketToken : this.bucketTokenMap.entrySet()) {
Expand All @@ -92,13 +88,9 @@ public void complete(String key, ResponseInfo info, JSONObject response) {
///////////////固定Zone测试/////////////////
@SmallTest
public void testPutBytesWithFixedZone() {
//params
Map<String, String> params = new HashMap<String, String>();
params.put("x:foo", "foo");
params.put("x:bar", "bar");
//mime type
final String mimeType = "text/plain";
final UploadOptions options = new UploadOptions(params, mimeType, true, null, null);
final UploadOptions options = new UploadOptions(null, mimeType, true, null, null);
byte[] putData = "hello qiniu cloud storage".getBytes();

for (Map.Entry<String, Zone> bucketZone : this.bucketZoneMap.entrySet()) {
Expand Down Expand Up @@ -134,14 +126,8 @@ public void complete(String key, ResponseInfo info, JSONObject response) {
try {
Assert.assertEquals("Qiniu.TestPutBytes upload failed", expectKey,
responseBody.getString("key"));
Assert.assertEquals("Qiniu.TestPutBytes mimetype failed", mimeType,
responseBody.getString("mimeType"));
Assert.assertEquals("Qiniu.TestPutBytes optional params x:foo failed", "foo",
responseBody.getString("foo"));
Assert.assertEquals("Qiniu.TestPutBytes optional params x:bar failed", "bar",
responseBody.getString("bar"));
} catch (Exception ex) {
Assert.fail("Qiniu.TestPutBytes " + ex.getMessage());

}
}
}
Expand All @@ -150,20 +136,18 @@ public void complete(String key, ResponseInfo info, JSONObject response) {
/////模拟域名失败后,再重试的场景,需要手动修改zone域名无效来模拟/////
@SmallTest
public void testPutBytesWithFixedZoneUseBackupDomains() {
//params
Map<String, String> params = new HashMap<String, String>();
params.put("x:foo", "foo");
params.put("x:bar", "bar");
//have changed old code , because token policy been changed
//mime type
final String mimeType = "text/plain";
final UploadOptions options = new UploadOptions(params, mimeType, true, null, null);
final UploadOptions options = new UploadOptions(null, mimeType, true, null, null);
byte[] putData = "hello qiniu cloud storage".getBytes();

for (Map.Entry<String, Zone> bucketZone : this.mockBucketZoneMap.entrySet()) {
final CountDownLatch signal = new CountDownLatch(1);
final String bucket = bucketZone.getKey();
final Zone zone = bucketZone.getValue();
final String upToken = this.bucketTokenMap.get(bucket);
Log.e("qiniutest",upToken);

final String expectKey = String.format("androidsdk/%s/qiniu_put_bytes_test.txt", bucket);

Expand All @@ -188,21 +172,17 @@ public void complete(String key, ResponseInfo info, JSONObject response) {
} catch (Exception ex) {
Assert.fail("Qiniu.TestPutBytes timeout");
}

Assert.assertNull(responseBody);
}

//retry will success
for (Map.Entry<String, Zone> bucketZone : this.mockBucketZoneMap.entrySet()) {
final CountDownLatch signal = new CountDownLatch(1);
final String bucket = bucketZone.getKey();
final Zone zone = bucketZone.getValue();
final String upToken = this.bucketTokenMap.get(bucket);

Log.e("qiniutest","retry:"+upToken);
final String expectKey = String.format("androidsdk/%s/qiniu_put_bytes_test.txt", bucket);

Configuration cfg = new Configuration.Builder()
.zone(zone)
.useHttps(false)
.build();
UploadManager uploadManagerWithCfg = new UploadManager(cfg);
Expand All @@ -212,6 +192,7 @@ public void complete(String key, ResponseInfo info, JSONObject response) {
Log.d("Qiniu.TestPutBytes", info.toString());

responseBody = response;
Log.e("qiniutest","responseBody:"+responseBody.toString());
signal.countDown();

}
Expand All @@ -224,14 +205,9 @@ public void complete(String key, ResponseInfo info, JSONObject response) {
}

try {
Log.e("qiniutest",responseBody.toString());
Assert.assertEquals("Qiniu.TestPutBytes upload failed", expectKey,
responseBody.getString("key"));
Assert.assertEquals("Qiniu.TestPutBytes mimetype failed", mimeType,
responseBody.getString("mimeType"));
Assert.assertEquals("Qiniu.TestPutBytes optional params x:foo failed", "foo",
responseBody.getString("foo"));
Assert.assertEquals("Qiniu.TestPutBytes optional params x:bar failed", "bar",
responseBody.getString("bar"));
} catch (Exception ex) {
Assert.fail("Qiniu.TestPutBytes " + ex.getMessage());
}
Expand Down
6 changes: 5 additions & 1 deletion library/src/androidTest/java/com/qiniu/android/HttpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,14 @@ public void complete(ResponseInfo rinfo, JSONObject response) {
// ResponseInfo.TimedOut == info.statusCode);
// }

/**
* 不同节点解析出来的ip不一样,所以这里是可能报错的 400 or 404
* @throws Throwable
*/
@SmallTest
public void testPostIP() throws Throwable {
StringMap x = new StringMap().put("Host", "up.qiniu.com");
httpManager.asyncPost(null,"http://183.131.7.18", "hello".getBytes(),
httpManager.asyncPost(null,"http://218.98.28.29", "hello".getBytes(),
x, UpToken.parse(TestConfig.token_z0), "hello".getBytes().length,
null, new CompletionHandler() {
@Override
Expand Down
4 changes: 2 additions & 2 deletions library/src/androidTest/java/com/qiniu/android/HttpsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected void setUp() throws Exception {

@SmallTest
public void testPost1() throws Throwable {
httpManager.asyncPost("https://www.baidu.com/", "hello".getBytes(), null,
httpManager.asyncPost(null,"https://www.baidu.com/", "hello".getBytes(), null,
UpToken.parse(TestConfig.token_z0), "hello".getBytes().length, null, new CompletionHandler() {
@Override
public void complete(ResponseInfo rinfo, JSONObject response) {
Expand All @@ -61,7 +61,7 @@ public void complete(ResponseInfo rinfo, JSONObject response) {

@SmallTest
public void testPost2() throws Throwable {
httpManager.asyncPost("https://static-fw.qbox.me/public/v28812/add-on/ga/analytics.js",
httpManager.asyncPost(null,"https://static-fw.qbox.me/public/v28812/add-on/ga/analytics.js",
"hello".getBytes(), null, UpToken.parse(TestConfig.token_z0), "hello".getBytes().length,
null, new CompletionHandler() {
@Override
Expand Down
Loading