use of com.google.firebase.firestore.core.Target in project firebase-android-sdk by firebase.
the class IndexBackfillerTest method testBackfillAppliesDeleteToRemoteDoc.
@Test
public void testBackfillAppliesDeleteToRemoteDoc() {
addFieldIndex("coll", "foo");
addDoc("coll/doc", version(5), "foo", 1);
int documentsProcessed = backfiller.backfill();
assertEquals(1, documentsProcessed);
Mutation delete = deleteMutation("coll/doc");
addMutationToOverlay("coll/doc", delete);
documentsProcessed = backfiller.backfill();
assertEquals(1, documentsProcessed);
Target target = query("coll").filter(filter("foo", "==", 2)).toTarget();
Set<DocumentKey> matching = indexManager.getDocumentsMatchingTarget(target);
assertTrue(matching.isEmpty());
}
use of com.google.firebase.firestore.core.Target in project firebase-android-sdk by firebase.
the class BundleSerializerTest method assertDecodesNamedQuery.
private void assertDecodesNamedQuery(String json, Query query) throws JSONException {
String queryJson = "{\n" + " name: 'query-1',\n" + " bundledQuery: {\n" + " parent: '" + TEST_PROJECT + "',\n" + " structuredQuery:\n" + json + ",\n" + " limitType: '" + (query.hasLimitToLast() ? "LAST" : "FIRST") + "'\n" + " },\n" + " readTime: '2020-01-01T00:00:01.000000001Z'\n" + "}";
NamedQuery actualNamedQuery = serializer.decodeNamedQuery(new JSONObject(queryJson));
long limit = query.hasLimitToFirst() ? query.getLimitToFirst() : (query.hasLimitToLast() ? query.getLimitToLast() : Target.NO_LIMIT);
Target target = new Target(query.getPath(), query.getCollectionGroup(), query.getFilters(), query.getExplicitOrderBy(), limit, query.getStartAt(), query.getEndAt());
BundledQuery bundledQuery = new BundledQuery(target, query.hasLimitToLast() ? Query.LimitType.LIMIT_TO_LAST : Query.LimitType.LIMIT_TO_FIRST);
NamedQuery expectedNamedQuery = new NamedQuery("query-1", bundledQuery, new SnapshotVersion(new com.google.firebase.Timestamp(1577836801, 1)));
assertEquals(expectedNamedQuery, actualNamedQuery);
}
use of com.google.firebase.firestore.core.Target in project firebase-android-sdk by firebase.
the class WatchChangeAggregator method handleExistenceFilter.
/**
* Handles existence filters and synthesizes deletes for filter mismatches. Targets that are
* invalidated by filter mismatches are added to `pendingTargetResets`.
*/
public void handleExistenceFilter(ExistenceFilterWatchChange watchChange) {
int targetId = watchChange.getTargetId();
int expectedCount = watchChange.getExistenceFilter().getCount();
TargetData targetData = queryDataForActiveTarget(targetId);
if (targetData != null) {
Target target = targetData.getTarget();
if (target.isDocumentQuery()) {
if (expectedCount == 0) {
// The existence filter told us the document does not exist. We deduce that this document
// does not exist and apply a deleted document to our updates. Without applying this
// deleted document there might be another query that will raise this document as part of
// a snapshot until it is resolved, essentially exposing inconsistency between queries.
DocumentKey key = DocumentKey.fromPath(target.getPath());
MutableDocument result = MutableDocument.newNoDocument(key, SnapshotVersion.NONE);
removeDocumentFromTarget(targetId, key, result);
} else {
hardAssert(expectedCount == 1, "Single document existence filter with count: %d", expectedCount);
}
} else {
long currentSize = getCurrentDocumentCountForTarget(targetId);
if (currentSize != expectedCount) {
// Existence filter mismatch: We reset the mapping and raise a new snapshot with
// `isFromCache:true`.
resetTarget(targetId);
pendingTargetResets.add(targetId);
}
}
}
}
use of com.google.firebase.firestore.core.Target in project firebase-android-sdk by firebase.
the class LocalSerializerTest method testEncodesLimitToLastQuery.
@Test
public void testEncodesLimitToLastQuery() {
Target target = new Target(path("room"), /* collectionGroup= */
null, Collections.emptyList(), Collections.emptyList(), /* limit=*/
42, /* startAt= */
null, /* endAt= */
null);
BundledQuery bundledQuery = new BundledQuery(target, Query.LimitType.LIMIT_TO_LAST);
com.google.firestore.bundle.BundledQuery encodedBundledQuery = serializer.encodeBundledQuery(bundledQuery);
BundledQuery decodedBundledQuery = serializer.decodeBundledQuery(encodedBundledQuery);
assertEquals(bundledQuery, decodedBundledQuery);
}
use of com.google.firebase.firestore.core.Target in project firebase-android-sdk by firebase.
the class LocalStoreTestCase method testLastLimboFreeSnapshotIsAdvancedDuringViewProcessing.
@Test
public void testLastLimboFreeSnapshotIsAdvancedDuringViewProcessing() {
// This test verifies that the `lastLimboFreeSnapshot` version for TargetData is advanced when
// we compute a limbo-free free view and that the mapping is persisted when we release a target.
Query query = query("foo");
Target target = query.toTarget();
int targetId = allocateQuery(query);
// Advance the target snapshot.
applyRemoteEvent(noChangeEvent(targetId, 10));
// At this point, we have not yet confirmed that the target is limbo free.
TargetData cachedTargetData = localStore.getTargetData(target);
Assert.assertEquals(SnapshotVersion.NONE, cachedTargetData.getLastLimboFreeSnapshotVersion());
// Mark the view synced, which updates the last limbo free snapshot version.
updateViews(targetId, /* fromCache=*/
false);
cachedTargetData = localStore.getTargetData(target);
Assert.assertEquals(version(10), cachedTargetData.getLastLimboFreeSnapshotVersion());
// The last limbo free snapshot version is persisted even if we release the target.
releaseTarget(targetId);
if (!garbageCollectorIsEager()) {
cachedTargetData = localStore.getTargetData(target);
Assert.assertEquals(version(10), cachedTargetData.getLastLimboFreeSnapshotVersion());
}
}
Aggregations