4
4
import static com .google .firebase .firestore .testutil .TestUtil .docMap ;
5
5
import static com .google .firebase .firestore .testutil .TestUtil .filter ;
6
6
import static com .google .firebase .firestore .testutil .TestUtil .map ;
7
+ import static com .google .firebase .firestore .testutil .TestUtil .patchMutation ;
7
8
import static com .google .firebase .firestore .testutil .TestUtil .query ;
8
9
import static org .junit .Assert .assertEquals ;
9
10
10
11
import com .google .android .gms .common .internal .Preconditions ;
12
+ import com .google .firebase .Timestamp ;
11
13
import com .google .firebase .database .collection .ImmutableSortedMap ;
12
14
import com .google .firebase .database .collection .ImmutableSortedSet ;
13
15
import com .google .firebase .firestore .auth .User ;
18
20
import com .google .firebase .firestore .model .DocumentSet ;
19
21
import com .google .firebase .firestore .model .FieldIndex ;
20
22
import com .google .firebase .firestore .model .MutableDocument ;
23
+ import com .google .firebase .firestore .model .mutation .Mutation ;
24
+ import com .google .firebase .firestore .model .mutation .MutationBatch ;
21
25
import java .util .ArrayList ;
22
26
import java .util .Arrays ;
23
27
import java .util .Collections ;
@@ -99,6 +103,19 @@ protected void addDocument(MutableDocument... docs) {
99
103
});
100
104
}
101
105
106
+ protected void addMutation (Mutation mutation ) {
107
+ persistence .runTransaction (
108
+ "addMutation" ,
109
+ () -> {
110
+ MutationBatch batch =
111
+ mutationQueue .addMutationBatch (
112
+ Timestamp .now (), Collections .emptyList (), Collections .singletonList (mutation ));
113
+ Map <DocumentKey , Mutation > overlayMap =
114
+ Collections .singletonMap (mutation .getKey (), mutation );
115
+ documentOverlayCache .saveOverlays (batch .getBatchId (), overlayMap );
116
+ });
117
+ }
118
+
102
119
protected <T > T expectOptimizedCollectionScan (Callable <T > c ) throws Exception {
103
120
try {
104
121
expectFullCollectionScan = false ;
@@ -169,6 +186,18 @@ private void createTestingCollection(
169
186
}
170
187
}
171
188
189
+ private void createMutationForCollection (String basePath , int totalSetCount ) {
190
+ ArrayList <Integer > indexes = new ArrayList <>();
191
+ for (int index = 0 ; index < totalSetCount * 10 ; index ++) {
192
+ indexes .add (index );
193
+ }
194
+ Collections .shuffle (indexes );
195
+
196
+ for (int i = 0 ; i < totalSetCount ; i ++) {
197
+ addMutation (patchMutation (basePath + "/" + indexes .get (i ), map ("a" , 5 )));
198
+ }
199
+ }
200
+
172
201
@ Test
173
202
public void testCombinesIndexedWithNonIndexedResults () throws Exception {
174
203
// Every set contains 10 documents
@@ -192,6 +221,7 @@ public void testCombinesIndexedWithNonIndexedResults() throws Exception {
192
221
Query query = query (basePath ).filter (filter ("match" , "==" , true ));
193
222
indexManager .createTargetIndices (query .toTarget ());
194
223
createTestingCollection (basePath , totalSetCount , portion , numOfFields );
224
+ createMutationForCollection (basePath , totalSetCount );
195
225
196
226
QueryContext counterWithoutIndex = new QueryContext ();
197
227
long beforeAutoStart = System .nanoTime ();
0 commit comments