Skip to content

FirebaseSegmentation SDK changes #673

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

Merged
merged 52 commits into from
Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
8881325
Implement Firebase segmentation SDK device local cache
diwu-arete Jun 13, 2019
864748f
[Firebase Segmentation] Add custom installation id cache layer and te…
diwu-arete Jun 14, 2019
0a3ebf6
Add test for updating cache
diwu-arete Jun 14, 2019
2d158ed
Switch to use SQLiteOpenHelper
diwu-arete Jun 15, 2019
f118d39
Switch to use SharedPreferences from SQLite.
diwu-arete Jun 17, 2019
4da5d31
Change the cache class to be singleton
diwu-arete Jun 18, 2019
d1ff0ec
Wrap shared pref commit in a async task.
diwu-arete Jun 18, 2019
2c5102c
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete Jun 18, 2019
41fbfee
Address comments
diwu-arete Jun 18, 2019
5fd2fa0
Google format fix
diwu-arete Jun 18, 2019
e950003
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete Jun 18, 2019
dba0c0e
Replace some deprecated code.
diwu-arete Jun 18, 2019
dc37bf8
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete Jun 18, 2019
ebdd626
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete Jun 18, 2019
f26741e
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete Jun 18, 2019
38c403f
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete Jun 18, 2019
a9a43a4
Package refactor
diwu-arete Jun 18, 2019
ca6dacf
nit
diwu-arete Jun 18, 2019
e7fff81
nit
diwu-arete Jun 18, 2019
bb8bf45
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete Jun 18, 2019
b381889
Add the state machine of updating custom installation id in the local
diwu-arete Jun 19, 2019
a72cf60
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete Jun 19, 2019
1adcfbd
minor format fix
diwu-arete Jun 20, 2019
6091f82
Address comments #1
diwu-arete Jun 20, 2019
ada5577
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete Jun 20, 2019
af5bcd1
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete Jun 20, 2019
de6fb6d
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete Jun 24, 2019
75e523b
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete Jun 24, 2019
134f06e
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete Jun 24, 2019
6a0f502
Http client in Firebase Segmentation SDK to call backend service.
diwu-arete Jun 26, 2019
4ac7db5
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete Jun 26, 2019
7f40978
Revert unintentional change
diwu-arete Jun 26, 2019
b2fc302
Fix connected device test
diwu-arete Jun 26, 2019
1f2ab34
Fix connected device test
diwu-arete Jun 26, 2019
402d8b6
Merge branch 'arete-floc' of github.com:firebase/firebase-android-sdk…
diwu-arete Jun 26, 2019
ce698cf
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete Jul 8, 2019
0e0278e
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete Jul 8, 2019
9880624
1. Add a few annotations to make java code Kotlin friendly
diwu-arete Jul 8, 2019
8ffb5bb
Fix java format
diwu-arete Jul 8, 2019
daf4698
Fix API version
diwu-arete Jul 8, 2019
7985e14
Change the segmentation API implementation to synchronous and put the
diwu-arete Jul 9, 2019
9f36d35
Fix a async getResult race issue.
diwu-arete Jul 9, 2019
047c0af
OkHttpClient -> HttpsUrlConnection
diwu-arete Jul 10, 2019
8b39c31
Use gzip for compressing content and fix ourput stream memory leak risk.
diwu-arete Jul 18, 2019
dc1a63c
Addressed a few comments
diwu-arete Jul 22, 2019
b401d31
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete Jul 22, 2019
8ba1c9b
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete Jul 22, 2019
143ed74
FirebaseSegmentation SDK
diwu-arete Jul 30, 2019
e5f0cd3
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete Jul 30, 2019
a5250c1
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete Jul 30, 2019
6daae2a
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete Aug 5, 2019
4d5b2de
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete Aug 6, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ public void testUpdateCustomInstallationId_CacheOk_BackendOk() throws Exception
}

@Test
public void testUpdateCustomInstallationId_CacheOk_BackendError() throws InterruptedException {
public void testUpdateCustomInstallationId_CacheOk_BackendError_Retryable()
throws InterruptedException {
FirebaseSegmentation firebaseSegmentation =
new FirebaseSegmentation(
firebaseApp, firebaseInstanceId, actualCache, backendClientReturnsError);
Expand All @@ -150,6 +151,31 @@ public void testUpdateCustomInstallationId_CacheOk_BackendError() throws Interru
.isEqualTo(CustomInstallationIdCache.CacheStatus.PENDING_UPDATE);
}

@Test
public void testUpdateCustomInstallationId_CacheOk_BackendError_NotRetryable()
throws InterruptedException {
when(backendClientReturnsError.updateCustomInstallationId(
anyLong(), anyString(), anyString(), anyString(), anyString()))
.thenReturn(SegmentationServiceClient.Code.CONFLICT);
FirebaseSegmentation firebaseSegmentation =
new FirebaseSegmentation(
firebaseApp, firebaseInstanceId, actualCache, backendClientReturnsError);

// Expect exception
try {
Tasks.await(firebaseSegmentation.setCustomInstallationId(CUSTOM_INSTALLATION_ID));
fail();
} catch (ExecutionException expected) {
Throwable cause = expected.getCause();
assertThat(cause).isInstanceOf(SetCustomInstallationIdException.class);
assertThat(((SetCustomInstallationIdException) cause).getStatus())
.isEqualTo(SetCustomInstallationIdException.Status.DUPLICATED_CUSTOM_INSTALLATION_ID);
}

CustomInstallationIdCacheEntryValue entryValue = actualCache.readCacheEntryValue();
assertThat(entryValue).isNull();
}

@Test
public void testUpdateCustomInstallationId_CacheError_BackendOk() throws InterruptedException {
FirebaseSegmentation firebaseSegmentation =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private Void updateCustomInstallationId(String customInstallationId)
instanceIdResult = Tasks.await(firebaseInstanceId.getInstanceId());
} catch (ExecutionException | InterruptedException e) {
throw new SetCustomInstallationIdException(
"Failed to get Firebase instance id", Status.CLIENT_ERROR);
Status.CLIENT_ERROR, "Failed to get Firebase instance id");
}

boolean firstUpdateCacheResult =
Expand All @@ -140,7 +140,7 @@ private Void updateCustomInstallationId(String customInstallationId)

if (!firstUpdateCacheResult) {
throw new SetCustomInstallationIdException(
"Failed to update client side cache", Status.CLIENT_ERROR);
Status.CLIENT_ERROR, "Failed to update client side cache");
}

// Start requesting backend when first cache updae is done.
Expand All @@ -164,19 +164,30 @@ private Void updateCustomInstallationId(String customInstallationId)
instanceIdResult.getId(),
CustomInstallationIdCache.CacheStatus.SYNCED));
break;
case HTTP_CLIENT_ERROR:
throw new SetCustomInstallationIdException(Status.CLIENT_ERROR);
case UNAUTHORIZED:
localCache.clear();
throw new SetCustomInstallationIdException(
Status.CLIENT_ERROR, "Instance id token is invalid.");
case CONFLICT:
throw new SetCustomInstallationIdException(Status.DUPLICATED_CUSTOM_INSTALLATION_ID);
localCache.clear();
throw new SetCustomInstallationIdException(
Status.DUPLICATED_CUSTOM_INSTALLATION_ID,
"The custom installation id is used by another Firebase installation in your project.");
case HTTP_CLIENT_ERROR:
localCache.clear();
throw new SetCustomInstallationIdException(Status.CLIENT_ERROR, "Http client error(4xx)");
case NETWORK_ERROR:
case SERVER_ERROR:
default:
// These are considered retryable errors, so not to clean up the cache.
throw new SetCustomInstallationIdException(Status.BACKEND_ERROR);
}

if (finalUpdateCacheResult) {
return null;
} else {
throw new SetCustomInstallationIdException(
"Failed to update client side cache", Status.CLIENT_ERROR);
Status.CLIENT_ERROR, "Failed to update client side cache");
}
}

Expand Down Expand Up @@ -204,7 +215,7 @@ private Void clearCustomInstallationId() throws SetCustomInstallationIdException
instanceIdResult = Tasks.await(firebaseInstanceId.getInstanceId());
} catch (ExecutionException | InterruptedException e) {
throw new SetCustomInstallationIdException(
"Failed to get Firebase instance id", Status.CLIENT_ERROR);
Status.CLIENT_ERROR, "Failed to get Firebase instance id");
}

boolean firstUpdateCacheResult =
Expand All @@ -214,7 +225,7 @@ private Void clearCustomInstallationId() throws SetCustomInstallationIdException

if (!firstUpdateCacheResult) {
throw new SetCustomInstallationIdException(
"Failed to update client side cache", Status.CLIENT_ERROR);
Status.CLIENT_ERROR, "Failed to update client side cache");
}

String iid = instanceIdResult.getId();
Expand All @@ -231,17 +242,23 @@ private Void clearCustomInstallationId() throws SetCustomInstallationIdException
case OK:
finalUpdateCacheResult = localCache.clear();
break;
case UNAUTHORIZED:
throw new SetCustomInstallationIdException(
Status.CLIENT_ERROR, "Instance id token is invalid.");
case HTTP_CLIENT_ERROR:
throw new SetCustomInstallationIdException(Status.CLIENT_ERROR);
throw new SetCustomInstallationIdException(Status.CLIENT_ERROR, "Http client error(4xx)");
case NETWORK_ERROR:
case SERVER_ERROR:
default:
// These are considered retryable errors, so not to clean up the cache.
throw new SetCustomInstallationIdException(Status.BACKEND_ERROR);
}

if (finalUpdateCacheResult) {
return null;
} else {
throw new SetCustomInstallationIdException(
"Failed to update client side cache", Status.CLIENT_ERROR);
Status.CLIENT_ERROR, "Failed to update client side cache");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public enum Status {
this.status = status;
}

SetCustomInstallationIdException(@NonNull String message, @NonNull Status status) {
SetCustomInstallationIdException(@NonNull Status status, @NonNull String message) {
super(message);
this.status = status;
}

SetCustomInstallationIdException(
@NonNull String message, @NonNull Status status, Throwable cause) {
@NonNull Status status, @NonNull String message, Throwable cause) {
super(message, cause);
this.status = status;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ public class SegmentationServiceClient {
public enum Code {
OK,

HTTP_CLIENT_ERROR,

CONFLICT,

UNAUTHORIZED,

NETWORK_ERROR,

SERVER_ERROR,
HTTP_CLIENT_ERROR,

UNAUTHORIZED,
SERVER_ERROR,
}

@NonNull
Expand Down Expand Up @@ -100,6 +100,9 @@ public Code updateCustomInstallationId(
case 409:
return Code.CONFLICT;
default:
if (httpResponseCode / 100 == 4) {
return Code.HTTP_CLIENT_ERROR;
}
return Code.SERVER_ERROR;
}
} catch (IOException e) {
Expand Down Expand Up @@ -158,6 +161,9 @@ public Code clearCustomInstallationId(
case 401:
return Code.UNAUTHORIZED;
default:
if (httpResponseCode / 100 == 4) {
return Code.HTTP_CLIENT_ERROR;
}
return Code.SERVER_ERROR;
}
} catch (IOException e) {
Expand Down