Search in sources :

Example 66 with MutableDocument

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);
}
Also used : MutableDocument(com.google.firebase.firestore.model.MutableDocument) Test(org.junit.Test)

Example 67 with MutableDocument

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());
}
Also used : MutableDocument(com.google.firebase.firestore.model.MutableDocument) Test(org.junit.Test)

Example 68 with MutableDocument

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);
}
Also used : Document(com.google.firebase.firestore.model.Document) MutableDocument(com.google.firebase.firestore.model.MutableDocument)

Example 69 with MutableDocument

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);
}
Also used : Query(com.google.firebase.firestore.core.Query) MutableDocument(com.google.firebase.firestore.model.MutableDocument) DocumentSet(com.google.firebase.firestore.model.DocumentSet) Test(org.junit.Test)

Example 70 with MutableDocument

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());
}
Also used : MutableDocument(com.google.firebase.firestore.model.MutableDocument) Test(org.junit.Test)

Aggregations

MutableDocument (com.google.firebase.firestore.model.MutableDocument)166 Test (org.junit.Test)125 DocumentKey (com.google.firebase.firestore.model.DocumentKey)43 Mutation.calculateOverlayMutation (com.google.firebase.firestore.model.mutation.Mutation.calculateOverlayMutation)30 TestUtil.deleteMutation (com.google.firebase.firestore.testutil.TestUtil.deleteMutation)30 TestUtil.mergeMutation (com.google.firebase.firestore.testutil.TestUtil.mergeMutation)30 TestUtil.patchMutation (com.google.firebase.firestore.testutil.TestUtil.patchMutation)30 TestUtil.setMutation (com.google.firebase.firestore.testutil.TestUtil.setMutation)30 HashMap (java.util.HashMap)22 TestUtil.wrapObject (com.google.firebase.firestore.testutil.TestUtil.wrapObject)18 ArrayList (java.util.ArrayList)18 TargetData (com.google.firebase.firestore.local.TargetData)15 WatchTargetChange (com.google.firebase.firestore.remote.WatchChange.WatchTargetChange)14 DocumentChange (com.google.firebase.firestore.remote.WatchChange.DocumentChange)13 ResourcePath (com.google.firebase.firestore.model.ResourcePath)12 Query (com.google.firebase.firestore.core.Query)10 Map (java.util.Map)10 SnapshotVersion (com.google.firebase.firestore.model.SnapshotVersion)8 Document (com.google.firebase.firestore.model.Document)7 Timestamp (com.google.firebase.Timestamp)6