use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class RemoteEventTest method testWillAccumulateDocumentAddedAndRemovedEvents.
@Test
public void testWillAccumulateDocumentAddedAndRemovedEvents() {
Map<Integer, TargetData> targetMap = activeQueries(1, 2, 3, 4, 5, 6);
MutableDocument existingDoc = doc("docs/1", 1, map("value", 1));
MutableDocument newDoc = doc("docs/2", 2, map("value", 2));
WatchChange change1 = new DocumentChange(asList(1, 2, 3), asList(4, 5, 6), existingDoc.getKey(), existingDoc);
WatchChange change2 = new DocumentChange(asList(1, 4), asList(2, 6), newDoc.getKey(), newDoc);
RemoteEvent event = createRemoteEvent(3, targetMap, noOutstandingResponses, keySet(existingDoc.getKey()), change1, change2);
assertEquals(version(3), event.getSnapshotVersion());
assertEquals(2, event.getDocumentUpdates().size());
assertEquals(existingDoc, event.getDocumentUpdates().get(existingDoc.getKey()));
assertEquals(newDoc, event.getDocumentUpdates().get(newDoc.getKey()));
assertEquals(6, event.getTargetChanges().size());
TargetChange mapping1 = targetChange(resumeToken, false, asList(newDoc), asList(existingDoc), null);
assertEquals(mapping1, event.getTargetChanges().get(1));
TargetChange mapping2 = targetChange(resumeToken, false, null, asList(existingDoc), null);
assertEquals(mapping2, event.getTargetChanges().get(2));
TargetChange mapping3 = targetChange(resumeToken, false, null, asList(existingDoc), null);
assertEquals(mapping3, event.getTargetChanges().get(3));
TargetChange mapping4 = targetChange(resumeToken, false, asList(newDoc), null, asList(existingDoc));
assertEquals(mapping4, event.getTargetChanges().get(4));
TargetChange mapping5 = targetChange(resumeToken, false, null, null, asList(existingDoc));
assertEquals(mapping5, event.getTargetChanges().get(5));
TargetChange mapping6 = targetChange(resumeToken, false, null, null, asList(existingDoc));
assertEquals(mapping6, event.getTargetChanges().get(6));
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class RemoteEventTest method testWillKeepResetMappingEvenWithUpdates.
@Test
public void testWillKeepResetMappingEvenWithUpdates() {
Map<Integer, TargetData> targetMap = activeQueries(1);
MutableDocument doc1 = doc("docs/1", 1, map("value", 1));
MutableDocument doc2 = doc("docs/2", 2, map("value", 2));
MutableDocument doc3 = doc("docs/3", 3, map("value", 3));
WatchChange change1 = new DocumentChange(asList(1), emptyList(), doc1.getKey(), doc1);
// Reset stream, ignoring doc1
WatchChange change2 = new WatchTargetChange(WatchTargetChangeType.Reset, asList(1));
// Add doc2, doc3
WatchChange change3 = new DocumentChange(asList(1), emptyList(), doc2.getKey(), doc2);
WatchChange change4 = new DocumentChange(asList(1), emptyList(), doc3.getKey(), doc3);
// Remove doc2 again, should not show up in reset mapping.
WatchChange change5 = new DocumentChange(emptyList(), asList(1), doc2.getKey(), doc2);
RemoteEvent event = createRemoteEvent(3, targetMap, noOutstandingResponses, keySet(doc1.getKey()), change1, change2, change3, change4, change5);
assertEquals(version(3), event.getSnapshotVersion());
assertEquals(3, event.getDocumentUpdates().size());
assertEquals(doc1, event.getDocumentUpdates().get(doc1.getKey()));
assertEquals(doc2, event.getDocumentUpdates().get(doc2.getKey()));
assertEquals(doc3, event.getDocumentUpdates().get(doc3.getKey()));
assertEquals(1, event.getTargetChanges().size());
// Only doc3 is part of the new mapping.
TargetChange expected = targetChange(resumeToken, false, asList(doc3), null, asList(doc1));
assertEquals(expected, event.getTargetChanges().get(1));
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class RemoteEventTest method testExistenceFilterMismatchRemovesCurrentChanges.
@Test
public void testExistenceFilterMismatchRemovesCurrentChanges() {
Map<Integer, TargetData> targetMap = activeQueries(1);
WatchChangeAggregator aggregator = createAggregator(targetMap, noOutstandingResponses, noExistingKeys);
WatchTargetChange markCurrent = new WatchTargetChange(WatchTargetChangeType.Current, asList(1));
aggregator.handleTargetChange(markCurrent);
MutableDocument doc1 = doc("docs/1", 1, map("value", 1));
DocumentChange addDoc = new DocumentChange(asList(1), emptyList(), doc1.getKey(), doc1);
aggregator.handleDocumentChange(addDoc);
// The existence filter mismatch will remove the document from target 1, but not synthesize a
// document delete.
WatchChange.ExistenceFilterWatchChange existenceFilter = new WatchChange.ExistenceFilterWatchChange(1, new ExistenceFilter(0));
aggregator.handleExistenceFilter(existenceFilter);
RemoteEvent event = aggregator.createRemoteEvent(version(3));
assertEquals(version(3), event.getSnapshotVersion());
assertEquals(1, event.getDocumentUpdates().size());
assertEquals(1, event.getTargetMismatches().size());
assertEquals(doc1, event.getDocumentUpdates().get(doc1.getKey()));
assertEquals(1, event.getTargetChanges().size());
TargetChange mapping1 = targetChange(ByteString.EMPTY, false, null, null, null);
assertEquals(mapping1, event.getTargetChanges().get(1));
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class RemoteEventTest method testTracksLimboDocuments.
@Test
public void testTracksLimboDocuments() {
Map<Integer, TargetData> listens = activeQueries(1);
listens.putAll(activeLimboQueries("doc/2", 2));
// Add 3 docs: 1 is limbo and non-limbo, 2 is limbo-only, 3 is non-limbo
MutableDocument doc1 = doc("docs/1", 1, map("key", "value"));
MutableDocument doc2 = doc("docs/2", 1, map("key", "value"));
MutableDocument doc3 = doc("docs/3", 1, map("key", "value"));
// Target 2 is a limbo target
DocumentChange docChange1 = new DocumentChange(asList(1, 2), emptyList(), doc1.getKey(), doc1);
DocumentChange docChange2 = new DocumentChange(asList(2), emptyList(), doc2.getKey(), doc2);
DocumentChange docChange3 = new DocumentChange(asList(1), emptyList(), doc3.getKey(), doc3);
WatchTargetChange targetsChange = new WatchTargetChange(WatchTargetChangeType.Current, asList(1, 2));
RemoteEvent event = createRemoteEvent(3, listens, noOutstandingResponses, noExistingKeys, docChange1, docChange2, docChange3, targetsChange);
Set<DocumentKey> limboDocuments = event.getResolvedLimboDocuments();
// Doc1 is in both limbo and non-limbo targets, therefore not tracked as limbo
assertFalse(limboDocuments.contains(doc1.getKey()));
// Doc2 is only in the limbo target, so is tracked as a limbo document
assertTrue(limboDocuments.contains(doc2.getKey()));
// Doc3 is only in the non-limbo target, therefore not tracked as limbo
assertFalse(limboDocuments.contains(doc3.getKey()));
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class LocalSerializerTest method testEncodesDeletedDocument.
@Test
public void testEncodesDeletedDocument() {
MutableDocument deletedDoc = deletedDoc("some/path", 42);
com.google.firebase.firestore.proto.MaybeDocument maybeDocProto = com.google.firebase.firestore.proto.MaybeDocument.newBuilder().setNoDocument(com.google.firebase.firestore.proto.NoDocument.newBuilder().setName("projects/p/databases/d/documents/some/path").setReadTime(com.google.protobuf.Timestamp.newBuilder().setSeconds(0).setNanos(42000))).build();
assertEquals(maybeDocProto, serializer.encodeMaybeDocument(deletedDoc));
MutableDocument decoded = serializer.decodeMaybeDocument(maybeDocProto);
assertEquals(deletedDoc, decoded);
}
Aggregations