|
21 | 21 | import static com.google.firebase.firestore.testutil.TestUtil.deletedDoc;
|
22 | 22 | import static com.google.firebase.firestore.testutil.TestUtil.doc;
|
23 | 23 | import static com.google.firebase.firestore.testutil.TestUtil.docMap;
|
| 24 | +import static com.google.firebase.firestore.testutil.TestUtil.existenceFilterEvent; |
24 | 25 | import static com.google.firebase.firestore.testutil.TestUtil.filter;
|
25 | 26 | import static com.google.firebase.firestore.testutil.TestUtil.key;
|
26 | 27 | import static com.google.firebase.firestore.testutil.TestUtil.keySet;
|
|
75 | 76 | import com.google.firebase.firestore.remote.WriteStream;
|
76 | 77 | import com.google.firebase.firestore.testutil.TestUtil;
|
77 | 78 | import com.google.firebase.firestore.util.AsyncQueue;
|
| 79 | +import com.google.protobuf.ByteString; |
78 | 80 | import java.util.ArrayList;
|
79 | 81 | import java.util.Arrays;
|
80 | 82 | import java.util.Collection;
|
@@ -1123,6 +1125,38 @@ public void testUsesTargetMappingToExecuteQueries() {
|
1123 | 1125 | assertQueryReturned("foo/a", "foo/b");
|
1124 | 1126 | }
|
1125 | 1127 |
|
| 1128 | + @Test |
| 1129 | + public void testIgnoresTargetMappingAfterExistenceFilterMismatch() { |
| 1130 | + assumeFalse(garbageCollectorIsEager()); |
| 1131 | + |
| 1132 | + Query query = query("foo").filter(filter("matches", "==", true)); |
| 1133 | + int targetId = allocateQuery(query); |
| 1134 | + |
| 1135 | + executeQuery(query); |
| 1136 | + |
| 1137 | + // Persist a mapping with a single document |
| 1138 | + applyRemoteEvent( |
| 1139 | + addedRemoteEvent( |
| 1140 | + asList(doc("foo/a", 10, map("matches", true))), asList(targetId), emptyList())); |
| 1141 | + applyRemoteEvent(noChangeEvent(targetId, 10)); |
| 1142 | + updateViews(targetId, /* fromCache= */ false); |
| 1143 | + |
| 1144 | + TargetData cachedTargetData = localStore.getTargetData(query.toTarget()); |
| 1145 | + Assert.assertEquals(version(10), cachedTargetData.getLastLimboFreeSnapshotVersion()); |
| 1146 | + |
| 1147 | + // Create an existence filter mismatch and verify that the last limbo free snapshot version |
| 1148 | + // is deleted |
| 1149 | + applyRemoteEvent(existenceFilterEvent(targetId, 2, 20)); |
| 1150 | + cachedTargetData = localStore.getTargetData(query.toTarget()); |
| 1151 | + Assert.assertEquals(version(0), cachedTargetData.getLastLimboFreeSnapshotVersion()); |
| 1152 | + Assert.assertEquals(ByteString.EMPTY, cachedTargetData.getResumeToken()); |
| 1153 | + |
| 1154 | + // Re-run the query as a collection scan |
| 1155 | + executeQuery(query); |
| 1156 | + assertRemoteDocumentsRead(/* byKey= */ 0, /* byCollection= */ 1); |
| 1157 | + assertQueryReturned("foo/a"); |
| 1158 | + } |
| 1159 | + |
1126 | 1160 | @Test
|
1127 | 1161 | public void testLastLimboFreeSnapshotIsAdvancedDuringViewProcessing() {
|
1128 | 1162 | // This test verifies that the `lastLimboFreeSnapshot` version for TargetData is advanced when
|
|
0 commit comments