Skip to content

Commit d2536aa

Browse files
Add Test
1 parent f4212b0 commit d2536aa

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616

1717
import static com.google.common.truth.Truth.assertThat;
1818
import static com.google.firebase.firestore.testutil.TestUtil.addedRemoteEvent;
19+
import static com.google.firebase.firestore.testutil.TestUtil.deletedDoc;
1920
import static com.google.firebase.firestore.testutil.TestUtil.doc;
2021
import static com.google.firebase.firestore.testutil.TestUtil.fieldIndex;
2122
import static com.google.firebase.firestore.testutil.TestUtil.filter;
2223
import static com.google.firebase.firestore.testutil.TestUtil.map;
2324
import static com.google.firebase.firestore.testutil.TestUtil.noChangeEvent;
2425
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;
2528
import static java.util.Collections.singletonList;
2629

2730
import com.google.firebase.firestore.core.Query;
@@ -105,4 +108,30 @@ public void testUsesPartialIndexesWhenAvailable() {
105108
assertRemoteDocumentsRead(/* byKey= */ 1, /* byQuery= */ 1);
106109
assertQueryReturned("coll/a", "coll/b");
107110
}
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+
}
108137
}

0 commit comments

Comments
 (0)