From 1efc766bef265db530e272be026fcd3308f7b445 Mon Sep 17 00:00:00 2001 From: yangsen Date: Fri, 17 Jul 2020 10:56:10 +0800 Subject: [PATCH 1/6] change CHANGLOG --- CHANGELOG.md | 3 +++ Qiniu_Android.iml | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 Qiniu_Android.iml diff --git a/CHANGELOG.md b/CHANGELOG.md index fcbcf5674..7ecf1eea0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ #Changelog +# 7.6.4 +* 修复io异常 + # 7.6.3 * 新增表单上传日志打点 diff --git a/Qiniu_Android.iml b/Qiniu_Android.iml new file mode 100644 index 000000000..ed0e1f40b --- /dev/null +++ b/Qiniu_Android.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file From 56a55b12b0b7d5d1c78e599f4257fe2f74055170 Mon Sep 17 00:00:00 2001 From: yangsen Date: Fri, 17 Jul 2020 11:37:45 +0800 Subject: [PATCH 2/6] change test token --- .../androidTest/java/com/qiniu/android/TestConfig.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/src/androidTest/java/com/qiniu/android/TestConfig.java b/library/src/androidTest/java/com/qiniu/android/TestConfig.java index 2b5c4ff98..95c42ecff 100644 --- a/library/src/androidTest/java/com/qiniu/android/TestConfig.java +++ b/library/src/androidTest/java/com/qiniu/android/TestConfig.java @@ -10,16 +10,16 @@ public final class TestConfig { // TODO: 2020-05-09 bad token for testPutBytesWithFixedZoneUseBackupDomains //华东上传凭证 public static final String bucket_z0 = "sdk-z0"; - public static final String token_z0 = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW:WYvuul25V_gUskDyy16eTI9KH_Y=:eyJzY29wZSI6Ind4YXBwdGVzdCIsImRlYWRsaW5lIjoxNTk0MjI0NzYyfQ=="; + public static final String token_z0 = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW:IZ8N6Jv2-gA6VrhungRGcSBmyV0=:eyJzY29wZSI6InNkay16MCIsImRlYWRsaW5lIjoxNTk0OTYwMzM1fQ=="; //华北上传凭证 public static final String bucket_z1 = "sdk-z1"; - public static final String token_z1 = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW:WYvuul25V_gUskDyy16eTI9KH_Y=:eyJzY29wZSI6Ind4YXBwdGVzdCIsImRlYWRsaW5lIjoxNTk0MjI0NzYyfQ=="; + public static final String token_z1 = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW:PjJNSsN-AvAWn_n8chAp-iwa8Ow=:eyJzY29wZSI6InNkay16MSIsImRlYWRsaW5lIjoxNTk0OTYwNDkwfQ=="; //华南上传凭证 public static final String bucket_z2 = "sdk-z2"; - public static final String token_z2 = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW:WYvuul25V_gUskDyy16eTI9KH_Y=:eyJzY29wZSI6Ind4YXBwdGVzdCIsImRlYWRsaW5lIjoxNTk0MjI0NzYyfQ=="; + public static final String token_z2 = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW:1knh1KVGogeVzfTx4KrGP_LLpt4=:eyJzY29wZSI6InNkay16MiIsImRlYWRsaW5lIjoxNTk0OTYwNTEzfQ=="; //北美上传凭证 public static final String bucket_na0 = "sdk-na0"; - public static final String token_na0 = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW:WYvuul25V_gUskDyy16eTI9KH_Y=:eyJzY29wZSI6Ind4YXBwdGVzdCIsImRlYWRsaW5lIjoxNTk0MjI0NzYyfQ=="; + public static final String token_na0 = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW:_sV0_8jdhJblnifDwzrBKbeBCQs=:eyJzY29wZSI6InNkay1uYTAiLCJkZWFkbGluZSI6MTU5NDk2MDU0M30="; public static final String ak = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW"; //dns prefetch token From a764e20da8bc3a1b896f83b99ab7a72257d3e31c Mon Sep 17 00:00:00 2001 From: yangsen Date: Fri, 17 Jul 2020 15:50:07 +0800 Subject: [PATCH 3/6] change test token --- .../androidTest/java/com/qiniu/android/TestConfig.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/src/androidTest/java/com/qiniu/android/TestConfig.java b/library/src/androidTest/java/com/qiniu/android/TestConfig.java index 95c42ecff..ae68cca3d 100644 --- a/library/src/androidTest/java/com/qiniu/android/TestConfig.java +++ b/library/src/androidTest/java/com/qiniu/android/TestConfig.java @@ -10,16 +10,16 @@ public final class TestConfig { // TODO: 2020-05-09 bad token for testPutBytesWithFixedZoneUseBackupDomains //华东上传凭证 public static final String bucket_z0 = "sdk-z0"; - public static final String token_z0 = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW:IZ8N6Jv2-gA6VrhungRGcSBmyV0=:eyJzY29wZSI6InNkay16MCIsImRlYWRsaW5lIjoxNTk0OTYwMzM1fQ=="; + public static final String token_z0 = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW:7MhcqtMD-_D1ADDRkMA1w0okmlE=:eyJzY29wZSI6InNkay16MCIsImRlYWRsaW5lIjoxNTk1MDU4MzEyfQ=="; //华北上传凭证 public static final String bucket_z1 = "sdk-z1"; - public static final String token_z1 = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW:PjJNSsN-AvAWn_n8chAp-iwa8Ow=:eyJzY29wZSI6InNkay16MSIsImRlYWRsaW5lIjoxNTk0OTYwNDkwfQ=="; + public static final String token_z1 = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW:R3WxmBCVotZkVoI0NNZgNDEqcTY=:eyJzY29wZSI6InNkay16MSIsImRlYWRsaW5lIjoxNTk1MDU4MzUwfQ=="; //华南上传凭证 public static final String bucket_z2 = "sdk-z2"; - public static final String token_z2 = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW:1knh1KVGogeVzfTx4KrGP_LLpt4=:eyJzY29wZSI6InNkay16MiIsImRlYWRsaW5lIjoxNTk0OTYwNTEzfQ=="; + public static final String token_z2 = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW:S9V-5ttyKKfzH59Ncs7wooEOpc4=:eyJzY29wZSI6InNkay16MiIsImRlYWRsaW5lIjoxNTk1MDU4MzY0fQ=="; //北美上传凭证 public static final String bucket_na0 = "sdk-na0"; - public static final String token_na0 = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW:_sV0_8jdhJblnifDwzrBKbeBCQs=:eyJzY29wZSI6InNkay1uYTAiLCJkZWFkbGluZSI6MTU5NDk2MDU0M30="; + public static final String token_na0 = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW:K-4seSpuZ1XivgHK_VrZVt4z5Pw=:eyJzY29wZSI6InNkay1uYTAiLCJkZWFkbGluZSI6MTU5NTA1ODM4NX0="; public static final String ak = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW"; //dns prefetch token From c2259dd558c4ac6959cd3211f77eb80b92063220 Mon Sep 17 00:00:00 2001 From: yangsen Date: Fri, 17 Jul 2020 18:07:44 +0800 Subject: [PATCH 4/6] change auto zone test case --- .../androidTest/java/com/qiniu/android/common/AutoZoneTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/src/androidTest/java/com/qiniu/android/common/AutoZoneTest.java b/library/src/androidTest/java/com/qiniu/android/common/AutoZoneTest.java index 2ccc04175..c508dbf7f 100644 --- a/library/src/androidTest/java/com/qiniu/android/common/AutoZoneTest.java +++ b/library/src/androidTest/java/com/qiniu/android/common/AutoZoneTest.java @@ -80,7 +80,7 @@ public void onSuccess() { @Override public void onFailure(int reason) { countDownLatch.countDown(); - fail(); + fail(reason + ""); } }); try { From ac4c2547650945a6966c2d9d1ee42a8141f0191b Mon Sep 17 00:00:00 2001 From: yangsen Date: Mon, 20 Jul 2020 14:11:38 +0800 Subject: [PATCH 5/6] handle some case --- .../android/BigDataConfigurationTest.java | 25 +++++++++ .../com/qiniu/android/CollectConfigTest.java | 26 +++++++++ .../java/com/qiniu/android/DnsApiTest.java | 29 ++++++++++ .../com/qiniu/android/HttpHeaderTest.java | 55 +++++++++++++++++++ .../java/com/qiniu/android/TestConfig.java | 4 ++ .../qiniu/android/common/AutoZoneTest.java | 17 ++++-- .../com/qiniu/android/collect/Config.java | 4 +- .../storage/persistent/DnsCacheFile.java | 2 +- 8 files changed, 155 insertions(+), 7 deletions(-) create mode 100644 library/src/androidTest/java/com/qiniu/android/BigDataConfigurationTest.java create mode 100644 library/src/androidTest/java/com/qiniu/android/CollectConfigTest.java create mode 100644 library/src/androidTest/java/com/qiniu/android/HttpHeaderTest.java diff --git a/library/src/androidTest/java/com/qiniu/android/BigDataConfigurationTest.java b/library/src/androidTest/java/com/qiniu/android/BigDataConfigurationTest.java new file mode 100644 index 000000000..d1410e9c1 --- /dev/null +++ b/library/src/androidTest/java/com/qiniu/android/BigDataConfigurationTest.java @@ -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); + } +} diff --git a/library/src/androidTest/java/com/qiniu/android/CollectConfigTest.java b/library/src/androidTest/java/com/qiniu/android/CollectConfigTest.java new file mode 100644 index 000000000..b8d5e75db --- /dev/null +++ b/library/src/androidTest/java/com/qiniu/android/CollectConfigTest.java @@ -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); + } +} diff --git a/library/src/androidTest/java/com/qiniu/android/DnsApiTest.java b/library/src/androidTest/java/com/qiniu/android/DnsApiTest.java index eae8abd84..d6f91e368 100644 --- a/library/src/androidTest/java/com/qiniu/android/DnsApiTest.java +++ b/library/src/androidTest/java/com/qiniu/android/DnsApiTest.java @@ -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; @@ -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 addressList = new ArrayList<>(); + addressList.add(address); + + ConcurrentHashMap> hashMap = new ConcurrentHashMap<>(); + hashMap.put("localhost", addressList); + + DnsPrefetcher dnsPrefetcher = DnsPrefetcher.getDnsPrefetcher(); + dnsPrefetcher.setConcurrentHashMap(hashMap); + + assertTrue(hashMap == dnsPrefetcher.getConcurrentHashMap()); + } public void testDns() throws Throwable { diff --git a/library/src/androidTest/java/com/qiniu/android/HttpHeaderTest.java b/library/src/androidTest/java/com/qiniu/android/HttpHeaderTest.java new file mode 100644 index 000000000..101fb8a58 --- /dev/null +++ b/library/src/androidTest/java/com/qiniu/android/HttpHeaderTest.java @@ -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 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.getDate("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)); + + } +} diff --git a/library/src/androidTest/java/com/qiniu/android/TestConfig.java b/library/src/androidTest/java/com/qiniu/android/TestConfig.java index ae68cca3d..9414af78c 100644 --- a/library/src/androidTest/java/com/qiniu/android/TestConfig.java +++ b/library/src/androidTest/java/com/qiniu/android/TestConfig.java @@ -22,6 +22,10 @@ public final class TestConfig { public static final String token_na0 = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW:K-4seSpuZ1XivgHK_VrZVt4z5Pw=:eyJzY29wZSI6InNkay1uYTAiLCJkZWFkbGluZSI6MTU5NTA1ODM4NX0="; public static final String ak = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW"; + + //测试通用的token + public static final String commonToken = token_na0; + //dns prefetch token public static final String uptoken_prefetch = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW:WYvuul25V_gUskDyy16eTI9KH_Y=:eyJzY29wZSI6Ind4YXBwdGVzdCIsImRlYWRsaW5lIjoxNTk0MjI0NzYyfQ=="; diff --git a/library/src/androidTest/java/com/qiniu/android/common/AutoZoneTest.java b/library/src/androidTest/java/com/qiniu/android/common/AutoZoneTest.java index c508dbf7f..3a8ce7cf2 100644 --- a/library/src/androidTest/java/com/qiniu/android/common/AutoZoneTest.java +++ b/library/src/androidTest/java/com/qiniu/android/common/AutoZoneTest.java @@ -45,11 +45,11 @@ public class AutoZoneTest extends AndroidTestCase { //// assertTrue(zoneInfo.upDomainsList.contains("upload-nb.qiniup.com")); // } -// public void testHttpFail() { -// AutoZone zone = new AutoZone(); -// ZoneInfo zoneInfo = zone.zoneInfo(ak + "_not_be_ak", bkt); -// assertNull(zoneInfo); -// } + public void testHttpFail() { + AutoZone zone = new AutoZone(); + ZoneInfo zoneInfo = zone.zoneInfo(ak + "_not_be_ak", bkt); + assertNull(zoneInfo); + } // public void testSplitE() { // String s1 = "bkt:key"; @@ -57,6 +57,13 @@ public class AutoZoneTest extends AndroidTestCase { // Assert.assertEquals(s1.split(":")[0], s2.split(":")[0]); // } + public void testUCServer(){ + String ucServer = "ucserver.test"; + AutoZone autoZone = new AutoZone(); + autoZone.setUcServer(ucServer); + assertTrue(autoZone.getUcServer() == ucServer); + } + public void testC1() { AutoZone autoZone = new AutoZone(); final CountDownLatch countDownLatch = new CountDownLatch(1); diff --git a/library/src/main/java/com/qiniu/android/collect/Config.java b/library/src/main/java/com/qiniu/android/collect/Config.java index 1bca25475..b5004ec1e 100644 --- a/library/src/main/java/com/qiniu/android/collect/Config.java +++ b/library/src/main/java/com/qiniu/android/collect/Config.java @@ -4,6 +4,8 @@ import com.qiniu.android.utils.ContextGetter; +import java.io.File; + /** * Created by Simon on 11/22/16. */ @@ -76,7 +78,7 @@ public final class Config { /** * dns缓存信息目录 */ - public static String dnscacheDir = Environment.getExternalStorageDirectory() + "/dnschache/"; + public static String dnscacheDir = Environment.getExternalStorageDirectory() + File.separator + "dnschache" + File.separator; /** * preQuery host diff --git a/library/src/main/java/com/qiniu/android/storage/persistent/DnsCacheFile.java b/library/src/main/java/com/qiniu/android/storage/persistent/DnsCacheFile.java index abd388eaf..7d0254972 100644 --- a/library/src/main/java/com/qiniu/android/storage/persistent/DnsCacheFile.java +++ b/library/src/main/java/com/qiniu/android/storage/persistent/DnsCacheFile.java @@ -20,7 +20,7 @@ public class DnsCacheFile implements Recorder { public DnsCacheFile(String directory) throws IOException { this.directory = directory; f = new File(directory); - if (!f.exists()) { + if (f.isDirectory() || !f.exists()) { boolean r = f.mkdirs(); if (!r) { throw new IOException("mkdir failed"); From d4c52ea88e39eb25d1605b508dda11ab2c98b34f Mon Sep 17 00:00:00 2001 From: yangsen Date: Mon, 20 Jul 2020 14:59:42 +0800 Subject: [PATCH 6/6] change token --- .../java/com/qiniu/android/CancelTest.java | 4 ++-- .../com/qiniu/android/FormUploadTest.java | 20 +++++++++---------- .../com/qiniu/android/HttpHeaderTest.java | 2 +- .../java/com/qiniu/android/HttpTest.java | 14 ++++++------- .../java/com/qiniu/android/HttpsTest.java | 4 ++-- .../com/qiniu/android/ResumeUploadTest.java | 4 ++-- .../com/qiniu/android/SyncFormUploadTest.java | 16 +++++++-------- .../java/com/qiniu/android/TestConfig.java | 2 +- .../com/qiniu/android/TestFileRecorder.java | 4 ++-- .../java/com/qiniu/android/TokenTest.java | 2 +- 10 files changed, 36 insertions(+), 36 deletions(-) diff --git a/library/src/androidTest/java/com/qiniu/android/CancelTest.java b/library/src/androidTest/java/com/qiniu/android/CancelTest.java index 056f01c32..b2cc15b92 100644 --- a/library/src/androidTest/java/com/qiniu/android/CancelTest.java +++ b/library/src/androidTest/java/com/qiniu/android/CancelTest.java @@ -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; @@ -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; diff --git a/library/src/androidTest/java/com/qiniu/android/FormUploadTest.java b/library/src/androidTest/java/com/qiniu/android/FormUploadTest.java index 6e9a43438..8d28a9580 100644 --- a/library/src/androidTest/java/com/qiniu/android/FormUploadTest.java +++ b/library/src/androidTest/java/com/qiniu/android/FormUploadTest.java @@ -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); } diff --git a/library/src/androidTest/java/com/qiniu/android/HttpHeaderTest.java b/library/src/androidTest/java/com/qiniu/android/HttpHeaderTest.java index 101fb8a58..6f8779da5 100644 --- a/library/src/androidTest/java/com/qiniu/android/HttpHeaderTest.java +++ b/library/src/androidTest/java/com/qiniu/android/HttpHeaderTest.java @@ -22,7 +22,7 @@ protected void setUp() throws Exception { public void testValue(){ - assertTrue(headers.getDate("date") != null); + assertTrue(headers.values("date") != null); assertTrue(headers.values("host") != null); } diff --git a/library/src/androidTest/java/com/qiniu/android/HttpTest.java b/library/src/androidTest/java/com/qiniu/android/HttpTest.java index 9c2c7a3e6..0ec0f64f9 100644 --- a/library/src/androidTest/java/com/qiniu/android/HttpTest.java +++ b/library/src/androidTest/java/com/qiniu/android/HttpTest.java @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { diff --git a/library/src/androidTest/java/com/qiniu/android/HttpsTest.java b/library/src/androidTest/java/com/qiniu/android/HttpsTest.java index 4308528e8..a70c7f754 100644 --- a/library/src/androidTest/java/com/qiniu/android/HttpsTest.java +++ b/library/src/androidTest/java/com/qiniu/android/HttpsTest.java @@ -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()); @@ -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) { diff --git a/library/src/androidTest/java/com/qiniu/android/ResumeUploadTest.java b/library/src/androidTest/java/com/qiniu/android/ResumeUploadTest.java index e70791bce..d7902abb1 100644 --- a/library/src/androidTest/java/com/qiniu/android/ResumeUploadTest.java +++ b/library/src/androidTest/java/com/qiniu/android/ResumeUploadTest.java @@ -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; @@ -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; diff --git a/library/src/androidTest/java/com/qiniu/android/SyncFormUploadTest.java b/library/src/androidTest/java/com/qiniu/android/SyncFormUploadTest.java index 58941a262..33ac29176 100644 --- a/library/src/androidTest/java/com/qiniu/android/SyncFormUploadTest.java +++ b/library/src/androidTest/java/com/qiniu/android/SyncFormUploadTest.java @@ -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()); @@ -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"); @@ -72,7 +72,7 @@ public void testNoKey() throws Throwable { Map params = new HashMap(); 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"); @@ -136,7 +136,7 @@ public void testFile() throws Throwable { Map params = new HashMap(); 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"); @@ -158,7 +158,7 @@ public void test0File() throws Throwable { Map params = new HashMap(); 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()); @@ -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); } @@ -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"); diff --git a/library/src/androidTest/java/com/qiniu/android/TestConfig.java b/library/src/androidTest/java/com/qiniu/android/TestConfig.java index 9414af78c..d39861b1f 100644 --- a/library/src/androidTest/java/com/qiniu/android/TestConfig.java +++ b/library/src/androidTest/java/com/qiniu/android/TestConfig.java @@ -19,7 +19,7 @@ public final class TestConfig { public static final String token_z2 = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW:S9V-5ttyKKfzH59Ncs7wooEOpc4=:eyJzY29wZSI6InNkay16MiIsImRlYWRsaW5lIjoxNTk1MDU4MzY0fQ=="; //北美上传凭证 public static final String bucket_na0 = "sdk-na0"; - public static final String token_na0 = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW:K-4seSpuZ1XivgHK_VrZVt4z5Pw=:eyJzY29wZSI6InNkay1uYTAiLCJkZWFkbGluZSI6MTU5NTA1ODM4NX0="; + public static final String token_na0 = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW:hNobj3oBf2OxjafAlH6przLDAOs=:eyJzY29wZSI6InNkay1uYTAiLCJkZWFkbGluZSI6MTU5NTMxNDIyN30="; public static final String ak = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW"; diff --git a/library/src/androidTest/java/com/qiniu/android/TestFileRecorder.java b/library/src/androidTest/java/com/qiniu/android/TestFileRecorder.java index 5c67f35da..6ece34b7b 100644 --- a/library/src/androidTest/java/com/qiniu/android/TestFileRecorder.java +++ b/library/src/androidTest/java/com/qiniu/android/TestFileRecorder.java @@ -89,7 +89,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) { Log.i("qiniutest", k + rinfo); key = k; @@ -125,7 +125,7 @@ public void progress(String key, double percent) { 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) { Log.i("qiniutest", k + rinfo); key = k; diff --git a/library/src/androidTest/java/com/qiniu/android/TokenTest.java b/library/src/androidTest/java/com/qiniu/android/TokenTest.java index f87334417..abee05d90 100644 --- a/library/src/androidTest/java/com/qiniu/android/TokenTest.java +++ b/library/src/androidTest/java/com/qiniu/android/TokenTest.java @@ -11,7 +11,7 @@ */ public class TokenTest extends AndroidTestCase { public void testRight() { - UpToken t = UpToken.parse(TestConfig.token_z0); + UpToken t = UpToken.parse(TestConfig.commonToken); Assert.assertNotSame(t, UpToken.NULL); }