use of com.google.firebase.firestore.local.TargetData in project firebase-android-sdk by firebase.
the class RemoteEventTest method testDoesNotSynthesizeDeleteInWrongState.
@Test
public void testDoesNotSynthesizeDeleteInWrongState() {
Map<Integer, TargetData> targetMap = activeLimboQueries("foo/doc", 1);
WatchTargetChange wrongState = new WatchTargetChange(WatchTargetChangeType.NoChange, asList(1));
RemoteEvent event = createRemoteEvent(3, targetMap, noOutstandingResponses, noExistingKeys, wrongState);
assertEquals(0, event.getDocumentUpdates().size());
assertEquals(0, event.getResolvedLimboDocuments().size());
}
use of com.google.firebase.firestore.local.TargetData in project firebase-android-sdk by firebase.
the class RemoteEventTest method testLastResumeTokenWins.
@Test
public void testLastResumeTokenWins() {
Map<Integer, TargetData> targetMap = activeQueries(1, 2);
WatchChangeAggregator aggregator = createAggregator(targetMap, noOutstandingResponses, noExistingKeys);
WatchTargetChange change1 = new WatchTargetChange(WatchTargetChangeType.Current, asList(1));
aggregator.handleTargetChange(change1);
ByteString resumeToken2 = ByteString.copyFromUtf8("resumeToken2");
WatchTargetChange change2 = new WatchTargetChange(WatchTargetChangeType.Current, asList(1), resumeToken2);
aggregator.handleTargetChange(change2);
ByteString resumeToken3 = ByteString.copyFromUtf8("resumeToken3");
WatchTargetChange change3 = new WatchTargetChange(WatchTargetChangeType.Current, asList(2), resumeToken3);
aggregator.handleTargetChange(change3);
RemoteEvent event = aggregator.createRemoteEvent(version(3));
assertEquals(2, event.getTargetChanges().size());
TargetChange mapping1 = targetChange(resumeToken2, true, null, null, null);
assertEquals(mapping1, event.getTargetChanges().get(1));
TargetChange mapping2 = targetChange(resumeToken3, true, null, null, null);
assertEquals(mapping2, event.getTargetChanges().get(2));
}
use of com.google.firebase.firestore.local.TargetData in project firebase-android-sdk by firebase.
the class RemoteEventTest method testSeparatesUpdates.
@Test
public void testSeparatesUpdates() {
Map<Integer, TargetData> targetMap = activeQueries(1);
MutableDocument newDoc = doc("docs/new", 1, map("key", "value"));
DocumentChange newDocChange = new DocumentChange(asList(1), emptyList(), newDoc.getKey(), newDoc);
MutableDocument existingDoc = doc("docs/existing", 1, map("some", "data"));
DocumentChange existingDocChange = new DocumentChange(asList(1), emptyList(), existingDoc.getKey(), existingDoc);
MutableDocument deletedDoc = deletedDoc("docs/deleted", 1);
DocumentChange deletedDocChange = new DocumentChange(asList(1), emptyList(), deletedDoc.getKey(), deletedDoc);
MutableDocument missingDoc = deletedDoc("docs/missing ", 1);
DocumentChange missingDocChange = new DocumentChange(asList(1), emptyList(), missingDoc.getKey(), missingDoc);
RemoteEvent event = createRemoteEvent(3, targetMap, noOutstandingResponses, keySet(existingDoc.getKey(), deletedDoc.getKey()), newDocChange, existingDocChange, deletedDocChange, missingDocChange);
TargetChange mapping = targetChange(resumeToken, false, asList(newDoc), asList(existingDoc), asList(deletedDoc));
assertEquals(mapping, event.getTargetChanges().get(1));
}
use of com.google.firebase.firestore.local.TargetData in project firebase-android-sdk by firebase.
the class RemoteSerializerTest method testEncodesFirstLevelKeyQueries.
@Test
public void testEncodesFirstLevelKeyQueries() {
Query q = Query.atPath(ResourcePath.fromString("docs/1"));
Target actual = serializer.encodeTarget(new TargetData(q.toTarget(), 1, 2, QueryPurpose.LISTEN));
DocumentsTarget.Builder docs = DocumentsTarget.newBuilder().addDocuments("projects/p/databases/d/documents/docs/1");
Target expected = Target.newBuilder().setDocuments(docs).setTargetId(1).setResumeToken(ByteString.EMPTY).build();
assertEquals(expected, actual);
assertEquals(serializer.decodeDocumentsTarget(serializer.encodeDocumentsTarget(q.toTarget())), q.toTarget());
}
use of com.google.firebase.firestore.local.TargetData 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));
}
Aggregations