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));
}
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());
}
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()));
}
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());
}
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());
}
Aggregations