diff --git a/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java b/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java index b5d0c0a7a6ce..e211be9ed79e 100644 --- a/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java +++ b/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java @@ -664,4 +664,9 @@ public List apply(CommitResponse commitResponse) { boolean isEmpty() { return mutations.isEmpty(); } + + /** Get the number of mutations. */ + public int getMutationsSize() { + return mutations.size(); + } } diff --git a/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/WriteBatchTest.java b/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/WriteBatchTest.java index f29d87ca0948..5af3ae8b6d9f 100644 --- a/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/WriteBatchTest.java +++ b/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/WriteBatchTest.java @@ -91,6 +91,8 @@ public void updateDocument() throws Exception { batch.update(documentReference, updateTime, "foo", "bar"); batch.update(documentReference, LocalFirestoreHelper.SINGLE_FIELD_MAP, updateTime); + assertEquals(4, batch.getMutationsSize()); + List writeResults = batch.commit().get(); List writes = new ArrayList<>(); @@ -126,6 +128,8 @@ public void setDocument() throws Exception { writes.add(set(LocalFirestoreHelper.SINGLE_FIELD_PROTO, Arrays.asList("foo"))); writes.add(set(LocalFirestoreHelper.SINGLE_FIELD_PROTO, Arrays.asList("foo"))); + assertEquals(4, batch.getMutationsSize()); + List writeResults = batch.commit().get(); for (int i = 0; i < writeResults.size(); ++i) { assertEquals(Timestamp.ofTimeSecondsAndNanos(i, i), writeResults.get(i).getUpdateTime()); @@ -144,6 +148,8 @@ public void omitWriteResultForDocumentTransforms() throws Exception { batch.set(documentReference, map("time", FieldValue.serverTimestamp())); + assertEquals(1, batch.getMutationsSize()); + List writeResults = batch.commit().get(); assertEquals(1, writeResults.size()); } @@ -159,6 +165,8 @@ public void createDocument() throws Exception { .create(documentReference, LocalFirestoreHelper.SINGLE_FIELD_MAP) .create(documentReference, LocalFirestoreHelper.SINGLE_FIELD_OBJECT); + assertEquals(2, batch.getMutationsSize()); + List writeResults = batch.commit().get(); List writes = new ArrayList<>(); @@ -188,6 +196,8 @@ public void deleteDocument() throws Exception { precondition.getUpdateTimeBuilder().setSeconds(1).setNanos(2); writes.add(delete(precondition.build())); + assertEquals(2, batch.getMutationsSize()); + List writeResults = batch.commit().get(); for (int i = 0; i < writeResults.size(); ++i) {