Skip to content

Commit 5e5808d

Browse files
committed
add mutation to local test
1 parent 17827f9 commit 5e5808d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
import static com.google.firebase.firestore.testutil.TestUtil.docMap;
55
import static com.google.firebase.firestore.testutil.TestUtil.filter;
66
import static com.google.firebase.firestore.testutil.TestUtil.map;
7+
import static com.google.firebase.firestore.testutil.TestUtil.patchMutation;
78
import static com.google.firebase.firestore.testutil.TestUtil.query;
89
import static org.junit.Assert.assertEquals;
910

1011
import com.google.android.gms.common.internal.Preconditions;
12+
import com.google.firebase.Timestamp;
1113
import com.google.firebase.database.collection.ImmutableSortedMap;
1214
import com.google.firebase.database.collection.ImmutableSortedSet;
1315
import com.google.firebase.firestore.auth.User;
@@ -18,6 +20,8 @@
1820
import com.google.firebase.firestore.model.DocumentSet;
1921
import com.google.firebase.firestore.model.FieldIndex;
2022
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;
2125
import java.util.ArrayList;
2226
import java.util.Arrays;
2327
import java.util.Collections;
@@ -99,6 +103,19 @@ protected void addDocument(MutableDocument... docs) {
99103
});
100104
}
101105

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+
102119
protected <T> T expectOptimizedCollectionScan(Callable<T> c) throws Exception {
103120
try {
104121
expectFullCollectionScan = false;
@@ -169,6 +186,18 @@ private void createTestingCollection(
169186
}
170187
}
171188

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+
172201
@Test
173202
public void testCombinesIndexedWithNonIndexedResults() throws Exception {
174203
// Every set contains 10 documents
@@ -192,6 +221,7 @@ public void testCombinesIndexedWithNonIndexedResults() throws Exception {
192221
Query query = query(basePath).filter(filter("match", "==", true));
193222
indexManager.createTargetIndices(query.toTarget());
194223
createTestingCollection(basePath, totalSetCount, portion, numOfFields);
224+
createMutationForCollection(basePath, totalSetCount);
195225

196226
QueryContext counterWithoutIndex = new QueryContext();
197227
long beforeAutoStart = System.nanoTime();

0 commit comments

Comments
 (0)