|
15 | 15 | package com.google.firebase.firestore;
|
16 | 16 |
|
17 | 17 | import static com.google.common.truth.Truth.assertWithMessage;
|
| 18 | +import static com.google.firebase.firestore.remote.TestingHooksUtil.captureExistenceFilterMismatches; |
18 | 19 | import static com.google.firebase.firestore.testutil.IntegrationTestUtil.isRunningAgainstEmulator;
|
19 | 20 | import static com.google.firebase.firestore.testutil.IntegrationTestUtil.nullList;
|
20 | 21 | import static com.google.firebase.firestore.testutil.IntegrationTestUtil.querySnapshotToIds;
|
|
37 | 38 | import com.google.android.gms.tasks.Task;
|
38 | 39 | import com.google.common.collect.Lists;
|
39 | 40 | import com.google.firebase.firestore.Query.Direction;
|
40 |
| -import com.google.firebase.firestore.remote.ExistenceFilterMismatchListener; |
| 41 | +import com.google.firebase.firestore.remote.TestingHooksUtil.ExistenceFilterMismatchInfo; |
41 | 42 | import com.google.firebase.firestore.testutil.EventAccumulator;
|
42 | 43 | import com.google.firebase.firestore.testutil.IntegrationTestUtil;
|
43 | 44 | import java.util.ArrayList;
|
|
47 | 48 | import java.util.List;
|
48 | 49 | import java.util.Map;
|
49 | 50 | import java.util.concurrent.Semaphore;
|
| 51 | +import java.util.concurrent.atomic.AtomicReference; |
50 | 52 | import org.junit.After;
|
51 | 53 | import org.junit.Test;
|
52 | 54 | import org.junit.runner.RunWith;
|
@@ -1079,25 +1081,14 @@ public void resumingAQueryShouldUseExistenceFilterToDetectDeletes() throws Excep
|
1079 | 1081 |
|
1080 | 1082 | // Resume the query and save the resulting snapshot for verification. Use some internal testing
|
1081 | 1083 | // hooks to "capture" the existence filter mismatches to verify them.
|
1082 |
| - ExistenceFilterMismatchListener existenceFilterMismatchListener = |
1083 |
| - new ExistenceFilterMismatchListener(); |
1084 |
| - QuerySnapshot snapshot2; |
1085 |
| - ExistenceFilterMismatchListener.ExistenceFilterMismatchInfo existenceFilterMismatchInfo; |
1086 |
| - try { |
1087 |
| - existenceFilterMismatchListener.startListening(); |
1088 |
| - snapshot2 = waitFor(collection.get()); |
1089 |
| - // TODO(b/270731363): Remove the "if" condition below once the Firestore Emulator is fixed |
1090 |
| - // to send an existence filter. |
1091 |
| - if (isRunningAgainstEmulator()) { |
1092 |
| - existenceFilterMismatchInfo = null; |
1093 |
| - } else { |
1094 |
| - existenceFilterMismatchInfo = |
1095 |
| - existenceFilterMismatchListener.getOrWaitForExistenceFilterMismatch( |
1096 |
| - /*timeoutMillis=*/ 5000); |
1097 |
| - } |
1098 |
| - } finally { |
1099 |
| - existenceFilterMismatchListener.stopListening(); |
1100 |
| - } |
| 1084 | + AtomicReference<QuerySnapshot> snapshot2Ref = new AtomicReference<>(); |
| 1085 | + ArrayList<ExistenceFilterMismatchInfo> existenceFilterMismatches = |
| 1086 | + captureExistenceFilterMismatches( |
| 1087 | + () -> { |
| 1088 | + QuerySnapshot querySnapshot = waitFor(collection.get()); |
| 1089 | + snapshot2Ref.set(querySnapshot); |
| 1090 | + }); |
| 1091 | + QuerySnapshot snapshot2 = snapshot2Ref.get(); |
1101 | 1092 |
|
1102 | 1093 | // Verify that the snapshot from the resumed query contains the expected documents; that is,
|
1103 | 1094 | // that it contains the 50 documents that were _not_ deleted.
|
@@ -1131,9 +1122,10 @@ public void resumingAQueryShouldUseExistenceFilterToDetectDeletes() throws Excep
|
1131 | 1122 |
|
1132 | 1123 | // Verify that Watch sent an existence filter with the correct counts when the query was
|
1133 | 1124 | // resumed.
|
1134 |
| - assertWithMessage("Watch should have sent an existence filter") |
1135 |
| - .that(existenceFilterMismatchInfo) |
1136 |
| - .isNotNull(); |
| 1125 | + assertWithMessage("Watch should have sent exactly 1 existence filter") |
| 1126 | + .that(existenceFilterMismatches) |
| 1127 | + .hasSize(1); |
| 1128 | + ExistenceFilterMismatchInfo existenceFilterMismatchInfo = existenceFilterMismatches.get(0); |
1137 | 1129 | assertWithMessage("localCacheCount")
|
1138 | 1130 | .that(existenceFilterMismatchInfo.localCacheCount())
|
1139 | 1131 | .isEqualTo(100);
|
|
0 commit comments