Skip to content

Commit a011927

Browse files
Simplify IndexFree tests (#790)
1 parent 8a7b33c commit a011927

File tree

2 files changed

+26
-51
lines changed

2 files changed

+26
-51
lines changed

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

Lines changed: 23 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,49 +1073,31 @@ public void testUsesTargetMappingToExecuteQueries() {
10731073

10741074
@Test
10751075
public void testLastLimboFreeSnapshotIsAdvancedDuringViewProcessing() {
1076-
assumeFalse(garbageCollectorIsEager());
1077-
assumeTrue(queryEngine instanceof IndexFreeQueryEngine);
1078-
10791076
// This test verifies that the `lastLimboFreeSnapshot` version for QueryData is advanced when
10801077
// we compute a limbo-free free view and that the mapping is persisted when we release a query.
10811078

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));
1079+
Query query = Query.atPath(ResourcePath.fromString("foo"));
10871080
int targetId = allocateQuery(query);
10881081

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()));
1082+
// Advance the query snapshot.
10951083
applyRemoteEvent(noChangeEvent(targetId, 10));
10961084

10971085
// At this point, we have not yet confirmed that the query is limbo free.
1098-
Assert.assertEquals(
1099-
SnapshotVersion.NONE, localStore.getQueryData(query).getLastLimboFreeSnapshotVersion());
1086+
QueryData cachedQueryData = localStore.getQueryData(query);
1087+
Assert.assertEquals(SnapshotVersion.NONE, cachedQueryData.getLastLimboFreeSnapshotVersion());
11001088

1101-
// Update the view, but don't mark the view synced.
1102-
Assert.assertEquals(
1103-
SnapshotVersion.NONE, localStore.getQueryData(query).getLastLimboFreeSnapshotVersion());
1089+
// Mark the view synced, which updates the last limbo free snapshot version.
11041090
udpateViews(targetId, /* fromCache=*/ false);
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());
1091+
cachedQueryData = localStore.getQueryData(query);
1092+
Assert.assertEquals(version(10), cachedQueryData.getLastLimboFreeSnapshotVersion());
11101093

11111094
// The last limbo free snapshot version is persisted even if we release the query.
11121095
releaseQuery(query);
1113-
allocateQuery(query);
11141096

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");
1097+
if (!garbageCollectorIsEager()) {
1098+
cachedQueryData = localStore.getQueryData(query);
1099+
Assert.assertEquals(version(10), cachedQueryData.getLastLimboFreeSnapshotVersion());
1100+
}
11191101
}
11201102

11211103
@Test
@@ -1130,28 +1112,26 @@ public void testQueriesIncludeLocallyModifiedDocuments() {
11301112

11311113
applyRemoteEvent(
11321114
addedRemoteEvent(
1133-
asList(doc("foo/a", 10, map("matches", true)), doc("foo/b", 10, map("matches", true))),
1134-
asList(targetId),
1135-
emptyList()));
1115+
asList(doc("foo/a", 10, map("matches", true))), asList(targetId), emptyList()));
11361116
applyRemoteEvent(noChangeEvent(targetId, 10));
11371117
udpateViews(targetId, /* fromCache= */ false);
11381118

11391119
// Execute the query based on the RemoteEvent.
11401120
executeQuery(query);
1141-
assertQueryReturned("foo/a", "foo/b");
1121+
assertQueryReturned("foo/a");
11421122

11431123
// Write a document.
1144-
writeMutation(setMutation("foo/c", map("matches", true)));
1124+
writeMutation(setMutation("foo/b", map("matches", true)));
11451125

11461126
// Execute the query and make sure that the pending mutation is included in the result.
11471127
executeQuery(query);
1148-
assertQueryReturned("foo/a", "foo/b", "foo/c");
1128+
assertQueryReturned("foo/a", "foo/b");
11491129

11501130
acknowledgeMutation(11);
11511131

11521132
// Execute the query and make sure that the acknowledged mutation is included in the result.
11531133
executeQuery(query);
1154-
assertQueryReturned("foo/a", "foo/b", "foo/c");
1134+
assertQueryReturned("foo/a", "foo/b");
11551135
}
11561136

11571137
@Test
@@ -1167,23 +1147,17 @@ public void testQueriesIncludeDocumentsFromOtherQueries() {
11671147

11681148
applyRemoteEvent(
11691149
addedRemoteEvent(
1170-
asList(doc("foo/a", 10, map("matches", true)), doc("foo/b", 10, map("matches", true))),
1171-
asList(targetId),
1172-
emptyList()));
1150+
asList(doc("foo/a", 10, map("matches", true))), asList(targetId), emptyList()));
11731151
applyRemoteEvent(noChangeEvent(targetId, 10));
11741152
udpateViews(targetId, /* fromCache=*/ false);
11751153
releaseQuery(filteredQuery);
11761154

11771155
// Start another query and add more matching documents to the collection.
1178-
Query fullQuery =
1179-
Query.atPath(ResourcePath.fromString("foo")).filter(filter("matches", "==", true));
1180-
targetId = allocateQuery(filteredQuery);
1156+
Query fullQuery = Query.atPath(ResourcePath.fromString("foo"));
1157+
targetId = allocateQuery(fullQuery);
11811158
applyRemoteEvent(
11821159
addedRemoteEvent(
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))),
1160+
asList(doc("foo/a", 10, map("matches", true)), doc("foo/b", 20, map("matches", true))),
11871161
asList(targetId),
11881162
emptyList()));
11891163
releaseQuery(fullQuery);
@@ -1192,7 +1166,7 @@ public void testQueriesIncludeDocumentsFromOtherQueries() {
11921166
// matches are included in the result set.
11931167
allocateQuery(filteredQuery);
11941168
executeQuery(filteredQuery);
1195-
assertQueryReturned("foo/a", "foo/b", "foo/c");
1169+
assertQueryReturned("foo/a", "foo/b");
11961170
}
11971171

11981172
@Test
@@ -1217,9 +1191,8 @@ public void testQueriesFilterDocumentsThatNoLongerMatch() {
12171191
releaseQuery(filteredQuery);
12181192

12191193
// Modify one of the documents to no longer match while the filtered query is inactive.
1220-
Query fullQuery =
1221-
Query.atPath(ResourcePath.fromString("foo")).filter(filter("matches", "==", true));
1222-
targetId = allocateQuery(filteredQuery);
1194+
Query fullQuery = Query.atPath(ResourcePath.fromString("foo"));
1195+
targetId = allocateQuery(fullQuery);
12231196
applyRemoteEvent(
12241197
addedRemoteEvent(
12251198
asList(doc("foo/a", 10, map("matches", true)), doc("foo/b", 20, map("matches", false))),

firebase-firestore/src/testUtil/java/com/google/firebase/firestore/testutil/TestUtil.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,13 +418,15 @@ public QueryData getQueryDataForTarget(int targetId) {
418418
}
419419
});
420420

421+
SnapshotVersion version = SnapshotVersion.NONE;
422+
421423
for (MaybeDocument doc : docs) {
422424
DocumentChange change =
423425
new DocumentChange(updatedInTargets, removedFromTargets, doc.getKey(), doc);
424426
aggregator.handleDocumentChange(change);
427+
version = doc.getVersion().compareTo(version) > 0 ? doc.getVersion() : version;
425428
}
426429

427-
SnapshotVersion version = docs.get(0).getVersion();
428430
return aggregator.createRemoteEvent(version);
429431
}
430432

0 commit comments

Comments
 (0)