|
39 | 39 | import com.google.firebase.firestore.testutil.EventAccumulator;
|
40 | 40 | import com.google.firebase.firestore.testutil.IntegrationTestUtil;
|
41 | 41 | import java.util.ArrayList;
|
| 42 | +import java.util.HashMap; |
42 | 43 | import java.util.LinkedHashMap;
|
43 | 44 | import java.util.List;
|
44 | 45 | import java.util.Map;
|
@@ -1032,40 +1033,39 @@ public void testMultipleUpdatesWhileOffline() {
|
1032 | 1033 | }
|
1033 | 1034 |
|
1034 | 1035 | @Test
|
1035 |
| - public void resumingQueryShouldRemoveDeletedDocumentsIndicatedByExistenceFilter() { |
1036 |
| - Map<String, Map<String, Object>> testDocs = new LinkedHashMap<>(); |
| 1036 | + public void resumingQueryShouldRemoveDeletedDocumentsIndicatedByExistenceFilter() |
| 1037 | + throws InterruptedException { |
| 1038 | + Map<String, Map<String, Object>> testData = new HashMap<>(); |
1037 | 1039 | for (int i = 1; i <= 100; i++) {
|
1038 |
| - testDocs.put("doc" + i, map("key", i)); |
| 1040 | + testData.put("doc" + i, map("key", i)); |
1039 | 1041 | }
|
1040 | 1042 |
|
1041 | 1043 | // Setup firestore with disabled persistence and populate a collection with testDocs.
|
1042 | 1044 | FirebaseFirestore firestore = testFirestore();
|
1043 | 1045 | firestore.setFirestoreSettings(
|
1044 | 1046 | new FirebaseFirestoreSettings.Builder().setPersistenceEnabled(false).build());
|
1045 | 1047 | CollectionReference collection = firestore.collection(autoId());
|
1046 |
| - writeAllDocs(collection, testDocs); |
| 1048 | + writeAllDocs(collection, testData); |
1047 | 1049 |
|
| 1050 | + // Populate the cache and save the resume token. |
1048 | 1051 | QuerySnapshot snapshot1 = waitFor(collection.get());
|
1049 | 1052 | assertEquals(snapshot1.size(), 100);
|
| 1053 | + List<DocumentSnapshot> documents = snapshot1.getDocuments(); |
1050 | 1054 |
|
1051 | 1055 | // Delete 50 docs in transaction so that it doesn't affect local cache.
|
1052 | 1056 | waitFor(
|
1053 | 1057 | firestore.runTransaction(
|
1054 | 1058 | transaction -> {
|
1055 | 1059 | for (int i = 1; i <= 50; i++) {
|
1056 |
| - DocumentReference docRef = collection.document("doc" + i); |
| 1060 | + DocumentReference docRef = documents.get(i).getReference(); |
1057 | 1061 | transaction.delete(docRef);
|
1058 | 1062 | }
|
1059 | 1063 | return null;
|
1060 | 1064 | }));
|
1061 | 1065 |
|
1062 | 1066 | // Wait 10 seconds, during which Watch will stop tracking the query
|
1063 | 1067 | // 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 |
| - } |
| 1068 | + Thread.sleep(10000); |
1069 | 1069 |
|
1070 | 1070 | QuerySnapshot snapshot2 = waitFor(collection.get());
|
1071 | 1071 | assertEquals(snapshot2.size(), 50);
|
|
0 commit comments