Search in sources :

Example 31 with TargetData

use of com.google.firebase.firestore.local.TargetData in project firebase-android-sdk by firebase.

the class RemoteEventTest method testResumeTokenHandledPerTarget.

@Test
public void testResumeTokenHandledPerTarget() {
    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(2), resumeToken2);
    aggregator.handleTargetChange(change2);
    RemoteEvent event = aggregator.createRemoteEvent(version(3));
    assertEquals(2, event.getTargetChanges().size());
    TargetChange mapping1 = targetChange(resumeToken, true, null, null, null);
    assertEquals(mapping1, event.getTargetChanges().get(1));
    TargetChange mapping2 = targetChange(resumeToken2, 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 32 with TargetData

use of com.google.firebase.firestore.local.TargetData in project firebase-android-sdk by firebase.

the class RemoteEventTest method testWillIgnoreEventsForPendingTargets.

@Test
public void testWillIgnoreEventsForPendingTargets() {
    Map<Integer, TargetData> targetMap = activeQueries(1);
    MutableDocument doc1 = doc("docs/1", 1, map("value", 1));
    MutableDocument doc2 = doc("docs/2", 2, map("value", 2));
    // We're waiting for the watch and unwatch ack
    Map<Integer, Integer> outstanding = new HashMap<>();
    outstanding.put(1, 2);
    WatchChange change1 = new DocumentChange(asList(1), emptyList(), doc1.getKey(), doc1);
    WatchChange change2 = new WatchTargetChange(WatchTargetChangeType.Removed, asList(1));
    WatchChange change3 = new WatchTargetChange(WatchTargetChangeType.Added, asList(1));
    WatchChange change4 = new DocumentChange(asList(1), emptyList(), doc2.getKey(), doc2);
    RemoteEvent event = createRemoteEvent(3, targetMap, outstanding, noExistingKeys, change1, change2, change3, change4);
    assertEquals(version(3), event.getSnapshotVersion());
    // doc1 is ignored because the target was not active at the time, but for
    // doc2 the target is active.
    assertEquals(1, event.getDocumentUpdates().size());
    assertEquals(doc2, event.getDocumentUpdates().get(doc2.getKey()));
    assertEquals(1, event.getTargetChanges().size());
}
Also used : TargetData(com.google.firebase.firestore.local.TargetData) HashMap(java.util.HashMap) 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)

Example 33 with TargetData

use of com.google.firebase.firestore.local.TargetData in project firebase-android-sdk by firebase.

the class RemoteEventTest method testSynthesizeDeletes.

@Test
public void testSynthesizeDeletes() {
    Map<Integer, TargetData> targetMap = activeLimboQueries("foo/doc", 1);
    WatchTargetChange shouldSynthesize = new WatchTargetChange(WatchTargetChangeType.Current, asList(1));
    RemoteEvent event = createRemoteEvent(3, targetMap, noOutstandingResponses, noExistingKeys, shouldSynthesize);
    DocumentKey synthesized = key("docs/2");
    assertNull(event.getDocumentUpdates().get(synthesized));
    MutableDocument expected = deletedDoc("foo/doc", 3);
    assertEquals(expected, event.getDocumentUpdates().get(expected.getKey()));
    assertTrue(event.getResolvedLimboDocuments().contains(expected.getKey()));
}
Also used : TargetData(com.google.firebase.firestore.local.TargetData) DocumentKey(com.google.firebase.firestore.model.DocumentKey) MutableDocument(com.google.firebase.firestore.model.MutableDocument) WatchTargetChange(com.google.firebase.firestore.remote.WatchChange.WatchTargetChange) Test(org.junit.Test)

Example 34 with TargetData

use of com.google.firebase.firestore.local.TargetData in project firebase-android-sdk by firebase.

the class RemoteEventTest method testExistenceFilterMismatchClearsTarget.

@Test
public void testExistenceFilterMismatchClearsTarget() {
    Map<Integer, TargetData> targetMap = activeQueries(1, 2);
    MutableDocument doc1 = doc("docs/1", 1, map("value", 1));
    MutableDocument doc2 = doc("docs/2", 2, map("value", 2));
    WatchChange change1 = new DocumentChange(asList(1), emptyList(), doc1.getKey(), doc1);
    WatchChange change2 = new DocumentChange(asList(1), emptyList(), doc2.getKey(), doc2);
    WatchChange change3 = new WatchTargetChange(WatchTargetChangeType.Current, asList(1));
    WatchChangeAggregator aggregator = createAggregator(targetMap, noOutstandingResponses, keySet(doc1.getKey(), doc2.getKey()), change1, change2, change3);
    RemoteEvent event = aggregator.createRemoteEvent(version(3));
    assertEquals(version(3), event.getSnapshotVersion());
    assertEquals(2, event.getDocumentUpdates().size());
    assertEquals(doc1, event.getDocumentUpdates().get(doc1.getKey()));
    assertEquals(doc2, event.getDocumentUpdates().get(doc2.getKey()));
    assertEquals(2, event.getTargetChanges().size());
    TargetChange mapping1 = targetChange(resumeToken, true, null, asList(doc1, doc2), null);
    assertEquals(mapping1, event.getTargetChanges().get(1));
    TargetChange mapping2 = targetChange(resumeToken, false, null, null, null);
    assertEquals(mapping2, event.getTargetChanges().get(2));
    WatchChange.ExistenceFilterWatchChange watchChange = new WatchChange.ExistenceFilterWatchChange(1, new ExistenceFilter(1));
    aggregator.handleExistenceFilter(watchChange);
    event = aggregator.createRemoteEvent(version(3));
    TargetChange mapping3 = targetChange(ByteString.EMPTY, false, null, null, asList(doc1, doc2));
    assertEquals(1, event.getTargetChanges().size());
    assertEquals(mapping3, event.getTargetChanges().get(1));
    assertEquals(1, event.getTargetMismatches().size());
    assertEquals(0, event.getDocumentUpdates().size());
}
Also used : MutableDocument(com.google.firebase.firestore.model.MutableDocument) DocumentChange(com.google.firebase.firestore.remote.WatchChange.DocumentChange) WatchTargetChange(com.google.firebase.firestore.remote.WatchChange.WatchTargetChange) TargetData(com.google.firebase.firestore.local.TargetData) WatchTargetChange(com.google.firebase.firestore.remote.WatchChange.WatchTargetChange) Test(org.junit.Test)

Example 35 with TargetData

use of com.google.firebase.firestore.local.TargetData in project firebase-android-sdk by firebase.

the class RemoteSerializerTest method testEncodesReadTime.

@Test
public void testEncodesReadTime() {
    Query q = Query.atPath(ResourcePath.fromString("docs"));
    TargetData targetData = new TargetData(q.toTarget(), 1, 2, QueryPurpose.LISTEN).withResumeToken(ByteString.EMPTY, version(4000000));
    Target actual = serializer.encodeTarget(targetData);
    StructuredQuery.Builder structuredQueryBuilder = StructuredQuery.newBuilder().addFrom(CollectionSelector.newBuilder().setCollectionId("docs")).addOrderBy(defaultKeyOrder());
    QueryTarget.Builder queryBuilder = QueryTarget.newBuilder().setParent("projects/p/databases/d/documents").setStructuredQuery(structuredQueryBuilder);
    Target expected = Target.newBuilder().setQuery(queryBuilder).setTargetId(1).setReadTime(Timestamp.newBuilder().setSeconds(4)).build();
    assertEquals(expected, actual);
    assertEquals(serializer.decodeQueryTarget(serializer.encodeQueryTarget(q.toTarget())), q.toTarget());
}
Also used : TargetData(com.google.firebase.firestore.local.TargetData) StructuredQuery(com.google.firestore.v1.StructuredQuery) QueryTarget(com.google.firestore.v1.Target.QueryTarget) 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)

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