Skip to content

Commit 7fe5625

Browse files
Add test
1 parent 37d1168 commit 7fe5625

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static com.google.firebase.firestore.testutil.TestUtil.fieldIndex;
2424
import static com.google.firebase.firestore.testutil.TestUtil.filter;
2525
import static com.google.firebase.firestore.testutil.TestUtil.map;
26+
import static com.google.firebase.firestore.testutil.TestUtil.patchMutation;
2627
import static com.google.firebase.firestore.testutil.TestUtil.query;
2728
import static com.google.firebase.firestore.testutil.TestUtil.setMutation;
2829
import static org.junit.Assert.assertEquals;
@@ -46,7 +47,7 @@ Persistence getPersistence() {
4647
}
4748

4849
@Test
49-
public void combinesIndexedWithNonIndexedResults() throws Exception {
50+
public void testCombinesIndexedWithNonIndexedResults() throws Exception {
5051
MutableDocument doc1 = doc("coll/a", 1, map("foo", true));
5152
MutableDocument doc2 = doc("coll/b", 2, map("foo", true));
5253
MutableDocument doc3 = doc("coll/c", 3, map("foo", true));
@@ -70,7 +71,7 @@ public void combinesIndexedWithNonIndexedResults() throws Exception {
7071
}
7172

7273
@Test
73-
public void usesPartialIndexForLimitQueries() throws Exception {
74+
public void testUsesPartialIndexForLimitQueries() throws Exception {
7475
MutableDocument doc1 = doc("coll/1", 1, map("a", 1, "b", 0));
7576
MutableDocument doc2 = doc("coll/2", 1, map("a", 1, "b", 1));
7677
MutableDocument doc3 = doc("coll/3", 1, map("a", 1, "b", 2));
@@ -87,4 +88,24 @@ public void usesPartialIndexForLimitQueries() throws Exception {
8788
DocumentSet result = expectOptimizedCollectionScan(() -> runQuery(query, SnapshotVersion.NONE));
8889
assertEquals(docSet(query.comparator(), doc2), result);
8990
}
91+
92+
@Test
93+
public void testRefillsIndexedLimitQueries() throws Exception {
94+
MutableDocument doc1 = doc("coll/1", 1, map("a", 1));
95+
MutableDocument doc2 = doc("coll/2", 1, map("a", 2));
96+
MutableDocument doc3 = doc("coll/3", 1, map("a", 3));
97+
MutableDocument doc4 = doc("coll/4", 1, map("a", 4));
98+
addDocument(doc1, doc2, doc3, doc4);
99+
100+
indexManager.addFieldIndex(fieldIndex("coll", "a", Kind.ASCENDING));
101+
indexManager.updateIndexEntries(docMap(doc1, doc2, doc3, doc4));
102+
indexManager.updateCollectionGroup("coll", IndexOffset.fromDocument(doc4));
103+
104+
addMutation(patchMutation("coll/4", map("a", 5)));
105+
106+
Query query =
107+
query("coll").filter(filter("a", "==", 1)).filter(filter("b", "==", 1)).limitToFirst(3);
108+
DocumentSet result = expectOptimizedCollectionScan(() -> runQuery(query, SnapshotVersion.NONE));
109+
assertEquals(docSet(query.comparator(), doc1, doc2, doc4), result);
110+
}
90111
}

0 commit comments

Comments
 (0)