@@ -1073,31 +1073,49 @@ public void testUsesTargetMappingToExecuteQueries() {
1073
1073
1074
1074
@ Test
1075
1075
public void testLastLimboFreeSnapshotIsAdvancedDuringViewProcessing () {
1076
+ assumeFalse (garbageCollectorIsEager ());
1077
+ assumeTrue (queryEngine instanceof IndexFreeQueryEngine );
1078
+
1076
1079
// This test verifies that the `lastLimboFreeSnapshot` version for QueryData is advanced when
1077
1080
// we compute a limbo-free free view and that the mapping is persisted when we release a query.
1078
1081
1079
- Query query = Query .atPath (ResourcePath .fromString ("foo" ));
1082
+ writeMutation (setMutation ("foo/ignored" , map ("matches" , false )));
1083
+ acknowledgeMutation (10 );
1084
+
1085
+ Query query =
1086
+ Query .atPath (ResourcePath .fromString ("foo" )).filter (filter ("matches" , "==" , true ));
1080
1087
int targetId = allocateQuery (query );
1081
1088
1082
- // Advance the query snapshot.
1089
+ // Mark the query as current.
1090
+ applyRemoteEvent (
1091
+ addedRemoteEvent (
1092
+ asList (doc ("foo/a" , 10 , map ("matches" , true )), doc ("foo/b" , 10 , map ("matches" , true ))),
1093
+ asList (targetId ),
1094
+ emptyList ()));
1083
1095
applyRemoteEvent (noChangeEvent (targetId , 10 ));
1084
1096
1085
1097
// At this point, we have not yet confirmed that the query is limbo free.
1086
- QueryData cachedQueryData = localStore . getQueryData ( query );
1087
- Assert . assertEquals ( SnapshotVersion .NONE , cachedQueryData .getLastLimboFreeSnapshotVersion ());
1098
+ Assert . assertEquals (
1099
+ SnapshotVersion .NONE , localStore . getQueryData ( query ) .getLastLimboFreeSnapshotVersion ());
1088
1100
1089
- // Mark the view synced, which updates the last limbo free snapshot version.
1101
+ // Update the view, but don't mark the view synced.
1102
+ Assert .assertEquals (
1103
+ SnapshotVersion .NONE , localStore .getQueryData (query ).getLastLimboFreeSnapshotVersion ());
1090
1104
udpateViews (targetId , /* fromCache=*/ false );
1091
- cachedQueryData = localStore .getQueryData (query );
1092
- Assert .assertEquals (version (10 ), cachedQueryData .getLastLimboFreeSnapshotVersion ());
1105
+
1106
+ // The query is marked limbo-free only when we mark the view synced.
1107
+ udpateViews (targetId , /* fromCache=*/ false );
1108
+ Assert .assertNotEquals (
1109
+ SnapshotVersion .NONE , localStore .getQueryData (query ).getLastLimboFreeSnapshotVersion ());
1093
1110
1094
1111
// The last limbo free snapshot version is persisted even if we release the query.
1095
1112
releaseQuery (query );
1113
+ allocateQuery (query );
1096
1114
1097
- if (! garbageCollectorIsEager ()) {
1098
- cachedQueryData = localStore . getQueryData (query );
1099
- Assert . assertEquals ( version ( 10 ), cachedQueryData . getLastLimboFreeSnapshotVersion () );
1100
- }
1115
+ // Verify that we only read the two documents that match the query.
1116
+ executeQuery (query );
1117
+ assertRemoteDocumentsRead ( 2 );
1118
+ assertQueryReturned ( "foo/a" , "foo/b" );
1101
1119
}
1102
1120
1103
1121
@ Test
@@ -1112,26 +1130,28 @@ public void testQueriesIncludeLocallyModifiedDocuments() {
1112
1130
1113
1131
applyRemoteEvent (
1114
1132
addedRemoteEvent (
1115
- asList (doc ("foo/a" , 10 , map ("matches" , true ))), asList (targetId ), emptyList ()));
1133
+ asList (doc ("foo/a" , 10 , map ("matches" , true )), doc ("foo/b" , 10 , map ("matches" , true ))),
1134
+ asList (targetId ),
1135
+ emptyList ()));
1116
1136
applyRemoteEvent (noChangeEvent (targetId , 10 ));
1117
1137
udpateViews (targetId , /* fromCache= */ false );
1118
1138
1119
1139
// Execute the query based on the RemoteEvent.
1120
1140
executeQuery (query );
1121
- assertQueryReturned ("foo/a" );
1141
+ assertQueryReturned ("foo/a" , "foo/b" );
1122
1142
1123
1143
// Write a document.
1124
- writeMutation (setMutation ("foo/b " , map ("matches" , true )));
1144
+ writeMutation (setMutation ("foo/c " , map ("matches" , true )));
1125
1145
1126
1146
// Execute the query and make sure that the pending mutation is included in the result.
1127
1147
executeQuery (query );
1128
- assertQueryReturned ("foo/a" , "foo/b" );
1148
+ assertQueryReturned ("foo/a" , "foo/b" , "foo/c" );
1129
1149
1130
1150
acknowledgeMutation (11 );
1131
1151
1132
1152
// Execute the query and make sure that the acknowledged mutation is included in the result.
1133
1153
executeQuery (query );
1134
- assertQueryReturned ("foo/a" , "foo/b" );
1154
+ assertQueryReturned ("foo/a" , "foo/b" , "foo/c" );
1135
1155
}
1136
1156
1137
1157
@ Test
@@ -1147,17 +1167,23 @@ public void testQueriesIncludeDocumentsFromOtherQueries() {
1147
1167
1148
1168
applyRemoteEvent (
1149
1169
addedRemoteEvent (
1150
- asList (doc ("foo/a" , 10 , map ("matches" , true ))), asList (targetId ), emptyList ()));
1170
+ asList (doc ("foo/a" , 10 , map ("matches" , true )), doc ("foo/b" , 10 , map ("matches" , true ))),
1171
+ asList (targetId ),
1172
+ emptyList ()));
1151
1173
applyRemoteEvent (noChangeEvent (targetId , 10 ));
1152
1174
udpateViews (targetId , /* fromCache=*/ false );
1153
1175
releaseQuery (filteredQuery );
1154
1176
1155
1177
// Start another query and add more matching documents to the collection.
1156
- Query fullQuery = Query .atPath (ResourcePath .fromString ("foo" ));
1157
- targetId = allocateQuery (fullQuery );
1178
+ Query fullQuery =
1179
+ Query .atPath (ResourcePath .fromString ("foo" )).filter (filter ("matches" , "==" , true ));
1180
+ targetId = allocateQuery (filteredQuery );
1158
1181
applyRemoteEvent (
1159
1182
addedRemoteEvent (
1160
- asList (doc ("foo/a" , 10 , map ("matches" , true )), doc ("foo/b" , 20 , map ("matches" , true ))),
1183
+ asList (
1184
+ doc ("foo/a" , 10 , map ("matches" , true )),
1185
+ doc ("foo/b" , 10 , map ("matches" , true )),
1186
+ doc ("foo/c" , 20 , map ("matches" , true ))),
1161
1187
asList (targetId ),
1162
1188
emptyList ()));
1163
1189
releaseQuery (fullQuery );
@@ -1166,7 +1192,7 @@ public void testQueriesIncludeDocumentsFromOtherQueries() {
1166
1192
// matches are included in the result set.
1167
1193
allocateQuery (filteredQuery );
1168
1194
executeQuery (filteredQuery );
1169
- assertQueryReturned ("foo/a" , "foo/b" );
1195
+ assertQueryReturned ("foo/a" , "foo/b" , "foo/c" );
1170
1196
}
1171
1197
1172
1198
@ Test
@@ -1191,8 +1217,9 @@ public void testQueriesFilterDocumentsThatNoLongerMatch() {
1191
1217
releaseQuery (filteredQuery );
1192
1218
1193
1219
// Modify one of the documents to no longer match while the filtered query is inactive.
1194
- Query fullQuery = Query .atPath (ResourcePath .fromString ("foo" ));
1195
- targetId = allocateQuery (fullQuery );
1220
+ Query fullQuery =
1221
+ Query .atPath (ResourcePath .fromString ("foo" )).filter (filter ("matches" , "==" , true ));
1222
+ targetId = allocateQuery (filteredQuery );
1196
1223
applyRemoteEvent (
1197
1224
addedRemoteEvent (
1198
1225
asList (doc ("foo/a" , 10 , map ("matches" , true )), doc ("foo/b" , 20 , map ("matches" , false ))),
0 commit comments