Skip to content

Commit b2322e9

Browse files
authored
Merge pull request #455 from YangSen-qn/develop
add fog cn east 1 zone
2 parents ca3278f + 1bf3371 commit b2322e9

14 files changed

+172
-49
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
#Changelog
2+
## 8.2.0(2021-04-01)
3+
## 增加
4+
* 增加雾存储 FixedZone.zoneFogCnEast1
5+
26
## 8.2.0(2021-02-20)
37
## 增加
48
* 增加网络监控功能,选择最优 Host 进行上传

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ https://github.com/qiniudemo/qiniu-lab-android
2929
| 7.0.7 | Android 2.2+ | android-async-http 1.4.8 |
3030

3131
### 注意
32-
* 推荐使用最新版:8.2.0
32+
* 推荐使用最新版:8.2.1
3333
* AndroidNetwork.getMobileDbm()可以获取手机信号强度,需要如下权限(API>=18时生效)
3434
```
3535
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.io.File;
2121
import java.io.IOException;
22+
import java.util.Date;
2223
import java.util.Iterator;
2324
import java.util.LinkedList;
2425
import java.util.Queue;
@@ -184,6 +185,7 @@ public void testSwitchRegionV2() {
184185
Configuration configuration = new Configuration.Builder()
185186
.resumeUploadVersion(Configuration.RESUME_UPLOAD_VERSION_V2)
186187
.useConcurrentResumeUpload(true)
188+
.chunkSize(4*1024*1024)
187189
.useHttps(true)
188190
.build();
189191
int[] sizeArray = {5000, 8000, 10000, 20000};
@@ -204,6 +206,7 @@ public void testCancelV2() {
204206
Configuration configuration = new Configuration.Builder()
205207
.resumeUploadVersion(Configuration.RESUME_UPLOAD_VERSION_V2)
206208
.useConcurrentResumeUpload(true)
209+
.chunkSize(4*1024*1024)
207210
.useHttps(true)
208211
.build();
209212
int[] sizeArray = {10000, 20000};
@@ -223,11 +226,13 @@ public void testHttpV2(){
223226
Configuration configuration = new Configuration.Builder()
224227
.resumeUploadVersion(Configuration.RESUME_UPLOAD_VERSION_V2)
225228
.useConcurrentResumeUpload(true)
229+
.chunkSize(4*1024*1024)
226230
.useHttps(false)
227231
.build();
228232
int[] sizeArray = {500, 1000, 3000, 4000, 5000, 8000, 10000, 20000};
233+
long timestamp = new Date().getTime();
229234
for (int size : sizeArray) {
230-
String key = "android_concurrent_resume_http_v2_" + size + "k";
235+
String key = "android_concurrent_resume_http_v2_" + timestamp + "_" + size + "k";
231236
try {
232237
File file = TempFile.createFile(size, key);
233238
uploadFileAndAssertSuccessResult(file, key, configuration, null);
@@ -243,6 +248,7 @@ public void testHttpsV2(){
243248
.resumeUploadVersion(Configuration.RESUME_UPLOAD_VERSION_V2)
244249
.useConcurrentResumeUpload(true)
245250
.useHttps(true)
251+
.chunkSize(4*1024*1024)
246252
.build();
247253
int[] sizeArray = {500, 1000, 3000, 4000, 5000, 8000, 10000, 20000};
248254
for (int size : sizeArray) {
@@ -262,7 +268,7 @@ public void testReuploadV2(){
262268
.resumeUploadVersion(Configuration.RESUME_UPLOAD_VERSION_V2)
263269
.useConcurrentResumeUpload(true)
264270
.useHttps(true)
265-
.chunkSize(1024*1024)
271+
.chunkSize(4*1024*1024)
266272
.build();
267273
int[] sizeArray = {30000};
268274
for (int size : sizeArray) {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.qiniu.android.common.AutoZone;
44
import com.qiniu.android.common.FixedZone;
5+
import com.qiniu.android.http.dns.DnsPrefetchTransaction;
56
import com.qiniu.android.http.dns.DnsPrefetcher;
67
import com.qiniu.android.http.dns.IDnsNetworkAddress;
78
import com.qiniu.android.storage.UpToken;
@@ -87,15 +88,13 @@ public boolean shouldWait() {
8788
public void testMutiThreadPrefetch(){
8889

8990
final AutoZone zone = new AutoZone();
90-
final DnsPrefetcher dnsPrefetcher = DnsPrefetcher.getInstance();
91-
9291
final TestParam param = new TestParam();
9392

9493
for (int i = 0; i < param.count; i++) {
9594
new Thread(new Runnable() {
9695
@Override
9796
public void run() {
98-
boolean isSuccess = dnsPrefetcher.checkAndPrefetchDnsIfNeed(zone, UpToken.parse(TestConfig.token_z0));
97+
boolean isSuccess = DnsPrefetchTransaction.addDnsCheckAndPrefetchTransaction(zone, UpToken.parse(TestConfig.token_z0));
9998
synchronized (this){
10099
if (isSuccess){
101100
param.successCount += 1;

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ public void testSwitchRegionV2() {
198198
Configuration configuration = new Configuration.Builder()
199199
.resumeUploadVersion(Configuration.RESUME_UPLOAD_VERSION_V2)
200200
.useConcurrentResumeUpload(false)
201+
.chunkSize(4*1024*1024)
201202
.useHttps(true)
202203
.build();
203204
int[] sizeArray = {5000, 8000, 10000, 20000};
@@ -218,6 +219,7 @@ public void testCancelV2() {
218219
Configuration configuration = new Configuration.Builder()
219220
.resumeUploadVersion(Configuration.RESUME_UPLOAD_VERSION_V2)
220221
.useConcurrentResumeUpload(false)
222+
.chunkSize(4*1024*1024)
221223
.useHttps(true)
222224
.build();
223225
int[] sizeArray = {10000, 20000};
@@ -237,6 +239,7 @@ public void testHttpV2(){
237239
Configuration configuration = new Configuration.Builder()
238240
.resumeUploadVersion(Configuration.RESUME_UPLOAD_VERSION_V2)
239241
.useConcurrentResumeUpload(false)
242+
.chunkSize(4*1024*1024)
240243
.useHttps(false)
241244
.build();
242245
int[] sizeArray = {500, 1000, 3000, 4000, 5000, 8000, 10000, 20000};
@@ -256,6 +259,7 @@ public void testHttpsV2(){
256259
Configuration configuration = new Configuration.Builder()
257260
.resumeUploadVersion(Configuration.RESUME_UPLOAD_VERSION_V2)
258261
.useConcurrentResumeUpload(false)
262+
.chunkSize(4*1024*1024)
259263
.useHttps(true)
260264
.build();
261265
int[] sizeArray = {500, 1000, 3000, 4000, 5000, 8000, 10000, 20000};
@@ -276,7 +280,7 @@ public void testReuploadV2(){
276280
.resumeUploadVersion(Configuration.RESUME_UPLOAD_VERSION_V2)
277281
.useConcurrentResumeUpload(false)
278282
.useHttps(true)
279-
.chunkSize(1024*1024)
283+
.chunkSize(4*1024*1024)
280284
.build();
281285
int[] sizeArray = {30000};
282286
for (int size : sizeArray) {
@@ -361,6 +365,7 @@ public void testCustomParamV2() {
361365
Configuration configuration = new Configuration.Builder()
362366
.resumeUploadVersion(Configuration.RESUME_UPLOAD_VERSION_V2)
363367
.useConcurrentResumeUpload(false)
368+
.chunkSize(4*1024*1024)
364369
.useHttps(false)
365370
.build();
366371

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

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66
import com.qiniu.android.storage.UpProgressHandler;
77
import com.qiniu.android.storage.UploadManager;
88
import com.qiniu.android.storage.UploadOptions;
9+
import com.qiniu.android.utils.Etag;
910
import com.qiniu.android.utils.LogUtil;
1011

1112
import org.json.JSONObject;
1213

1314
import java.io.File;
15+
import java.io.IOException;
1416

1517
public class UploadBaseTest extends BaseTest {
1618

17-
protected UploadOptions defaultOptions = new UploadOptions(null, null, false, new UpProgressHandler() {
19+
protected UploadOptions defaultOptions = new UploadOptions(null, null, true, new UpProgressHandler() {
1820
@Override
1921
public void progress(String key, double percent) {
2022
LogUtil.d("== upload key:" + (key == null ? "" : key) + " progress:" + percent);
@@ -58,6 +60,18 @@ public boolean shouldWait() {
5860
assertTrue(completeInfo.responseInfo.toString(), completeInfo.responseInfo != null);
5961
assertTrue(completeInfo.responseInfo.toString(), completeInfo.responseInfo.isOK());
6062
assertTrue(completeInfo.responseInfo.toString(), verifyUploadKey(key, completeInfo.key));
63+
64+
// 成功验证 etag
65+
String etag = null;
66+
String serverEtag = null;
67+
try {
68+
etag = Etag.file(file);
69+
serverEtag = completeInfo.responseInfo.response.getString("hash");
70+
} catch (Exception e) {
71+
e.printStackTrace();
72+
}
73+
LogUtil.d("=== upload etag:" + etag + " response etag:" + serverEtag);
74+
assertEquals("file:" + etag + " server etag:" + serverEtag, etag, serverEtag);
6175
}
6276

6377
protected void uploadFileAndAssertResult(int statusCode,
@@ -96,6 +110,20 @@ public boolean shouldWait() {
96110
assertTrue(completeInfo.responseInfo.toString(), completeInfo.responseInfo != null);
97111
assertTrue(completeInfo.responseInfo.toString(), completeInfo.responseInfo.statusCode == statusCode);
98112
assertTrue(completeInfo.responseInfo.toString(), verifyUploadKey(key, completeInfo.key));
113+
114+
// 成功验证 etag
115+
if (statusCode == 200) {
116+
String etag = null;
117+
String serverEtag = null;
118+
try {
119+
etag = Etag.file(file);
120+
serverEtag = completeInfo.responseInfo.response.getString("hash");
121+
} catch (Exception e) {
122+
e.printStackTrace();
123+
}
124+
LogUtil.d("=== upload etag:" + etag + " response etag:" + serverEtag);
125+
assertEquals("file:" + etag + " server etag:" + serverEtag, etag, serverEtag);
126+
}
99127
}
100128

101129
protected void uploadFile(File file,
@@ -146,6 +174,18 @@ public boolean shouldWait() {
146174
assertTrue(completeInfo.responseInfo.toString(), completeInfo.responseInfo != null);
147175
assertTrue(completeInfo.responseInfo.toString(), completeInfo.responseInfo.isOK());
148176
assertTrue(completeInfo.responseInfo.toString(), verifyUploadKey(key, completeInfo.key));
177+
178+
// 成功验证 etag
179+
String etag = null;
180+
String serverEtag = null;
181+
try {
182+
etag = Etag.data(data);
183+
serverEtag = completeInfo.responseInfo.response.getString("hash");
184+
} catch (Exception e) {
185+
e.printStackTrace();
186+
}
187+
LogUtil.d("=== upload etag:" + etag + " response etag:" + serverEtag);
188+
assertEquals("file:" + etag + " server etag:" + serverEtag, etag, serverEtag);
149189
}
150190

151191
protected void uploadDataAndAssertResult(int statusCode,
@@ -183,6 +223,20 @@ public boolean shouldWait() {
183223
assertTrue(completeInfo.responseInfo.toString(), completeInfo.responseInfo != null);
184224
assertTrue(completeInfo.responseInfo.toString(), completeInfo.responseInfo.statusCode == statusCode);
185225
assertTrue(completeInfo.responseInfo.toString(), verifyUploadKey(key, completeInfo.key));
226+
227+
// 成功验证 etag
228+
if (statusCode == 200) {
229+
String etag = null;
230+
String serverEtag = null;
231+
try {
232+
etag = Etag.data(data);
233+
serverEtag = completeInfo.responseInfo.response.getString("hash");
234+
} catch (Exception e) {
235+
e.printStackTrace();
236+
}
237+
LogUtil.d("=== upload etag:" + etag + " response etag:" + serverEtag);
238+
assertEquals("file:" + etag + " server etag:" + serverEtag, etag, serverEtag);
239+
}
186240
}
187241

188242
protected void uploadData(byte[] data,

library/src/main/java/com/qiniu/android/common/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
public final class Constants {
5-
public static final String VERSION = "8.2.0";
5+
public static final String VERSION = "8.2.1";
66

77
public static final String UTF_8 = "utf-8";
88
}

library/src/main/java/com/qiniu/android/common/FixedZone.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ public final class FixedZone extends Zone {
4747
new String[]{"upload-as0.qbox.me", "up-as0.qbox.me"},
4848
"as0");
4949

50+
/**
51+
* zone fog-cn-east-1 雾存储 华东-1
52+
* 分片上传暂时仅支持分片 api v2
53+
* 分片 api v2设置方式:配置 Configuration 的 resumeUploadVersion 为 Configuration.RESUME_UPLOAD_VERSION_V2
54+
* eg:
55+
* Configuration configuration = new Configuration.Builder()
56+
* .resumeUploadVersion(Configuration.RESUME_UPLOAD_VERSION_V2)
57+
* .build();
58+
*
59+
* @return 实例
60+
*/
61+
public static final Zone zoneFogCnEast1 = new FixedZone(new String[]{"upload-fog-cn-east-1.qiniup.com", "up-fog-cn-east-1.qiniup.com"},
62+
new String[]{"upload-fog-cn-east-1.qiniup.com", "up-fog-cn-east-1.qiniup.com"},
63+
"fog-cn-east-1");
64+
5065
private ZonesInfo zonesInfo;
5166

5267
public static FixedZone localsZoneInfo() {

library/src/main/java/com/qiniu/android/storage/PartsUploadPerformerV1.java

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
class PartsUploadPerformerV1 extends PartsUploadPerformer {
1818

19-
private static long BlockSize = 4 * 1024 * 1024;
19+
private static int BlockSize = 4 * 1024 * 1024;
2020

2121
PartsUploadPerformerV1(File file,
2222
String fileName,
@@ -71,7 +71,7 @@ void uploadNextData(final PartsUploadPerformerDataCompleteHandler completeHandle
7171
return;
7272
}
7373

74-
chunk.data = getDataWithChunk(chunk, block);
74+
chunk.data = getChunkDataWithRetry(chunk, block);
7575
if (chunk.data == null) {
7676
LogUtil.i("key:" + StringUtils.toNonnullString(key) + " no chunk left");
7777

@@ -184,24 +184,49 @@ public void complete(ResponseInfo responseInfo, UploadRegionRequestMetrics reque
184184

185185
}
186186

187-
private byte[] getDataWithChunk(UploadData chunk,
188-
UploadBlock block) {
187+
private byte[] getChunkDataWithRetry(UploadData chunk, UploadBlock block) {
188+
byte[] uploadData = null;
189+
190+
int maxTime = 3;
191+
int index = 0;
192+
while (index < maxTime) {
193+
uploadData = getChunkData(chunk, block);
194+
if (uploadData != null) {
195+
break;
196+
}
197+
index ++;
198+
}
199+
200+
return uploadData;
201+
}
202+
203+
private synchronized byte[] getChunkData(UploadData chunk, UploadBlock block) {
189204
if (randomAccessFile == null || chunk == null || block == null) {
190205
return null;
191206
}
192-
byte[] data = new byte[(int) chunk.size];
207+
int readSize = 0;
208+
byte[] data = new byte[chunk.size];
193209
try {
194-
synchronized (randomAccessFile) {
195-
randomAccessFile.seek((chunk.offset + block.offset));
196-
randomAccessFile.read(data, 0, (int) chunk.size);
210+
randomAccessFile.seek((chunk.offset + block.offset));
211+
while (readSize < chunk.size) {
212+
int ret = randomAccessFile.read(data, readSize, (chunk.size - readSize));
213+
if (ret < 0) {
214+
break;
215+
}
216+
readSize += ret;
217+
}
218+
219+
// 读数据非预期
220+
if (readSize != chunk.size) {
221+
data = null;
197222
}
198223
} catch (IOException e) {
199224
data = null;
200225
}
201226
return data;
202227
}
203228

204-
private long getUploadChunkSize() {
229+
private int getUploadChunkSize() {
205230
if (config.useConcurrentResumeUpload) {
206231
return BlockSize;
207232
} else {

0 commit comments

Comments
 (0)