use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class ViewTest method testAddsDocumentsBasedOnQuery.
@Test
public void testAddsDocumentsBasedOnQuery() {
Query query = messageQuery();
View view = new View(query, DocumentKey.emptyKeySet());
MutableDocument doc1 = doc("rooms/eros/messages/1", 0, map("text", "msg1"));
MutableDocument doc2 = doc("rooms/eros/messages/2", 0, map("text", "msg2"));
MutableDocument doc3 = doc("rooms/other/messages/1", 0, map("text", "msg3"));
ImmutableSortedMap<DocumentKey, Document> updates = docUpdates(doc1, doc2, doc3);
View.DocumentChanges docViewChanges = view.computeDocChanges(updates);
TargetChange targetChange = ackTarget(doc1, doc2, doc3);
ViewSnapshot snapshot = view.applyChanges(docViewChanges, targetChange).getSnapshot();
assertEquals(query, snapshot.getQuery());
assertEquals(asList(doc1, doc2), snapshot.getDocuments().toList());
assertEquals(asList(DocumentViewChange.create(Type.ADDED, doc1), DocumentViewChange.create(Type.ADDED, doc2)), snapshot.getChanges());
assertFalse(snapshot.isFromCache());
assertTrue(snapshot.didSyncStateChange());
assertFalse(snapshot.hasPendingWrites());
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class ViewTest method testSuppressesWriteAcknowledgementIfWatchHasNotCaughtUp.
@Test
public void testSuppressesWriteAcknowledgementIfWatchHasNotCaughtUp() {
// This test verifies that we don't get three events for a ServerTimestamp mutation. We suppress
// the event generated by the write acknowledgement and instead wait for Watch to catch up.
Query query = messageQuery();
MutableDocument doc1 = doc("rooms/eros/messages/1", 1, map("time", 1)).setHasLocalMutations();
MutableDocument doc1Committed = doc("rooms/eros/messages/1", 2, map("time", 2)).setHasCommittedMutations();
MutableDocument doc1Acknowledged = doc("rooms/eros/messages/1", 2, map("time", 2));
MutableDocument doc2 = doc("rooms/eros/messages/2", 1, map("time", 1)).setHasLocalMutations();
MutableDocument doc2Modified = doc("rooms/eros/messages/2", 2, map("time", 3)).setHasLocalMutations();
MutableDocument doc2Acknowledged = doc("rooms/eros/messages/2", 2, map("time", 3));
View view = new View(query, DocumentKey.emptyKeySet());
View.DocumentChanges changes = view.computeDocChanges(docUpdates(doc1, doc2));
ViewChange snap = view.applyChanges(changes);
assertEquals(asList(DocumentViewChange.create(Type.ADDED, doc1), DocumentViewChange.create(Type.ADDED, doc2)), snap.getSnapshot().getChanges());
changes = view.computeDocChanges(docUpdates(doc1Committed, doc2Modified));
snap = view.applyChanges(changes);
// The 'doc1Committed' update is suppressed
assertEquals(Collections.singletonList(DocumentViewChange.create(Type.MODIFIED, doc2Modified)), snap.getSnapshot().getChanges());
changes = view.computeDocChanges(docUpdates(doc1Acknowledged, doc2Acknowledged));
snap = view.applyChanges(changes);
assertEquals(asList(DocumentViewChange.create(Type.MODIFIED, doc1Acknowledged), DocumentViewChange.create(Type.METADATA, doc2Acknowledged)), snap.getSnapshot().getChanges());
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class ViewTest method testDoesNotNeedRefillForDeletionsWhenNotNearTheLimit.
@Test
public void testDoesNotNeedRefillForDeletionsWhenNotNearTheLimit() {
Query query = messageQuery().limitToFirst(20);
MutableDocument doc1 = doc("rooms/eros/messages/0", 0, map());
MutableDocument doc2 = doc("rooms/eros/messages/1", 0, map());
View view = new View(query, DocumentKey.emptyKeySet());
View.DocumentChanges changes = view.computeDocChanges(docUpdates(doc1, doc2));
assertEquals(2, changes.documentSet.size());
assertFalse(changes.needsRefill());
assertEquals(2, changes.changeSet.getChanges().size());
view.applyChanges(changes);
// Remove one of the docs.
changes = view.computeDocChanges(docUpdates(deletedDoc("rooms/eros/messages/1", 0)));
assertEquals(1, changes.documentSet.size());
assertFalse(changes.needsRefill());
assertEquals(1, changes.changeSet.getChanges().size());
view.applyChanges(changes);
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class ViewTest method testReturnsNeedsRefillOnReorderInLimitQuery.
@Test
public void testReturnsNeedsRefillOnReorderInLimitQuery() {
Query query = messageQuery().orderBy(orderBy("order")).limitToFirst(2);
MutableDocument doc1 = doc("rooms/eros/messages/0", 0, map("order", 1));
MutableDocument doc2 = doc("rooms/eros/messages/1", 0, map("order", 2));
MutableDocument doc3 = doc("rooms/eros/messages/2", 0, map("order", 3));
View view = new View(query, DocumentKey.emptyKeySet());
// Start with a full view.
View.DocumentChanges changes = view.computeDocChanges(docUpdates(doc1, doc2, doc3));
assertEquals(2, changes.documentSet.size());
assertFalse(changes.needsRefill());
assertEquals(2, changes.changeSet.getChanges().size());
view.applyChanges(changes);
// Move one of the docs.
doc2 = doc("rooms/eros/messages/1", 1, map("order", 2000));
changes = view.computeDocChanges(docUpdates(doc2));
assertEquals(2, changes.documentSet.size());
assertTrue(changes.needsRefill());
assertEquals(1, changes.changeSet.getChanges().size());
// Refill it with all three current docs.
changes = view.computeDocChanges(docUpdates(doc1, doc2, doc3), changes);
assertEquals(2, changes.documentSet.size());
assertFalse(changes.needsRefill());
assertEquals(2, changes.changeSet.getChanges().size());
view.applyChanges(changes);
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class ViewTest method testHandlesApplyingIrrelevantDocs.
@Test
public void testHandlesApplyingIrrelevantDocs() {
Query query = messageQuery().limitToFirst(2);
MutableDocument doc1 = doc("rooms/eros/messages/0", 0, map());
MutableDocument doc2 = doc("rooms/eros/messages/1", 0, map());
View view = new View(query, DocumentKey.emptyKeySet());
// Start with a full view.
View.DocumentChanges changes = view.computeDocChanges(docUpdates(doc1, doc2));
assertEquals(2, changes.documentSet.size());
assertFalse(changes.needsRefill());
assertEquals(2, changes.changeSet.getChanges().size());
view.applyChanges(changes);
// Remove a doc that isn't even in the results.
changes = view.computeDocChanges(docUpdates(deletedDoc("rooms/eros/messages/2", 0)));
assertEquals(2, changes.documentSet.size());
assertFalse(changes.needsRefill());
assertEquals(0, changes.changeSet.getChanges().size());
view.applyChanges(changes);
}
Aggregations