Search in sources :

Example 11 with TargetData

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());
}
Also used : TargetData(com.google.firebase.firestore.local.TargetData) WatchTargetChange(com.google.firebase.firestore.remote.WatchChange.WatchTargetChange) Test(org.junit.Test)

Example 12 with TargetData

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));
}
Also used : TargetData(com.google.firebase.firestore.local.TargetData) WatchTargetChange(com.google.firebase.firestore.remote.WatchChange.WatchTargetChange) ByteString(com.google.protobuf.ByteString) WatchTargetChange(com.google.firebase.firestore.remote.WatchChange.WatchTargetChange) Test(org.junit.Test)

Example 13 with TargetData

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));
}
Also used : TargetData(com.google.firebase.firestore.local.TargetData) WatchTargetChange(com.google.firebase.firestore.remote.WatchChange.WatchTargetChange) MutableDocument(com.google.firebase.firestore.model.MutableDocument) DocumentChange(com.google.firebase.firestore.remote.WatchChange.DocumentChange) Test(org.junit.Test)

Example 14 with TargetData

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());
}
Also used : TargetData(com.google.firebase.firestore.local.TargetData) DocumentsTarget(com.google.firestore.v1.Target.DocumentsTarget) DocumentsTarget(com.google.firestore.v1.Target.DocumentsTarget) Target(com.google.firestore.v1.Target) QueryTarget(com.google.firestore.v1.Target.QueryTarget) StructuredQuery(com.google.firestore.v1.StructuredQuery) Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 15 with TargetData

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));
}
Also used : TargetData(com.google.firebase.firestore.local.TargetData) WatchTargetChange(com.google.firebase.firestore.remote.WatchChange.WatchTargetChange) MutableDocument(com.google.firebase.firestore.model.MutableDocument) DocumentChange(com.google.firebase.firestore.remote.WatchChange.DocumentChange) WatchTargetChange(com.google.firebase.firestore.remote.WatchChange.WatchTargetChange) Test(org.junit.Test)

Aggregations

TargetData (com.google.firebase.firestore.local.TargetData)38 Test (org.junit.Test)23 WatchTargetChange (com.google.firebase.firestore.remote.WatchChange.WatchTargetChange)22 MutableDocument (com.google.firebase.firestore.model.MutableDocument)15 DocumentChange (com.google.firebase.firestore.remote.WatchChange.DocumentChange)14 HashMap (java.util.HashMap)8 Query (com.google.firebase.firestore.core.Query)7 StructuredQuery (com.google.firestore.v1.StructuredQuery)6 DocumentKey (com.google.firebase.firestore.model.DocumentKey)5 WatchChangeAggregator (com.google.firebase.firestore.remote.WatchChangeAggregator)4 ByteString (com.google.protobuf.ByteString)4 ImmutableSortedSet (com.google.firebase.database.collection.ImmutableSortedSet)3 Target (com.google.firestore.v1.Target)3 DocumentsTarget (com.google.firestore.v1.Target.DocumentsTarget)3 QueryTarget (com.google.firestore.v1.Target.QueryTarget)3 Map (java.util.Map)3 WatchChange (com.google.firebase.firestore.remote.WatchChange)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 Target (com.google.firebase.firestore.core.Target)1