Skip to content

Commit 6ee7bdf

Browse files
Add test for b/226360573 (#3603)
1 parent 0472f6f commit 6ee7bdf

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

firebase-firestore/src/test/java/com/google/firebase/firestore/local/QueryEngineTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ private <T> T expectFullCollectionScan(Callable<T> c) throws Exception {
195195
}
196196
}
197197

198-
private DocumentSet runQuery(Query query, SnapshotVersion lastLimboFreeSnapshotVersion) {
198+
protected DocumentSet runQuery(Query query, SnapshotVersion lastLimboFreeSnapshotVersion) {
199199
Preconditions.checkNotNull(
200200
expectFullCollectionScan,
201201
"Encountered runQuery() call not wrapped in expectOptimizedCollectionQuery()/expectFullCollectionQuery()");

firebase-firestore/src/test/java/com/google/firebase/firestore/local/SQLiteQueryEngineTest.java

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@
1818
import static com.google.firebase.firestore.model.FieldIndex.Segment.*;
1919
import static com.google.firebase.firestore.testutil.TestUtil.doc;
2020
import static com.google.firebase.firestore.testutil.TestUtil.docMap;
21+
import static com.google.firebase.firestore.testutil.TestUtil.docSet;
2122
import static com.google.firebase.firestore.testutil.TestUtil.fieldIndex;
2223
import static com.google.firebase.firestore.testutil.TestUtil.filter;
2324
import static com.google.firebase.firestore.testutil.TestUtil.map;
2425
import static com.google.firebase.firestore.testutil.TestUtil.query;
2526
import static com.google.firebase.firestore.testutil.TestUtil.setMutation;
26-
import static org.junit.Assert.assertTrue;
27+
import static org.junit.Assert.assertEquals;
2728

28-
import com.google.firebase.database.collection.ImmutableSortedMap;
2929
import com.google.firebase.firestore.core.Query;
30-
import com.google.firebase.firestore.model.Document;
31-
import com.google.firebase.firestore.model.DocumentKey;
30+
import com.google.firebase.firestore.model.DocumentSet;
3231
import com.google.firebase.firestore.model.MutableDocument;
3332
import com.google.firebase.firestore.model.SnapshotVersion;
33+
import org.junit.Ignore;
3434
import org.junit.Test;
3535
import org.junit.runner.RunWith;
3636
import org.robolectric.RobolectricTestRunner;
@@ -50,7 +50,7 @@ public void combinesIndexedWithNonIndexedResults() throws Exception {
5050
MutableDocument doc1 = doc("coll/a", 1, map("foo", true));
5151
MutableDocument doc2 = doc("coll/b", 2, map("foo", true));
5252
MutableDocument doc3 = doc("coll/c", 3, map("foo", true));
53-
MutableDocument doc4 = doc("coll/d", 3, map("foo", true));
53+
MutableDocument doc4 = doc("coll/d", 3, map("foo", true)).setHasLocalMutations();
5454

5555
indexManager.addFieldIndex(fieldIndex("coll", "foo", Kind.ASCENDING));
5656

@@ -63,15 +63,29 @@ public void combinesIndexedWithNonIndexedResults() throws Exception {
6363
addMutation(setMutation("coll/d", map("foo", true)));
6464

6565
Query queryWithFilter = query("coll").filter(filter("foo", "==", true));
66-
ImmutableSortedMap<DocumentKey, Document> results =
67-
expectOptimizedCollectionScan(
68-
() ->
69-
queryEngine.getDocumentsMatchingQuery(
70-
queryWithFilter, SnapshotVersion.NONE, DocumentKey.emptyKeySet()));
66+
DocumentSet results =
67+
expectOptimizedCollectionScan(() -> runQuery(queryWithFilter, SnapshotVersion.NONE));
7168

72-
assertTrue(results.containsKey(doc1.getKey()));
73-
assertTrue(results.containsKey(doc2.getKey()));
74-
assertTrue(results.containsKey(doc3.getKey()));
75-
assertTrue(results.containsKey(doc4.getKey()));
69+
assertEquals(docSet(queryWithFilter.comparator(), doc1, doc2, doc3, doc4), results);
70+
}
71+
72+
@Test
73+
@Ignore("b/226360573")
74+
public void usesPartialIndexForLimitQueries() throws Exception {
75+
MutableDocument doc1 = doc("coll/1", 1, map("a", 1, "b", 0));
76+
MutableDocument doc2 = doc("coll/2", 1, map("a", 1, "b", 1));
77+
MutableDocument doc3 = doc("coll/3", 1, map("a", 1, "b", 2));
78+
MutableDocument doc4 = doc("coll/4", 1, map("a", 1, "b", 3));
79+
MutableDocument doc5 = doc("coll/5", 1, map("a", 2, "b", 3));
80+
addDocument(doc1, doc2, doc3, doc4, doc5);
81+
82+
indexManager.addFieldIndex(fieldIndex("coll", "a", Kind.ASCENDING));
83+
indexManager.updateIndexEntries(docMap(doc1, doc2, doc3, doc4, doc5));
84+
indexManager.updateCollectionGroup("coll", IndexOffset.fromDocument(doc5));
85+
86+
Query query =
87+
query("coll").filter(filter("a", "==", 1)).filter(filter("b", "==", 1)).limitToFirst(3);
88+
DocumentSet result = expectOptimizedCollectionScan(() -> runQuery(query, SnapshotVersion.NONE));
89+
assertEquals(docSet(query.comparator(), doc1), result);
7690
}
7791
}

0 commit comments

Comments
 (0)