|
14 | 14 |
|
15 | 15 | package com.google.firebase.firestore;
|
16 | 16 |
|
| 17 | +import static com.google.firebase.firestore.testutil.IntegrationTestUtil.isRunningAgainstEmulator; |
17 | 18 | import static com.google.firebase.firestore.testutil.IntegrationTestUtil.nullList;
|
18 | 19 | import static com.google.firebase.firestore.testutil.IntegrationTestUtil.querySnapshotToIds;
|
19 | 20 | import static com.google.firebase.firestore.testutil.IntegrationTestUtil.querySnapshotToValues;
|
|
29 | 30 | import static org.junit.Assert.assertFalse;
|
30 | 31 | import static org.junit.Assert.assertNull;
|
31 | 32 | import static org.junit.Assert.assertTrue;
|
| 33 | +import static org.junit.Assume.assumeFalse; |
32 | 34 |
|
33 | 35 | import androidx.test.ext.junit.runners.AndroidJUnit4;
|
34 | 36 | import com.google.android.gms.tasks.Task;
|
|
37 | 39 | import com.google.firebase.firestore.testutil.EventAccumulator;
|
38 | 40 | import com.google.firebase.firestore.testutil.IntegrationTestUtil;
|
39 | 41 | import java.util.ArrayList;
|
| 42 | +import java.util.HashMap; |
40 | 43 | import java.util.LinkedHashMap;
|
41 | 44 | import java.util.List;
|
42 | 45 | import java.util.Map;
|
@@ -1029,6 +1032,46 @@ public void testMultipleUpdatesWhileOffline() {
|
1029 | 1032 | assertEquals(asList(map("foo", "zzyzx", "bar", "2")), querySnapshotToValues(snapshot2));
|
1030 | 1033 | }
|
1031 | 1034 |
|
| 1035 | + @Test |
| 1036 | + public void resumingQueryShouldRemoveDeletedDocumentsIndicatedByExistenceFilter() |
| 1037 | + throws InterruptedException { |
| 1038 | + assumeFalse( |
| 1039 | + "Skip this test when running against the Firestore emulator as there is a bug related to " |
| 1040 | + + "sending existence filter in response: b/270731363.", |
| 1041 | + isRunningAgainstEmulator()); |
| 1042 | + |
| 1043 | + Map<String, Map<String, Object>> testData = new HashMap<>(); |
| 1044 | + for (int i = 1; i <= 100; i++) { |
| 1045 | + testData.put("doc" + i, map("key", i)); |
| 1046 | + } |
| 1047 | + CollectionReference collection = testCollectionWithDocs(testData); |
| 1048 | + |
| 1049 | + // Populate the cache and save the resume token. |
| 1050 | + QuerySnapshot snapshot1 = waitFor(collection.get()); |
| 1051 | + assertEquals(snapshot1.size(), 100); |
| 1052 | + List<DocumentSnapshot> documents = snapshot1.getDocuments(); |
| 1053 | + |
| 1054 | + // Delete 50 docs in transaction so that it doesn't affect local cache. |
| 1055 | + waitFor( |
| 1056 | + collection |
| 1057 | + .getFirestore() |
| 1058 | + .runTransaction( |
| 1059 | + transaction -> { |
| 1060 | + for (int i = 1; i <= 50; i++) { |
| 1061 | + DocumentReference docRef = documents.get(i).getReference(); |
| 1062 | + transaction.delete(docRef); |
| 1063 | + } |
| 1064 | + return null; |
| 1065 | + })); |
| 1066 | + |
| 1067 | + // Wait 10 seconds, during which Watch will stop tracking the query |
| 1068 | + // and will send an existence filter rather than "delete" events. |
| 1069 | + Thread.sleep(10000); |
| 1070 | + |
| 1071 | + QuerySnapshot snapshot2 = waitFor(collection.get()); |
| 1072 | + assertEquals(snapshot2.size(), 50); |
| 1073 | + } |
| 1074 | + |
1032 | 1075 | // TODO(orquery): Enable this test when prod supports OR queries.
|
1033 | 1076 | @Ignore
|
1034 | 1077 | @Test
|
|
0 commit comments