Skip to content

Commit c9da511

Browse files
committed
断点续传多host
1 parent 455f1e2 commit c9da511

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

src/com/qiniu/resumableio/ResumableClient.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public ICancel bput(String host, InputStreamAt input, String ctx, long blockOffs
130130
return client;
131131
}
132132

133-
public ICancel mkfile(String key, long fsize, String mimeType, Map<String, String> params, String ctxs, CallRet ret) {
133+
public ICancel mkfile(final String key, final long fsize, final String mimeType, final Map<String, String> params, final String ctxs, final CallRet ret) {
134134
String url = Conf.UP_HOST + mkfilePath(key, fsize, mimeType, params);
135135
StringEntity entity = null;
136136
try {
@@ -140,7 +140,24 @@ public ICancel mkfile(String key, long fsize, String mimeType, Map<String, Strin
140140
ret.onFailure(new QiniuException(QiniuException.InvalidEncode, "mkfile", e));
141141
return null;
142142
}
143-
return call(makeClientExecutor(), url, entity, ret);
143+
144+
CallRet retryRet = new RetryRet(ret){
145+
@Override
146+
public void onFailure(QiniuException ex) {
147+
if (RetryRet.noRetry(ex)){
148+
ret.onFailure(ex);
149+
return;
150+
}
151+
String url2 = Conf.UP_HOST2 + mkfilePath(key, fsize, mimeType, params);
152+
StringEntity entity2 = null;
153+
try {
154+
entity2 = new StringEntity(ctxs);
155+
} catch (UnsupportedEncodingException e) {
156+
}
157+
call(makeClientExecutor(), url2, entity2, ret);
158+
}
159+
};
160+
return call(makeClientExecutor(), url, entity, retryRet);
144161
}
145162

146163
private static String mkfilePath(String key, long fsize, String mimeType, Map<String, String> params){

tests/src/com/qiniu/test/UploadTest.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void tearDown() throws Exception {
9393
}
9494

9595
@SmallTest
96-
public void testS() throws IOException, JSONException, InterruptedException {
96+
public void testIOkilo() throws IOException, JSONException, InterruptedException {
9797
file = createFile(0.2, ".test");
9898
uri = Uri.fromFile(file);
9999
IO.putFile(context, uptoken, key, uri, extra, jsonRet);
@@ -114,7 +114,7 @@ public void testIOMultiHost() throws IOException, JSONException, InterruptedExce
114114
}
115115

116116
@MediumTest
117-
public void testM() throws IOException, JSONException, InterruptedException {
117+
public void testIOMega() throws IOException, JSONException, InterruptedException {
118118
file = createFile(0.1, "--—— 中 文 .test");
119119
uri = Uri.fromFile(file);
120120
IO.putFile(context, uptoken, key, uri, extra, jsonRet);
@@ -123,7 +123,7 @@ public void testM() throws IOException, JSONException, InterruptedException {
123123
}
124124

125125
@SmallTest
126-
public void testRS() throws IOException, JSONException, InterruptedException {
126+
public void testRIOkilo() throws IOException, JSONException, InterruptedException {
127127
file = createFile(0.2, ".test");
128128
uri = Uri.fromFile(file);
129129
ResumableIO.putFile(context, uptoken, key, uri, rextra, jsonRet);
@@ -132,14 +132,26 @@ public void testRS() throws IOException, JSONException, InterruptedException {
132132
}
133133

134134
@MediumTest
135-
public void testRM() throws IOException, JSONException, InterruptedException {
135+
public void testRIOMega() throws IOException, JSONException, InterruptedException {
136136
file = createFile(4, ".test");
137137
uri = Uri.fromFile(file);
138138
ResumableIO.putFile(context, uptoken, key, uri, rextra, jsonRet);
139139
sem.acquire();
140140
successCheck();
141141
}
142142

143+
@MediumTest
144+
public void testRIOMutiHost() throws IOException, JSONException, InterruptedException {
145+
String old = Conf.UP_HOST;
146+
Conf.UP_HOST = "http://127.0.0.1:1";
147+
file = createFile(4, ".test");
148+
uri = Uri.fromFile(file);
149+
ResumableIO.putFile(context, uptoken, key, uri, rextra, jsonRet);
150+
sem.acquire();
151+
Conf.UP_HOST = old;
152+
successCheck();
153+
}
154+
143155
// @MediumTest
144156
// public void testRL() throws IOException, JSONException, InterruptedException {
145157
// file = createFile(8.6, ".test");

0 commit comments

Comments
 (0)