use of com.google.firebase.firestore.core.View in project firebase-android-sdk by firebase.
the class DocumentChangeTest method validatePositions.
private static void validatePositions(com.google.firebase.firestore.core.Query query, Collection<MutableDocument> initialDocsList, Collection<MutableDocument> addedList, Collection<MutableDocument> modifiedList, Collection<MutableDocument> removedList) {
ImmutableSortedMap<DocumentKey, Document> initialDocs = docUpdates(initialDocsList.toArray(new MutableDocument[] {}));
ImmutableSortedMap<DocumentKey, Document> updates = emptyDocumentMap();
for (MutableDocument doc : addedList) {
updates = updates.insert(doc.getKey(), doc);
}
for (MutableDocument doc : modifiedList) {
updates = updates.insert(doc.getKey(), doc);
}
for (MutableDocument doc : removedList) {
updates = updates.insert(doc.getKey(), doc);
}
View view = new View(query, DocumentKey.emptyKeySet());
View.DocumentChanges initialChanges = view.computeDocChanges(initialDocs);
TargetChange initialTargetChange = ackTarget(initialDocsList.toArray(new MutableDocument[] {}));
ViewSnapshot initialSnapshot = view.applyChanges(initialChanges, initialTargetChange).getSnapshot();
View.DocumentChanges updateChanges = view.computeDocChanges(updates);
TargetChange updateTargetChange = targetChange(ByteString.EMPTY, true, addedList, modifiedList, removedList);
ViewSnapshot updatedSnapshot = view.applyChanges(updateChanges, updateTargetChange).getSnapshot();
if (updatedSnapshot == null) {
// Nothing changed, no positions to verify
return;
}
List<Document> expected = new ArrayList<>(updatedSnapshot.getDocuments().toList());
List<Document> actual = new ArrayList<>(initialSnapshot.getDocuments().toList());
FirebaseFirestore firestore = mock(FirebaseFirestore.class);
List<DocumentChange> changes = DocumentChange.changesFromSnapshot(firestore, MetadataChanges.EXCLUDE, updatedSnapshot);
for (DocumentChange change : changes) {
if (change.getType() != Type.ADDED) {
actual.remove(change.getOldIndex());
}
if (change.getType() != Type.REMOVED) {
actual.add(change.getNewIndex(), change.getDocument().getDocument());
}
}
assertEquals(expected, actual);
}
use of com.google.firebase.firestore.core.View in project firebase-android-sdk by firebase.
the class QueryEngineTestCase method runQuery.
private DocumentSet runQuery(Query query, SnapshotVersion lastLimboFreeSnapshotVersion) {
Preconditions.checkNotNull(expectFullCollectionScan, "Encountered runQuery() call not wrapped in expectOptimizedCollectionQuery()/expectFullCollectionQuery()");
ImmutableSortedMap<DocumentKey, Document> docs = queryEngine.getDocumentsMatchingQuery(query, lastLimboFreeSnapshotVersion, targetCache.getMatchingKeysForTargetId(TEST_TARGET_ID));
View view = new View(query, new ImmutableSortedSet<>(Collections.emptyList(), DocumentKey::compareTo));
View.DocumentChanges viewDocChanges = view.computeDocChanges(docs);
return view.applyChanges(viewDocChanges).getSnapshot().getDocuments();
}
Aggregations