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);
}
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));
}
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);
}
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;
}
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);
}
Aggregations