Skip to content

Http client in Firebase Segmentation SDK to call backend service. #573

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 45 commits into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
45 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
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
52 changes: 4 additions & 48 deletions firebase-segmentation/firebase-segmentation.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,12 @@

plugins {
id 'firebase-library'
id 'com.google.protobuf'
}

firebaseLibrary {
testLab.enabled = true
}

protobuf {
// Configure the protoc executable
protoc {
// Download from repositories
artifact = 'com.google.protobuf:protoc:3.4.0'
}
plugins {
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:1.12.0'
}
javalite {
// The codegen for lite comes as a separate artifact
artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
}
}
generateProtoTasks {
all().each { task ->
task.builtins {
// In most cases you don't need the full Java output
// if you use the lite output.
remove java
}
task.plugins {
grpc {
option 'lite'
}
javalite {}
}
}
}
}

android {
compileSdkVersion project.targetSdkVersion

Expand All @@ -63,13 +30,6 @@ android {
versionName version
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
sourceSets {
main {
proto {
srcDir 'src/main/proto'
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
Expand All @@ -83,18 +43,14 @@ android {

dependencies {
implementation project(':firebase-common')
implementation project(':protolite-well-known-types')

implementation('com.google.firebase:firebase-iid:17.0.3') {
exclude group: "com.google.firebase", module: "firebase-common"
}
implementation 'io.grpc:grpc-stub:1.21.0'
implementation 'io.grpc:grpc-protobuf-lite:1.21.0'
implementation 'io.grpc:grpc-okhttp:1.21.0'

implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.multidex:multidex:2.0.0'
implementation 'com.google.android.gms:play-services-tasks:16.0.1'
implementation 'com.squareup.okhttp:okhttp:2.7.5'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.google.android.gms:play-services-tasks:17.0.0'

compileOnly "com.google.auto.value:auto-value-annotations:1.6.5"
annotationProcessor "com.google.auto.value:auto-value:1.6.2"
Expand All @@ -103,7 +59,7 @@ dependencies {
testImplementation 'junit:junit:4.12'
testImplementation "org.robolectric:robolectric:$robolectricVersion"

androidTestImplementation "androidx.annotation:annotation:1.1.0"
androidTestImplementation "androidx.annotation:annotation:1.0.0"
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test:runner:1.2.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,24 @@ public void setUp() {
firebaseApp =
FirebaseApp.initializeApp(
ApplicationProvider.getApplicationContext(),
new FirebaseOptions.Builder().setApplicationId("1:123456789:android:abcdef").build());
new FirebaseOptions.Builder()
.setApplicationId("1:123456789:android:abcdef")
.setApiKey("api_key")
.build());
actualCache = new CustomInstallationIdCache(firebaseApp);

when(backendClientReturnsOk.updateCustomInstallationId(
anyLong(), anyString(), anyString(), anyString(), anyString()))
.thenReturn(SegmentationServiceClient.Code.OK);
when(backendClientReturnsOk.clearCustomInstallationId(
anyLong(), anyString(), anyString(), anyString()))
.thenReturn(Tasks.forResult(SegmentationServiceClient.Code.OK));
when(backendClientReturnsOk.clearCustomInstallationId(anyLong(), anyString(), anyString()))
.thenReturn(Tasks.forResult(SegmentationServiceClient.Code.OK));
.thenReturn(SegmentationServiceClient.Code.OK);
when(backendClientReturnsError.updateCustomInstallationId(
anyLong(), anyString(), anyString(), anyString(), anyString()))
.thenReturn(SegmentationServiceClient.Code.SERVER_ERROR);
when(backendClientReturnsError.clearCustomInstallationId(
anyLong(), anyString(), anyString(), anyString()))
.thenReturn(Tasks.forResult(SegmentationServiceClient.Code.SERVER_INTERNAL_ERROR));
when(backendClientReturnsError.clearCustomInstallationId(anyLong(), anyString(), anyString()))
.thenReturn(Tasks.forResult(SegmentationServiceClient.Code.SERVER_INTERNAL_ERROR));
.thenReturn(SegmentationServiceClient.Code.SERVER_ERROR);
when(firebaseInstanceId.getInstanceId())
.thenReturn(
Tasks.forResult(
Expand All @@ -98,13 +103,13 @@ public String getToken() {
return "iid_token";
}
}));
when(cacheReturnsError.insertOrUpdateCacheEntry(any())).thenReturn(Tasks.forResult(false));
when(cacheReturnsError.insertOrUpdateCacheEntry(any())).thenReturn(false);
when(cacheReturnsError.readCacheEntryValue()).thenReturn(null);
}

@After
public void cleanUp() throws Exception {
Tasks.await(actualCache.clear());
actualCache.clear();
}

@Test
Expand Down Expand Up @@ -165,12 +170,11 @@ public void testUpdateCustomInstallationId_CacheError_BackendOk() throws Interru

@Test
public void testClearCustomInstallationId_CacheOk_BackendOk() throws Exception {
Tasks.await(
actualCache.insertOrUpdateCacheEntry(
CustomInstallationIdCacheEntryValue.create(
CUSTOM_INSTALLATION_ID,
FIREBASE_INSTANCE_ID,
CustomInstallationIdCache.CacheStatus.SYNCED)));
actualCache.insertOrUpdateCacheEntry(
CustomInstallationIdCacheEntryValue.create(
CUSTOM_INSTALLATION_ID,
FIREBASE_INSTANCE_ID,
CustomInstallationIdCache.CacheStatus.SYNCED));
FirebaseSegmentation firebaseSegmentation =
new FirebaseSegmentation(
firebaseApp, firebaseInstanceId, actualCache, backendClientReturnsOk);
Expand All @@ -183,12 +187,11 @@ public void testClearCustomInstallationId_CacheOk_BackendOk() throws Exception {

@Test
public void testClearCustomInstallationId_CacheOk_BackendError() throws Exception {
Tasks.await(
actualCache.insertOrUpdateCacheEntry(
CustomInstallationIdCacheEntryValue.create(
CUSTOM_INSTALLATION_ID,
FIREBASE_INSTANCE_ID,
CustomInstallationIdCache.CacheStatus.SYNCED)));
actualCache.insertOrUpdateCacheEntry(
CustomInstallationIdCacheEntryValue.create(
CUSTOM_INSTALLATION_ID,
FIREBASE_INSTANCE_ID,
CustomInstallationIdCache.CacheStatus.SYNCED));
FirebaseSegmentation firebaseSegmentation =
new FirebaseSegmentation(
firebaseApp, firebaseInstanceId, actualCache, backendClientReturnsError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.gms.tasks.Tasks;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import org.junit.After;
Expand Down Expand Up @@ -55,8 +54,8 @@ public void setUp() {

@After
public void cleanUp() throws Exception {
Tasks.await(cache0.clear());
Tasks.await(cache1.clear());
cache0.clear();
cache1.clear();
}

@Test
Expand All @@ -68,12 +67,9 @@ public void testReadCacheEntry_Null() {
@Test
public void testUpdateAndReadCacheEntry() throws Exception {
assertTrue(
Tasks.await(
cache0.insertOrUpdateCacheEntry(
CustomInstallationIdCacheEntryValue.create(
"123456",
"cAAAAAAAAAA",
CustomInstallationIdCache.CacheStatus.PENDING_UPDATE))));
cache0.insertOrUpdateCacheEntry(
CustomInstallationIdCacheEntryValue.create(
"123456", "cAAAAAAAAAA", CustomInstallationIdCache.CacheStatus.PENDING_UPDATE)));
CustomInstallationIdCacheEntryValue entryValue = cache0.readCacheEntryValue();
assertThat(entryValue.getCustomInstallationId()).isEqualTo("123456");
assertThat(entryValue.getFirebaseInstanceId()).isEqualTo("cAAAAAAAAAA");
Expand All @@ -82,10 +78,9 @@ public void testUpdateAndReadCacheEntry() throws Exception {
assertNull(cache1.readCacheEntryValue());

assertTrue(
Tasks.await(
cache0.insertOrUpdateCacheEntry(
CustomInstallationIdCacheEntryValue.create(
"123456", "cAAAAAAAAAA", CustomInstallationIdCache.CacheStatus.SYNCED))));
cache0.insertOrUpdateCacheEntry(
CustomInstallationIdCacheEntryValue.create(
"123456", "cAAAAAAAAAA", CustomInstallationIdCache.CacheStatus.SYNCED)));
entryValue = cache0.readCacheEntryValue();
assertThat(entryValue.getCustomInstallationId()).isEqualTo("123456");
assertThat(entryValue.getFirebaseInstanceId()).isEqualTo("cAAAAAAAAAA");
Expand Down
Loading