@@ -1048,7 +1048,10 @@ public void resumingAQueryShouldUseBloomFilterToAvoidFullRequery() throws Except
1048
1048
1049
1049
// Each iteration of the "while" loop below runs a single iteration of the test. The test will
1050
1050
// be run multiple times only if a bloom filter false positive occurs.
1051
+ int attemptNumber = 0 ;
1051
1052
while (true ) {
1053
+ attemptNumber ++;
1054
+
1052
1055
// Create 100 documents in a new collection.
1053
1056
CollectionReference collection = testCollectionWithDocs (testData );
1054
1057
@@ -1135,6 +1138,33 @@ public void resumingAQueryShouldUseBloomFilterToAvoidFullRequery() throws Except
1135
1138
assertWithMessage ("Watch should have sent an existence filter" ).that (existenceFilterMismatchInfo ).isNotNull ();
1136
1139
assertWithMessage ("localCacheCount" ).that (existenceFilterMismatchInfo .localCacheCount ()).isEqualTo (100 );
1137
1140
assertWithMessage ("existenceFilterCount" ).that (existenceFilterMismatchInfo .existenceFilterCount ()).isEqualTo (50 );
1141
+
1142
+ // Skip the verification of the bloom filter when testing against production because the bloom
1143
+ // filter is only implemented in nightly.
1144
+ // TODO(b/271949433) Remove this "if" block once the bloom filter logic is deployed to
1145
+ // production.
1146
+ if (IntegrationTestUtil .getTargetBackend () != IntegrationTestUtil .TargetBackend .NIGHTLY ) {
1147
+ return ;
1148
+ }
1149
+
1150
+ // Verify that Watch sent a valid bloom filter.
1151
+ WatchChangeAggregatorTestingHooksAccessor .ExistenceFilterBloomFilterInfo bloomFilter = existenceFilterMismatchInfo .bloomFilter ();
1152
+ assertWithMessage ("The bloom filter specified in the existence filter" ).that (bloomFilter ).isNotNull ();
1153
+ assertWithMessage ("hashCount" ).that (bloomFilter .hashCount ()).isGreaterThan (0 );
1154
+ assertWithMessage ("bitmapLength" ).that (bloomFilter .bitmapLength ()).isGreaterThan (0 );
1155
+ assertWithMessage ("padding" ).that (bloomFilter .padding ()).isGreaterThan (0 );
1156
+ assertWithMessage ("padding" ).that (bloomFilter .padding ()).isLessThan (8 );
1157
+
1158
+ // Verify that the bloom filter was successfully used to avert a full requery. If a false
1159
+ // positive occurred then retry the entire test. Although statistically rare, false positives
1160
+ // are expected to happen occasionally. When a false positive _does_ happen, just retry the
1161
+ // test with a different set of documents. If that retry _also_ experiences a false positive,
1162
+ // then fail the test because that is so improbable that something must have gone wrong.
1163
+ if (attemptNumber == 1 && ! bloomFilter .applied ()) {
1164
+ continue ;
1165
+ }
1166
+
1167
+ assertWithMessage ("bloom filter successfully applied with attemptNumber=" + attemptNumber ).that (bloomFilter .applied ()).isTrue ();
1138
1168
}
1139
1169
}
1140
1170
0 commit comments