Skip to content

Commit

Permalink
Merge branch 'master' into update_gson
Browse files Browse the repository at this point in the history
  • Loading branch information
yangsen committed Sep 21, 2022
2 parents 7698ce7 + 37b928c commit 686513c
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 58 deletions.
28 changes: 28 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
codecov:
ci:
- prow.qiniu.io # prow 里面运行需添加,其他 CI 不要
require_ci_to_pass: no # 改为 no,否则 codecov 会等待其他 GitHub 上所有 CI 通过才会留言。

github_checks: #关闭github checks
annotations: false

comment:
layout: "reach, diff, flags, files"
behavior: new # 默认是更新旧留言,改为 new,删除旧的,增加新的。
require_changes: false # if true: only post the comment if coverage changes
require_base: no # [yes :: must have a base report to post]
require_head: yes # [yes :: must have a head report to post]
branches: # branch names that can post comment
- "master"

coverage:
status: # 评判 pr 通过的标准
patch: off
project: # project 统计所有代码x
default:
# basic
target: 60% # 总体通过标准
threshold: 3% # 允许单次下降的幅度
base: auto
if_not_found: success
if_ci_failed: error
15 changes: 0 additions & 15 deletions src/main/java/com/qiniu/common/Zone.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,21 +179,6 @@ public static Zone xinjiapo() {
return zoneAs0();
}

/**
* 雾存储 华东-1
*/
public static Zone zoneFogCnEast1() {
return new Builder()
.region("fog-cn-east-1")
.upHttp("http://upload-fog-cn-east-1.qiniup.com").upHttps("https://upload-fog-cn-east-1.qiniup.com")
.upBackupHttp("http://up-fog-cn-east-1.qiniup.com").upBackupHttps("https://up-fog-cn-east-1.qiniup.com")
.iovipHttp("http://iovip-fog-cn-east-1.qbox.me").iovipHttps("https://iovip-fog-cn-east-1.qbox.me")
.rsHttp("http://rs-fog-cn-east-1.qbox.me").rsHttps("https://rs-fog-cn-east-1.qbox.me")
.rsfHttp("http://rsf-fog-cn-east-1.qbox.me").rsfHttps("https://rsf-fog-cn-east-1.qbox.me")
.apiHttp("http://api-fog-cn-east-1.qiniuapi.com").apiHttps("https://api-fog-cn-east-1.qiniuapi.com")
.build();
}

/**
* 自动根据AccessKey和Bucket来判断所在机房,并获取相关的域名
* 空间所在的对应机房可以在空间创建的时候选择,或者创建完毕之后,从后台查看
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/qiniu/storage/BucketManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1096,13 +1096,21 @@ private void check(String bucket) throws QiniuException {

/**
* 批量文件管理请求
* <p>
* 如果遇到超时比较多,可减小单次 batch 操作的数量,或者在创建 BucketManager 时尝试增加超时时间;
* 增加超时时间的具体方式如下:
* Configuration cfg = new Configuration();
* cfg.readTimeout = 120;
* BucketManager bucketManager = new BucketManager(auth, cfg);
* <p>
* 如果 BucketManager 定义了 Client ,可以指定 Client 的超时时间。
*/
public Response batch(BatchOperations operations) throws QiniuException {
return rsPost(operations.execBucket(), "/batch", operations.toBody());
}

/**
* 文件管理批量操作指令构建对象
* 文件管理批量操作指令构建对象,单次 BatchOperations 的操作数最多为 1000(即 add 最多 1000 个),如果遇到超时,需要调小操作数量
*/
public static class BatchOperations {
private ArrayList<String> ops;
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/com/qiniu/storage/Region.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static Region regionCnEast2() {
accUpHost("upload-cn-east-2.qiniup.com").
iovipHost("iovip-cn-east-2.qiniuio.com").
rsHost("rs-cn-east-2.qiniuapi.com").
rsfHost("rsf-cn-east-2-qiniuapi.com").
rsfHost("rsf-cn-east-2.qiniuapi.com").
apiHost("api-cn-east-2.qiniuapi.com").
build();
}
Expand Down Expand Up @@ -181,6 +181,21 @@ public static Region huanan() {
return region2();
}

/**
* 亚太-首尔机房相关域名
*/
public static Region regionApNorthEast1() {
return new Builder().
region("ap-northeast-1").
srcUpHost("up-ap-northeast-1.qiniup.com").
accUpHost("upload-ap-northeast-1.qiniup.com").
iovipHost("iovip-ap-northeast-1.qiniuio.com").
rsHost("rs-ap-northeast-1.qiniuapi.com").
rsfHost("rsf-ap-northeast-1.qiniuapi.com").
apiHost("api-ap-northeast-1.qiniuapi.com").
build();
}

/**
* 北美机房相关域名
*/
Expand Down Expand Up @@ -225,21 +240,6 @@ public static Region xinjiapo() {
return regionAs0();
}

/**
* 雾存储 华东-1
*/
public static Region regionFogCnEast1() {
return new Builder()
.region("fog-cn-east-1")
.srcUpHost("up-fog-cn-east-1.qiniup.com")
.accUpHost("upload-fog-cn-east-1.qiniup.com")
.iovipHost("iovip-fog-cn-east-1.qbox.me")
.rsHost("rs-fog-cn-east-1.qbox.me")
.rsfHost("rsf-fog-cn-east-1.qbox.me")
.apiHost("api-fog-cn-east-1.qiniuapi.com")
.build();
}

/*
* 自动根据AccessKey和Bucket来判断所在机房,并获取相关的域名
* 空间所在的对应机房可以在空间创建的时候选择,或者创建完毕之后,从后台查看
Expand Down
97 changes: 72 additions & 25 deletions src/test/java/test/com/qiniu/TestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,29 +122,76 @@ public static TestFile[] getTestFileArray(String fileSaveKey, String fileMimeTyp
z0_auto.regionId = "z0";
z0_auto.region = Region.region0();

TestFile fog = new TestFile();
fog.key = fileSaveKey;
fog.mimeType = fileMimeType;
fog.bucketName = "java-sdk-fog-cn-east1";
fog.testDomain = "javasdk-fog-cn-east1.peterpy.cn";
fog.testUrl = "http://" + fog.testDomain + "/" + fileSaveKey;
fog.testDomainTimeStamp = "javasdk-fog-cn-east1-timestamp.peterpy.cn";
fog.testUrlTimeStamp = "http://" + fog.testDomainTimeStamp + "/" + fileSaveKey;
fog.regionId = "fog-cn-east-1";
fog.region = Region.regionFogCnEast1();

TestFile fog1 = new TestFile();
fog1.key = fileSaveKey;
fog1.mimeType = fileMimeType;
fog1.bucketName = "java-sdk-fog-cn-east1";
fog1.testDomain = "javasdk-fog-cn-east1.peterpy.cn";
fog1.testUrl = "http://" + fog.testDomain + "/" + fileSaveKey;
fog1.testDomainTimeStamp = "javasdk-fog-cn-east1-timestamp.peterpy.cn";
fog1.testUrlTimeStamp = "http://" + fog.testDomainTimeStamp + "/" + fileSaveKey;
fog1.regionId = "fog-cn-east-1";
fog1.region = toRegion(Zone.zoneFogCnEast1());

return new TestFile[] { z0 };
return new TestFile[]{z0};
}

public static TestFile[] getAllRegionTestFileArray() {
return getAllRegionTestFileArray(testDefaultKey, "image/png");
}

public static TestFile[] getAllRegionTestFileArray(String fileSaveKey, String fileMimeType) {
if (StringUtils.isNullOrEmpty(fileSaveKey)) {
fileSaveKey = testDefaultKey;
}
if (StringUtils.isNullOrEmpty(fileMimeType)) {
fileMimeType = "application/octet-stream";
}

TestFile na0 = new TestFile();
na0.key = fileSaveKey;
na0.mimeType = fileMimeType;
na0.bucketName = testBucket_na0;
na0.testDomain = testDomain_na0;
na0.testUrl = "http://" + testDomain_na0 + "/" + fileSaveKey;
na0.testDomainTimeStamp = testDomain_na0_timeStamp;
na0.testUrlTimeStamp = "http://" + testDomain_na0_timeStamp + "/" + fileSaveKey;
na0.regionId = "na0";
na0.region = Region.regionNa0();

TestFile z0 = new TestFile();
z0.key = fileSaveKey;
z0.mimeType = fileMimeType;
z0.bucketName = testBucket_z0;
z0.testDomain = testDomain_z0;
z0.testUrl = "http://" + testDomain_z0 + "/" + fileSaveKey;
z0.testDomainTimeStamp = testDomain_z0_timeStamp;
z0.testUrlTimeStamp = "http://" + testDomain_z0_timeStamp + "/" + fileSaveKey;
z0.regionId = "z0";
z0.region = Region.region0();

TestFile z1 = new TestFile();
z1.key = fileSaveKey;
z1.mimeType = fileMimeType;
z1.bucketName = testBucket_z1;
z1.regionId = "z1";
z1.region = Region.region1();

TestFile z2 = new TestFile();
z2.key = fileSaveKey;
z2.mimeType = fileMimeType;
z2.bucketName = "sdk-z2";
z2.regionId = "z2";
z2.region = Region.region2();

TestFile as0 = new TestFile();
as0.key = fileSaveKey;
as0.mimeType = fileMimeType;
as0.bucketName = "sdk-as0";
as0.regionId = "as0";
as0.region = Region.regionAs0();

TestFile z0_auto = new TestFile();
z0_auto.key = fileSaveKey;
z0_auto.mimeType = fileMimeType;
z0_auto.bucketName = testBucket_z0;
z0_auto.testDomain = testDomain_z0;
z0_auto.testUrl = "http://" + testDomain_z0 + "/" + fileSaveKey;
z0_auto.testDomainTimeStamp = testDomain_z0_timeStamp;
z0_auto.testUrlTimeStamp = "http://" + testDomain_z0_timeStamp + "/" + fileSaveKey;
z0_auto.regionId = "z0";
z0_auto.region = Region.region0();

return new TestFile[]{z0, z1, z2, as0, na0};
}

public static TestFile[] getRetryTestFileArray() {
Expand Down Expand Up @@ -200,9 +247,9 @@ private static String[] getHosts(String https, String http) {
String s1 = toDomain(http);
String s2 = toDomain(https);
if (s2 != null && !s2.equalsIgnoreCase(s1)) {
return new String[] { s1, s2 };
return new String[]{s1, s2};
}
return new String[] { s1 };
return new String[]{s1};
}

private static String toDomain(String d1) {
Expand Down
15 changes: 14 additions & 1 deletion src/test/java/test/com/qiniu/storage/BucketTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void testFile(TestConfig.TestFile file, BucketManager bucketManager) thro
@Test
@Tag("IntegrationTest")
public void testDomains() throws Exception {
testFileWithHandler(new TestFileHandler() {
testAllRegionFileWithHandler(new TestFileHandler() {
@Override
public void testFile(TestConfig.TestFile file, BucketManager bucketManager) throws IOException {
try {
Expand Down Expand Up @@ -1817,6 +1817,19 @@ private void testFileWithHandler(TestFileHandler handler) throws Exception {
}
}

private void testAllRegionFileWithHandler(TestFileHandler handler) throws Exception {
if (handler == null) {
return;
}

TestConfig.TestFile[] files = TestConfig.getAllRegionTestFileArray();
for (TestConfig.TestFile file : files) {
Configuration cfg = new Configuration(file.getRegion());
BucketManager bucketManager = new BucketManager(TestConfig.testAuth, cfg);
handler.testFile(file, bucketManager);
}
}

private interface TestFileHandler {
void testFile(TestConfig.TestFile file, BucketManager bucketManager) throws Exception;
}
Expand Down

0 comments on commit 686513c

Please sign in to comment.