|
21 | 21 | import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testCollectionWithDocs;
|
22 | 22 | import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testFirestore;
|
23 | 23 | import static com.google.firebase.firestore.testutil.IntegrationTestUtil.waitFor;
|
| 24 | +import static com.google.firebase.firestore.testutil.IntegrationTestUtil.writeAllDocs; |
24 | 25 | import static com.google.firebase.firestore.testutil.TestUtil.expectError;
|
25 | 26 | import static com.google.firebase.firestore.testutil.TestUtil.map;
|
| 27 | +import static com.google.firebase.firestore.util.Util.autoId; |
26 | 28 | import static java.util.Arrays.asList;
|
27 | 29 | import static java.util.Collections.singletonList;
|
28 | 30 | import static org.junit.Assert.assertEquals;
|
@@ -1029,6 +1031,46 @@ public void testMultipleUpdatesWhileOffline() {
|
1029 | 1031 | assertEquals(asList(map("foo", "zzyzx", "bar", "2")), querySnapshotToValues(snapshot2));
|
1030 | 1032 | }
|
1031 | 1033 |
|
| 1034 | + @Test |
| 1035 | + public void resumingQueryShouldRemoveDeletedDocumentsIndicatedByExistenceFilter() { |
| 1036 | + Map<String, Map<String, Object>> testDocs = new LinkedHashMap<>(); |
| 1037 | + for (int i = 1; i <= 100; i++) { |
| 1038 | + testDocs.put("doc" + i, map("key", i)); |
| 1039 | + } |
| 1040 | + |
| 1041 | + // Setup firestore with disabled persistence and populate a collection with testDocs. |
| 1042 | + FirebaseFirestore firestore = testFirestore(); |
| 1043 | + firestore.setFirestoreSettings( |
| 1044 | + new FirebaseFirestoreSettings.Builder().setPersistenceEnabled(false).build()); |
| 1045 | + CollectionReference collection = firestore.collection(autoId()); |
| 1046 | + writeAllDocs(collection, testDocs); |
| 1047 | + |
| 1048 | + QuerySnapshot snapshot1 = waitFor(collection.get()); |
| 1049 | + assertEquals(snapshot1.size(), 100); |
| 1050 | + |
| 1051 | + // Delete 50 docs in transaction so that it doesn't affect local cache. |
| 1052 | + waitFor( |
| 1053 | + firestore.runTransaction( |
| 1054 | + transaction -> { |
| 1055 | + for (int i = 1; i <= 50; i++) { |
| 1056 | + DocumentReference docRef = collection.document("doc" + i); |
| 1057 | + transaction.delete(docRef); |
| 1058 | + } |
| 1059 | + return null; |
| 1060 | + })); |
| 1061 | + |
| 1062 | + // Wait 10 seconds, during which Watch will stop tracking the query |
| 1063 | + // and will send an existence filter rather than "delete" events. |
| 1064 | + try { |
| 1065 | + Thread.sleep(10000); |
| 1066 | + } catch (InterruptedException ex) { |
| 1067 | + Thread.currentThread().interrupt(); |
| 1068 | + } |
| 1069 | + |
| 1070 | + QuerySnapshot snapshot2 = waitFor(collection.get()); |
| 1071 | + assertEquals(snapshot2.size(), 50); |
| 1072 | + } |
| 1073 | + |
1032 | 1074 | // TODO(orquery): Enable this test when prod supports OR queries.
|
1033 | 1075 | @Ignore
|
1034 | 1076 | @Test
|
|
0 commit comments