-
Notifications
You must be signed in to change notification settings - Fork 692
Setup the Autoconfiguration for Firestore Emulator #2244
Conversation
@dzou Can we disable |
Ya I considered that, though I wasn't sure if it made sense to make the code accommodate the emulator since the emulator is test-only. What do you both think? @dmitry-s @meltsufin |
Let's wait for a response from the Firestore team. |
Will try following up again. |
Codecov Report
@@ Coverage Diff @@
## master #2244 +/- ##
============================================
+ Coverage 73.54% 73.79% +0.25%
- Complexity 2078 2090 +12
============================================
Files 258 259 +1
Lines 7469 7510 +41
Branches 772 774 +2
============================================
+ Hits 5493 5542 +49
+ Misses 1620 1613 -7
+ Partials 356 355 -1
Continue to review full report at Codecov.
|
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.
@dzou I have left few messages :)
...springframework/cloud/gcp/autoconfigure/firestore/GcpFirestoreEmulatorAutoConfiguration.java
Outdated
Show resolved
Hide resolved
...springframework/cloud/gcp/autoconfigure/firestore/GcpFirestoreEmulatorAutoConfiguration.java
Show resolved
Hide resolved
...springframework/cloud/gcp/autoconfigure/firestore/GcpFirestoreEmulatorAutoConfiguration.java
Outdated
Show resolved
Hide resolved
Thanks for the review @eddumelendez ! @meltsufin , @dmitry-s - I updated this PR so users should now be able to specify the host-port of a locally running emulator for firestore and it will work. The work to make this into a test resource can be deferred and grouped with the other work like with spanner emulator. |
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.
A couple of technicality nits.
...springframework/cloud/gcp/autoconfigure/firestore/GcpFirestoreEmulatorAutoConfiguration.java
Outdated
Show resolved
Hide resolved
private static Credentials emulatorCredentials() { | ||
final Map<String, List<String>> headerMap = new HashMap<>(); | ||
headerMap.put("Authorization", Collections.singletonList("Bearer owner")); | ||
headerMap.put("google-cloud-resource-prefix", Collections.singletonList("projects/my-project/databases/(default)")); |
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.
"my-project" -- is it because it's a fake value that's unused? Can you leave a comment about that?
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.
Done. I just changed it to plug in the current project-id. I guess this is more technically correct.
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.
Or maybe I should make this so the emulator config doesn't require a real project (and not inject a projectIdProvider into the configuration)... Maybe that would make more sense; what do you think?
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.
Maybe just hardcode "unused" as project ID?
...springframework/cloud/gcp/autoconfigure/firestore/GcpFirestoreEmulatorAutoConfiguration.java
Show resolved
Hide resolved
...springframework/cloud/gcp/autoconfigure/firestore/GcpFirestoreEmulatorAutoConfiguration.java
Outdated
Show resolved
Hide resolved
...-firestore/src/main/java/org/springframework/cloud/gcp/data/firestore/FirestoreTemplate.java
Show resolved
Hide resolved
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.
Looks good; I don't think the commit changing the project to current default came though, but then perhaps hardcoding a fake value is better anyway.
private static Credentials emulatorCredentials() { | ||
final Map<String, List<String>> headerMap = new HashMap<>(); | ||
headerMap.put("Authorization", Collections.singletonList("Bearer owner")); | ||
headerMap.put("google-cloud-resource-prefix", Collections.singletonList("projects/my-project/databases/(default)")); |
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.
Maybe just hardcode "unused" as project ID?
...springframework/cloud/gcp/autoconfigure/firestore/GcpFirestoreEmulatorAutoConfiguration.java
Outdated
Show resolved
Hide resolved
...-firestore/src/main/java/org/springframework/cloud/gcp/data/firestore/FirestoreTemplate.java
Show resolved
Hide resolved
...springframework/cloud/gcp/autoconfigure/firestore/GcpFirestoreEmulatorAutoConfiguration.java
Show resolved
Hide resolved
Kudos, SonarCloud Quality Gate passed!
|
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
Can you update the PR description, since you've worked through all the problems by now? I use PR descriptions a lot when doing archaeological digs for why something is. |
Will do! |
Add support for using the Firestore emulator.
spring.cloud.gcp.firestore.emulator.enabled=true
and host port set viaspring.cloud.gcp.firestore.host-port=xxxx
.Fixes #1956.
Previous Notes:
If you try to run the reactive firestore sample with the emulator, you will get the error:
The emulator will throw an error if you attempt to set stream/resume tokens in the request. However, our reactive Firestore Template uses this functionality and includes these tokens in the requests: see code
So resolving #1956 may not be possible in the end. Maybe this could benefit from a second set of eyes too.