Skip to content
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

Firestore API #83

Merged
merged 15 commits into from
Nov 2, 2017
Merged

Firestore API #83

merged 15 commits into from
Nov 2, 2017

Conversation

hiranya911
Copy link
Contributor

Usage:

Firestore fs = FirestoreClient.getFirestore();

@hiranya911
Copy link
Contributor Author

@mikelehen Code is pretty much the same as it was when you reviewed a while ago. It has just been updated/merged with the other changes that has been done recently in the master branch.

Copy link

@mikelehen mikelehen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically looks good, but a couple comments / suggestions.

pom.xml Outdated
</dependency>
<dependency>
<groupId>com.google.api</groupId>
<artifactId>gax</artifactId>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this? I'm not really sure what it is, but I don't see any obvious references to it (e.g. com.google.api classes or anything)...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a transitive dependency for Firestore/GRPC. Without it I get the following test failures:

testServiceAccountProjectId(com.google.firebase.cloud.FirestoreClientTest)  Time elapsed: 0.001 sec  <<< ERROR!
java.lang.NoClassDefFoundError: com/google/api/gax/rpc/ClientSettings
	at com.google.firebase.cloud.FirestoreClientTest.testServiceAccountProjectId(FirestoreClientTest.java:42)
Caused by: java.lang.ClassNotFoundException: com.google.api.gax.rpc.ClientSettings
	at com.google.firebase.cloud.FirestoreClientTest.testServiceAccountProjectId(FirestoreClientTest.java:42)

testAppDelete(com.google.firebase.cloud.FirestoreClientTest)  Time elapsed: 0 sec  <<< ERROR!
java.lang.NoClassDefFoundError: Could not initialize class com.google.cloud.firestore.FirestoreOptions
	at com.google.firebase.cloud.FirestoreClientTest.testAppDelete(FirestoreClientTest.java:56)

testExplicitProjectId(com.google.firebase.cloud.FirestoreClientTest)  Time elapsed: 0 sec  <<< ERROR!
java.lang.NoClassDefFoundError: Could not initialize class com.google.cloud.firestore.FirestoreOptions
	at com.google.firebase.cloud.FirestoreClientTest.testExplicitProjectId(FirestoreClientTest.java:30)

I think Firestore should declare this dependency. I'll report this for Firestore.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I don't think that should be necessary. FWIW, our docs don't mention needing it (https://firebase.google.com/docs/firestore/quickstart under the java tab just shows the one import)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


private FirestoreClient(FirebaseApp app) {
checkNotNull(app, "FirebaseApp must not be null");
// The following will be further simplified once we migrate to GoogleCredentials.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this comment stale?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. Removed.


@Override
public void destroy() {
// NOTE: We don't explicitly tear down anything here, but public methods of StorageClient

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StorageClient => FirestoreClient

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the comment as described below.

@Override
public void destroy() {
// NOTE: We don't explicitly tear down anything here, but public methods of StorageClient
// will now fail because calls to getOptions() and getToken() will hit FirebaseApp,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"getOptions() and getToken()" => "getCredentials()" ?

Copy link
Contributor Author

@hiranya911 hiranya911 Oct 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think with the current design a Firestore instance can continue to work even after the FirebaseApp has been deleted. The user won't be able to call FirestoreClient.getFirestore(), but if the user already has a Firestore reference, that will continue to work. Firestore API will have to provide some way to clean it up/tear it down to properly support this.

I've updated the comment here accordingly.

Edit: I'm also thinking about controlling the thread pool provided to Firestore client. Perhaps there's some way to inject some cleanup logic there. I'll do it as a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"population", 77846L,
"capital", false
);
WriteResult result = reference.set(expected).get();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add instructions to CONTRIBUTING.md (or wherever) to open up your Firestore security rules?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@hiranya911 hiranya911 assigned hiranya911 and unassigned mikelehen Oct 9, 2017
@hiranya911
Copy link
Contributor Author

Made the suggested changes.

@hiranya911 hiranya911 assigned mikelehen and unassigned hiranya911 Oct 9, 2017
Copy link

@mikelehen mikelehen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except undoing my bad advice (sorry).

CONTRIBUTING.md Outdated
@@ -138,7 +138,9 @@ makes a large number of writes to the Firebase realtime database. Download the s
private key from the "Settings > Service Accounts" page of the project, and save it as
`integration_cert.json` at the root of the codebase. Also obtain the web API key of the project
from the "Settings > General" page, and save it as `integration_apikey.txt` at the root of the
codebase. Now run the following command to invoke the integration test suite:
codebase. Also make sure Firestore security rules configured in the project allow reads and writes
from any authenticated client. Finally, run the following command to invoke the integration test

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Er, sorry. I think I was confused before. Since this is an admin SDK, you're using a service account, which overrides Firebase Rules, so I don't think they need to do anything special.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, sounds good. Good to know that Firestore rules can also be overridden in Admin SDK like RTDB rules.

@hiranya911 hiranya911 assigned hiranya911 and unassigned mikelehen Oct 9, 2017
@hiranya911 hiranya911 merged commit 202c332 into master Nov 2, 2017
@hiranya911 hiranya911 deleted the hkj-firestore-java branch November 22, 2017 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants