From 64f3b2be23eab15df420e5890f14409fa52c8411 Mon Sep 17 00:00:00 2001 From: Gremi64 Date: Fri, 8 Feb 2019 16:11:29 +0100 Subject: [PATCH] Fixes #4423 - Getter on mutations size (#4424) * Fixes #4423 Getter over mutations size Allow knowing the size of the list. For exemple, the batch size is limited to 500 mutations * Fixes #4423 - Getter on mutations size Allow knowing the size of the list. For exemple, the batch size is limited to 500 mutations Fixes #4423 * Correction format code --- .../java/com/google/cloud/firestore/UpdateBuilder.java | 5 +++++ .../com/google/cloud/firestore/WriteBatchTest.java | 10 ++++++++++ 2 files changed, 15 insertions(+) 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 3d7240211c50..b9be38743fe1 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 7ac71a5cf137..6522d98a8096 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) {