Skip to content

Commit 9471221

Browse files
authored
Firestore: QueryTest.java: Use a WriteBatch to delete documents rather than a transaction (#5167)
1 parent 392da5f commit 9471221

File tree

1 file changed

+18
-28
lines changed
  • firebase-firestore/src/androidTest/java/com/google/firebase/firestore

1 file changed

+18
-28
lines changed

firebase-firestore/src/androidTest/java/com/google/firebase/firestore/QueryTest.java

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,21 +1068,18 @@ public void resumingAQueryShouldUseBloomFilterToAvoidFullRequery() throws Except
10681068
}
10691069
assertWithMessage("createdDocuments").that(createdDocuments).hasSize(100);
10701070

1071-
// Delete 50 of the 100 documents. Do this in a transaction, rather than
1072-
// DocumentReference.delete(), to avoid affecting the local cache.
1071+
// Delete 50 of the 100 documents. Use a WriteBatch, rather than DocumentReference.delete(),
1072+
// to avoid affecting the local cache.
10731073
HashSet<String> deletedDocumentIds = new HashSet<>();
1074-
waitFor(
1075-
collection
1076-
.getFirestore()
1077-
.runTransaction(
1078-
transaction -> {
1079-
for (int i = 0; i < createdDocuments.size(); i += 2) {
1080-
DocumentReference documentToDelete = createdDocuments.get(i);
1081-
transaction.delete(documentToDelete);
1082-
deletedDocumentIds.add(documentToDelete.getId());
1083-
}
1084-
return null;
1085-
}));
1074+
{
1075+
WriteBatch writeBatchForDocumentDeletes = collection.getFirestore().batch();
1076+
for (int i = 0; i < createdDocuments.size(); i += 2) {
1077+
DocumentReference documentToDelete = createdDocuments.get(i);
1078+
writeBatchForDocumentDeletes.delete(documentToDelete);
1079+
deletedDocumentIds.add(documentToDelete.getId());
1080+
}
1081+
waitFor(writeBatchForDocumentDeletes.commit());
1082+
}
10861083
assertWithMessage("deletedDocumentIds").that(deletedDocumentIds).hasSize(50);
10871084

10881085
// Wait for 10 seconds, during which Watch will stop tracking the query and will send an
@@ -1240,22 +1237,15 @@ public void bloomFilterShouldCorrectlyEncodeComplexUnicodeCharacters() throws Ex
12401237
.containsExactlyElementsIn(testDocIds);
12411238
}
12421239

1243-
// Delete one of the documents so that the next call to getDocs() will experience an existence
1244-
// filter mismatch. Do this deletion in a transaction, rather than using deleteDoc(), to avoid
1240+
// Delete one of the documents so that the next call to collection.get() will experience an
1241+
// existence filter mismatch. Use a WriteBatch, rather than DocumentReference.delete(), to avoid
12451242
// affecting the local cache.
12461243
DocumentReference documentToDelete = collection.document("DocumentToDelete");
1247-
waitFor(
1248-
collection
1249-
.getFirestore()
1250-
.runTransaction(
1251-
transaction -> {
1252-
DocumentSnapshot documentToDeleteSnapshot = transaction.get(documentToDelete);
1253-
assertWithMessage("documentToDeleteSnapshot.exists()")
1254-
.that(documentToDeleteSnapshot.exists())
1255-
.isTrue();
1256-
transaction.delete(documentToDelete);
1257-
return null;
1258-
}));
1244+
{
1245+
WriteBatch writeBatchForDocumentDeletes = collection.getFirestore().batch();
1246+
writeBatchForDocumentDeletes.delete(documentToDelete);
1247+
waitFor(writeBatchForDocumentDeletes.commit());
1248+
}
12591249

12601250
// Wait for 10 seconds, during which Watch will stop tracking the query and will send an
12611251
// existence filter rather than "delete" events when the query is resumed.

0 commit comments

Comments
 (0)