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 CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#Changelog

# 7.6.4
* 修复io异常

# 7.6.3
* 新增表单上传日志打点

Expand Down
19 changes: 19 additions & 0 deletions Qiniu_Android.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="Qiniu_Android" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
<option name="BUILDABLE" value="false" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.qiniu.android;

import android.test.AndroidTestCase;

import com.qiniu.android.bigdata.Configuration;

public class BigDataConfigurationTest extends AndroidTestCase {

public void testCopy(){
Configuration configuration = new Configuration();
configuration.connectTimeout = 15;

Configuration configurationCopy = Configuration.copy(configuration);

assertTrue(configurationCopy.connectTimeout == configuration.connectTimeout);
}

public void testCopyNoValue(){
Configuration configuration = null;

Configuration configurationCopy = Configuration.copy(configuration);

assertTrue(configurationCopy != null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public boolean isCancelled() {
});
runTestOnUiThread(new Runnable() { // THIS IS THE KEY TO SUCCESS
public void run() {
uploadManager.put(tempFile, expectKey, TestConfig.token_z0, new UpCompletionHandler() {
uploadManager.put(tempFile, expectKey, TestConfig.commonToken, new UpCompletionHandler() {
public void complete(String k, ResponseInfo rinfo, JSONObject response) {
temp.expectKey = expectKey;
temp.key = k;
Expand Down Expand Up @@ -179,7 +179,7 @@ public boolean isCancelled() {
});
runTestOnUiThread(new Runnable() { // THIS IS THE KEY TO SUCCESS
public void run() {
uploadManager.put(tempDate, expectKey, TestConfig.token_z0, new UpCompletionHandler() {
uploadManager.put(tempDate, expectKey, TestConfig.commonToken, new UpCompletionHandler() {
public void complete(String k, ResponseInfo rinfo, JSONObject response) {
temp.expectKey = expectKey;
temp.key = k;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.qiniu.android;

import android.test.AndroidTestCase;

import com.qiniu.android.collect.Config;

public class CollectConfigTest extends AndroidTestCase {

public void testQuick(){
Config.quick();
assertTrue(Config.uploadThreshold == 1024);
assertTrue(Config.interval == 2);
}

public void testNormal(){
Config.normal();
assertTrue(Config.uploadThreshold == 4*1024);
assertTrue(Config.interval == 10);
}

public void testSlow(){
Config.slow();
assertTrue(Config.uploadThreshold == 150*1024);
assertTrue(Config.interval == 300);
}
}
29 changes: 29 additions & 0 deletions library/src/androidTest/java/com/qiniu/android/DnsApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

Expand All @@ -39,6 +41,33 @@ public class DnsApiTest extends AndroidTestCase {
@Override
protected void setUp() throws Exception {
configuration = new Configuration.Builder().build();
DnsPrefetcher dnsPrefetcher = DnsPrefetcher.getDnsPrefetcher();
dnsPrefetcher.setToken(TestConfig.commonToken);
}

public void testConcurrentHashMap(){
InetAddress address = null;
try {
address = InetAddress.getByName("127.0.0.1");
} catch (UnknownHostException e) {
e.printStackTrace();
}

if (address == null){
return;
}

List<InetAddress> addressList = new ArrayList<>();
addressList.add(address);

ConcurrentHashMap<String, List<InetAddress>> hashMap = new ConcurrentHashMap<>();
hashMap.put("localhost", addressList);

DnsPrefetcher dnsPrefetcher = DnsPrefetcher.getDnsPrefetcher();
dnsPrefetcher.setConcurrentHashMap(hashMap);

assertTrue(hashMap == dnsPrefetcher.getConcurrentHashMap());

}

public void testDns() throws Throwable {
Expand Down
20 changes: 10 additions & 10 deletions library/src/androidTest/java/com/qiniu/android/FormUploadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ public class FormUploadTest extends InstrumentationTestCase {
public void setUp() throws Exception {
this.uploadManager = new UploadManager();
this.bucketTokenMap = new HashMap<>();
this.bucketTokenMap.put(TestConfig.bucket_z0, TestConfig.token_z0);
this.bucketTokenMap.put(TestConfig.bucket_z1, TestConfig.token_z1);
this.bucketTokenMap.put(TestConfig.bucket_z2, TestConfig.token_z2);
// this.bucketTokenMap.put(TestConfig.bucket_z0, TestConfig.token_z0);
// this.bucketTokenMap.put(TestConfig.bucket_z1, TestConfig.token_z1);
// this.bucketTokenMap.put(TestConfig.bucket_z2, TestConfig.token_z2);
this.bucketTokenMap.put(TestConfig.bucket_na0, TestConfig.token_na0);

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_na0, FixedZone.zoneNa0);
// 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_na0, FixedZone.zoneNa0);


//mock
this.mockBucketZoneMap = new HashMap<>();
this.mockBucketZoneMap.put(TestConfig.bucket_z0, TestConfig.mock_bucket_zone0);
this.mockBucketZoneMap.put(TestConfig.bucket_z1, TestConfig.mock_bucket_zone1);
this.mockBucketZoneMap.put(TestConfig.bucket_z2, TestConfig.mock_bucket_zone2);
// this.mockBucketZoneMap.put(TestConfig.bucket_z0, TestConfig.mock_bucket_zone0);
// this.mockBucketZoneMap.put(TestConfig.bucket_z1, TestConfig.mock_bucket_zone1);
// this.mockBucketZoneMap.put(TestConfig.bucket_z2, TestConfig.mock_bucket_zone2);
this.mockBucketZoneMap.put(TestConfig.bucket_na0, TestConfig.mock_bucket_zoneNa0);

}
Expand Down
55 changes: 55 additions & 0 deletions library/src/androidTest/java/com/qiniu/android/HttpHeaderTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.qiniu.android;
import android.test.AndroidTestCase;

import com.qiniu.android.http.Headers;

import java.util.HashMap;

public class HttpHeaderTest extends AndroidTestCase {

private Headers headers;

@Override
protected void setUp() throws Exception {
super.setUp();

HashMap<String, String> keyVaules = new HashMap<>();
keyVaules.put("date", "2020-07-15 07:40:01");
keyVaules.put("host", "127.0.0.1");
// keyVaules.put("", "illegal key");
headers = Headers.of(keyVaules);
}

public void testValue(){

assertTrue(headers.values("date") != null);
assertTrue(headers.values("host") != null);
}

public void testCount(){

assertTrue(headers.get("host") != null);
assertTrue(headers.values("host") != null);
}

public void testBuilder(){
String dateKey = "date";
String dateValue = "2020-07-15 20:02:30";
String hostKey = "host";
String hostValue = "127.0.0.1";

Headers.Builder builder0 = new Headers.Builder();
builder0.add(dateKey, dateValue);
builder0.add(hostKey + ":" + hostValue);
Headers headers0 = builder0.build();

String host = headers0.get(hostKey);
assertTrue(headers0.get(dateKey).equals(dateValue));
assertTrue(headers0.get(hostKey).equals(hostValue));

Headers.Builder builder1 = new Headers.Builder();
builder1.addAll(headers0);
assertTrue(builder1.get(dateKey).equals(dateValue));

}
}
14 changes: 7 additions & 7 deletions library/src/androidTest/java/com/qiniu/android/HttpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected void setUp() throws Exception {
@SmallTest
public void testPost1() throws Throwable {
httpManager.asyncPost(null,"http://www.baidu.com",
"hello".getBytes(), null, UpToken.parse(TestConfig.token_z0), "hello".getBytes().length,
"hello".getBytes(), null, UpToken.parse(TestConfig.commonToken), "hello".getBytes().length,
null, new CompletionHandler() {
@Override
public void complete(ResponseInfo rinfo, JSONObject response) {
Expand All @@ -70,7 +70,7 @@ public void complete(ResponseInfo rinfo, JSONObject response) {
public void testPost2() throws Throwable {

httpManager.asyncPost(null,"http://up.qiniu.com", "hello".getBytes(), null,
UpToken.parse(TestConfig.token_z0), "hello".getBytes().length,
UpToken.parse(TestConfig.commonToken), "hello".getBytes().length,
null, new CompletionHandler() {
@Override
public void complete(ResponseInfo rinfo, JSONObject response) {
Expand All @@ -93,7 +93,7 @@ public void testPost3() throws Throwable {
runTestOnUiThread(new Runnable() { // THIS IS THE KEY TO SUCCESS
public void run() {
httpManager.asyncPost(null,"http://httpbin.org/status/500", "hello".getBytes(),
null, UpToken.parse(TestConfig.token_z0), "hello".getBytes().length,
null, UpToken.parse(TestConfig.commonToken), "hello".getBytes().length,
null, new CompletionHandler() {
@Override
public void complete(ResponseInfo rinfo, JSONObject response) {
Expand All @@ -120,7 +120,7 @@ public void testPost4() throws Throwable {
public void run() {
httpManager.asyncPost(null,"http://httpbin.org/status/418",
"hello".getBytes(),
null, UpToken.parse(TestConfig.token_z0), "hello".getBytes().length,
null, UpToken.parse(TestConfig.commonToken), "hello".getBytes().length,
null, new CompletionHandler() {
@Override
public void complete(ResponseInfo rinfo, JSONObject response) {
Expand All @@ -145,7 +145,7 @@ public void complete(ResponseInfo rinfo, JSONObject response) {
public void testPostNoDomain() throws Throwable {

httpManager.asyncPost(null,"http://no-domain.qiniu.com", "hello".getBytes(),
null, UpToken.parse(TestConfig.token_z0), "hello".getBytes().length,
null, UpToken.parse(TestConfig.commonToken), "hello".getBytes().length,
null, new CompletionHandler() {
@Override
public void complete(ResponseInfo rinfo, JSONObject response) {
Expand Down Expand Up @@ -195,7 +195,7 @@ public void complete(ResponseInfo rinfo, JSONObject response) {
public void testPostIP() throws Throwable {
StringMap x = new StringMap().put("Host", "up.qiniu.com");
httpManager.asyncPost(null,"http://218.98.28.29", "hello".getBytes(),
x, UpToken.parse(TestConfig.token_z0), "hello".getBytes().length,
x, UpToken.parse(TestConfig.commonToken), "hello".getBytes().length,
null, new CompletionHandler() {
@Override
public void complete(ResponseInfo rinfo, JSONObject response) {
Expand All @@ -220,7 +220,7 @@ public void testProxy() throws Throwable {
ProxyConfiguration p = new ProxyConfiguration("115.238.101.32", 80);
Client c = new Client(p, 10, 30, null, null);
c.asyncPost(null,"http://upproxy1.qiniu.com", "hello".getBytes(),
x, UpToken.parse(TestConfig.token_z0), "hello".getBytes().length,
x, UpToken.parse(TestConfig.commonToken), "hello".getBytes().length,
null, new CompletionHandler() {
@Override
public void complete(ResponseInfo rinfo, JSONObject response) {
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 @@ -41,7 +41,7 @@ protected void setUp() throws Exception {
@SmallTest
public void testPost1() throws Throwable {
httpManager.asyncPost(null,"https://www.baidu.com/", "hello".getBytes(), null,
UpToken.parse(TestConfig.token_z0), "hello".getBytes().length, null, new CompletionHandler() {
UpToken.parse(TestConfig.commonToken), "hello".getBytes().length, null, new CompletionHandler() {
@Override
public void complete(ResponseInfo rinfo, JSONObject response) {
Log.d("qiniutest", rinfo.toString());
Expand All @@ -62,7 +62,7 @@ public void complete(ResponseInfo rinfo, JSONObject response) {
@SmallTest
public void testPost2() throws Throwable {
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,
"hello".getBytes(), null, UpToken.parse(TestConfig.commonToken), "hello".getBytes().length,
null, new CompletionHandler() {
@Override
public void complete(ResponseInfo rinfo, JSONObject response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private void template(int size) throws Throwable {
final UploadOptions options = getUploadOptions();
runTestOnUiThread(new Runnable() { // THIS IS THE KEY TO SUCCESS
public void run() {
uploadManager.put(f, expectKey, TestConfig.token_z0, new UpCompletionHandler() {
uploadManager.put(f, expectKey, TestConfig.commonToken, new UpCompletionHandler() {
public void complete(String k, ResponseInfo rinfo, JSONObject response) {
Log.i("qiniutest", k + rinfo);
key = k;
Expand Down Expand Up @@ -138,7 +138,7 @@ private void template2(int size) throws Throwable {
.build();
UploadManager uploadManager2 = new UploadManager(c);
final UploadOptions options = getUploadOptions();
uploadManager2.put(f, expectKey, TestConfig.token_z0, new UpCompletionHandler() {
uploadManager2.put(f, expectKey, TestConfig.commonToken, new UpCompletionHandler() {
public void complete(String k, ResponseInfo rinfo, JSONObject response) {
Log.i("qiniutest", k + rinfo);
key = k;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void testHello() throws Throwable {
params.put("x:foo", "fooval");
final UploadOptions opt = new UploadOptions(params, null, true, null, null);
byte[] b = "hello".getBytes();
info = uploadManager.syncPut(b, expectKey, TestConfig.token_z0, opt);
info = uploadManager.syncPut(b, expectKey, TestConfig.commonToken, opt);
resp = info.response;

// Assert.assertTrue(info.toString(), info.isOK());
Expand All @@ -55,7 +55,7 @@ public void test0Data() throws Throwable {
params.put("x:foo", "fooval");
final UploadOptions opt = new UploadOptions(params, null, true, null, null);

info = uploadManager.syncPut("".getBytes(), expectKey, TestConfig.token_z0, opt);
info = uploadManager.syncPut("".getBytes(), expectKey, TestConfig.commonToken, opt);
resp = info.response;

// key = resp.optString("key");
Expand All @@ -72,7 +72,7 @@ public void testNoKey() throws Throwable {
Map<String, String> params = new HashMap<String, String>();
params.put("x:foo", "fooval");
final UploadOptions opt = new UploadOptions(params, null, true, null, null);
info = uploadManager.syncPut("hello".getBytes(), expectKey, TestConfig.token_z0, opt);
info = uploadManager.syncPut("hello".getBytes(), expectKey, TestConfig.commonToken, opt);

resp = info.response;
// key = resp.optString("key");
Expand Down Expand Up @@ -136,7 +136,7 @@ public void testFile() throws Throwable {
Map<String, String> params = new HashMap<String, String>();
params.put("x:foo", "fooval");
final UploadOptions opt = new UploadOptions(params, null, true, null, null);
info = uploadManager.syncPut(f, expectKey, TestConfig.token_z0, opt);
info = uploadManager.syncPut(f, expectKey, TestConfig.commonToken, opt);

resp = info.response;
// key = resp.optString("key");
Expand All @@ -158,7 +158,7 @@ public void test0File() throws Throwable {
Map<String, String> params = new HashMap<String, String>();
params.put("x:foo", "fooval");
final UploadOptions opt = new UploadOptions(params, null, true, null, null);
info = uploadManager.syncPut(f, expectKey, TestConfig.token_z0, opt);
info = uploadManager.syncPut(f, expectKey, TestConfig.commonToken, opt);

resp = info.response;
Assert.assertEquals(f.toString(), 0, f.length());
Expand All @@ -171,10 +171,10 @@ public void test0File() throws Throwable {

@SmallTest
public void test0byte() {
info = uploadManager.syncPut(new byte[0], null, TestConfig.token_z0, null);
info = uploadManager.syncPut(new byte[0], null, TestConfig.commonToken, null);
Assert.assertEquals(info.toString(), ResponseInfo.ZeroSizeFile, info.statusCode);

info = uploadManager.syncPut("", null, TestConfig.token_z0, null);
info = uploadManager.syncPut("", null, TestConfig.commonToken, null);
Assert.assertEquals(info.toString(), ResponseInfo.ZeroSizeFile, info.statusCode);
}

Expand All @@ -192,7 +192,7 @@ public void testHttps() throws Throwable {
.useHttps(true)
.build();
UploadManager uploadManager2 = new UploadManager(c);
info = uploadManager2.syncPut("hello".getBytes(), expectKey, TestConfig.token_z0, opt);
info = uploadManager2.syncPut("hello".getBytes(), expectKey, TestConfig.commonToken, opt);

resp = info.response;
// key = resp.optString("key");
Expand Down
Loading