|
16 | 16 |
|
17 | 17 | import static com.google.common.truth.Truth.assertThat;
|
18 | 18 | import static com.google.firebase.firestore.testutil.TestUtil.addedRemoteEvent;
|
| 19 | +import static com.google.firebase.firestore.testutil.TestUtil.deletedDoc; |
19 | 20 | import static com.google.firebase.firestore.testutil.TestUtil.doc;
|
20 | 21 | import static com.google.firebase.firestore.testutil.TestUtil.fieldIndex;
|
21 | 22 | import static com.google.firebase.firestore.testutil.TestUtil.filter;
|
22 | 23 | import static com.google.firebase.firestore.testutil.TestUtil.map;
|
23 | 24 | import static com.google.firebase.firestore.testutil.TestUtil.noChangeEvent;
|
24 | 25 | import static com.google.firebase.firestore.testutil.TestUtil.query;
|
| 26 | +import static com.google.firebase.firestore.testutil.TestUtil.updateRemoteEvent; |
| 27 | +import static java.util.Collections.emptyList; |
25 | 28 | import static java.util.Collections.singletonList;
|
26 | 29 |
|
27 | 30 | import com.google.firebase.firestore.core.Query;
|
@@ -105,4 +108,30 @@ public void testUsesPartialIndexesWhenAvailable() {
|
105 | 108 | assertRemoteDocumentsRead(/* byKey= */ 1, /* byQuery= */ 1);
|
106 | 109 | assertQueryReturned("coll/a", "coll/b");
|
107 | 110 | }
|
| 111 | + |
| 112 | + @Test |
| 113 | + public void testDeletedDocumentRemovesIndex() { |
| 114 | + FieldIndex index = fieldIndex("coll", 0, FieldIndex.INITIAL_STATE, "matches", Kind.ASCENDING); |
| 115 | + configureFieldIndexes(singletonList(index)); |
| 116 | + |
| 117 | + Query query = query("coll").filter(filter("matches", "==", true)); |
| 118 | + int targetId = allocateQuery(query); |
| 119 | + |
| 120 | + applyRemoteEvent(addedRemoteEvent(doc("coll/a", 10, map("matches", true)), targetId)); |
| 121 | + |
| 122 | + // Add the document to the index |
| 123 | + backfillIndexes(); |
| 124 | + |
| 125 | + executeQuery(query); |
| 126 | + assertRemoteDocumentsRead(/* byKey= */ 1, /* byQuery= */ 0); |
| 127 | + assertQueryReturned("coll/a"); |
| 128 | + |
| 129 | + applyRemoteEvent( |
| 130 | + updateRemoteEvent(deletedDoc("coll/a", 0), singletonList(targetId), emptyList())); |
| 131 | + |
| 132 | + // No backfill needed for deleted document. |
| 133 | + executeQuery(query); |
| 134 | + assertRemoteDocumentsRead(/* byKey= */ 0, /* byQuery= */ 0); |
| 135 | + assertQueryReturned(); |
| 136 | + } |
108 | 137 | }
|
0 commit comments