-
Notifications
You must be signed in to change notification settings - Fork 300
feat(rtdb): Connect to RTDB emulator when valid emulator URL is passed OR env vars are set correctly #299
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
Conversation
hiranya911
left a comment
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.
Please fix the test failures.
src/main/java/com/google/firebase/database/FirebaseDatabase.java
Outdated
Show resolved
Hide resolved
…ogic for inferring them correctly
src/main/java/com/google/firebase/database/connection/NettyWebSocketClient.java
Outdated
Show resolved
Hide resolved
src/test/java/com/google/firebase/database/FirebaseDatabaseTest.java
Outdated
Show resolved
Hide resolved
schmidt-sebastian
left a comment
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.
Thanks for this! I think from a functional perspective this is fine, but I wonder if there is a way to make it more obvious when we are talking out the environment variable and when we are talking about a database URL.
Furthermore, all existing SDKs always blindly overwrite any URL if the emulator host environment variable is set. I wonder if we should do the same?
src/main/java/com/google/firebase/database/FirebaseDatabase.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/firebase/database/connection/NettyWebSocketClient.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/firebase/database/connection/NettyWebSocketClient.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/firebase/database/util/EmulatorHelper.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/firebase/database/util/EmulatorHelper.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/firebase/database/util/EmulatorHelper.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/firebase/database/utilities/Utilities.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/firebase/database/utilities/Utilities.java
Outdated
Show resolved
Hide resolved
src/test/java/com/google/firebase/database/util/EmulatorHelperTest.java
Outdated
Show resolved
Hide resolved
hiranya911
left a comment
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.
Just a few suggestions, the main one being handling emulator credentials all within the FirebaseDatabase implementation. Basically allow empty credentials in FirebaseOptions when configured for emulator mode, and then init EmulatorCredentials in FirebaseDatabase.
src/main/java/com/google/firebase/database/util/EmulatorHelper.java
Outdated
Show resolved
Hide resolved
…FirebaseDatabase only, updated test cases
src/test/java/com/google/firebase/database/utilities/UtilitiesTest.java
Outdated
Show resolved
Hide resolved
… a valid URL through the databaseUrl field
yuchenshi
left a comment
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.
Code LGTM to me. Please address the comments and get an approval from at least one other reviewer before merging.
schmidt-sebastian
left a comment
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.
I left some more comments around URL parsing, but the rest of the code and the plumbing looks fantastic now! Thanks for your perseverance.
src/main/java/com/google/firebase/database/FirebaseDatabase.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/firebase/database/FirebaseDatabase.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/firebase/database/FirebaseDatabase.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/firebase/database/core/JvmAuthTokenProvider.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/firebase/database/util/EmulatorHelper.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/firebase/database/utilities/Utilities.java
Outdated
Show resolved
Hide resolved
src/test/java/com/google/firebase/database/FirebaseDatabaseTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/google/firebase/database/FirebaseDatabaseTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/google/firebase/database/FirebaseDatabaseTest.java
Outdated
Show resolved
Hide resolved
hiranya911
left a comment
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.
Thanks for seeing this through. Just one comment regarding the core SDK. I'll defer to @schmidt-sebastian regarding the changes in the database package.
hiranya911
left a comment
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.
LGTM with one comment. Feel free to merge once that comment and any other open comments from @schmidt-sebastian are addressed.
schmidt-sebastian
left a comment
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.
This looks great! Thanks for all the updates!
This PR makes it possible for the Java admin SDK to talk to the RTDB emulator instead of the actual database instance.
This can happen in the following fashion:-
firebaseio.com, has thensquery parameter)FIREBASE_RTDB_EMULATOR_HOSTis set to a value of the formhost:port.If either 1. or 2. is true, we decide to talk to the RTDB emulator. In such cases, we
EmulatorCredentials, which useowneras the access token.URL replacement happens in three places:-
FirebaseOptionsinstances inFirebaseAppdatabaseUrlis passed inFirebaseDatabase.getInstance(String url)FirebaseDatabase.getReferenceFromUrl(String url)Tests have been added with different combinations of passed-in URLs and environment variable values for classes
FirebaseApp,FirebaseDatabase, and also forEmulatorHelper: the helper class that actually does URL replacement if necessary.Notes for reviewers
I have made changes to existing behavior to
Utilities.parseUrl(String url): these changes were necessary to recognize thensquery parameter, and also to suppost valid<net_loc>URL semantics where a URL likehttp://localhost:8080/is deemed valid.These changes are nearly identical to changes to the same file in this Android SDK PR.
RELEASE NOTE: Developers can now test Realtime Database API calls by directing the SDK traffic to the RTDB emulator. Set the
FIREBASE_DATABASE_EMULATOR_HOSTenvironment variable to specify the emulator endpoint inhost:portformat.