Skip to content

Commit

Permalink
delete fog east host (#606)
Browse files Browse the repository at this point in the history
Co-authored-by: YangSen-qn <yangsen@qiniu.com>
  • Loading branch information
YangSen-qn and YangSen-qn authored Aug 5, 2024
1 parent 5bfcde4 commit 109f868
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 78 deletions.
1 change: 0 additions & 1 deletion examples/upload_v1_api.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class UploadDemo {
* 华南机房(region2): up-z2.qiniup.com 或 upload-z2.qiniup.com
* 北美机房(regionNa0): up-na0.qiniup.com 或 upload-na0.qiniup.com
* 新加坡机房(regionAs0): up-as0.qiniup.com 或 upload-as0.qiniup.com
* 雾存储华东一区(regionFogCnEast1): up-fog-cn-east-1.qiniup.com 或 upload-fog-cn-east-1.qiniup.com
*/
String urlPrefix = "urlPrefix"; // http://up.qiniup.com
//要上传的空间
Expand Down
1 change: 0 additions & 1 deletion examples/upload_v2_api.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class UploadDemo {
* 华南机房(region2): up-z2.qiniup.com 或 upload-z2.qiniup.com
* 北美机房(regionNa0): up-na0.qiniup.com 或 upload-na0.qiniup.com
* 新加坡机房(regionAs0): up-as0.qiniup.com 或 upload-as0.qiniup.com
* 雾存储华东一区(regionFogCnEast1): up-fog-cn-east-1.qiniup.com 或 upload-fog-cn-east-1.qiniup.com
*/
String urlPrefix = "urlPrefix" // http://up.qiniup.com";
// 要上传的空间
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/com/qiniu/storage/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import com.qiniu.http.Client;
import com.qiniu.http.MethodType;
import com.qiniu.http.RequestStreamBody;
import com.qiniu.util.Auth;
import com.qiniu.util.Json;
import com.qiniu.util.StringMap;
import com.qiniu.util.StringUtils;
import com.qiniu.util.*;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
Expand Down Expand Up @@ -461,7 +458,16 @@ public String getHost() throws QiniuException {
}

void setHost(String host) {
this.host = host;
URL tmpUrl = UrlUtils.parseHost(host);
if (tmpUrl == null) {
this.host = null;
return;
}

this.host = tmpUrl.getHost();
if (tmpUrl.getPort() >= 0) {
this.port = tmpUrl.getPort();
}
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/qiniu/storage/UpHostHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ private String failedUpHost(String regionKey) {
this.add("upload-z2.qiniup.com");
this.add("upload-na0.qiniup.com");
this.add("upload-as0.qiniup.com");
this.add("upload-fog-cn-east-1.qiniup.com");
}
};
Collections.shuffle(accHosts); // ?
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/qiniu/util/UrlUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.qiniu.util;

import java.io.CharArrayWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.BitSet;

Expand Down Expand Up @@ -191,6 +193,19 @@ public static String removeHostScheme(String host) {
return host;
}

public static URL parseHost(String host) {
if (StringUtils.isNullOrEmpty(host)) {
return null;
}

String tmpHost = setHostScheme(host, true);
try {
return new URL(tmpHost);
} catch (MalformedURLException e) {
return null;
}
}


/**
* 如果 host 包含 scheme 则优先使用 host 中包含的 scheme
Expand Down
4 changes: 0 additions & 4 deletions src/test/java/test/com/qiniu/TestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,6 @@ public String getRegionId() {
public Region getRegion() {
return region;
}

public boolean isFog() {
return regionId.equals("fog-cn-east-1");
}
}

}
8 changes: 4 additions & 4 deletions src/test/java/test/com/qiniu/processing/PfopTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import org.junit.jupiter.api.Test;
import test.com.qiniu.ResCode;
import test.com.qiniu.TestConfig;

import java.util.*;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand All @@ -31,9 +33,7 @@ public void testPfop() throws QiniuException {
Map<String, Region> bucketKeyMap = new HashMap<String, Region>();
TestConfig.TestFile[] files = TestConfig.getTestFileArray();
for (TestConfig.TestFile testFile : files) {
if (!testFile.isFog()) {
bucketKeyMap.put(testFile.getBucketName(), testFile.getRegion());
}
bucketKeyMap.put(testFile.getBucketName(), testFile.getRegion());
}
List<String> ids = new ArrayList<>();

Expand All @@ -55,7 +55,7 @@ public void testPfop() throws QiniuException {
String fopMp4 = String.format("avthumb/mp4/vcodec/libx264/s/320x240|saveas/%s",
UrlSafeBase64.encodeToString(mp4SaveEntry));

String fops = StringUtils.join(new String[] { fopM3u8, fopMp4 }, ";");
String fops = StringUtils.join(new String[]{fopM3u8, fopMp4}, ";");
System.out.println(fops);

try {
Expand Down
15 changes: 0 additions & 15 deletions src/test/java/test/com/qiniu/storage/BucketTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,6 @@ public void testFetch() throws Exception {
testFileWithHandler(new TestFileHandler() {
@Override
public void testFile(TestConfig.TestFile file, BucketManager bucketManager) throws IOException {
// 雾存储不支持 fetch
if (file.isFog()) {
return;
}

try {
String resUrl = "http://devtools.qiniu.com/qiniu.png";
String resKey = "qiniu.png";
Expand Down Expand Up @@ -972,11 +967,6 @@ public void testPutBucketAccessStyleMode() throws Exception {
testFileWithHandler(new TestFileHandler() {
@Override
public void testFile(TestConfig.TestFile file, BucketManager bucketManager) throws IOException {
// 雾存储没有域名
if (file.isFog()) {
return;
}

String bucket = file.getBucketName();
String url = file.getTestUrl();
System.out.println(bucket + " -- " + url);
Expand Down Expand Up @@ -1590,11 +1580,6 @@ public void testChangeFileType() throws Exception {
testFileWithHandler(new TestFileHandler() {
@Override
public void testFile(TestConfig.TestFile file, BucketManager bucketManager) throws IOException {
// 雾存储不支持 changeType
if (file.isFog()) {
return;
}

String bucket = file.getBucketName();
String key = file.getKey();
String keyToChangeType = "keyToChangeType" + Math.random();
Expand Down
4 changes: 0 additions & 4 deletions src/test/java/test/com/qiniu/storage/RecordUploadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ private void template(final int size, boolean isResumeV2, boolean isConcurrent)

TestConfig.TestFile[] files = TestConfig.getTestFileArray();
for (TestConfig.TestFile file : files) {
// 雾存储不支持 v1
if (file.isFog() && !isResumeV2) {
continue;
}
String bucket = file.getBucketName();
final Region region = file.getRegion();

Expand Down
36 changes: 14 additions & 22 deletions src/test/java/test/com/qiniu/storage/ResumeUploadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
import org.junit.jupiter.api.Test;
import test.com.qiniu.TempFile;
import test.com.qiniu.TestConfig;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand All @@ -33,12 +35,12 @@ public class ResumeUploadTest {

private static boolean[][] testConfigList = {
// isHttps, isResumeV2, isStream, isConcurrent
{ false, true, false, false }, { false, false, false, true }, { false, false, true, false },
{ false, false, true, true }, { false, true, false, false }, { false, true, false, true },
{ false, true, true, false }, { false, true, true, true }, { true, false, false, false },
{ true, false, false, true }, { true, false, true, false }, { true, false, true, true },
{ true, true, false, false }, { true, true, false, true }, { true, true, true, false },
{ true, true, true, true } };
{false, true, false, false}, {false, false, false, true}, {false, false, true, false},
{false, false, true, true}, {false, true, false, false}, {false, true, false, true},
{false, true, true, false}, {false, true, true, true}, {true, false, false, false},
{true, false, false, true}, {true, false, true, false}, {true, false, true, true},
{true, true, false, false}, {true, true, false, true}, {true, true, true, false},
{true, true, true, true}};

/**
* 检测自定义变量foo是否生效
Expand All @@ -51,10 +53,6 @@ public void testXVar() throws IOException {

TestConfig.TestFile[] files = TestConfig.getTestFileArray();
for (TestConfig.TestFile file : files) {
// 雾存储不支持 v1
if (file.isFog()) {
continue;
}
String bucket = file.getBucketName();
Region region = file.getRegion();
final String expectKey = "世/界";
Expand Down Expand Up @@ -99,10 +97,6 @@ private void template(int size, boolean isHttps, boolean isResumeV2, boolean isS
throws IOException {
TestConfig.TestFile[] files = TestConfig.getTestFileArray();
for (TestConfig.TestFile file : files) {
// 雾存储不支持 v1
if (file.isFog() && !isResumeV2) {
continue;
}
String bucket = file.getBucketName();
Region region = file.getRegion();
Configuration config = new Configuration(region);
Expand Down Expand Up @@ -169,14 +163,12 @@ private void template(int size, boolean isHttps, boolean isResumeV2, boolean isS
checkMd5 = true;
}
if (checkMd5) {
if (!file.isFog()) {
String md5 = Md5.md5(f);
String serverMd5 = getFileMD5(file.getTestDomain(), expectKey);
System.out.println(" md5:" + md5);
System.out.println("serverMd5:" + serverMd5);
assertNotNull(serverMd5);
assertEquals(md5, serverMd5);
}
String md5 = Md5.md5(f);
String serverMd5 = getFileMD5(file.getTestDomain(), expectKey);
System.out.println(" md5:" + md5);
System.out.println("serverMd5:" + serverMd5);
assertNotNull(serverMd5);
assertEquals(md5, serverMd5);
} else {
final String etag = Etag.file(f);
System.out.println(" etag:" + etag);
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/test/com/qiniu/storage/StreamUploadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import test.com.qiniu.TestConfig;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -73,9 +75,7 @@ private void template(int size, boolean https) throws IOException {
Map<String, Region> bucketKeyMap = new HashMap<String, Region>();
TestConfig.TestFile[] files = TestConfig.getTestFileArray();
for (TestConfig.TestFile testFile : files) {
if (!testFile.isFog()) {
bucketKeyMap.put(testFile.getBucketName(), testFile.getRegion());
}
bucketKeyMap.put(testFile.getBucketName(), testFile.getRegion());
}

for (Map.Entry<String, Region> entry : bucketKeyMap.entrySet()) {
Expand Down
32 changes: 14 additions & 18 deletions src/test/java/test/com/qiniu/storage/SwitchRegionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.File;
import java.io.IOException;
import java.net.URLEncoder;
Expand All @@ -36,13 +38,13 @@ public class SwitchRegionTest {
private static final int serialType = 1;
private static final int concurrentType = 2;

private static int[][] testConfigList = { { httpType, -1, formType }, { httpType, resumableV1Type, serialType },
{ httpType, resumableV1Type, concurrentType }, { httpType, resumableV2Type, serialType },
{ httpType, resumableV2Type, concurrentType },
private static int[][] testConfigList = {{httpType, -1, formType}, {httpType, resumableV1Type, serialType},
{httpType, resumableV1Type, concurrentType}, {httpType, resumableV2Type, serialType},
{httpType, resumableV2Type, concurrentType},

{ httpsType, -1, formType }, { httpsType, resumableV1Type, serialType },
{ httpsType, resumableV1Type, concurrentType }, { httpsType, resumableV2Type, serialType },
{ httpsType, resumableV2Type, concurrentType }, };
{httpsType, -1, formType}, {httpsType, resumableV1Type, serialType},
{httpsType, resumableV1Type, concurrentType}, {httpsType, resumableV2Type, serialType},
{httpsType, resumableV2Type, concurrentType}};

/**
* 分片上传 检测key、hash、fszie、fname是否符合预期
Expand All @@ -59,10 +61,6 @@ private void template(int size, int httpType, int uploadType, int uploadStyle) t

TestConfig.TestFile[] files = TestConfig.getTestFileArray();
for (TestConfig.TestFile file : files) {
// 雾存储不支持 v1
if (file.isFog() && uploadType == resumableV1Type) {
continue;
}
String bucket = file.getBucketName();

Region mockRegion = new Region.Builder().region("custom").srcUpHost("mock.src.host.com")
Expand Down Expand Up @@ -139,14 +137,12 @@ private void template(int size, int httpType, int uploadType, int uploadStyle) t
checkMd5 = true;
}
if (checkMd5) {
if (!file.isFog()) {
String md5 = Md5.md5(f);
String serverMd5 = getFileMD5(file.getTestDomain(), expectKey);
System.out.println(" md5:" + md5);
System.out.println("serverMd5:" + serverMd5);
assertNotNull(serverMd5);
assertEquals(md5, serverMd5);
}
String md5 = Md5.md5(f);
String serverMd5 = getFileMD5(file.getTestDomain(), expectKey);
System.out.println(" md5:" + md5);
System.out.println("serverMd5:" + serverMd5);
assertNotNull(serverMd5);
assertEquals(md5, serverMd5);
} else {
final String etag = Etag.file(f);
System.out.println(" etag:" + etag);
Expand Down

0 comments on commit 109f868

Please sign in to comment.