Skip to content

Commit

Permalink
Merge pull request #475 from YangSen-qn/http3
Browse files Browse the repository at this point in the history
Http3
  • Loading branch information
xwen-winnie authored Dec 10, 2021
2 parents 22b602c + d3aa558 commit 1f364ad
Show file tree
Hide file tree
Showing 25 changed files with 694 additions and 184 deletions.
6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/scopes/scope_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import java.util.regex.Matcher

apply plugin: 'com.android.library'

def versionName() {
def versionNameFunc() {
String config = 'library/src/main/java/com/qiniu/android/common/Constants.java'
String fileContents = new File(config).text
Matcher myMatcher = fileContents =~ /VERSION = "(.+)";/
Expand All @@ -16,8 +16,8 @@ def versionNameToCode(String version) {
return v.toLong()
}

String version = versionName()
int code = versionNameToCode(version)
String versionNameVar = versionNameFunc()
int code = versionNameToCode(versionNameVar)

android {
compileSdkVersion 30
Expand All @@ -27,7 +27,7 @@ android {
minSdkVersion 14
targetSdkVersion 30
versionCode code
versionName version
versionName versionNameVar
}
buildTypes {
release {
Expand Down Expand Up @@ -59,13 +59,14 @@ dependencies {
// implementation 'com.google.code.findbugs:jsr305:3.0.2'
implementation 'org.conscrypt:conscrypt-android:2.2.1'
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.13'

androidTestImplementation 'junit:junit:4.12'
// androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

task releaseJar(type: Jar, dependsOn: 'build') {
//指定生成的jar名
baseName 'qiniu-android-sdk-' + version
baseName 'qiniu-android-sdk-' + versionNameVar
//从哪里打包class文件
// from('build/intermediates/classes/release/com/qiniu/android/dns/')
//打包到jar后的目录结构
Expand All @@ -85,7 +86,7 @@ android.libraryVariants.all { variant ->
artifacts.add('archives', task)
}

setProperty('VERSION_NAME', version)
setProperty('VERSION_NAME', versionNameVar)
setProperty('VERSION_CODE', code)

apply from: '../mvn_push.gradle'
12 changes: 3 additions & 9 deletions library/src/androidTest/java/com/qiniu/android/BaseTest.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
package com.qiniu.android;

import android.test.AndroidTestCase;

import com.qiniu.android.utils.LogUtil;

import android.test.AndroidTestCase;

import java.util.Date;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
* Created by yangsen on 2020/5/26
*/
public class BaseTest extends AndroidTestCase {

@Override
protected void setUp() throws Exception {
super.setUp();
LogUtil.enableLog(true);
}
public class BaseTest extends AndroidTestCase{

private long maxWaitTimestamp = 0;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.qiniu.android;

import android.net.Uri;
import android.util.Log;

import com.qiniu.android.http.ResponseInfo;
import com.qiniu.android.storage.Configuration;
Expand All @@ -22,6 +23,13 @@

public class UploadBaseTest extends BaseTest {

@Override
protected void setUp() throws Exception {
super.setUp();
LogUtil.enableLog(true);
LogUtil.setLogLevel(Log.VERBOSE);
}

protected UploadOptions defaultOptions = new UploadOptions(null, null, true, new UpProgressBytesHandler() {
@Override
public void progress(String key, long uploadBytes, long totalBytes) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.qiniu.android.serverRegion;

import com.qiniu.android.BaseTest;
import com.qiniu.android.http.serverRegion.HttpServerManager;

public class HttpServerManagerTest extends BaseTest {

public void testServer() {
String host = "up.qiniu.com";
String ip = "192.168.1.1";
int duration = 10;
HttpServerManager manager = HttpServerManager.getInstance();
assertFalse("null host and ip add success", manager.addHttp3Server(null, null, duration));
assertFalse("null host add success", manager.addHttp3Server(null, ip, duration));
assertFalse("null ip add success", manager.addHttp3Server(host, null, duration));
assertFalse("empty host and ip add success", manager.addHttp3Server("", "", duration));
assertFalse("empty host add success", manager.addHttp3Server("", ip, duration));
assertFalse("empty ip add success", manager.addHttp3Server(host, "", duration));
assertFalse("liveDuration < 0 add success", manager.addHttp3Server(host, ip, -1));

manager.addHttp3Server(host, ip, duration);
assertTrue("host ip should support", manager.isServerSupportHttp3(host, ip));

assertFalse("null host and ip should not support", manager.isServerSupportHttp3(null, null));
assertFalse("null host should not support", manager.isServerSupportHttp3(null, ip));
assertFalse("null ip should not support", manager.isServerSupportHttp3(host, null));

assertFalse("empty host and ip should not support", manager.isServerSupportHttp3("", ""));
assertFalse("empty host should not support", manager.isServerSupportHttp3("", ip));
assertFalse("empty ip should not support", manager.isServerSupportHttp3(host, "ip"));

assertFalse("no exist host and ip should not support", manager.isServerSupportHttp3("host", "ip"));
assertFalse("no exist hos should not support", manager.isServerSupportHttp3("host", ip));
assertFalse("no exist ip should not support", manager.isServerSupportHttp3(host, "ip"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.qiniu.android.utils.LogUtil;
import com.qiniu.android.utils.Utils;

import java.lang.reflect.Field;
import java.util.Date;

/**
Expand Down Expand Up @@ -33,16 +34,26 @@ public void run() {

public void testTransactionManagerAddAndRemove(){

final boolean[] executedTransaction = {false};
final int[] executedTransaction = {0};
String normalName = "testNormalTransaction";
TransactionManager.Transaction normal = new TransactionManager.Transaction(normalName, 0, new Runnable() {
@Override
public void run() {
LogUtil.d("1: thread:" + Thread.currentThread().getId() + new Date().toString());
executedTransaction[0] = true;
executedTransaction[0] += 1;
}
});

try {
Field executedCountField = TransactionManager.Transaction.class.getDeclaredField("executedCount");
executedCountField.setAccessible(true);
long executedCount = executedCountField.getLong(normal);
System.out.print("A Transaction executedCount:" + executedCount);
assertEquals("A Transaction executedCount was not 1", 0, executedCount);
} catch (Exception e) {
e.printStackTrace();
}

String timeName = "testTimeTransaction";
TransactionManager.Transaction time = new TransactionManager.Transaction(timeName, 3, 2, new Runnable() {
@Override
Expand All @@ -63,7 +74,7 @@ public void run() {
wait(new WaitConditional() {
@Override
public boolean shouldWait() {
return !executedTransaction[0];
return executedTransaction[0] == 0;
}
}, 5 * 60);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


public final class Constants {
public static final String VERSION = "8.4.0";
public static final String VERSION = "8.5.0";

public static final String UTF_8 = "utf-8";
}
29 changes: 23 additions & 6 deletions library/src/main/java/com/qiniu/android/http/ResponseInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public final class ResponseInfo {
* 回复状态码
*/
public final int statusCode;

/**
* 请求使用的 http 版本信息
*/
public final String httpVersion;

/**
* response 信息
*/
Expand Down Expand Up @@ -98,6 +104,7 @@ public final class ResponseInfo {

private ResponseInfo(JSONObject json,
Map<String, String> responseHeader,
String httpVersion,
int statusCode,
String reqId,
String xlog,
Expand All @@ -106,6 +113,7 @@ private ResponseInfo(JSONObject json,
String error) {
this.response = json;
this.responseHeader = responseHeader;
this.httpVersion = httpVersion;
this.statusCode = statusCode;
this.reqId = reqId != null ? reqId : "";
this.xlog = xlog;
Expand All @@ -129,7 +137,7 @@ private ResponseInfo(JSONObject json,
}

public static ResponseInfo successResponse() {
ResponseInfo responseInfo = new ResponseInfo(null, null, RequestSuccess, "inter:reqid", "inter:xlog", "inter:xvia", null, null);
ResponseInfo responseInfo = new ResponseInfo(null, null, null, RequestSuccess, "inter:reqid", "inter:xlog", "inter:xvia", null, null);
return responseInfo;
}

Expand Down Expand Up @@ -179,7 +187,7 @@ public static ResponseInfo unexpectedSysCallError(String desc) {
}

public static ResponseInfo errorInfo(int statusCode, String error) {
ResponseInfo responseInfo = new ResponseInfo(null, null, statusCode, null, null, null, null, error);
ResponseInfo responseInfo = new ResponseInfo(null, null, "", statusCode, null, null, null, null, error);
return responseInfo;
}

Expand All @@ -188,8 +196,17 @@ public static ResponseInfo create(Request request,
Map<String, String> responseHeader,
JSONObject response,
String errorMessage) {
return create(request, null, responseCode, responseHeader, response, errorMessage);
}

public static ResponseInfo create(Request request,
String httpVersion,
int responseCode,
Map<String, String> responseHeader,
JSONObject response,
String errorMessage) {

String host = (request != null ? request.host : null);
String host = (request != null ? request.getHost() : null);
String reqId = null;
String xlog = null;
String xvia = null;
Expand All @@ -205,13 +222,13 @@ public static ResponseInfo create(Request request,
}
}

ResponseInfo responseInfo = new ResponseInfo(response, responseHeader, responseCode, reqId, xlog, xvia, host, errorMessage);
ResponseInfo responseInfo = new ResponseInfo(response, responseHeader, httpVersion, responseCode, reqId, xlog, xvia, host, errorMessage);
return responseInfo;
}

public ResponseInfo checkMaliciousResponse() {
if (statusCode == 200 && ((reqId == null || reqId.length() == 0) && xlog == null)) {
return new ResponseInfo(null, responseHeader, MaliciousResponseError, reqId, xlog, xvia, host, "this is a malicious response");
if (statusCode == 200 && (reqId == null && xlog == null)) {
return new ResponseInfo(null, responseHeader, httpVersion, MaliciousResponseError, reqId, xlog, xvia, host, "this is a malicious response");
} else {
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ConnectChecker {
private static SingleFlight<UploadSingleRequestMetrics> singleFlight = new SingleFlight<>();

public static boolean isConnected(UploadSingleRequestMetrics metrics) {
return metrics != null && metrics.response != null && metrics.response.statusCode > 99;
return metrics != null && metrics.getResponse() != null && metrics.getResponse().statusCode > 99;
}

public static UploadSingleRequestMetrics check() {
Expand Down Expand Up @@ -133,7 +133,7 @@ public Object call() throws Exception {
SystemHttpClient client = new SystemHttpClient();

LogUtil.i("== checkHost:" + host);
client.request(request, true, null, null, new IRequestClient.RequestClientCompleteHandler() {
client.request(request, new IRequestClient.Options(null, true, null), null, new IRequestClient.RequestClientCompleteHandler() {
@Override
public void complete(ResponseInfo responseInfo, UploadSingleRequestMetrics metrics, JSONObject response) {
synchronized (this) {
Expand Down
Loading

0 comments on commit 1f364ad

Please sign in to comment.