From 73ffaa2cf02dc07314027b10174bf08666ef4c26 Mon Sep 17 00:00:00 2001 From: Gremi64 Date: Fri, 1 Feb 2019 11:49:50 +0100 Subject: [PATCH 1/3] Fixes #4423 Getter over mutations size Allow knowing the size of the list. For exemple, the batch size is limited to 500 mutations --- .../main/java/com/google/cloud/firestore/UpdateBuilder.java | 5 +++++ 1 file changed, 5 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 b5d0c0a7a6ce..d196dc7c20f7 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(); + } } From 0ab8f6b101c56076654cc4a17fa2f6127df7dfda Mon Sep 17 00:00:00 2001 From: Gremi64 Date: Fri, 1 Feb 2019 14:44:11 +0100 Subject: [PATCH 2/3] 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 --- .../cloud/firestore/WriteBatchTest.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) 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..8284668860c0 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 @@ -90,7 +90,9 @@ public void updateDocument() throws Exception { batch.update(documentReference, "foo", "bar"); 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<>(); @@ -125,7 +127,9 @@ public void setDocument() throws Exception { writes.add(set(LocalFirestoreHelper.SINGLE_FIELD_PROTO)); 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()); @@ -143,7 +147,9 @@ public void omitWriteResultForDocumentTransforms() throws Exception { commitCapture.capture(), Matchers.>any()); batch.set(documentReference, map("time", FieldValue.serverTimestamp())); - + + assertEquals(1, batch.getMutationsSize()); + List writeResults = batch.commit().get(); assertEquals(1, writeResults.size()); } @@ -158,7 +164,9 @@ public void createDocument() throws Exception { batch .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<>(); @@ -187,7 +195,9 @@ public void deleteDocument() throws Exception { com.google.firestore.v1beta1.Precondition.newBuilder(); 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) { From ce8d0fbb1af005105ceac5787ba12524add700ca Mon Sep 17 00:00:00 2001 From: gremi64 Date: Fri, 8 Feb 2019 10:06:21 +0100 Subject: [PATCH 3/3] Correction format code --- .../google/cloud/firestore/UpdateBuilder.java | 2 +- .../cloud/firestore/WriteBatchTest.java | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) 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 d196dc7c20f7..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,7 +664,7 @@ 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 8284668860c0..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 @@ -90,9 +90,9 @@ public void updateDocument() throws Exception { batch.update(documentReference, "foo", "bar"); 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<>(); @@ -127,9 +127,9 @@ public void setDocument() throws Exception { writes.add(set(LocalFirestoreHelper.SINGLE_FIELD_PROTO)); 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()); @@ -147,9 +147,9 @@ public void omitWriteResultForDocumentTransforms() throws Exception { commitCapture.capture(), Matchers.>any()); batch.set(documentReference, map("time", FieldValue.serverTimestamp())); - + assertEquals(1, batch.getMutationsSize()); - + List writeResults = batch.commit().get(); assertEquals(1, writeResults.size()); } @@ -164,9 +164,9 @@ public void createDocument() throws Exception { batch .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<>(); @@ -195,9 +195,9 @@ public void deleteDocument() throws Exception { com.google.firestore.v1beta1.Precondition.newBuilder(); 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) {