-
Notifications
You must be signed in to change notification settings - Fork 615
Unified emulator settings for Database #1672
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 17 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9ef8a4b
Unified emulator settings for Database
samtstern 9d4be7d
API surface
samtstern 1ca25d4
Hide new methods
samtstern f39c11f
Remove the enum, flip the dependency
samtstern 0f931bb
Google Java Format
samtstern fb262d3
No more @KeepForSdk
samtstern 2762764
Respond to most review comments
samtstern 24b8f3a
Clone the map
samtstern 4dd3c23
Fix bug arising from shared DEFAULT
samtstern f7e2832
Change to freeze verbiage, make FirebaseApp responsible for freezing
samtstern 4ef9919
No more unnecessary builder
samtstern a2a4cd6
Move frozen to FirebaseApp
samtstern 4e1373f
Take sebastian's url parsing suggestion
samtstern 7f173e0
Update firebase-common/src/main/java/com/google/firebase/emulators/Em…
samtstern 6d1e179
Update firebase-common/src/main/java/com/google/firebase/emulators/Fi…
samtstern 2d67b78
Update firebase-common/src/main/java/com/google/firebase/emulators/Em…
samtstern 8a51a73
Final review nits
samtstern b072f54
One more getter
samtstern 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 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
36 changes: 36 additions & 0 deletions
36
firebase-common/src/main/java/com/google/firebase/emulators/EmulatedServiceSettings.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,36 @@ | ||
// Copyright 2020 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.emulators; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
/** | ||
* Settings to connect a single Firebase service to a local emulator. | ||
* | ||
* <p>TODO(samstern): Un-hide this once Firestore, Database, and Functions are implemented | ||
* | ||
* @see EmulatorSettings | ||
* @hide | ||
*/ | ||
public final class EmulatedServiceSettings { | ||
|
||
public final String host; | ||
public final int port; | ||
samtstern marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public EmulatedServiceSettings(@NonNull String host, int port) { | ||
this.host = host; | ||
this.port = port; | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
firebase-common/src/main/java/com/google/firebase/emulators/EmulatorSettings.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,87 @@ | ||
// Copyright 2020 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.emulators; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import com.google.firebase.components.Preconditions; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Settings that control which Firebase services should access a local emulator, rather than | ||
* production. | ||
* | ||
* <p>TODO(samstern): Un-hide this once Firestore, Database, and Functions are implemented | ||
* | ||
* @see com.google.firebase.FirebaseApp#enableEmulators(EmulatorSettings) | ||
* @hide | ||
*/ | ||
public final class EmulatorSettings { | ||
|
||
/** Empty emulator settings to be used as an internal default */ | ||
public static final EmulatorSettings DEFAULT = new EmulatorSettings.Builder().build(); | ||
|
||
public static final class Builder { | ||
|
||
private final Map<FirebaseEmulator, EmulatedServiceSettings> settingsMap = new HashMap<>(); | ||
|
||
/** Constructs an empty builder. */ | ||
public Builder() {} | ||
|
||
/** | ||
* Specify the emulator settings for a single service. | ||
* | ||
* @param emulator the emulated service. | ||
* @param settings the emulator settings. | ||
* @return the builder, for chaining. | ||
*/ | ||
@NonNull | ||
public Builder addEmulatedService( | ||
@NonNull FirebaseEmulator emulator, @NonNull EmulatedServiceSettings settings) { | ||
Preconditions.checkState( | ||
!settingsMap.containsKey(emulator), | ||
"Cannot call addEmulatedService twice for " + emulator.toString()); | ||
this.settingsMap.put(emulator, settings); | ||
return this; | ||
} | ||
|
||
@NonNull | ||
public EmulatorSettings build() { | ||
return new EmulatorSettings(new HashMap<>(settingsMap)); | ||
} | ||
} | ||
|
||
private final Map<FirebaseEmulator, EmulatedServiceSettings> settingsMap; | ||
|
||
private EmulatorSettings(@NonNull Map<FirebaseEmulator, EmulatedServiceSettings> settingsMap) { | ||
this.settingsMap = Collections.unmodifiableMap(settingsMap); | ||
} | ||
|
||
/** | ||
* Fetch the emulation settings for a single Firebase service. | ||
* | ||
* @hide | ||
*/ | ||
@Nullable | ||
public EmulatedServiceSettings getServiceSettings(@NonNull FirebaseEmulator emulator) { | ||
if (settingsMap.containsKey(emulator)) { | ||
return settingsMap.get(emulator); | ||
} | ||
|
||
return null; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
firebase-common/src/main/java/com/google/firebase/emulators/FirebaseEmulator.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,50 @@ | ||
// Copyright 2020 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.emulators; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
/** | ||
* Identifier Firebase services that can be emulated using the Firebase Emulator Suite. | ||
* | ||
* <p>TODO(samstern): Un-hide this once Firestore, Database, and Functions are implemented | ||
* | ||
* @see com.google.firebase.FirebaseApp#enableEmulators(EmulatorSettings) | ||
* @see EmulatorSettings | ||
* @see EmulatedServiceSettings | ||
* @hide | ||
*/ | ||
public final class FirebaseEmulator { | ||
|
||
private final String name; | ||
|
||
/** | ||
* Only to be called by SDKs which support emulators in order to make constants. | ||
* | ||
* @hide | ||
*/ | ||
@NonNull | ||
public static FirebaseEmulator forName(String name) { | ||
return new FirebaseEmulator(name); | ||
} | ||
|
||
private FirebaseEmulator(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} |
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 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
Oops, something went wrong.
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.
How will this interact with firestore's
terminate()
? afaicr one can terminate one instance of firestore at which point the call toFirebaseFirestore#getInstance()
will create a new firestore instance, should we allow the following sequence of calls?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 calling this out, I resolved all the other comments since they were straightforward but I will have to look into this one more deeply.
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.
Ok actually I do not want to allow that sequence of calls. One of the main reasons for this is to make sure that app developers can reason about their emulation settings at a single point before any Firebase service has done any communication.
If you call
terminate()
the settings should still apply. If you want to nuke them you'll need to callFirebaseApp#delete()
and then make a new app.WDYT?
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.
That's a good point and sgtm. You may want to confirm this behavior with firestore folks though
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.
Will do during the Firestore PR.