35
35
36
36
import android .os .SystemClock ;
37
37
38
+ import androidx .annotation .Nullable ;
38
39
import androidx .test .ext .junit .runners .AndroidJUnit4 ;
39
40
import com .google .android .gms .tasks .Task ;
40
41
import com .google .common .collect .Lists ;
@@ -1090,7 +1091,13 @@ public void resumingAQueryShouldUseBloomFilterToAvoidFullRequery() throws Except
1090
1091
existenceFilterMismatchAccumulator .register ();
1091
1092
try {
1092
1093
snapshot2 = waitFor (collection .get ());
1093
- existenceFilterMismatchInfo = existenceFilterMismatchAccumulator .waitForExistenceFilterMismatch (/*timeoutMillis=*/ 5000 );
1094
+ // TODO(b/270731363): Remove the "if" condition below once the Firestore Emulator is fixed
1095
+ // to send an existence filter.
1096
+ if (isRunningAgainstEmulator ()) {
1097
+ existenceFilterMismatchInfo = null ;
1098
+ } else {
1099
+ existenceFilterMismatchInfo = existenceFilterMismatchAccumulator .waitForExistenceFilterMismatch (/*timeoutMillis=*/ 5000 );
1100
+ }
1094
1101
} finally {
1095
1102
existenceFilterMismatchAccumulator .unregister ();
1096
1103
}
@@ -1125,6 +1132,7 @@ public void resumingAQueryShouldUseBloomFilterToAvoidFullRequery() throws Except
1125
1132
1126
1133
// Verify that Watch sent an existence filter with the correct counts when the query was
1127
1134
// resumed.
1135
+ assertWithMessage ("Watch should have sent an existence filter" ).that (existenceFilterMismatchInfo ).isNotNull ();
1128
1136
assertWithMessage ("localCacheCount" ).that (existenceFilterMismatchInfo .localCacheCount ()).isEqualTo (100 );
1129
1137
assertWithMessage ("existenceFilterCount" ).that (existenceFilterMismatchInfo .existenceFilterCount ()).isEqualTo (50 );
1130
1138
}
@@ -1150,6 +1158,7 @@ void unregister() {
1150
1158
listenerRegistration = null ;
1151
1159
}
1152
1160
1161
+ @ Nullable
1153
1162
WatchChangeAggregatorTestingHooksAccessor .ExistenceFilterMismatchInfo waitForExistenceFilterMismatch (long timeoutMillis ) throws InterruptedException {
1154
1163
if (listenerRegistration == null ) {
1155
1164
throw new IllegalStateException ("must be registered before waiting for an existence filter mismatch" );
@@ -1163,36 +1172,31 @@ private final class ExistenceFilterMismatchListenerImpl implements WatchChangeAg
1163
1172
1164
1173
@ Override
1165
1174
public void onExistenceFilterMismatch (WatchChangeAggregatorTestingHooksAccessor .ExistenceFilterMismatchInfo info ) {
1166
- synchronized (existenceFilterMismatchesLock ) {
1175
+ synchronized (existenceFilterMismatches ) {
1167
1176
existenceFilterMismatches .add (info );
1168
- existenceFilterMismatchesLock .notifyAll ();
1177
+ existenceFilterMismatches .notifyAll ();
1169
1178
}
1170
1179
}
1171
1180
1181
+ @ Nullable
1172
1182
WatchChangeAggregatorTestingHooksAccessor .ExistenceFilterMismatchInfo waitForExistenceFilterMismatch (long timeoutMillis ) throws InterruptedException {
1173
1183
if (timeoutMillis <= 0 ) {
1174
1184
throw new IllegalArgumentException ("invalid timeout: " + timeoutMillis );
1175
1185
}
1176
- synchronized (existenceFilterMismatchesLock ) {
1186
+ synchronized (existenceFilterMismatches ) {
1177
1187
long endTimeMillis = SystemClock .uptimeMillis () + timeoutMillis ;
1178
1188
while (true ) {
1179
1189
if (existenceFilterMismatches .size () > 0 ) {
1180
1190
return existenceFilterMismatches .remove (0 );
1181
1191
}
1182
1192
long currentWaitMillis = endTimeMillis - SystemClock .uptimeMillis ();
1183
1193
if (currentWaitMillis <= 0 ) {
1184
- throw new WaitForExistenceFilterMismatchTimeoutException ( "timeout (" + timeoutMillis + "ms) waiting for an existence filter mismatch" ) ;
1194
+ return null ;
1185
1195
}
1186
- existenceFilterMismatchesLock .wait (currentWaitMillis );
1196
+ existenceFilterMismatches .wait (currentWaitMillis );
1187
1197
}
1188
1198
}
1189
1199
}
1190
-
1191
- final class WaitForExistenceFilterMismatchTimeoutException extends RuntimeException {
1192
- WaitForExistenceFilterMismatchTimeoutException (String message ) {
1193
- super (message );
1194
- }
1195
- }
1196
1200
}
1197
1201
1198
1202
}
0 commit comments