use of com.google.firebase.firestore.core.Query in project firebase-android-sdk by firebase.
the class BundleSerializerTest method testDecodesLimitToLastQuery.
@Test
public void testDecodesLimitToLastQuery() throws JSONException {
String json = "{ from: [ { collectionId: 'coll' } ], limit: {value: 5 } }";
Query query = TestUtil.query("coll").limitToLast(5);
assertDecodesNamedQuery(json, query);
}
use of com.google.firebase.firestore.core.Query in project firebase-android-sdk by firebase.
the class LocalStoreTestCase method testQueriesIncludeLocallyModifiedDocuments.
@Test
public void testQueriesIncludeLocallyModifiedDocuments() {
assumeFalse(garbageCollectorIsEager());
// This test verifies that queries that have a persisted TargetMapping include documents that
// were modified by local edits after the target mapping was written.
Query query = query("foo").filter(filter("matches", "==", true));
int targetId = allocateQuery(query);
applyRemoteEvent(addedRemoteEvent(doc("foo/a", 10, map("matches", true)), targetId));
applyRemoteEvent(noChangeEvent(targetId, 10));
updateViews(targetId, /* fromCache= */
false);
// Execute the query based on the RemoteEvent.
executeQuery(query);
assertQueryReturned("foo/a");
// Write a document.
writeMutation(setMutation("foo/b", map("matches", true)));
// Execute the query and make sure that the pending mutation is included in the result.
executeQuery(query);
assertQueryReturned("foo/a", "foo/b");
acknowledgeMutation(11);
// Execute the query and make sure that the acknowledged mutation is included in the result.
executeQuery(query);
assertQueryReturned("foo/a", "foo/b");
}
use of com.google.firebase.firestore.core.Query in project firebase-android-sdk by firebase.
the class LocalStoreTestCase method testHandlesSetMutationThenTransformThenRemoteEventThenTransform.
@Test
public void testHandlesSetMutationThenTransformThenRemoteEventThenTransform() {
Query query = query("foo");
allocateQuery(query);
assertTargetId(2);
writeMutation(setMutation("foo/bar", map("sum", 0)));
assertChanged(doc("foo/bar", 0, map("sum", 0)).setHasLocalMutations());
assertContains(doc("foo/bar", 0, map("sum", 0)).setHasLocalMutations());
applyRemoteEvent(addedRemoteEvent(doc("foo/bar", 1, map("sum", 0)), asList(2), emptyList()));
acknowledgeMutation(1);
assertChanged(doc("foo/bar", 1, map("sum", 0)));
assertContains(doc("foo/bar", 1, map("sum", 0)));
writeMutation(patchMutation("foo/bar", map("sum", FieldValue.increment(1))));
assertChanged(doc("foo/bar", 1, map("sum", 1)).setHasLocalMutations());
assertContains(doc("foo/bar", 1, map("sum", 1)).setHasLocalMutations());
// The value in this remote event gets ignored since we still have a pending transform mutation.
applyRemoteEvent(addedRemoteEvent(doc("foo/bar", 2, map("sum", 1337)), asList(2), emptyList()));
assertChanged(doc("foo/bar", 2, map("sum", 1)).setHasLocalMutations());
assertContains(doc("foo/bar", 2, map("sum", 1)).setHasLocalMutations());
// Add another increment. Note that we still compute the increment based on the local value.
writeMutation(patchMutation("foo/bar", map("sum", FieldValue.increment(2))));
assertChanged(doc("foo/bar", 2, map("sum", 3)).setHasLocalMutations());
assertContains(doc("foo/bar", 2, map("sum", 3)).setHasLocalMutations());
acknowledgeMutationWithTransformResults(3, 1);
assertChanged(doc("foo/bar", 3, map("sum", 3)).setHasLocalMutations());
assertContains(doc("foo/bar", 3, map("sum", 3)).setHasLocalMutations());
acknowledgeMutationWithTransformResults(4, 1339);
assertChanged(doc("foo/bar", 4, map("sum", 1339)).setHasCommittedMutations());
assertContains(doc("foo/bar", 4, map("sum", 1339)).setHasCommittedMutations());
}
use of com.google.firebase.firestore.core.Query in project firebase-android-sdk by firebase.
the class LocalStoreTestCase method testCollectsGarbageAfterChangeBatch.
@Test
public void testCollectsGarbageAfterChangeBatch() {
assumeTrue(garbageCollectorIsEager());
Query query = query("foo");
allocateQuery(query);
assertTargetId(2);
List<Integer> none = asList();
List<Integer> two = asList(2);
applyRemoteEvent(addedRemoteEvent(doc("foo/bar", 2, map("foo", "bar")), two, none));
assertContains(doc("foo/bar", 2, map("foo", "bar")));
applyRemoteEvent(updateRemoteEvent(doc("foo/bar", 2, map("foo", "baz")), none, two));
assertNotContains("foo/bar");
}
use of com.google.firebase.firestore.core.Query 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