Skip to content

Commit 58966fe

Browse files
author
jordanqin
committed
update qcloud sdk to 5.9.38
1 parent 7ea33d5 commit 58966fe

File tree

4 files changed

+88
-7
lines changed

4 files changed

+88
-7
lines changed

QCloudCosXml/cos-android-base/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ android {
66
minSdkVersion 15
77
targetSdkVersion 28
88

9-
versionCode 50937
10-
versionName '5.9.35'
9+
versionCode 50938
10+
versionName '5.9.36'
1111

1212
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
1313

QCloudCosXml/cos-android/src/androidTest/java/com/tencent/cos/xml/common/OtherTest.java

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
import com.tencent.cos.xml.utils.DigestUtils;
4646
import com.tencent.qcloud.core.http.RequestBodySerializer;
4747
import com.tencent.qcloud.core.logger.QCloudLogger;
48+
import com.tencent.qcloud.core.util.Base64Utils;
4849
import com.tencent.qcloud.core.util.DomainSwitchUtils;
50+
import com.tencent.qcloud.core.util.OkhttpInternalUtils;
4951

5052
import org.junit.Assert;
5153
import org.junit.Test;
@@ -61,6 +63,9 @@
6163
import java.net.HttpURLConnection;
6264
import java.net.URL;
6365
import java.net.URLEncoder;
66+
import java.security.MessageDigest;
67+
import java.security.NoSuchAlgorithmException;
68+
import java.util.ArrayList;
6469

6570
import okhttp3.MediaType;
6671
import okhttp3.OkHttpClient;
@@ -173,24 +178,68 @@ public void onFail(CosXmlClientException exception, CosXmlServiceException servi
173178
QCloudLogger.i("QCloudTest", url);
174179
Assert.assertEquals("https://bucket.cos.ap-shanghai.myqcloud.com/objectexample", url);
175180
}
176-
181+
182+
public String onGetMd5(String filePath) throws IOException {
183+
InputStream inputStream = null;
184+
try{
185+
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
186+
File file = new File(filePath);
187+
inputStream = new FileInputStream(file);
188+
byte[] buff = new byte[8 * 1024];
189+
int readLen;
190+
long remainLength = file.length();
191+
while (remainLength > 0L && (readLen = inputStream.read(buff, 0,
192+
(buff.length > remainLength ? (int) remainLength : buff.length)))!= -1){
193+
messageDigest.update(buff, 0, readLen);
194+
remainLength -= readLen;
195+
}
196+
return Base64Utils.encode(messageDigest.digest());
197+
} catch (IOException e) {
198+
throw e;
199+
} catch (NoSuchAlgorithmException e) {
200+
throw new IOException("unSupport Md5 algorithm", e);
201+
} finally {
202+
if(inputStream != null) OkhttpInternalUtils.closeQuietly(inputStream);
203+
}
204+
}
205+
177206
@Test public void testPresignedRequest() {
207+
String filePath = TestUtils.smallFilePath();
178208
PresignedUrlRequest presignedUrlRequest = new PresignedUrlRequest(TestConst.PERSIST_BUCKET, TestConst.PERSIST_BUCKET_SMALL_OBJECT_PATH) {
179209
@Override
180210
public RequestBodySerializer getRequestBody() throws CosXmlClientException {
181-
return RequestBodySerializer.file("image/png", new File(TestUtils.smallFilePath()));
211+
return RequestBodySerializer.file("image/png", new File(filePath));
182212
}
183213
};
184214
presignedUrlRequest.setRequestMethod("PUT");
185215
presignedUrlRequest.setSignKeyTime(3600);
186216
presignedUrlRequest.addNoSignHeader("Host");
217+
String md5;
218+
// try {
219+
// md5 = DigestUtils.getMD5(filePath);
220+
// } catch (CosXmlClientException e) {
221+
// throw new RuntimeException(e);
222+
// }
223+
224+
try {
225+
md5 = onGetMd5(filePath);
226+
} catch (IOException e) {
227+
throw new RuntimeException(e);
228+
}
229+
230+
// try {
231+
// presignedUrlRequest.setRequestHeaders(HttpConstants.Header.CONTENT_MD5, md5);
232+
// } catch (CosXmlClientException e) {
233+
// throw new RuntimeException(e);
234+
// }
187235
CosXmlSimpleService defaultService = ServiceFactory.INSTANCE.newDefaultService();
188236
try {
189237
String signUrl = defaultService.getPresignedURL(presignedUrlRequest);
190238
QCloudLogger.i("QCloudTest", signUrl);
191239
MediaType imageType = MediaType.parse("image/png");
192240
Request request = new Request.Builder()
193241
.url(signUrl)
242+
// .header(HttpConstants.Header.CONTENT_MD5, md5)
194243
.put(RequestBody.create(imageType, new File(TestUtils.smallFilePath())))
195244
.build();
196245
Response response = new OkHttpClient().newCall(request).execute();
@@ -424,4 +473,35 @@ public void testIsMyqcloudUrl(){
424473
assertFalse(DomainSwitchUtils.isMyqcloudUrl(testUrls[5]));
425474
assertFalse(DomainSwitchUtils.isMyqcloudUrl(testUrls[6]));
426475
}
476+
477+
@Test
478+
public void testMultiThreadedCosXmlService() {
479+
try {
480+
// 线程数常量
481+
int THREAD_COUNT = 10000;
482+
Thread[] threads = new Thread[THREAD_COUNT];
483+
ArrayList<Throwable> exceptions = new ArrayList<>();
484+
for (int i = 0; i < THREAD_COUNT; i++) {
485+
threads[i] = new Thread(() -> {
486+
CosXmlSimpleService service = ServiceFactory.INSTANCE.newDefaultService();
487+
service.getConfig();
488+
});
489+
threads[i].setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
490+
@Override
491+
public void uncaughtException(Thread t, Throwable e) {
492+
e.printStackTrace();
493+
exceptions.add(e);
494+
}
495+
});
496+
threads[i].start();
497+
}
498+
for (int i = 0; i < THREAD_COUNT; i++) {
499+
threads[i].join();
500+
}
501+
assertTrue(exceptions.isEmpty());
502+
} catch (Exception e) {
503+
e.printStackTrace();
504+
Assert.fail(e.getMessage());
505+
}
506+
}
427507
}

QCloudCosXml/cos-android/src/androidTest/java/com/tencent/cos/xml/transfer/UploadTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,13 @@ public void onSuccess(InitiateMultipartUpload initiateMultipartUpload) {
415415
}
416416

417417
@Test public void testUploadSmallFileByPath() {
418+
String filePath = TestUtils.smallFilePath();
418419

419420
TransferManager transferManager = ServiceFactory.INSTANCE.newDefaultTransferManager();
420421
// String filePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/deviceId.mp3";
421422
PutObjectRequest putObjectRequest = new PutObjectRequest(TestConst.PERSIST_BUCKET,
422423
TestConst.PERSIST_BUCKET_SMALL_OBJECT_PATH,
423-
TestUtils.filePath("N好.", 1024));
424+
filePath);
424425

425426
// try {
426427
// // 设置 content-type

QCloudCosXml/version.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
*/
2323

2424
ext {
25-
cosSdkVersionCode = 50940
26-
cosSdkVersionName = '5.9.37'
25+
cosSdkVersionCode = 50941
26+
cosSdkVersionName = '5.9.38'
2727
}

0 commit comments

Comments
 (0)