Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UC query result support disk cache #506

Merged
merged 31 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1f364ad
Merge pull request #475 from YangSen-qn/http3
xwen-winnie Dec 10, 2021
ef8169f
change uc query retry host order
Jul 19, 2023
bc3f3dc
Merge branch 'master' of YangSen-qn:qiniu/android-sdk into remove-reg…
Jul 20, 2023
112ff06
change test case
Jul 21, 2023
8193846
change test case
Jul 24, 2023
a052eb6
Merge branch 'master' of YangSen-qn:qiniu/android-sdk into remove-reg…
Jul 27, 2023
027d9ba
change mvn_push
Jul 31, 2023
47f87a6
update test token
Jul 31, 2023
21fff24
change gradle.properties: config jvm
Aug 1, 2023
5f060f7
change test case
Aug 2, 2023
4600249
Merge branch 'master' of YangSen-qn:qiniu/android-sdk into fix-publish
Aug 2, 2023
13ba1e5
update mvn_push.gradle
Aug 2, 2023
8608aa2
update test case
Aug 2, 2023
5d73445
version to 8.6.0
Aug 7, 2023
4ddce97
Merge branch 'fix-publish'
Aug 7, 2023
0f28b16
change publish
Oct 9, 2023
8a0b360
fix zone add createZonesInfo
Oct 11, 2023
06c6ae7
update android gradle plugin
Oct 11, 2023
ae58017
Merge branch 'master' of YangSen-qn:qiniu/android-sdk into fixzone
Oct 12, 2023
99a8f69
change publish
Oct 12, 2023
54c3003
add Cache - part 1
Oct 12, 2023
64d0057
auto zone support disk cache
Oct 19, 2023
b876c6b
optimize upload run
Oct 20, 2023
0d746d3
change test case
Oct 20, 2023
d96a439
change test token
Oct 20, 2023
cccaef5
change test case
Oct 20, 2023
546892a
Merge branch 'develop' of YangSen-qn:qiniu/android-sdk into query-dis…
Oct 24, 2023
21e3a11
Merge branch 'master' of YangSen-qn:qiniu/android-sdk into query-disk…
Oct 24, 2023
71e44cf
optimize some code
Oct 25, 2023
21f38d4
auto zone build date
Nov 3, 2023
79a7e12
cache timestamp unit to S
Nov 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions library/src/androidTest/java/com/qiniu/android/TestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ public final class TestConfig {
// TODO: 2020-05-09 bad token for testPutBytesWithFixedZoneUseBackupDomains
// 华东上传凭证
public static final String bucket_z0 = "kodo-phone-zone0-space";
public static final String token_z0 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:IySl002XpGBWsDKkKNK7g_ByUrU=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZTAtc3BhY2UiLCJkZWFkbGluZSI6MTcwMjI2NDUyOSwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
public static final String token_z0 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:kCuN1lxE7wby0SgsYmgleVQh5pk=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZTAtc3BhY2UiLCJkZWFkbGluZSI6MTcwMjk1Mzg5MSwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
// 华北上传凭证
public static final String bucket_z1 = "kodo-phone-zone1-space";
public static final String token_z1 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:SRqIrj9rqtDuq7N9ZuZppqnFvGI=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZTEtc3BhY2UiLCJkZWFkbGluZSI6MTcwMjI2NDUyOSwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
public static final String token_z1 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:6GJohI_Ldf_hBwGATV3iYeuMVZ0=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZTEtc3BhY2UiLCJkZWFkbGluZSI6MTcwMjk1Mzg5MSwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
// 华南上传凭证
public static final String bucket_z2 = "kodo-phone-zone2-space";
public static final String token_z2 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:59MIAaRbhMJUjyTayLSsTMO99H8=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZTItc3BhY2UiLCJkZWFkbGluZSI6MTcwMjI2NDUyOSwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
public static final String token_z2 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:gy-wF5GQuoffNKUmRMKC0wVQDHQ=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZTItc3BhY2UiLCJkZWFkbGluZSI6MTcwMjk1Mzg5MSwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
// 北美上传凭证
public static final String bucket_na0 = "kodo-phone-zone-na0-space";
public static final String token_na0 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:hv6IeMz-bitw_nxnxYEeWJPRFq4=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZS1uYTAtc3BhY2UiLCJkZWFkbGluZSI6MTcwMjI2NDUyOSwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
public static final String token_na0 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:mEbYwqz9BbvKpjemh7arZA01SCY=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZS1uYTAtc3BhY2UiLCJkZWFkbGluZSI6MTcwMjk1Mzg5MSwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
// 东南亚上传凭证
public static final String bucket_as0 = "kodo-phone-zone-as0-space";
public static final String token_as0 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:umlUjNLKvlx7QM9dA7r7xD0Kolc=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZS1hczAtc3BhY2UiLCJkZWFkbGluZSI6MTcwMjI2NDUyOSwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
public static final String token_as0 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:b5V9b1I3FCrNYJ1aQznlcGvyKe0=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZS1hczAtc3BhY2UiLCJkZWFkbGluZSI6MTcwMjk1Mzg5MSwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
// 华北浙江2上传凭证
public static final String bucket_cn_east_2 = "kodo-phone-cn-east-2";
public static final String token_cn_east_2 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:3p87j64XIiAFG7H73leG8zjU120=:eyJzY29wZSI6ImtvZG8tcGhvbmUtY24tZWFzdC0yIiwiZGVhZGxpbmUiOjE3MDIyNjQ1MjksICJyZXR1cm5Cb2R5Ijoie1wiZm9vXCI6JCh4OmZvbyksIFwiYmFyXCI6JCh4OmJhciksIFwibWltZVR5cGVcIjokKG1pbWVUeXBlKSwgXCJoYXNoXCI6JChldGFnKSwgXCJrZXlcIjokKGtleSksIFwiZm5hbWVcIjokKGZuYW1lKSwgXCJmc2l6ZVwiOiQoZnNpemUpfSJ9";
public static final String invalidBucketToken = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:Bq_GcfQI_T5hZl78g1SboR4o75k=:eyJzY29wZSI6InpvbmVfaW52YWxpZCIsImRlYWRsaW5lIjoxNzAyMjY0NTI5LCAicmV0dXJuQm9keSI6IntcImZvb1wiOiQoeDpmb28pLCBcImJhclwiOiQoeDpiYXIpLCBcIm1pbWVUeXBlXCI6JChtaW1lVHlwZSksIFwiaGFzaFwiOiQoZXRhZyksIFwia2V5XCI6JChrZXkpLCBcImZuYW1lXCI6JChmbmFtZSksIFwiZnNpemVcIjokKGZzaXplKX0ifQ==";
public static final String token_cn_east_2 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:5wMZsrDWTJuYW-aYz6AsBJJhol4=:eyJzY29wZSI6ImtvZG8tcGhvbmUtY24tZWFzdC0yIiwiZGVhZGxpbmUiOjE3MDI5NTM4OTEsICJyZXR1cm5Cb2R5Ijoie1wiZm9vXCI6JCh4OmZvbyksIFwiYmFyXCI6JCh4OmJhciksIFwibWltZVR5cGVcIjokKG1pbWVUeXBlKSwgXCJoYXNoXCI6JChldGFnKSwgXCJrZXlcIjokKGtleSksIFwiZm5hbWVcIjokKGZuYW1lKSwgXCJmc2l6ZVwiOiQoZnNpemUpfSJ9";
public static final String invalidBucketToken = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:AF6tAFx4teQul_zEMXWzbN79_eI=:eyJzY29wZSI6InpvbmVfaW52YWxpZCIsImRlYWRsaW5lIjoxNzAyOTUzODkxLCAicmV0dXJuQm9keSI6IntcImZvb1wiOiQoeDpmb28pLCBcImJhclwiOiQoeDpiYXIpLCBcIm1pbWVUeXBlXCI6JChtaW1lVHlwZSksIFwiaGFzaFwiOiQoZXRhZyksIFwia2V5XCI6JChrZXkpLCBcImZuYW1lXCI6JChmbmFtZSksIFwiZnNpemVcIjokKGZzaXplKX0ifQ==";

// -----------
public static final String ak = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ public void complete(int code, ResponseInfo responseInfo, UploadRegionRequestMet
ZonesInfo info = zone.getZonesInfo(token);
assertTrue("before clear cache: info was null", info != null);
assertTrue("before clear cache: info was't valid", info.isValid());
assertTrue("before clear cache: info was temporary", !info.isTemporary());

// 清除不能影响通过 token 获取 ZonesInfo
AutoZone.clearCache();
info = zone.getZonesInfo(token);
assertTrue("after clear cache: info was null", info != null);
assertTrue("after clear cache: info was't valid", info.isValid());
assertTrue("after clear cache: info was't temporary", info.isTemporary());
}

@Test
Expand Down
101 changes: 101 additions & 0 deletions library/src/androidTest/java/com/qiniu/android/utils/CacheTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.qiniu.android.utils;

import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.qiniu.android.BaseTest;

import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class CacheTest extends BaseTest {

@Test
public void testCache() {
Info info = new Info();
info.foo = "foo";
info.bar = 1;

String key = "info_key";
Cache cache = new Cache.Builder(Info.class)
.setVersion("v1")
.setFlushCount(1)
.builder();

cache.cache(key, info, true);


// 1. 测试内存缓存
Info memInfo = (Info) cache.cacheForKey(key);
assertEquals("foo", memInfo.foo);

// 2. 测试删除内存缓存
cache.clearMemoryCache();
memInfo = (Info) cache.cacheForKey(key);
assertEquals(null, memInfo);

// 3. 测试 load
cache = new Cache.Builder(Info.class)
.setVersion("v1")
.setFlushCount(1)
.builder();
memInfo = (Info) cache.cacheForKey(key);
assertEquals("foo", memInfo.foo);

// 4. 测试清除磁盘缓存测试
cache.clearDiskCache();
cache = new Cache.Builder(Info.class)
.setVersion("v1")
.setFlushCount(1)
.builder();
memInfo = (Info) cache.cacheForKey(key);
assertEquals(null, memInfo);

// 5. 测试异步 flush
cache.cache(key, info, false);

try {
Thread.sleep(3 * 1000);
} catch (Exception e) {
}

cache = new Cache.Builder(Info.class)
.setVersion("v1")
.setFlushCount(1)
.builder();
memInfo = (Info) cache.cacheForKey(key);
assertEquals("foo", memInfo.foo);
assertEquals(1, memInfo.bar);
}

static class Info implements Cache.Object {
String foo;
int bar;

Info(){
}

public Info(JSONObject jsonObject) {
if (jsonObject == null) {
return;
}

this.foo = jsonObject.optString("foo");
this.bar = jsonObject.optInt("bar");
}

@Override
public JSONObject toJson() {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("foo", this.foo);
jsonObject.put("bar", this.bar);
} catch (JSONException e) {
e.printStackTrace();
}
return jsonObject;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void testAsyncRetry() {
testStatus.maxCount = 1000;
testStatus.completeCount = 0;

SingleFlight singleFlight = new SingleFlight();
SingleFlight<String> singleFlight = new SingleFlight<>();
for (int i = 0; i < testStatus.maxCount; i++) {
singleFlightPerform(singleFlight, i, 0, true, new CompleteHandler() {
@Override
Expand All @@ -121,16 +121,16 @@ public boolean shouldWait() {
LogUtil.d("== async completeCount:" + testStatus.completeCount + " end");
}

private void singleFlightPerform(final SingleFlight singleFlight,
private void singleFlightPerform(final SingleFlight<String> singleFlight,
final int index,
final int retryCount,
final boolean isAsync,
final CompleteHandler completeHandler) {

try {
singleFlight.perform("key", new SingleFlight.ActionHandler() {
singleFlight.perform("key", new SingleFlight.ActionHandler<String>() {
@Override
public void action(final SingleFlight.CompleteHandler singleFlightCompleteHandler) throws Exception {
public void action(final SingleFlight.CompleteHandler<String> singleFlightCompleteHandler) throws Exception {

final CompleteHandler completeHandlerP = new CompleteHandler() {
@Override
Expand Down Expand Up @@ -160,9 +160,9 @@ public void run() {
completeHandlerP.complete();
}
}
}, new SingleFlight.CompleteHandler() {
}, new SingleFlight.CompleteHandler<String>() {
@Override
public void complete(Object value) {
public void complete(String value) {
if (retryCount < RetryCount) {
singleFlightPerform(singleFlight, index, retryCount + 1, isAsync, completeHandler);
} else {
Expand Down
Loading
Loading