-
Notifications
You must be signed in to change notification settings - Fork 624
[FLoC] Change FLoC instrumental tests to be unit tests. #1058
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
Changes from all commits
Commits
Show all changes
67 commits
Select commit
Hold shift + click to select a range
8881325
Implement Firebase segmentation SDK device local cache
diwu-arete 864748f
[Firebase Segmentation] Add custom installation id cache layer and te…
diwu-arete 0a3ebf6
Add test for updating cache
diwu-arete 2d158ed
Switch to use SQLiteOpenHelper
diwu-arete f118d39
Switch to use SharedPreferences from SQLite.
diwu-arete 4da5d31
Change the cache class to be singleton
diwu-arete d1ff0ec
Wrap shared pref commit in a async task.
diwu-arete 2c5102c
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete 41fbfee
Address comments
diwu-arete 5fd2fa0
Google format fix
diwu-arete e950003
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete dba0c0e
Replace some deprecated code.
diwu-arete dc37bf8
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete ebdd626
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete f26741e
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete 38c403f
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete a9a43a4
Package refactor
diwu-arete ca6dacf
nit
diwu-arete e7fff81
nit
diwu-arete bb8bf45
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete b381889
Add the state machine of updating custom installation id in the local
diwu-arete a72cf60
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete 1adcfbd
minor format fix
diwu-arete 6091f82
Address comments #1
diwu-arete ada5577
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete af5bcd1
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete de6fb6d
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete 75e523b
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete 134f06e
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete 6a0f502
Http client in Firebase Segmentation SDK to call backend service.
diwu-arete 4ac7db5
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete 7f40978
Revert unintentional change
diwu-arete b2fc302
Fix connected device test
diwu-arete 1f2ab34
Fix connected device test
diwu-arete 402d8b6
Merge branch 'arete-floc' of github.com:firebase/firebase-android-sdk…
diwu-arete ce698cf
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete 0e0278e
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete 9880624
1. Add a few annotations to make java code Kotlin friendly
diwu-arete 8ffb5bb
Fix java format
diwu-arete daf4698
Fix API version
diwu-arete 7985e14
Change the segmentation API implementation to synchronous and put the
diwu-arete 9f36d35
Fix a async getResult race issue.
diwu-arete 047c0af
OkHttpClient -> HttpsUrlConnection
diwu-arete 8b39c31
Use gzip for compressing content and fix ourput stream memory leak risk.
diwu-arete dc1a63c
Addressed a few comments
diwu-arete b401d31
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete 8ba1c9b
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete 143ed74
FirebaseSegmentation SDK
diwu-arete e5f0cd3
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete a5250c1
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete 6daae2a
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete 4d5b2de
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete 78ce7cd
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete d467379
Restrict Firebase API key to Android app package name.
diwu-arete 818e471
Explicitly add internet permission
diwu-arete e2fbc88
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete a7ef2db
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete f866315
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete a4fcd34
Disable registrar test for FirebaseSegmentation.
diwu-arete 557ea7a
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete 0149308
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete f757b26
Disable test lab
diwu-arete 34caf2c
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete 461f654
Add api info for segmentation API
diwu-arete 2a0a7a4
[FLoC] Replace the custom installation id cache SharedPref
diwu-arete 7b36ad5
[FLoC] Change FLoC instrumental tests to be unit tests.
diwu-arete b5bd948
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...e-segmentation/src/test/java/com/google/firebase/segmentation/TestOnCompleteListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2019 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.firebase.segmentation; | ||
|
||
import androidx.annotation.NonNull; | ||
import com.google.android.gms.tasks.OnCompleteListener; | ||
import com.google.android.gms.tasks.Task; | ||
import java.io.IOException; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Helper listener that works around a limitation of the Tasks API where await() cannot be called on | ||
* the main thread. This listener works around it by running itself on a different thread, thus | ||
* allowing the main thread to be woken up when the Tasks complete. | ||
*/ | ||
public class TestOnCompleteListener<TResult> implements OnCompleteListener<TResult> { | ||
private static final long TIMEOUT_MS = 5000; | ||
private final CountDownLatch latch = new CountDownLatch(1); | ||
private Task<TResult> task; | ||
private volatile TResult result; | ||
private volatile Exception exception; | ||
private volatile boolean successful; | ||
|
||
@Override | ||
public void onComplete(@NonNull Task<TResult> task) { | ||
this.task = task; | ||
successful = task.isSuccessful(); | ||
if (successful) { | ||
result = task.getResult(); | ||
} else { | ||
exception = task.getException(); | ||
} | ||
latch.countDown(); | ||
} | ||
|
||
/** Blocks until the {@link #onComplete} is called. */ | ||
public TResult await() throws InterruptedException, ExecutionException { | ||
if (!latch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS)) { | ||
throw new InterruptedException("timed out waiting for result"); | ||
} | ||
if (successful) { | ||
return result; | ||
} else { | ||
if (exception instanceof InterruptedException) { | ||
throw (InterruptedException) exception; | ||
} | ||
if (exception instanceof SetCustomInstallationIdException) { | ||
throw new ExecutionException(exception); | ||
} | ||
if (exception instanceof IOException) { | ||
throw new ExecutionException(exception); | ||
} | ||
throw new IllegalStateException("got an unexpected exception type", exception); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,16 +19,16 @@ | |
import static org.junit.Assert.assertTrue; | ||
|
||
import androidx.test.core.app.ApplicationProvider; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
import com.google.firebase.FirebaseApp; | ||
import com.google.firebase.FirebaseOptions; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.RobolectricTestRunner; | ||
|
||
/** Instrumented tests for {@link CustomInstallationIdCache} */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Update the javadocs. |
||
@RunWith(AndroidJUnit4.class) | ||
@RunWith(RobolectricTestRunner.class) | ||
public class CustomInstallationIdCacheTest { | ||
|
||
private FirebaseApp firebaseApp0; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: We can move this into an initialization method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, first, I don't think we can put this entire block into initialization() since it's not always the same in every test case.
If you meant that move TestOnCompleteListener onCompleteListener = new TestOnCompleteListener<>() into initialization, I also think putting here is better since it's a whole logic block with the two lines below. Also, if a test case uses onCompleteListener more than once, then putting it in initialization is also not perfect.