23
23
import static com .google .firebase .firestore .testutil .TestUtil .fieldIndex ;
24
24
import static com .google .firebase .firestore .testutil .TestUtil .filter ;
25
25
import static com .google .firebase .firestore .testutil .TestUtil .map ;
26
+ import static com .google .firebase .firestore .testutil .TestUtil .patchMutation ;
26
27
import static com .google .firebase .firestore .testutil .TestUtil .query ;
27
28
import static com .google .firebase .firestore .testutil .TestUtil .setMutation ;
28
29
import static org .junit .Assert .assertEquals ;
@@ -46,7 +47,7 @@ Persistence getPersistence() {
46
47
}
47
48
48
49
@ Test
49
- public void combinesIndexedWithNonIndexedResults () throws Exception {
50
+ public void testCombinesIndexedWithNonIndexedResults () throws Exception {
50
51
MutableDocument doc1 = doc ("coll/a" , 1 , map ("foo" , true ));
51
52
MutableDocument doc2 = doc ("coll/b" , 2 , map ("foo" , true ));
52
53
MutableDocument doc3 = doc ("coll/c" , 3 , map ("foo" , true ));
@@ -70,7 +71,7 @@ public void combinesIndexedWithNonIndexedResults() throws Exception {
70
71
}
71
72
72
73
@ Test
73
- public void usesPartialIndexForLimitQueries () throws Exception {
74
+ public void testUsesPartialIndexForLimitQueries () throws Exception {
74
75
MutableDocument doc1 = doc ("coll/1" , 1 , map ("a" , 1 , "b" , 0 ));
75
76
MutableDocument doc2 = doc ("coll/2" , 1 , map ("a" , 1 , "b" , 1 ));
76
77
MutableDocument doc3 = doc ("coll/3" , 1 , map ("a" , 1 , "b" , 2 ));
@@ -87,4 +88,24 @@ public void usesPartialIndexForLimitQueries() throws Exception {
87
88
DocumentSet result = expectOptimizedCollectionScan (() -> runQuery (query , SnapshotVersion .NONE ));
88
89
assertEquals (docSet (query .comparator (), doc2 ), result );
89
90
}
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
+ }
90
111
}
0 commit comments