use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class ViewTest method testRemembersLocalMutationsFromPreviousCallToComputeChanges.
@Test
public void testRemembersLocalMutationsFromPreviousCallToComputeChanges() {
Query query = messageQuery().limitToFirst(2);
MutableDocument doc1 = doc("rooms/eros/messages/0", 0, map());
MutableDocument doc2 = doc("rooms/eros/messages/1", 0, map()).setHasLocalMutations();
View view = new View(query, DocumentKey.emptyKeySet());
// Start with a full view.
View.DocumentChanges changes = view.computeDocChanges(docUpdates(doc1, doc2));
assertEquals(keySet(doc2.getKey()), changes.mutatedKeys);
MutableDocument doc3 = doc("rooms/eros/messages/2", 0, map());
changes = view.computeDocChanges(docUpdates(doc3), changes);
assertEquals(keySet(doc2.getKey()), changes.mutatedKeys);
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class ViewTest method testRaisesHasPendingWritesForPendingMutationsInInitialSnapshot.
@Test
public void testRaisesHasPendingWritesForPendingMutationsInInitialSnapshot() {
Query query = messageQuery();
MutableDocument doc1 = doc("rooms/eros/messages/1", 0, map()).setHasLocalMutations();
View view = new View(query, DocumentKey.emptyKeySet());
View.DocumentChanges changes = view.computeDocChanges(docUpdates(doc1));
ViewChange viewChange = view.applyChanges(changes);
assertTrue(viewChange.getSnapshot().hasPendingWrites());
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class SQLiteOverlayMigrationManagerTest method assertContains.
/**
* Asserts that the given local store contains the given document.
*/
private void assertContains(MutableDocument expected) {
Document actual = localStore.readDocument(expected.getKey());
assertEquals(expected, actual);
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class SQLiteQueryEngineTest method testRefillsIndexedLimitQueries.
@Test
public void testRefillsIndexedLimitQueries() throws Exception {
MutableDocument doc1 = doc("coll/1", 1, map("a", 1));
MutableDocument doc2 = doc("coll/2", 1, map("a", 2));
MutableDocument doc3 = doc("coll/3", 1, map("a", 3));
MutableDocument doc4 = doc("coll/4", 1, map("a", 4));
addDocument(doc1, doc2, doc3, doc4);
indexManager.addFieldIndex(fieldIndex("coll", "a", Kind.ASCENDING));
indexManager.updateIndexEntries(docMap(doc1, doc2, doc3, doc4));
indexManager.updateCollectionGroup("coll", IndexOffset.fromDocument(doc4));
addMutation(patchMutation("coll/3", map("a", 5)));
Query query = query("coll").orderBy(orderBy("a")).limitToFirst(3);
DocumentSet result = expectOptimizedCollectionScan(() -> runQuery(query, SnapshotVersion.NONE));
assertEquals(docSet(query.comparator(), doc1, doc2, doc4), result);
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class DocumentViewChangeSetTest method testTrack.
@Test
public void testTrack() {
DocumentViewChangeSet set = new DocumentViewChangeSet();
MutableDocument added = doc("a/1", 0, EMPTY_MAP);
MutableDocument removed = doc("a/2", 0, EMPTY_MAP);
MutableDocument modified = doc("a/3", 0, EMPTY_MAP);
MutableDocument addedThenModified = doc("b/1", 0, EMPTY_MAP);
MutableDocument addedThenRemoved = doc("b/2", 0, EMPTY_MAP);
MutableDocument removedThenAdded = doc("b/3", 0, EMPTY_MAP);
MutableDocument modifiedThenRemoved = doc("b/4", 0, EMPTY_MAP);
MutableDocument modifiedThenModified = doc("b/5", 0, EMPTY_MAP);
set.addChange(DocumentViewChange.create(Type.ADDED, added));
set.addChange(DocumentViewChange.create(Type.REMOVED, removed));
set.addChange(DocumentViewChange.create(Type.MODIFIED, modified));
set.addChange(DocumentViewChange.create(Type.ADDED, addedThenModified));
set.addChange(DocumentViewChange.create(Type.MODIFIED, addedThenModified));
set.addChange(DocumentViewChange.create(Type.ADDED, addedThenRemoved));
set.addChange(DocumentViewChange.create(Type.REMOVED, addedThenRemoved));
set.addChange(DocumentViewChange.create(Type.REMOVED, removedThenAdded));
set.addChange(DocumentViewChange.create(Type.ADDED, removedThenAdded));
set.addChange(DocumentViewChange.create(Type.MODIFIED, modifiedThenRemoved));
set.addChange(DocumentViewChange.create(Type.REMOVED, modifiedThenRemoved));
set.addChange(DocumentViewChange.create(Type.MODIFIED, modifiedThenModified));
set.addChange(DocumentViewChange.create(Type.MODIFIED, modifiedThenModified));
List<DocumentViewChange> changes = set.getChanges();
assertEquals(7, changes.size());
assertEquals(added, changes.get(0).getDocument());
assertEquals(Type.ADDED, changes.get(0).getType());
assertEquals(removed, changes.get(1).getDocument());
assertEquals(Type.REMOVED, changes.get(1).getType());
assertEquals(modified, changes.get(2).getDocument());
assertEquals(Type.MODIFIED, changes.get(2).getType());
assertEquals(addedThenModified, changes.get(3).getDocument());
assertEquals(Type.ADDED, changes.get(3).getType());
assertEquals(removedThenAdded, changes.get(4).getDocument());
assertEquals(Type.MODIFIED, changes.get(4).getType());
assertEquals(modifiedThenRemoved, changes.get(5).getDocument());
assertEquals(Type.REMOVED, changes.get(5).getType());
assertEquals(modifiedThenModified, changes.get(6).getDocument());
assertEquals(Type.MODIFIED, changes.get(6).getType());
}
Aggregations