Search in sources :

Example 71 with MutableDocument

use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.

the class DocumentViewChangeSetTest method testDocumentViewChangeConstructor.

@Test
public void testDocumentViewChangeConstructor() {
    MutableDocument doc1 = doc("a/b", 0, EMPTY_MAP);
    Type type = Type.MODIFIED;
    DocumentViewChange change = DocumentViewChange.create(type, doc1);
    assertEquals(change.getDocument(), doc1);
    assertEquals(change.getType(), type);
}
Also used : Type(com.google.firebase.firestore.core.DocumentViewChange.Type) MutableDocument(com.google.firebase.firestore.model.MutableDocument) Test(org.junit.Test)

Example 72 with MutableDocument

use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.

the class QuerySnapshotTest method testIncludeMetadataChanges.

@Test
public void testIncludeMetadataChanges() {
    MutableDocument doc1Old = doc("foo/bar", 1, wrapObject("a", "b")).setHasLocalMutations();
    MutableDocument doc1New = doc("foo/bar", 1, wrapObject("a", "b"));
    MutableDocument doc2Old = doc("foo/baz", 1, wrapObject("a", "b"));
    MutableDocument doc2New = doc("foo/baz", 1, wrapObject("a", "c"));
    DocumentSet oldDocuments = docSet(Document.KEY_COMPARATOR, doc1Old, doc2Old);
    DocumentSet newDocuments = docSet(Document.KEY_COMPARATOR, doc1New, doc2New);
    List<DocumentViewChange> documentChanges = Arrays.asList(DocumentViewChange.create(DocumentViewChange.Type.METADATA, doc1New), DocumentViewChange.create(DocumentViewChange.Type.MODIFIED, doc2New));
    FirebaseFirestore firestore = TestUtil.firestore();
    com.google.firebase.firestore.core.Query fooQuery = query("foo");
    ViewSnapshot viewSnapshot = new ViewSnapshot(fooQuery, newDocuments, oldDocuments, documentChanges, /*isFromCache=*/
    false, /*mutatedKeys=*/
    keySet(), /*didSyncStateChange=*/
    true, /* excludesMetadataChanges= */
    false);
    QuerySnapshot snapshot = new QuerySnapshot(new Query(fooQuery, firestore), viewSnapshot, firestore);
    QueryDocumentSnapshot doc1Snap = QueryDocumentSnapshot.fromDocument(firestore, doc1New, /*fromCache=*/
    false, /*hasPendingWrites=*/
    false);
    QueryDocumentSnapshot doc2Snap = QueryDocumentSnapshot.fromDocument(firestore, doc2New, /*fromCache=*/
    false, /*hasPendingWrites=*/
    false);
    assertEquals(1, snapshot.getDocumentChanges().size());
    List<DocumentChange> changesWithoutMetadata = Arrays.asList(new DocumentChange(doc2Snap, DocumentChange.Type.MODIFIED, /*oldIndex=*/
    1, /*newIndex=*/
    1));
    assertEquals(changesWithoutMetadata, snapshot.getDocumentChanges());
    List<DocumentChange> changesWithMetadata = Arrays.asList(new DocumentChange(doc1Snap, DocumentChange.Type.MODIFIED, /*oldIndex=*/
    0, /*newIndex=*/
    0), new DocumentChange(doc2Snap, DocumentChange.Type.MODIFIED, /*oldIndex=*/
    1, /*newIndex=*/
    1));
    assertEquals(changesWithMetadata, snapshot.getDocumentChanges(MetadataChanges.INCLUDE));
}
Also used : MutableDocument(com.google.firebase.firestore.model.MutableDocument) ViewSnapshot(com.google.firebase.firestore.core.ViewSnapshot) DocumentViewChange(com.google.firebase.firestore.core.DocumentViewChange) DocumentSet(com.google.firebase.firestore.model.DocumentSet) Test(org.junit.Test)

Example 73 with MutableDocument

use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.

the class LocalStoreTestCase 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 74 with MutableDocument

use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.

the class LruGarbageCollectorTestCase method cacheADocumentInTransaction.

private MutableDocument cacheADocumentInTransaction() {
    MutableDocument doc = nextTestDocument();
    documentCache.add(doc, doc.getVersion());
    return doc;
}
Also used : MutableDocument(com.google.firebase.firestore.model.MutableDocument)

Example 75 with MutableDocument

use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.

the class LruGarbageCollectorTestCase method testGetsSize.

@Test
public void testGetsSize() {
    long initialSize = garbageCollector.getByteSize();
    persistence.runTransaction("fill cache", () -> {
        // Simulate a bunch of ack'd mutations
        for (int i = 0; i < 50; i++) {
            MutableDocument doc = cacheADocumentInTransaction();
            markDocumentEligibleForGcInTransaction(doc.getKey());
        }
    });
    long finalSize = garbageCollector.getByteSize();
    assertTrue(finalSize > initialSize);
}
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