-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Firestore:Fix Observable in calls instead of wrapping in ApiFuture #6148
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
chingor13
merged 7 commits into
googleapis:master
from
abhinav-qlogic:api-firestore-5887
Sep 11, 2019
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
817f455
Fix getAll and get methods With observer
abhinav-qlogic e28a7ba
Fix getAll and get method changes
abhinav-qlogic c998ec4
getAll and get method changes
abhinav-qlogic 0cdd424
get method javadoc changes
abhinav-qlogic a553d5a
Fix review changes
abhinav-qlogic 70b827f
review changes
abhinav-qlogic 74a4aec
review changes
abhinav-qlogic 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
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 |
|---|---|---|
|
|
@@ -22,13 +22,16 @@ | |
| import static java.util.Arrays.asList; | ||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertNotEquals; | ||
| import static org.junit.Assert.assertNotNull; | ||
| import static org.junit.Assert.assertNull; | ||
| import static org.junit.Assert.assertTrue; | ||
| import static org.junit.Assert.fail; | ||
|
|
||
| import com.google.api.core.ApiFuture; | ||
| import com.google.api.core.ApiFutures; | ||
| import com.google.api.core.SettableApiFuture; | ||
| import com.google.api.gax.rpc.ApiStreamObserver; | ||
| import com.google.cloud.Timestamp; | ||
| import com.google.cloud.firestore.CollectionReference; | ||
| import com.google.cloud.firestore.DocumentChange; | ||
|
|
@@ -1327,4 +1330,53 @@ private static final class ListenerEvent { | |
| this.error = error; | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void getAllWithObserver() throws Exception { | ||
| DocumentReference ref1 = randomColl.document("doc1"); | ||
| ref1.set(ALL_SUPPORTED_TYPES_MAP).get(); | ||
|
|
||
| DocumentReference ref2 = randomColl.document("doc2"); | ||
| ref2.set(ALL_SUPPORTED_TYPES_MAP).get(); | ||
|
|
||
| DocumentReference ref3 = randomColl.document("doc3"); | ||
|
|
||
| final List<DocumentSnapshot> documentSnapshots = | ||
| Collections.synchronizedList(new ArrayList<DocumentSnapshot>()); | ||
| final DocumentReference[] documentReferences = {ref1, ref2, ref3}; | ||
| final SettableApiFuture<Void> future = SettableApiFuture.create(); | ||
| firestore.getAll( | ||
| documentReferences, | ||
| FieldMask.of("foo"), | ||
| new ApiStreamObserver<DocumentSnapshot>() { | ||
|
|
||
| @Override | ||
| public void onNext(DocumentSnapshot documentSnapshot) { | ||
| documentSnapshots.add(documentSnapshot); | ||
| } | ||
|
|
||
| @Override | ||
| public void onError(Throwable throwable) { | ||
| future.setException(throwable); | ||
| } | ||
|
|
||
| @Override | ||
| public void onCompleted() { | ||
| future.set(null); | ||
| } | ||
| }); | ||
|
|
||
| future.get(); | ||
|
Contributor
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. Thank you for updating this! |
||
|
|
||
| assertEquals( | ||
| ALL_SUPPORTED_TYPES_OBJECT, documentSnapshots.get(0).toObject(AllSupportedTypes.class)); | ||
| assertEquals( | ||
| ALL_SUPPORTED_TYPES_OBJECT, documentSnapshots.get(1).toObject(AllSupportedTypes.class)); | ||
| assertNotEquals( | ||
| ALL_SUPPORTED_TYPES_OBJECT, documentSnapshots.get(2).toObject(AllSupportedTypes.class)); | ||
| assertEquals(ref1.getId(), documentSnapshots.get(0).getId()); | ||
| assertEquals(ref2.getId(), documentSnapshots.get(1).getId()); | ||
| assertEquals(ref3.getId(), documentSnapshots.get(2).getId()); | ||
| assertEquals(3, documentSnapshots.size()); | ||
| } | ||
| } | ||
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.
Please match the signature above and change the order to:
getAll(DocumentReference[] documentReferences, @Nullable FieldMask fieldMask, final ApiStreamObserver<DocumentSnapshot> responseObserver)Putting the observer last also makes for much more readable code when a Lambda is used.